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:
parent
929b8d2b62
commit
57b8afbdab
11 changed files with 33 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var base58check = require('./base58check')
|
var base58check = require('./base58check')
|
||||||
var ecdsa = require('./ecdsa')
|
var ecdsa = require('./ecdsa')
|
||||||
var network = require('./network')
|
var networks = require('./networks')
|
||||||
var secureRandom = require('secure-random')
|
var secureRandom = require('secure-random')
|
||||||
|
|
||||||
var Address = require('./address')
|
var Address = require('./address')
|
||||||
|
@ -72,7 +72,7 @@ ECKey.prototype.toHex = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ECKey.prototype.toWIF = function(version) {
|
ECKey.prototype.toWIF = function(version) {
|
||||||
version = version || network.bitcoin.wif
|
version = version || networks.bitcoin.wif
|
||||||
|
|
||||||
var buffer = this.toBuffer()
|
var buffer = this.toBuffer()
|
||||||
if (this.pub.compressed) {
|
if (this.pub.compressed) {
|
||||||
|
@ -115,7 +115,7 @@ ECPubKey.prototype.verify = function(hash, sig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPubKey.prototype.getAddress = function(version) {
|
ECPubKey.prototype.getAddress = function(version) {
|
||||||
version = version || network.bitcoin.pubKeyHash
|
version = version || networks.bitcoin.pubKeyHash
|
||||||
|
|
||||||
return new Address(crypto.hash160(this.toBuffer()), version)
|
return new Address(crypto.hash160(this.toBuffer()), version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ var CJS = require('crypto-js')
|
||||||
var crypto = require('./crypto')
|
var crypto = require('./crypto')
|
||||||
var ECKey = require('./eckey').ECKey
|
var ECKey = require('./eckey').ECKey
|
||||||
var ECPubKey = require('./eckey').ECPubKey
|
var ECPubKey = require('./eckey').ECPubKey
|
||||||
var Network = require('./network')
|
var networks = require('./networks')
|
||||||
|
|
||||||
var sec = require('./sec')
|
var sec = require('./sec')
|
||||||
var ecparams = sec("secp256k1")
|
var ecparams = sec("secp256k1")
|
||||||
|
@ -27,7 +27,7 @@ function HDWallet(seed, networkString) {
|
||||||
this.chaincode = I.slice(32)
|
this.chaincode = I.slice(32)
|
||||||
this.network = networkString || 'bitcoin'
|
this.network = networkString || 'bitcoin'
|
||||||
|
|
||||||
if(!Network.hasOwnProperty(this.network)) {
|
if(!networks.hasOwnProperty(this.network)) {
|
||||||
throw new Error("Unknown network: " + this.network)
|
throw new Error("Unknown network: " + this.network)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ HDWallet.fromBuffer = function(input) {
|
||||||
var version = input.readUInt32BE(0)
|
var version = input.readUInt32BE(0)
|
||||||
|
|
||||||
var type
|
var type
|
||||||
for(var name in Network) {
|
for(var name in networks) {
|
||||||
var network = Network[name]
|
var network = networks[name]
|
||||||
|
|
||||||
for(var t in network.bip32) {
|
for(var t in network.bip32) {
|
||||||
if (version != network.bip32[t]) continue
|
if (version != network.bip32[t]) continue
|
||||||
|
@ -128,7 +128,7 @@ HDWallet.prototype.getAddress = function() {
|
||||||
|
|
||||||
HDWallet.prototype.toBuffer = function(priv) {
|
HDWallet.prototype.toBuffer = function(priv) {
|
||||||
// Version
|
// 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)
|
var buffer = new Buffer(HDWallet.LENGTH)
|
||||||
|
|
||||||
// 4 bytes: version bytes
|
// 4 bytes: version bytes
|
||||||
|
@ -245,7 +245,7 @@ HDWallet.prototype.derivePrivate = function(index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
HDWallet.prototype.getKeyVersion = function() {
|
HDWallet.prototype.getKeyVersion = function() {
|
||||||
return Network[this.network].pubKeyHash
|
return networks[this.network].pubKeyHash
|
||||||
}
|
}
|
||||||
|
|
||||||
HDWallet.prototype.toString = HDWallet.prototype.toBase58
|
HDWallet.prototype.toString = HDWallet.prototype.toBase58
|
||||||
|
|
|
@ -22,6 +22,6 @@ module.exports = {
|
||||||
Transaction: T.Transaction,
|
Transaction: T.Transaction,
|
||||||
TransactionIn: T.TransactionIn,
|
TransactionIn: T.TransactionIn,
|
||||||
TransactionOut: T.TransactionOut,
|
TransactionOut: T.TransactionOut,
|
||||||
network: require('./network'),
|
networks: require('./networks'),
|
||||||
Wallet: require('./wallet')
|
Wallet: require('./wallet')
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ var assert = require('assert')
|
||||||
var Address = require('./address')
|
var Address = require('./address')
|
||||||
var crypto = require('./crypto')
|
var crypto = require('./crypto')
|
||||||
var convert = require('./convert')
|
var convert = require('./convert')
|
||||||
var Network = require('./network')
|
var networks = require('./networks')
|
||||||
var Opcode = require('./opcode')
|
var Opcode = require('./opcode')
|
||||||
|
|
||||||
function Script(data) {
|
function Script(data) {
|
||||||
|
@ -193,7 +193,7 @@ Script.prototype.toScriptHash = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.prototype.getToAddress = function(network) {
|
Script.prototype.getToAddress = function(network) {
|
||||||
network = network || Network.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
if(isPubkeyhash.call(this)) {
|
if(isPubkeyhash.call(this)) {
|
||||||
return new Address(new Buffer(this.chunks[2]), network.pubKeyHash)
|
return new Address(new Buffer(this.chunks[2]), network.pubKeyHash)
|
||||||
|
@ -205,7 +205,7 @@ Script.prototype.getToAddress = function(network) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.prototype.getFromAddress = function(version) {
|
Script.prototype.getFromAddress = function(version) {
|
||||||
version = version || Network.bitcoin.pubKeyHash
|
version = version || networks.bitcoin.pubKeyHash
|
||||||
|
|
||||||
return new Address(this.simpleInHash(), version)
|
return new Address(this.simpleInHash(), version)
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ Script.prototype.writeBytes = function(data) {
|
||||||
*/
|
*/
|
||||||
Script.createOutputScript = function(address, network) {
|
Script.createOutputScript = function(address, network) {
|
||||||
assert(address instanceof Address)
|
assert(address instanceof Address)
|
||||||
network = network || Network.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
var script = new Script()
|
var script = new Script()
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ var convert = require('./convert')
|
||||||
var crypto = require('./crypto')
|
var crypto = require('./crypto')
|
||||||
var ECKey = require('./eckey').ECKey
|
var ECKey = require('./eckey').ECKey
|
||||||
var ecdsa = require('./ecdsa')
|
var ecdsa = require('./ecdsa')
|
||||||
var Network = require('./network')
|
var networks = require('./networks')
|
||||||
|
|
||||||
var Transaction = function (doc) {
|
var Transaction = function (doc) {
|
||||||
if (!(this instanceof Transaction)) { return new Transaction(doc) }
|
if (!(this instanceof Transaction)) { return new Transaction(doc) }
|
||||||
|
@ -112,7 +112,7 @@ Transaction.prototype.addOutput = function (address, value, network) {
|
||||||
address = Address.fromBase58Check(address)
|
address = Address.fromBase58Check(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
network = network || Network.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
this.outs.push(new TransactionOut({
|
this.outs.push(new TransactionOut({
|
||||||
value: value,
|
value: value,
|
||||||
|
@ -368,7 +368,7 @@ Transaction.deserialize = function(buffer) {
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.sign = function(index, key, type, network) {
|
Transaction.prototype.sign = function(index, key, type, network) {
|
||||||
assert(key instanceof ECKey)
|
assert(key instanceof ECKey)
|
||||||
network = network || Network.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
var address = key.pub.getAddress(network.pubKeyHash)
|
var address = key.pub.getAddress(network.pubKeyHash)
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ function TransactionOut(data) {
|
||||||
this.value = data.value
|
this.value = data.value
|
||||||
this.address = data.address
|
this.address = data.address
|
||||||
|
|
||||||
var network = data.network || Network.bitcoin
|
var network = data.network || networks.bitcoin
|
||||||
if (this.script.buffer.length > 0) {
|
if (this.script.buffer.length > 0) {
|
||||||
this.address = this.script.getToAddress(network)
|
this.address = this.script.getToAddress(network)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ var convert = require('./convert')
|
||||||
var Transaction = require('./transaction').Transaction
|
var Transaction = require('./transaction').Transaction
|
||||||
var HDNode = require('./hdwallet.js')
|
var HDNode = require('./hdwallet.js')
|
||||||
var rng = require('secure-random')
|
var rng = require('secure-random')
|
||||||
var Network = require('./network')
|
var networks = require('./networks')
|
||||||
|
|
||||||
function Wallet(seed, options) {
|
function Wallet(seed, options) {
|
||||||
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
|
if (!(this instanceof Wallet)) { return new Wallet(seed, options); }
|
||||||
|
@ -174,7 +174,7 @@ function Wallet(seed, options) {
|
||||||
checkDust(value)
|
checkDust(value)
|
||||||
|
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.addOutput(to, value, Network[network])
|
tx.addOutput(to, value, networks[network])
|
||||||
|
|
||||||
var utxo = getCandidateOutputs(value)
|
var utxo = getCandidateOutputs(value)
|
||||||
var totalInValue = 0
|
var totalInValue = 0
|
||||||
|
@ -190,7 +190,7 @@ function Wallet(seed, options) {
|
||||||
|
|
||||||
var change = totalInValue - value - fee
|
var change = totalInValue - value - fee
|
||||||
if(change > 0 && !isDust(change)) {
|
if(change > 0 && !isDust(change)) {
|
||||||
tx.addOutput(changeAddress || getChangeAddress(), change, Network[network])
|
tx.addOutput(changeAddress || getChangeAddress(), change, networks[network])
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ function Wallet(seed, options) {
|
||||||
|
|
||||||
function estimateFeePadChangeOutput(tx){
|
function estimateFeePadChangeOutput(tx){
|
||||||
var tmpTx = tx.clone()
|
var tmpTx = tx.clone()
|
||||||
tmpTx.addOutput(getChangeAddress(), 0, Network[network])
|
tmpTx.addOutput(getChangeAddress(), 0, networks[network])
|
||||||
return tmpTx.estimateFee()
|
return tmpTx.estimateFee()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ function Wallet(seed, options) {
|
||||||
tx.ins.forEach(function(inp,i) {
|
tx.ins.forEach(function(inp,i) {
|
||||||
var output = me.outputs[inp.outpoint.hash + ':' + inp.outpoint.index]
|
var output = me.outputs[inp.outpoint.hash + ':' + inp.outpoint.index]
|
||||||
if (output) {
|
if (output) {
|
||||||
tx.sign(i, me.getPrivateKeyForAddress(output.address), false, Network[network])
|
tx.sign(i, me.getPrivateKeyForAddress(output.address), false, networks[network])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return tx
|
return tx
|
||||||
|
|
|
@ -5,7 +5,7 @@ var ECKey = require('../../src/eckey').ECKey;
|
||||||
var T = require('../../src/transaction');
|
var T = require('../../src/transaction');
|
||||||
var Transaction = T.Transaction;
|
var Transaction = T.Transaction;
|
||||||
var Script = require('../../src/script');
|
var Script = require('../../src/script');
|
||||||
var network = require('../../src/network');
|
var networks = require('../../src/networks');
|
||||||
var crypto = require('../../src/crypto');
|
var crypto = require('../../src/crypto');
|
||||||
|
|
||||||
var helloblock = require('helloblock-js')({
|
var helloblock = require('helloblock-js')({
|
||||||
|
@ -31,7 +31,7 @@ describe('p2sh', function() {
|
||||||
})
|
})
|
||||||
var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers)
|
var redeemScript = Script.createMultisigOutputScript(2, pubKeyBuffers)
|
||||||
var hash160 = crypto.hash160(redeemScript.buffer)
|
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
|
// Check what our target address's starting value is
|
||||||
var targetAddress = 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r';
|
var targetAddress = 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r';
|
||||||
|
@ -50,7 +50,7 @@ describe('p2sh', function() {
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
var unspent = resource[0];
|
var unspent = resource[0];
|
||||||
tx.addInput(unspent.txHash, unspent.index)
|
tx.addInput(unspent.txHash, unspent.index)
|
||||||
tx.addOutput(targetAddress, 100000, network.testnet)
|
tx.addOutput(targetAddress, 100000, networks.testnet)
|
||||||
|
|
||||||
var signatures = privKeys.map(function(privKey) {
|
var signatures = privKeys.map(function(privKey) {
|
||||||
return tx.signScriptSig(0, redeemScript, privKey)
|
return tx.signScriptSig(0, redeemScript, privKey)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var ECKey = require('../src/eckey').ECKey
|
var ECKey = require('../src/eckey').ECKey
|
||||||
var Message = require('../').Message
|
var Message = require('../').Message
|
||||||
var network = require('../').network
|
var networks = require('../').networks
|
||||||
|
|
||||||
var fixtures = require('./fixtures/message')
|
var fixtures = require('./fixtures/message')
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ describe('Message', function() {
|
||||||
var key = ECKey.makeRandom()
|
var key = ECKey.makeRandom()
|
||||||
var sig = Message.sign(key, msg)
|
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))
|
assert(Message.verify(addr, sig, msg))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var crypto = require('..').crypto
|
var crypto = require('..').crypto
|
||||||
var network = require('..').network
|
var networks = require('..').networks
|
||||||
|
|
||||||
var Address = require('../src/address.js')
|
var Address = require('../src/address.js')
|
||||||
var Script = require('../src/script.js')
|
var Script = require('../src/script.js')
|
||||||
|
@ -116,7 +116,7 @@ describe('Script', function() {
|
||||||
var redeemScript = Script.createMultisigOutputScript(2, pubKeys)
|
var redeemScript = Script.createMultisigOutputScript(2, pubKeys)
|
||||||
|
|
||||||
var hash160 = crypto.hash160(redeemScript.buffer)
|
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')
|
assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v')
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,11 +2,11 @@ var assert = require('assert')
|
||||||
|
|
||||||
var Address = require('../src/address')
|
var Address = require('../src/address')
|
||||||
var ECKey = require('../src/eckey').ECKey
|
var ECKey = require('../src/eckey').ECKey
|
||||||
|
var networks = require('..').networks
|
||||||
var T = require('../src/transaction')
|
var T = require('../src/transaction')
|
||||||
var Transaction = T.Transaction
|
var Transaction = T.Transaction
|
||||||
var TransactionOut = T.TransactionOut
|
var TransactionOut = T.TransactionOut
|
||||||
var Script = require('../src/script')
|
var Script = require('../src/script')
|
||||||
var network = require('..').network
|
|
||||||
|
|
||||||
var fixtureTxes = require('./fixtures/mainnet_tx')
|
var fixtureTxes = require('./fixtures/mainnet_tx')
|
||||||
var fixtureTx1Hex = fixtureTxes.prevTx
|
var fixtureTx1Hex = fixtureTxes.prevTx
|
||||||
|
@ -176,7 +176,7 @@ describe('Transaction', function() {
|
||||||
it('supports alternative networks', function(){
|
it('supports alternative networks', function(){
|
||||||
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
||||||
|
|
||||||
tx.addOutput(addr, 40000, network.testnet)
|
tx.addOutput(addr, 40000, networks.testnet)
|
||||||
verifyTransactionOut()
|
verifyTransactionOut()
|
||||||
|
|
||||||
assert.equal(tx.outs[0].address.toString(), addr)
|
assert.equal(tx.outs[0].address.toString(), addr)
|
||||||
|
@ -250,7 +250,7 @@ describe('Transaction', function() {
|
||||||
it('works for multi-sig redeem script', function() {
|
it('works for multi-sig redeem script', function() {
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.addInput('d6f72aab8ff86ff6289842a0424319bf2ddba85dc7c52757912297f948286389', 0)
|
tx.addInput('d6f72aab8ff86ff6289842a0424319bf2ddba85dc7c52757912297f948286389', 0)
|
||||||
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, network.testnet)
|
tx.addOutput('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', 1, networks.testnet)
|
||||||
|
|
||||||
var privKeys = [
|
var privKeys = [
|
||||||
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf',
|
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf',
|
||||||
|
|
Loading…
Reference in a new issue