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