How to use the bitcore.Networks function in bitcore

To help you get started, we’ve selected a few bitcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitpay / bitcore-p2p / test / pool.js View on Github external
'use strict';

var chai = require('chai');

/* jshint unused: false */
var should = chai.should();
var expect = chai.expect;

var bitcore = require('bitcore');
var P2P = require('../');
var Peer = P2P.Peer;
var MessagesData = require('./data/messages');
var Messages = P2P.Messages;
var Pool = P2P.Pool;
var Networks = bitcore.Networks;

var dns = require('dns');
var sinon = require('sinon');

describe('Pool', function() {

  it('should be able to create instance', function() {
    var pool = new Pool();
    should.exist(pool.network);
    expect(pool.network).to.satisfy(function(network) {
      return network === Networks.testnet || network === Networks.livenet;
    });
  });

  it('should be able to create instance setting the network', function() {
    var pool = new Pool(Networks.testnet);
github quartzjer / pennybank / bc-p2cm.js View on Github external
getUTXO(address, function(utxo){
  console.log(utxo.toJSON());
  
  // test sending a small bit to a p2cm
  var privateKey1 = new bitcore.PrivateKey('612b3ca3f368cf2658c2e1777d2fa28e6bcde8ea19312cbf69e09e7333e13994',bitcore.Networks.testnet);
  var privateKey2 = new bitcore.PrivateKey('d65788b9947b41625ffff946bc145187c6b85d1686e60becdf34567f17478730',bitcore.Networks.testnet);
  var publicKey1 = privateKey1.publicKey;
  var publicKey2 = privateKey2.publicKey;

  var P2CMScript = new bitcore.Script.buildMultisigOut([publicKey1, publicKey2], 1);

  // now do the secrets/hashing part
  var A_secret = new Buffer("a236d85656fb05bf157d5328f191c7e6","hex");
  var B_secret = new Buffer("65b3e07dbb2861cad500906e1af5c2c6","hex");
  
  // prepend (in reverse order)
  P2CMScript
  .prepend('OP_EQUALVERIFY')
  .prepend(hash160(B_secret))
  .prepend('OP_HASH160')
  .prepend('OP_EQUALVERIFY')
github quartzjer / pennybank / bc-p2cm.js View on Github external
var crypto = require('crypto');
var bitcore = require('bitcore');
var Sighash = require('./node_modules/bitcore/lib/transaction/sighash')
var explorers = require('bitcore-explorers');
var insight = new explorers.Insight(bitcore.Networks.testnet);


// testnet
var privateKey = bitcore.PrivateKey({
  "bn":"8c026a359a13f707a3497ef58da45b628958ff98b5f33322cf29ede12fcfd56f",
  "compressed":true,
  "network":"testnet"
});
var address = privateKey.toAddress();
console.log("address",address);

getUTXO(address, function(utxo){
  console.log(utxo.toJSON());
  
  // test sending a small bit to a p2cm
  var privateKey1 = new bitcore.PrivateKey('612b3ca3f368cf2658c2e1777d2fa28e6bcde8ea19312cbf69e09e7333e13994',bitcore.Networks.testnet);
github bitpay / bitcore-channel / test / signatures.js View on Github external
it('has no false positive on payment validation', function() {
    var provider = getProvider();
    var consumer = getValidatedConsumer().consumer;

    var payment = consumer.incrementPaymentBy(1000);
    payment.transaction.nLockTime = 1;

    (function() {
      provider.validPayment(payment);
    }).should.throw();
  });

});

var providerKey = new bitcore.PrivateKey('58e78db594be551a8f4c7070fd8695363992bd1eb37d01cd4a4da608f3dc5c2d', bitcore.Networks.testnet);
var fundingKey = new bitcore.PrivateKey('79b0630419ad72397d211db4988c98ffcb5955b14f6ec5c5651eec5c98d7e557', bitcore.Networks.testnet);
var commitmentKey = new bitcore.PrivateKey('17bc93ac93f4a26599d3af49e59206e8276259febba503434eacb871f9bbad75', bitcore.Networks.testnet);
var providerAddress = providerKey.toAddress(Networks.testnet);

var getConsumer = function() {

  var Consumer = require('../').Consumer;
  var refundAddress = 'mzCXqcsLBerwyoRZzBFQELHaJ1ZtBSxxe6';

  var consumer = new Consumer({
    network: 'testnet',
    fundingKey: fundingKey,
    commitmentKey: commitmentKey,
    providerPublicKey: providerKey.publicKey,
    providerAddress: providerKey.toAddress(),
    refundAddress: refundAddress
github bitpay / bitcore-node / test / services / address / index.unit.js View on Github external
'use strict';

var should = require('chai').should();
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var bitcorenode = require('../../../');
var AddressService = bitcorenode.services.Address;
var blockData = require('../../data/livenet-345003.json');
var bitcore = require('bitcore');
var Networks = bitcore.Networks;
var EventEmitter = require('events').EventEmitter;
var errors = bitcorenode.errors;

var mockdb = {
};

var mocknode = {
  db: mockdb,
  services: {
    bitcoind: {
      on: sinon.stub()
    }
  }
};

describe('Address Service', function() {
github bitpay / bitcore-node / index.js View on Github external
'use strict';

var BitcoreNode = require('./lib/node');
var BitcoreHTTP = require('./api/lib/http');
var bitcore = require('bitcore');
var Promise = require('bluebird');
Promise.longStackTraces();


if (require.main === module) {
  var config = require('config');
  var nodeConfig = config.get('BitcoreHTTP.BitcoreNode');
  var httpConfig = config.get('BitcoreHTTP');
  var network = nodeConfig.network;
  console.log('Starting bitcore-node-http', network, 'network');
  bitcore.Networks.defaultNetwork = bitcore.Networks.get(network);
  var node = BitcoreNode.create(nodeConfig);
  node.on('error', function(err) {
    if (err.code === 'ECONNREFUSED') {
      console.log('Connection to bitcoind failed');
    } else {
      console.log('Error: ', err);
    }
  });
  process.on('SIGINT', function() {
    node.stop();
    process.exit();
  });
  var http = new BitcoreHTTP(node, httpConfig);
  http.start()
    .catch(function(err) {
      http.stop();
github bitpay / bitcore-node / lib / networkmonitor.js View on Github external
'use strict';

var util = require('util');
var EventEmitter = require('eventemitter2').EventEmitter2;
var Promise = require('bluebird').Promise;

var bitcore = require('bitcore');
var Networks = bitcore.Networks;
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
var p2p = require('bitcore-p2p');
var Peer = p2p.Peer;

function NetworkMonitor(eventBus, peer) {
  $.checkArgument(eventBus);
  $.checkArgument(peer);
  this.bus = eventBus;
  this.peer = peer;
  this.messages = new p2p.Messages({
    network: this.peer.network,
  });
  this.ignoreInv = true;
  this.setupPeer(peer);
}
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / src / network.js View on Github external
loading.stop()
    next(err)
  })

  pool.on('peerdisconnect', function (peer, err) {
    if (peer.getHeaders) {
      loaderPeer = null
    }
  })

  pool.connect()
}

module.exports = {
  Network: Network,
  main: bitcore.Networks.livenet,
  test: bitcore.Networks.testnet,
  PushTxTimeoutError: PushTxTimeoutError
}
github bitpay / bitcore-node / lib / services / block.js View on Github external
BlockService.prototype.getBlockByHeight = function(height) {
  $.checkArgument(_.isNumber(height), 'Block height must be a number');
  var self = this;
  if (height === 0) {
    return Promise.resolve(
      Block.fromBuffer(genesisBlocks[bitcore.Networks.defaultNetwork])
    );
  }

  return Promise.try(function() {
      return self.rpc.getBlockHashAsync(height);
    })
    .catch(blockNotFound)
    .then(function(result) {
      var blockHash = result.result;
      return self.getBlock(blockHash);
    });
};