wrap tx and block objects.

This commit is contained in:
Christopher Jeffrey 2014-09-25 13:45:42 -07:00
parent aa06d48a1b
commit 7de0f9e85b
2 changed files with 19 additions and 3 deletions

View File

@ -25,7 +25,7 @@ bitcoind.start(function(err) {
// });
bitcoind.once('tx', function(tx) {
console.log('Broadcasting tx...');
bitcoind._broadcastTx(tx, function(err, hash) {
tx.broadcast(function(err, hash) {
if (err) throw err;
console.log('tx hash: %s', hash);
});

View File

@ -173,6 +173,8 @@ Bitcoin.prototype._pollBlocks = function() {
return bitcoindjs.pollBlocks(function(err, blocks) {
if (err) return setTimeout(next, self.pollInterval);
return utils.forEach(blocks, function(block, nextBlock) {
block = bitcoin.block(block);
// XXX Bad workaround
if (self._emitted[block.hash]) {
return setImmediate(function() {
@ -208,6 +210,8 @@ Bitcoin.prototype._pollMempool = function() {
return bitcoindjs.pollMempool(function(err, txs) {
if (err) return setTimeout(next, self.pollInterval);
return utils.forEach(txs, function(tx, nextTx) {
tx = bitcoin.tx(tx);
// XXX Bad workaround
if (self._emitted[tx.hash]) {
return setImmediate(function() {
@ -230,7 +234,10 @@ Bitcoin.prototype._pollMempool = function() {
};
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) {
@ -238,7 +245,10 @@ Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
callback = 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 =
@ -286,6 +296,12 @@ function Block(data) {
if (data instanceof Block) {
return data;
}
var self = this;
Object.keys(data).forEach(function(key) {
self[key] = data[key];
});
}
/**