bitcore/lib/networks.js

95 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-11-20 07:23:46 -08:00
'use strict';
2014-11-24 10:40:20 -08:00
var _ = require('lodash');
2014-11-20 07:23:46 -08:00
2014-11-24 10:40:20 -08:00
/**
* A network is merely a map containing values that correspond to version
* numbers for each bitcoin network. Currently only supporting "livenet"
* (a.k.a. "mainnet") and "testnet".
2014-11-26 07:56:43 -08:00
* @constructor
2014-11-24 10:40:20 -08:00
*/
function Network() {}
var hex = function(hex) { return new Buffer(hex, 'hex'); };
2014-11-24 10:40:20 -08:00
/**
* @instance
* @member Network#livenet
*/
var livenet = new Network();
_.extend(livenet, {
name: 'livenet',
alias: 'mainnet',
pubkeyhash: 0x00,
privatekey: 0x80,
scripthash: 0x05,
xpubkey: 0x0488b21e,
2014-12-05 08:10:09 -08:00
xprivkey: 0x0488ade4,
networkMagic: hex('f9beb4d9'),
2014-12-05 08:10:09 -08:00
port: 8333,
dnsSeeds: [
'seed.bitcoin.sipa.be',
'dnsseed.bluematt.me',
'dnsseed.bitcoin.dashjr.org',
'seed.bitcoinstats.com',
'seed.bitnodes.io',
'bitseed.xf2.org'
]
2014-11-24 10:40:20 -08:00
});
/**
* @instance
* @member Network#testnet
*/
var testnet = new Network();
_.extend(testnet, {
name: 'testnet',
2014-11-22 12:50:08 -08:00
alias: 'testnet',
2014-11-24 10:40:20 -08:00
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
2014-12-05 08:10:09 -08:00
xprivkey: 0x04358394,
networkMagic: hex('0b110907'),
2014-12-05 08:10:09 -08:00
port: 18333,
dnsSeeds: [
'testnet-seed.bitcoin.petertodd.org',
'testnet-seed.bluematt.me'
],
2014-11-24 10:40:20 -08:00
});
var networkMaps = {};
2014-10-06 11:00:03 -07:00
2014-11-24 10:40:20 -08:00
_.each(_.values(livenet), function(value) {
2014-12-05 08:10:09 -08:00
if (_.isArray(value)) return;
2014-11-24 10:40:20 -08:00
networkMaps[value] = livenet;
});
_.each(_.values(testnet), function(value) {
2014-12-05 08:10:09 -08:00
if (_.isArray(value)) return;
2014-11-24 10:40:20 -08:00
networkMaps[value] = testnet;
});
/**
* @function
* @member Network#getNetwork
* Retrieves the network associated with a magic number or string.
* @param {string|number|Network} arg
* @return Network
*/
function getNetwork(arg) {
if (arg === livenet || arg === testnet) {
return arg;
}
return networkMaps[arg];
}
/**
* @namespace Network
*/
module.exports = {
2014-11-26 13:38:15 -08:00
defaultNetwork: livenet,
2014-11-24 10:40:20 -08:00
livenet: livenet,
mainnet: livenet,
2014-11-24 10:40:20 -08:00
testnet: testnet,
get: getNetwork
};