wrap tx and block objects.
This commit is contained in:
parent
aa06d48a1b
commit
7de0f9e85b
@ -25,7 +25,7 @@ bitcoind.start(function(err) {
|
|||||||
// });
|
// });
|
||||||
bitcoind.once('tx', function(tx) {
|
bitcoind.once('tx', function(tx) {
|
||||||
console.log('Broadcasting tx...');
|
console.log('Broadcasting tx...');
|
||||||
bitcoind._broadcastTx(tx, function(err, hash) {
|
tx.broadcast(function(err, hash) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('tx hash: %s', hash);
|
console.log('tx hash: %s', hash);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -173,6 +173,8 @@ Bitcoin.prototype._pollBlocks = function() {
|
|||||||
return bitcoindjs.pollBlocks(function(err, blocks) {
|
return bitcoindjs.pollBlocks(function(err, blocks) {
|
||||||
if (err) return setTimeout(next, self.pollInterval);
|
if (err) return setTimeout(next, self.pollInterval);
|
||||||
return utils.forEach(blocks, function(block, nextBlock) {
|
return utils.forEach(blocks, function(block, nextBlock) {
|
||||||
|
block = bitcoin.block(block);
|
||||||
|
|
||||||
// XXX Bad workaround
|
// XXX Bad workaround
|
||||||
if (self._emitted[block.hash]) {
|
if (self._emitted[block.hash]) {
|
||||||
return setImmediate(function() {
|
return setImmediate(function() {
|
||||||
@ -208,6 +210,8 @@ Bitcoin.prototype._pollMempool = function() {
|
|||||||
return bitcoindjs.pollMempool(function(err, txs) {
|
return bitcoindjs.pollMempool(function(err, txs) {
|
||||||
if (err) return setTimeout(next, self.pollInterval);
|
if (err) return setTimeout(next, self.pollInterval);
|
||||||
return utils.forEach(txs, function(tx, nextTx) {
|
return utils.forEach(txs, function(tx, nextTx) {
|
||||||
|
tx = bitcoin.tx(tx);
|
||||||
|
|
||||||
// XXX Bad workaround
|
// XXX Bad workaround
|
||||||
if (self._emitted[tx.hash]) {
|
if (self._emitted[tx.hash]) {
|
||||||
return setImmediate(function() {
|
return setImmediate(function() {
|
||||||
@ -230,7 +234,10 @@ Bitcoin.prototype._pollMempool = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Bitcoin.prototype.getBlock = function(blockHash, callback) {
|
Bitcoin.prototype.getBlock = function(blockHash, callback) {
|
||||||
return bitcoindjs.getBlock(blockHash, callback);
|
return bitcoindjs.getBlock(blockHash, function(err, block) {
|
||||||
|
if (err) return callback(err);
|
||||||
|
return callback(null, bitcoind.block(block));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
|
Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
|
||||||
@ -238,7 +245,10 @@ Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
|
|||||||
callback = blockHash;
|
callback = blockHash;
|
||||||
blockHash = '';
|
blockHash = '';
|
||||||
}
|
}
|
||||||
return bitcoindjs.getTx(txHash, blockHash, callback);
|
return bitcoindjs.getTx(txHash, blockHash, function(err, tx) {
|
||||||
|
if (err) return callback(err);
|
||||||
|
return callback(null, bitcoind.tx(tx));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Bitcoin.prototype.log =
|
Bitcoin.prototype.log =
|
||||||
@ -286,6 +296,12 @@ function Block(data) {
|
|||||||
if (data instanceof Block) {
|
if (data instanceof Block) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
Object.keys(data).forEach(function(key) {
|
||||||
|
self[key] = data[key];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user