Merge pull request #49 from maraoz/fix/testnet
Fix testnet and optimize performance
This commit is contained in:
commit
6cf224b0a7
16
config/testnet.yml
Normal file
16
config/testnet.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
BitcoreNode:
|
||||||
|
LevelUp: ./testnet-db
|
||||||
|
network: testnet
|
||||||
|
NetworkMonitor:
|
||||||
|
host: localhost
|
||||||
|
port: 18333
|
||||||
|
Reporter: none # none, simple, matrix
|
||||||
|
BitcoreHTTP:
|
||||||
|
host: localhost
|
||||||
|
port: 8080
|
||||||
|
RPC:
|
||||||
|
user: user
|
||||||
|
pass: password
|
||||||
|
protocol: http
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 18332
|
||||||
@ -9,5 +9,14 @@ module.exports = {
|
|||||||
'000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a6' +
|
'000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a6' +
|
||||||
'7962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b' +
|
'7962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b' +
|
||||||
'8d578a4c702b6bf11d5fac00000000', 'hex'),
|
'8d578a4c702b6bf11d5fac00000000', 'hex'),
|
||||||
testnet: new Buffer('')
|
testnet: new Buffer('010000000000000000000000000000000000000000000000000000000000' +
|
||||||
}
|
'0000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a5132' +
|
||||||
|
'3a9fb8aa4b1e5e4adae5494dffff001d1aa4ae1801010000000100000000' +
|
||||||
|
'00000000000000000000000000000000000000000000000000000000ffff' +
|
||||||
|
'ffff4d04ffff001d0104455468652054696d65732030332f4a616e2f3230' +
|
||||||
|
'3039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f' +
|
||||||
|
'6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01' +
|
||||||
|
'000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a6' +
|
||||||
|
'7962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b' +
|
||||||
|
'8d578a4c702b6bf11d5fac00000000', 'hex')
|
||||||
|
};
|
||||||
|
|||||||
@ -9,13 +9,15 @@ var $ = bitcore.util.preconditions;
|
|||||||
var _ = bitcore.deps._;
|
var _ = bitcore.deps._;
|
||||||
var p2p = require('bitcore-p2p');
|
var p2p = require('bitcore-p2p');
|
||||||
var Peer = p2p.Peer;
|
var Peer = p2p.Peer;
|
||||||
var messages = new p2p.Messages();
|
|
||||||
|
|
||||||
function NetworkMonitor(eventBus, peer) {
|
function NetworkMonitor(eventBus, peer) {
|
||||||
$.checkArgument(eventBus);
|
$.checkArgument(eventBus);
|
||||||
$.checkArgument(peer);
|
$.checkArgument(peer);
|
||||||
this.bus = eventBus;
|
this.bus = eventBus;
|
||||||
this.peer = peer;
|
this.peer = peer;
|
||||||
|
this.messages = new p2p.Messages({
|
||||||
|
network: this.peer.network,
|
||||||
|
});
|
||||||
this.setupPeer(peer);
|
this.setupPeer(peer);
|
||||||
}
|
}
|
||||||
util.inherits(NetworkMonitor, EventEmitter);
|
util.inherits(NetworkMonitor, EventEmitter);
|
||||||
@ -41,7 +43,7 @@ NetworkMonitor.prototype.setupPeer = function(peer) {
|
|||||||
peer.on('inv', function(m) {
|
peer.on('inv', function(m) {
|
||||||
self.emit('inv', m.inventory);
|
self.emit('inv', m.inventory);
|
||||||
// TODO only ask for data if tx or block is unknown
|
// TODO only ask for data if tx or block is unknown
|
||||||
peer.sendMessage(messages.GetData(m.inventory));
|
peer.sendMessage(self.messages.GetData(m.inventory));
|
||||||
});
|
});
|
||||||
peer.on('tx', function(m) {
|
peer.on('tx', function(m) {
|
||||||
self.bus.process(m.transaction)
|
self.bus.process(m.transaction)
|
||||||
@ -69,7 +71,7 @@ NetworkMonitor.prototype.requestBlocks = function(locator) {
|
|||||||
$.checkArgument(_.isArray(locator) &&
|
$.checkArgument(_.isArray(locator) &&
|
||||||
_.isUndefined(locator[0]) ||
|
_.isUndefined(locator[0]) ||
|
||||||
_.isString(locator[0]), 'start must be a block hash string array');
|
_.isString(locator[0]), 'start must be a block hash string array');
|
||||||
this.peer.sendMessage(messages.GetBlocks({
|
this.peer.sendMessage(this.messages.GetBlocks({
|
||||||
starts: locator,
|
starts: locator,
|
||||||
//stop: '000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9' // TODO: remove this!!!
|
//stop: '000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9' // TODO: remove this!!!
|
||||||
}));
|
}));
|
||||||
|
|||||||
14
lib/node.js
14
lib/node.js
@ -53,7 +53,7 @@ BitcoreNode.create = function(opts) {
|
|||||||
);
|
);
|
||||||
var rpc = opts.rpc || Promise.promisifyAll(new RPC(opts.RPC));
|
var rpc = opts.rpc || Promise.promisifyAll(new RPC(opts.RPC));
|
||||||
|
|
||||||
var transactionService = opts.transactionService || new TransactionService({
|
var transactionService = opts.transactionService || new TransactionService({
|
||||||
rpc: rpc,
|
rpc: rpc,
|
||||||
database: database
|
database: database
|
||||||
});
|
});
|
||||||
@ -75,6 +75,9 @@ BitcoreNode.create = function(opts) {
|
|||||||
BitcoreNode.prototype.initialize = function() {
|
BitcoreNode.prototype.initialize = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
||||||
|
var prevHeight = 0;
|
||||||
|
var statTimer = 5 * 1000;
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (!self.blockchain) {
|
if (!self.blockchain) {
|
||||||
// not ready yet
|
// not ready yet
|
||||||
@ -82,8 +85,10 @@ BitcoreNode.prototype.initialize = function() {
|
|||||||
}
|
}
|
||||||
var tipHash = self.blockchain.tip;
|
var tipHash = self.blockchain.tip;
|
||||||
var block = self.blockCache[tipHash];
|
var block = self.blockCache[tipHash];
|
||||||
console.log('block', block.id, 'height', block.height);
|
var delta = block.height - prevHeight;
|
||||||
}, 5 * 1000);
|
prevHeight = block.height;
|
||||||
|
console.log(block.id, block.height, 'vel', delta * 1000 / statTimer, 'b/s');
|
||||||
|
}, statTimer);
|
||||||
|
|
||||||
this.bus.register(bitcore.Block, function(block) {
|
this.bus.register(bitcore.Block, function(block) {
|
||||||
|
|
||||||
@ -100,6 +105,8 @@ BitcoreNode.prototype.initialize = function() {
|
|||||||
block.height = self.blockchain.height[block.id];
|
block.height = self.blockchain.height[block.id];
|
||||||
block.work = self.blockchain.work[block.id];
|
block.work = self.blockchain.work[block.id];
|
||||||
|
|
||||||
|
//console.log('block', block.id, block.height);
|
||||||
|
|
||||||
return Promise.each(blockchainChanges.unconfirmed, function(hash) {
|
return Promise.each(blockchainChanges.unconfirmed, function(hash) {
|
||||||
return self.blockService.unconfirm(self.blockCache[hash]);
|
return self.blockService.unconfirm(self.blockCache[hash]);
|
||||||
})
|
})
|
||||||
@ -144,7 +151,6 @@ BitcoreNode.prototype.start = function() {
|
|||||||
|
|
||||||
this.blockService.getBlockchain().then(function(blockchain) {
|
this.blockService.getBlockchain().then(function(blockchain) {
|
||||||
if (!blockchain) {
|
if (!blockchain) {
|
||||||
console.log('nothing');
|
|
||||||
self.blockchain = new BlockChain();
|
self.blockchain = new BlockChain();
|
||||||
self.bus.process(genesis);
|
self.bus.process(genesis);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -200,7 +200,9 @@ BlockService.prototype.getLatest = function() {
|
|||||||
return self.getBlock(blockHash);
|
return self.getBlock(blockHash);
|
||||||
|
|
||||||
}).catch(LevelUp.errors.NotFoundError, function() {
|
}).catch(LevelUp.errors.NotFoundError, function() {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,6 +253,7 @@ BlockService.prototype.confirm = function(block, ops) {
|
|||||||
//console.log(4);
|
//console.log(4);
|
||||||
self._setBlockByTs(ops, block);
|
self._setBlockByTs(ops, block);
|
||||||
|
|
||||||
|
//console.log(4.1);
|
||||||
self._setTip(ops, block);
|
self._setTip(ops, block);
|
||||||
|
|
||||||
//console.log(5);
|
//console.log(5);
|
||||||
@ -471,23 +474,23 @@ BlockService.prototype.getBlockchain = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return self.database.getAsync(Index.tip)
|
return self.database.getAsync(Index.tip)
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
if (err.notFound) {
|
if (err.notFound) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
.then(function(tip) {
|
.then(function(tip) {
|
||||||
if (!tip) {
|
if (!tip) {
|
||||||
console.log('No tip found');
|
console.log('No tip found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('Tip is', tip);
|
console.log('Tip is', tip);
|
||||||
blockchain.tip = tip;
|
blockchain.tip = tip;
|
||||||
return fetchUnlessGenesis(tip).then(function() {
|
return fetchUnlessGenesis(tip).then(function() {
|
||||||
return blockchain;
|
return blockchain;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = BlockService;
|
module.exports = BlockService;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ var _ = bitcore.deps._;
|
|||||||
var $ = bitcore.util.preconditions;
|
var $ = bitcore.util.preconditions;
|
||||||
|
|
||||||
var NULLTXHASH = bitcore.util.buffer.emptyBuffer(32).toString('hex');
|
var NULLTXHASH = bitcore.util.buffer.emptyBuffer(32).toString('hex');
|
||||||
var GENESISTX = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
var GENESISTX = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
|
||||||
|
|
||||||
var helper = function(name) {
|
var helper = function(name) {
|
||||||
return function(txId, output) {
|
return function(txId, output) {
|
||||||
@ -50,15 +50,16 @@ var helperAddress = function(index) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var Index = {
|
var Index = {
|
||||||
output: 'txo-', // txo-<txid>-<n> -> serialized Output
|
output: 'txo-', // txo-<txid>-<n> -> serialized Output
|
||||||
spent: 'txs-', // txo-<txid>-<n>-<spend txid>-<m> -> block height of confirmation for spend
|
spent: 'txs-', // txo-<txid>-<n>-<spend txid>-<m> -> block height of confirmation for spend
|
||||||
address: 'txa-', // txa-<address>-<txid>-<n> -> Output
|
address: 'txa-', // txa-<address>-<txid>-<n> -> Output
|
||||||
addressSpent: 'txas-', // txa-<address>-<txid>-<n> -> {
|
addressSpent: 'txas-',
|
||||||
// heightSpent: number, (may be -1 for unconfirmed tx)
|
// txa-<address>-<txid>-<n> -> {
|
||||||
// spentTx: string, spentTxInputIndex: number, spendInput: Input
|
// heightSpent: number, (may be -1 for unconfirmed tx)
|
||||||
// }
|
// spentTx: string, spentTxInputIndex: number, spendInput: Input
|
||||||
transaction: 'btx-' // btx-<txid> -> block in main chain that confirmed the tx
|
// }
|
||||||
}
|
transaction: 'btx-' // btx-<txid> -> block in main chain that confirmed the tx
|
||||||
|
};
|
||||||
|
|
||||||
_.extend(Index, {
|
_.extend(Index, {
|
||||||
getOutput: helper(Index.output),
|
getOutput: helper(Index.output),
|
||||||
@ -76,7 +77,7 @@ _.extend(Index, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function TransactionService (opts) {
|
function TransactionService(opts) {
|
||||||
opts = _.extend({}, opts);
|
opts = _.extend({}, opts);
|
||||||
this.database = opts.database || Promise.promisifyAll(new LevelUp(config.get('LevelUp')));
|
this.database = opts.database || Promise.promisifyAll(new LevelUp(config.get('LevelUp')));
|
||||||
this.rpc = opts.rpc || Promise.promisifyAll(new RPC(config.get('RPC')));
|
this.rpc = opts.rpc || Promise.promisifyAll(new RPC(config.get('RPC')));
|
||||||
@ -91,7 +92,6 @@ TransactionService.transactionRPCtoBitcore = function(rpcResponse) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype.getTransaction = function(transactionId) {
|
TransactionService.prototype.getTransaction = function(transactionId) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (transactionId === GENESISTX) {
|
if (transactionId === GENESISTX) {
|
||||||
@ -106,27 +106,24 @@ TransactionService.prototype.getTransaction = function(transactionId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype._confirmOutput = function(ops, block, transaction) {
|
TransactionService.prototype._confirmOutput = function(ops, block, transaction) {
|
||||||
|
var txid = transaction.id;
|
||||||
return function(output, index) {
|
return function(output, index) {
|
||||||
ops.push({
|
ops.push({
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: Index.getOutput(transaction.id, index),
|
key: Index.getOutput(txid, index),
|
||||||
value: output.toJSON()
|
value: output.toJSON()
|
||||||
});
|
});
|
||||||
var address;
|
var address;
|
||||||
// TODO: Move this logic to bitcore
|
if (output.script.isPublicKeyHashOut() || output.script.isScriptHashOut()) {
|
||||||
if (output.script.isPublicKeyOut()) {
|
|
||||||
var hash = bitcore.crypto.Hash.sha256ripemd160(output.script.chunks[0].buf);
|
|
||||||
address = new bitcore.Address(hash, bitcore.Networks.defaultNetwork, bitcore.Address.PayToPublicKeyHash);
|
|
||||||
} else if (output.script.isPublicKeyHashOut() || output.script.isScriptHashOut()) {
|
|
||||||
address = output.script.toAddress();
|
address = output.script.toAddress();
|
||||||
}
|
}
|
||||||
if (address) {
|
if (address) {
|
||||||
|
var out4addr = output.toObject();
|
||||||
|
out4addr.heightConfirmed = block.height;
|
||||||
ops.push({
|
ops.push({
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: Index.getOutputsForAddress(address, transaction.id, index),
|
key: Index.getOutputsForAddress(address, txid, index),
|
||||||
value: JSON.stringify(_.extend(output.toObject(), {
|
value: JSON.stringify(out4addr)
|
||||||
heightConfirmed: block.height
|
|
||||||
}))
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -134,13 +131,14 @@ TransactionService.prototype._confirmOutput = function(ops, block, transaction)
|
|||||||
|
|
||||||
TransactionService.prototype._confirmInput = function(ops, block, transaction) {
|
TransactionService.prototype._confirmInput = function(ops, block, transaction) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var txid = transaction.id;
|
||||||
return function(input, index) {
|
return function(input, index) {
|
||||||
if (input.prevTxId.toString('hex') === NULLTXHASH) {
|
if (input.prevTxId.toString('hex') === NULLTXHASH) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
ops.push({
|
ops.push({
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: Index.getOutput(transaction.id, index),
|
key: Index.getOutput(txid, index),
|
||||||
value: JSON.stringify(_.extend(input.toObject(), {
|
value: JSON.stringify(_.extend(input.toObject(), {
|
||||||
heightConfirmed: block.height
|
heightConfirmed: block.height
|
||||||
}))
|
}))
|
||||||
@ -151,15 +149,14 @@ TransactionService.prototype._confirmInput = function(ops, block, transaction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Promise.try(function() {
|
return Promise.try(function() {
|
||||||
return self._getAddressForInput(input)
|
var address = self._getAddressForInput(input);
|
||||||
}).then(function(address) {
|
|
||||||
if (address) {
|
if (address) {
|
||||||
ops.push({
|
ops.push({
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: Index.getSpentOutputsForAddress(address, transaction.id, index),
|
key: Index.getSpentOutputsForAddress(address, txid, index),
|
||||||
value: JSON.stringify({
|
value: JSON.stringify({
|
||||||
heightSpent: block.height,
|
heightSpent: block.height,
|
||||||
spentTx: transaction.id,
|
spentTx: txid,
|
||||||
spentTxInputIndex: index,
|
spentTxInputIndex: index,
|
||||||
spendInput: input.toObject()
|
spendInput: input.toObject()
|
||||||
})
|
})
|
||||||
@ -171,29 +168,8 @@ TransactionService.prototype._confirmInput = function(ops, block, transaction) {
|
|||||||
|
|
||||||
TransactionService.prototype._getAddressForInput = function(input) {
|
TransactionService.prototype._getAddressForInput = function(input) {
|
||||||
var script = input.script;
|
var script = input.script;
|
||||||
var self = this;
|
// TODO: move this to bitcore
|
||||||
|
return new bitcore.Script(script.chunks[script.chunks.length - 1]).toAddress();
|
||||||
if (script.isPublicKeyHashIn()) {
|
|
||||||
var hash = bitcore.crypto.Hash.sha256ripemd160(script.chunks[0].buf);
|
|
||||||
return new bitcore.Address(
|
|
||||||
hash, bitcore.Networks.defaultNetwork, bitcore.Address.PayToPublicKeyHash
|
|
||||||
);
|
|
||||||
} else if (script.isPublicKeyIn()) {
|
|
||||||
/*
|
|
||||||
return self.getTransaction(input.prevTxId.toString('hex')).then(function(transaction) {
|
|
||||||
var outputScript = transaction.outputs[input.outputIndex].script;
|
|
||||||
if (outputScript.isPublicKeyOut()) {
|
|
||||||
return new bitcore.Address(
|
|
||||||
bitcore.crypto.Hash.sha256ripemd160(outputScript.chunks[0].buf),
|
|
||||||
bitcore.Networks.defaultNetwork, bitcore.Address.PayToPublicKeyHash
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
return new bitcore.Script(script.chunks[script.chunks.length - 1]).toAddress();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype._confirmTransaction = function(ops, block, transaction) {
|
TransactionService.prototype._confirmTransaction = function(ops, block, transaction) {
|
||||||
@ -203,11 +179,12 @@ TransactionService.prototype._confirmTransaction = function(ops, block, transact
|
|||||||
key: Index.getBlockForTransaction(transaction),
|
key: Index.getBlockForTransaction(transaction),
|
||||||
value: block.id
|
value: block.id
|
||||||
});
|
});
|
||||||
return Promise.all(
|
var confirmFunctions =
|
||||||
_.map(transaction.outputs, self._confirmOutput(ops, block, transaction))
|
_.map(transaction.outputs, self._confirmOutput(ops, block, transaction))
|
||||||
.concat(
|
.concat(
|
||||||
_.map(transaction.inputs, self._confirmInput(ops, block, transaction))
|
_.map(transaction.inputs, self._confirmInput(ops, block, transaction))
|
||||||
));
|
);
|
||||||
|
return Promise.all(confirmFunctions);
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype._unconfirmTransaction = function(ops, block, transaction) {
|
TransactionService.prototype._unconfirmTransaction = function(ops, block, transaction) {
|
||||||
@ -219,9 +196,9 @@ TransactionService.prototype._unconfirmTransaction = function(ops, block, transa
|
|||||||
});
|
});
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
_.map(transaction.outputs, self._unconfirmOutput(ops, block, transaction))
|
_.map(transaction.outputs, self._unconfirmOutput(ops, block, transaction))
|
||||||
.concat(
|
.concat(
|
||||||
_.map(transaction.inputs, self._unconfirmInput(ops, block, transaction))
|
_.map(transaction.inputs, self._unconfirmInput(ops, block, transaction))
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = TransactionService;
|
module.exports = TransactionService;
|
||||||
|
|||||||
22
package.json
22
package.json
@ -5,29 +5,17 @@
|
|||||||
"author": "BitPay <dev@bitpay.com>",
|
"author": "BitPay <dev@bitpay.com>",
|
||||||
"repository": "git://github.com/bitpay/bitcore-node.git",
|
"repository": "git://github.com/bitpay/bitcore-node.git",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
|
||||||
"name": "Matias Alejo Garcia",
|
|
||||||
"email": "ematiu@gmail.com"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Manuel Araoz",
|
"name": "Manuel Araoz",
|
||||||
"email": "manuelaraoz@gmail.com"
|
"email": "manuelaraoz@gmail.com"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Mario Colque",
|
"name": "Yemel Jardi",
|
||||||
"email": "colquemario@gmail.com"
|
"email": "angel.jardi@gmail.com"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Gustavo Cortez",
|
"name": "Esteban Ordano",
|
||||||
"email": "cmgustavo83@gmail.com"
|
"email": "eordano@gmail.com"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Juan Ignacio Sosa Lopez",
|
|
||||||
"email": "bechilandia@gmail.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Ivan Socolsky",
|
|
||||||
"email": "jungans@gmail.com"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@ -47,7 +35,7 @@
|
|||||||
"async": "0.9.0",
|
"async": "0.9.0",
|
||||||
"bitcoind-rpc": "^0.2.1",
|
"bitcoind-rpc": "^0.2.1",
|
||||||
"bitcore": "bitpay/bitcore",
|
"bitcore": "bitpay/bitcore",
|
||||||
"bitcore-p2p": "^0.11.0",
|
"bitcore-p2p": "^0.13.0",
|
||||||
"bluebird": "^2.9.12",
|
"bluebird": "^2.9.12",
|
||||||
"body-parser": "^1.12.0",
|
"body-parser": "^1.12.0",
|
||||||
"bufferput": "bitpay/node-bufferput",
|
"bufferput": "bitpay/node-bufferput",
|
||||||
|
|||||||
@ -25,6 +25,7 @@ describe('NetworkMonitor', function() {
|
|||||||
mockBlock.id = 'asd';
|
mockBlock.id = 'asd';
|
||||||
busMock = new EventBus();
|
busMock = new EventBus();
|
||||||
peerMock = new EventEmitter();
|
peerMock = new EventEmitter();
|
||||||
|
peerMock.network = Networks.testnet;
|
||||||
peerMock.sendMessage = sinon.spy();
|
peerMock.sendMessage = sinon.spy();
|
||||||
peerMock.connect = function() {
|
peerMock.connect = function() {
|
||||||
this.emit('ready');
|
this.emit('ready');
|
||||||
|
|||||||
@ -71,27 +71,26 @@ describe('TransactionService', function() {
|
|||||||
it('confirms correctly the first transaction on genesis block', function(callback) {
|
it('confirms correctly the first transaction on genesis block', function(callback) {
|
||||||
var ops = [];
|
var ops = [];
|
||||||
service._confirmTransaction(ops, genesisBlock, genesisTx).then(function() {
|
service._confirmTransaction(ops, genesisBlock, genesisTx).then(function() {
|
||||||
ops.map(function(k) {
|
var opsObj = ops.map(function(k) {
|
||||||
if (bitcore.util.js.isValidJSON(k.value)) {
|
if (bitcore.util.js.isValidJSON(k.value)) {
|
||||||
k.value = JSON.parse(k.value);
|
k.value = JSON.parse(k.value);
|
||||||
}
|
}
|
||||||
return k;
|
return k;
|
||||||
}).should.deep.equal([
|
});
|
||||||
{ type: 'put',
|
opsObj.should.deep.equal([{
|
||||||
key: 'btx-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
|
type: 'put',
|
||||||
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' },
|
key: 'btx-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
|
||||||
{ type: 'put',
|
value: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
||||||
key: 'txo-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b-0',
|
}, {
|
||||||
value:
|
type: 'put',
|
||||||
{ satoshis: 5000000000,
|
key: 'txo-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b-0',
|
||||||
script: '65 0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG' } },
|
value: {
|
||||||
{ type: 'put',
|
satoshis: 5000000000,
|
||||||
key: 'txa-1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa-4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b-0',
|
script: '65 0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909' +
|
||||||
value:
|
'a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7b' +
|
||||||
{ satoshis: 5000000000,
|
'a0b8d578a4c702b6bf11d5f OP_CHECKSIG'
|
||||||
script: '65 0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG',
|
}
|
||||||
heightConfirmed: 0} }
|
}]);
|
||||||
]);
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -113,52 +112,46 @@ describe('TransactionService', function() {
|
|||||||
k.value = JSON.parse(k.value);
|
k.value = JSON.parse(k.value);
|
||||||
}
|
}
|
||||||
return k;
|
return k;
|
||||||
}).should.deep.equal([
|
}).should.deep.equal([{
|
||||||
{ type: 'put',
|
type: 'put',
|
||||||
key: 'btx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
|
key: 'btx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
|
||||||
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee' },
|
value: '00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee'
|
||||||
{ type: 'put',
|
}, {
|
||||||
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
type: 'put',
|
||||||
value:
|
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
||||||
{ satoshis: 1000000000,
|
value: {
|
||||||
script: '65 0x04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG' } },
|
satoshis: 1000000000,
|
||||||
{ type: 'put',
|
script: '65 0x04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG'
|
||||||
key: 'txa-1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
}
|
||||||
value:
|
}, {
|
||||||
{ satoshis: 1000000000,
|
type: 'put',
|
||||||
script: '65 0x04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG',
|
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1',
|
||||||
heightConfirmed: 170 } },
|
value: {
|
||||||
{ type: 'put',
|
satoshis: 4000000000,
|
||||||
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1',
|
script: '65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG'
|
||||||
value:
|
}
|
||||||
{ satoshis: 4000000000,
|
}, {
|
||||||
script: '65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG' } },
|
type: 'put',
|
||||||
{ type: 'put',
|
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
||||||
key: 'txa-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-1',
|
value: {
|
||||||
value:
|
prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
|
||||||
{ satoshis: 4000000000,
|
outputIndex: 0,
|
||||||
script: '65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG',
|
sequenceNumber: 4294967295,
|
||||||
heightConfirmed: 170 } },
|
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901',
|
||||||
{ type: 'put',
|
heightConfirmed: 170
|
||||||
key: 'txo-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
}
|
||||||
value:
|
}, ]);
|
||||||
{ prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
|
/* TODO: This should work if address spent is accepted for public key. Add test for P2PKH if not accepted
|
||||||
|
* { type: 'put',
|
||||||
|
key: 'txas-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
||||||
|
value:
|
||||||
|
{ heightSpent: 170,
|
||||||
|
spentTx: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
|
||||||
|
spentTxInputIndex: 0,
|
||||||
|
spendInput: { prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
|
||||||
outputIndex: 0,
|
outputIndex: 0,
|
||||||
sequenceNumber: 4294967295,
|
sequenceNumber: 4294967295,
|
||||||
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901',
|
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901' }}}]);*/
|
||||||
heightConfirmed: 170 } },
|
|
||||||
]);
|
|
||||||
/* TODO: This should work if address spent is accepted for public key. Add test for P2PKH if not accepted
|
|
||||||
* { type: 'put',
|
|
||||||
key: 'txas-12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16-0',
|
|
||||||
value:
|
|
||||||
{ heightSpent: 170,
|
|
||||||
spentTx: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16',
|
|
||||||
spentTxInputIndex: 0,
|
|
||||||
spendInput: { prevTxId: '0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9',
|
|
||||||
outputIndex: 0,
|
|
||||||
sequenceNumber: 4294967295,
|
|
||||||
script: '71 0x304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901' }}}]);*/
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user