Network: rename Network to Networks

This change removes the most common ambiguities.
As the network module is not representative of a class, the lower case
has been used.
This commit is contained in:
Daniel Cousens 2014-05-05 13:23:22 +10:00
parent 929b8d2b62
commit 57b8afbdab
11 changed files with 33 additions and 33 deletions

View file

@ -1,7 +1,7 @@
var assert = require('assert')
var base58check = require('./base58check')
var ecdsa = require('./ecdsa')
var network = require('./network')
var networks = require('./networks')
var secureRandom = require('secure-random')
var Address = require('./address')
@ -72,7 +72,7 @@ ECKey.prototype.toHex = function() {
}
ECKey.prototype.toWIF = function(version) {
version = version || network.bitcoin.wif
version = version || networks.bitcoin.wif
var buffer = this.toBuffer()
if (this.pub.compressed) {
@ -115,7 +115,7 @@ ECPubKey.prototype.verify = function(hash, sig) {
}
ECPubKey.prototype.getAddress = function(version) {
version = version || network.bitcoin.pubKeyHash
version = version || networks.bitcoin.pubKeyHash
return new Address(crypto.hash160(this.toBuffer()), version)
}

View file

@ -8,7 +8,7 @@ var CJS = require('crypto-js')
var crypto = require('./crypto')
var ECKey = require('./eckey').ECKey
var ECPubKey = require('./eckey').ECPubKey
var Network = require('./network')
var networks = require('./networks')
var sec = require('./sec')
var ecparams = sec("secp256k1")
@ -27,7 +27,7 @@ function HDWallet(seed, networkString) {
this.chaincode = I.slice(32)
this.network = networkString || 'bitcoin'
if(!Network.hasOwnProperty(this.network)) {
if(!networks.hasOwnProperty(this.network)) {
throw new Error("Unknown network: " + this.network)
}
@ -70,8 +70,8 @@ HDWallet.fromBuffer = function(input) {
var version = input.readUInt32BE(0)
var type
for(var name in Network) {
var network = Network[name]
for(var name in networks) {
var network = networks[name]
for(var t in network.bip32) {
if (version != network.bip32[t]) continue
@ -128,7 +128,7 @@ HDWallet.prototype.getAddress = function() {
HDWallet.prototype.toBuffer = function(priv) {
// Version
var version = Network[this.network].bip32[priv ? 'priv' : 'pub']
var version = networks[this.network].bip32[priv ? 'priv' : 'pub']
var buffer = new Buffer(HDWallet.LENGTH)
// 4 bytes: version bytes
@ -245,7 +245,7 @@ HDWallet.prototype.derivePrivate = function(index) {
}
HDWallet.prototype.getKeyVersion = function() {
return Network[this.network].pubKeyHash
return networks[this.network].pubKeyHash
}
HDWallet.prototype.toString = HDWallet.prototype.toBase58

View file

@ -22,6 +22,6 @@ module.exports = {
Transaction: T.Transaction,
TransactionIn: T.TransactionIn,
TransactionOut: T.TransactionOut,
network: require('./network'),
networks: require('./networks'),
Wallet: require('./wallet')
}

View file

@ -2,7 +2,7 @@ var assert = require('assert')
var Address = require('./address')
var crypto = require('./crypto')
var convert = require('./convert')
var Network = require('./network')
var networks = require('./networks')
var Opcode = require('./opcode')
function Script(data) {
@ -193,7 +193,7 @@ Script.prototype.toScriptHash = function() {
}
Script.prototype.getToAddress = function(network) {
network = network || Network.bitcoin
network = network || networks.bitcoin
if(isPubkeyhash.call(this)) {
return new Address(new Buffer(this.chunks[2]), network.pubKeyHash)
@ -205,7 +205,7 @@ Script.prototype.getToAddress = function(network) {
}
Script.prototype.getFromAddress = function(version) {
version = version || Network.bitcoin.pubKeyHash
version = version || networks.bitcoin.pubKeyHash
return new Address(this.simpleInHash(), version)
}
@ -348,7 +348,7 @@ Script.prototype.writeBytes = function(data) {
*/
Script.createOutputScript = function(address, network) {
assert(address instanceof Address)
network = network || Network.bitcoin
network = network || networks.bitcoin
var script = new Script()

View file

@ -9,7 +9,7 @@ var convert = require('./convert')
var crypto = require('./crypto')
var ECKey = require('./eckey').ECKey
var ecdsa = require('./ecdsa')
var Network = require('./network')
var networks = require('./networks')
var Transaction = function (doc) {
if (!(this instanceof Transaction)) { return new Transaction(doc) }
@ -112,7 +112,7 @@ Transaction.prototype.addOutput = function (address, value, network) {
address = Address.fromBase58Check(address)
}
network = network || Network.bitcoin
network = network || networks.bitcoin
this.outs.push(new TransactionOut({
value: value,
@ -368,7 +368,7 @@ Transaction.deserialize = function(buffer) {
*/
Transaction.prototype.sign = function(index, key, type, network) {
assert(key instanceof ECKey)
network = network || Network.bitcoin
network = network || networks.bitcoin
var address = key.pub.getAddress(network.pubKeyHash)
@ -445,7 +445,7 @@ function TransactionOut(data) {
this.value = data.value
this.address = data.address
var network = data.network || Network.bitcoin
var network = data.network || networks.bitcoin
if (this.script.buffer.length > 0) {
this.address = this.script.getToAddress(network)
}

View file

@ -2,7 +2,7 @@ var convert = require('./convert')
var Transaction = require('./transaction').Transaction
var HDNode = require('./hdwallet.js')
var rng = require('secure-random')
var Network = require('./network')
var networks = require('./networks')
function Wallet(seed, options) {
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
@ -174,7 +174,7 @@ function Wallet(seed, options) {
checkDust(value)
var tx = new Transaction()
tx.addOutput(to, value, Network[network])
tx.addOutput(to, value, networks[network])
var utxo = getCandidateOutputs(value)
var totalInValue = 0
@ -190,7 +190,7 @@ function Wallet(seed, options) {
var change = totalInValue - value - fee
if(change > 0 && !isDust(change)) {
tx.addOutput(changeAddress || getChangeAddress(), change, Network[network])
tx.addOutput(changeAddress || getChangeAddress(), change, networks[network])
}
break
}
@ -246,7 +246,7 @@ function Wallet(seed, options) {
function estimateFeePadChangeOutput(tx){
var tmpTx = tx.clone()
tmpTx.addOutput(getChangeAddress(), 0, Network[network])
tmpTx.addOutput(getChangeAddress(), 0, networks[network])
return tmpTx.estimateFee()
}
@ -266,7 +266,7 @@ function Wallet(seed, options) {
tx.ins.forEach(function(inp,i) {
var output = me.outputs[inp.outpoint.hash + ':' + inp.outpoint.index]
if (output) {
tx.sign(i, me.getPrivateKeyForAddress(output.address), false, Network[network])
tx.sign(i, me.getPrivateKeyForAddress(output.address), false, networks[network])
}
})
return tx

View file

@ -5,7 +5,7 @@ var ECKey = require('../../src/eckey').ECKey;
var T = require('../../src/transaction');
var Transaction = T.Transaction;
var Script = require('../../src/script');
var network = require('../../src/network');
var networks = require('../../src/networks');
var crypto = require('../../src/crypto');
var helloblock = require('helloblock-js')({
@ -31,7 +31,7 @@ describe('p2sh', function() {
})
var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers)
var hash160 = crypto.hash160(redeemScript.buffer)
var multisigAddress = new Address(hash160, network.testnet.scriptHash)
var multisigAddress = new Address(hash160, networks.testnet.scriptHash)
// Check what our target address's starting value is
var targetAddress = 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r';
@ -50,7 +50,7 @@ describe('p2sh', function() {
var tx = new Transaction()
var unspent = resource[0];
tx.addInput(unspent.txHash, unspent.index)
tx.addOutput(targetAddress, 100000, network.testnet)
tx.addOutput(targetAddress, 100000, networks.testnet)
var signatures = privKeys.map(function(privKey) {
return tx.signScriptSig(0, redeemScript, privKey)

View file

@ -1,7 +1,7 @@
var assert = require('assert')
var ECKey = require('../src/eckey').ECKey
var Message = require('../').Message
var network = require('../').network
var networks = require('../').networks
var fixtures = require('./fixtures/message')
@ -86,7 +86,7 @@ describe('Message', function() {
var key = ECKey.makeRandom()
var sig = Message.sign(key, msg)
var addr = key.pub.getAddress(network.testnet.pubKeyHash)
var addr = key.pub.getAddress(networks.testnet.pubKeyHash)
assert(Message.verify(addr, sig, msg))
})
})

View file

@ -1,6 +1,6 @@
var assert = require('assert')
var crypto = require('..').crypto
var network = require('..').network
var networks = require('..').networks
var Address = require('../src/address.js')
var Script = require('../src/script.js')
@ -116,7 +116,7 @@ describe('Script', function() {
var redeemScript = Script.createMultisigOutputScript(2, pubKeys)
var hash160 = crypto.hash160(redeemScript.buffer)
var multisigAddress = new Address(hash160, network.bitcoin.scriptHash)
var multisigAddress = new Address(hash160, networks.bitcoin.scriptHash)
assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v')
})

View file

@ -2,11 +2,11 @@ var assert = require('assert')
var Address = require('../src/address')
var ECKey = require('../src/eckey').ECKey
var networks = require('..').networks
var T = require('../src/transaction')
var Transaction = T.Transaction
var TransactionOut = T.TransactionOut
var Script = require('../src/script')
var network = require('..').network
var fixtureTxes = require('./fixtures/mainnet_tx')
var fixtureTx1Hex = fixtureTxes.prevTx
@ -176,7 +176,7 @@ describe('Transaction', function() {
it('supports alternative networks', function(){
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
tx.addOutput(addr, 40000, network.testnet)
tx.addOutput(addr, 40000, networks.testnet)
verifyTransactionOut()
assert.equal(tx.outs[0].address.toString(), addr)
@ -250,7 +250,7 @@ describe('Transaction', function() {
it('works for multi-sig redeem script', function() {
var tx = new Transaction()
tx.addInput('d6f72aab8ff86ff6289842a0424319bf2ddba85dc7c52757912297f948286389', 0)
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, network.testnet)
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, networks.testnet)
var privKeys = [
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf',