2014-04-17 05:43:34 +10:00
|
|
|
// https://en.bitcoin.it/wiki/List_of_address_prefixes
|
2014-04-29 15:07:15 -07:00
|
|
|
// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
|
2014-06-17 14:48:06 +08:00
|
|
|
|
|
|
|
var networks = {
|
2014-04-17 05:43:34 +10:00
|
|
|
bitcoin: {
|
2015-03-16 10:37:28 +11:00
|
|
|
magic: 0xd9b4bef9,
|
|
|
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
2014-04-17 05:43:34 +10:00
|
|
|
bip32: {
|
2014-06-03 15:58:42 +10:00
|
|
|
public: 0x0488b21e,
|
|
|
|
private: 0x0488ade4
|
2014-04-17 05:43:34 +10:00
|
|
|
},
|
2014-06-17 21:05:18 +10:00
|
|
|
pubKeyHash: 0x00,
|
|
|
|
scriptHash: 0x05,
|
2014-06-17 12:03:14 +08:00
|
|
|
wif: 0x80,
|
2014-06-17 16:30:50 +08:00
|
|
|
dustThreshold: 546, // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/core.h#L151-L162
|
2015-03-16 10:38:20 +11:00
|
|
|
feePerKb: 10000 // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/main.cpp#L53
|
2014-04-17 05:43:34 +10:00
|
|
|
},
|
2014-11-27 16:29:24 +11:00
|
|
|
testnet: {
|
2015-03-16 10:37:28 +11:00
|
|
|
magic: 0xd9b4bef9,
|
|
|
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
2014-04-29 15:07:15 -07:00
|
|
|
bip32: {
|
2014-11-27 16:29:24 +11:00
|
|
|
public: 0x043587cf,
|
|
|
|
private: 0x04358394
|
2014-04-29 15:07:15 -07:00
|
|
|
},
|
2014-11-27 16:29:24 +11:00
|
|
|
pubKeyHash: 0x6f,
|
|
|
|
scriptHash: 0xc4,
|
|
|
|
wif: 0xef,
|
|
|
|
dustThreshold: 546,
|
2015-03-16 10:38:20 +11:00
|
|
|
feePerKb: 10000
|
2014-04-17 05:43:34 +10:00
|
|
|
},
|
|
|
|
litecoin: {
|
2015-03-16 10:37:28 +11:00
|
|
|
magic: 0xd9b4bef9,
|
|
|
|
messagePrefix: '\x19Litecoin Signed Message:\n',
|
2014-04-29 15:07:15 -07:00
|
|
|
bip32: {
|
2014-06-03 15:58:42 +10:00
|
|
|
public: 0x019da462,
|
|
|
|
private: 0x019d9cfe
|
2014-04-29 15:07:15 -07:00
|
|
|
},
|
2014-06-17 21:05:18 +10:00
|
|
|
pubKeyHash: 0x30,
|
|
|
|
scriptHash: 0x05,
|
2014-06-17 12:03:14 +08:00
|
|
|
wif: 0xb0,
|
2014-06-17 16:30:50 +08:00
|
|
|
dustThreshold: 0, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L360-L365
|
|
|
|
dustSoftThreshold: 100000, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.h#L53
|
2015-03-16 10:38:20 +11:00
|
|
|
feePerKb: 100000 // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L56
|
2014-02-28 16:05:43 +08:00
|
|
|
},
|
2014-11-27 16:29:24 +11:00
|
|
|
dogecoin: {
|
2015-03-16 10:37:28 +11:00
|
|
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
2014-04-17 05:43:34 +10:00
|
|
|
bip32: {
|
2014-11-27 16:29:24 +11:00
|
|
|
public: 0x02facafd,
|
|
|
|
private: 0x02fac398
|
2014-04-17 05:43:34 +10:00
|
|
|
},
|
2014-11-27 16:29:24 +11:00
|
|
|
pubKeyHash: 0x1e,
|
|
|
|
scriptHash: 0x16,
|
|
|
|
wif: 0x9e,
|
|
|
|
dustThreshold: 0, // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/core.h#L155-L160
|
|
|
|
dustSoftThreshold: 100000000, // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/main.h#L62
|
2015-03-16 10:38:20 +11:00
|
|
|
feePerKb: 100000000 // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/main.cpp#L58
|
2014-02-28 16:05:43 +08:00
|
|
|
}
|
2014-05-16 15:39:17 +10:00
|
|
|
}
|
2014-06-17 16:23:09 +08:00
|
|
|
|
2015-03-16 10:38:20 +11:00
|
|
|
function estimateFee (tx, network) {
|
|
|
|
var baseFee = network.feePerKb
|
2015-03-16 10:51:21 +11:00
|
|
|
var byteSize = tx.byteLength()
|
2014-06-17 16:23:09 +08:00
|
|
|
|
2015-03-16 10:38:20 +11:00
|
|
|
var fee = baseFee * Math.ceil(byteSize / 1000)
|
|
|
|
if (network.dustSoftThreshold === undefined) return fee
|
2014-06-17 16:23:09 +08:00
|
|
|
|
2015-03-16 11:03:19 +11:00
|
|
|
tx.outs.forEach(function (output) {
|
|
|
|
if (output.value < network.dustSoftThreshold) {
|
2015-03-16 10:38:20 +11:00
|
|
|
fee += baseFee
|
|
|
|
}
|
|
|
|
})
|
2014-06-17 16:23:09 +08:00
|
|
|
|
2015-03-16 10:38:20 +11:00
|
|
|
return fee
|
2014-06-17 16:23:09 +08:00
|
|
|
}
|
|
|
|
|
2015-03-16 10:37:28 +11:00
|
|
|
// FIXME: 1.5.3 compatibility patch(s)
|
2015-03-16 10:38:20 +11:00
|
|
|
function patchEstimateFee (network, tx) {
|
|
|
|
return estimateFee(tx, network)
|
|
|
|
}
|
|
|
|
|
2015-03-16 10:37:28 +11:00
|
|
|
for (var networkName in networks) {
|
|
|
|
var network = networks[networkName]
|
|
|
|
|
2015-03-16 10:38:20 +11:00
|
|
|
network.estimateFee = patchEstimateFee.bind(null, network)
|
2015-03-16 10:37:28 +11:00
|
|
|
}
|
|
|
|
|
2014-06-17 14:48:06 +08:00
|
|
|
module.exports = networks
|