diff --git a/example/index.js b/example/index.js index 051aea8b..35a5b020 100755 --- a/example/index.js +++ b/example/index.js @@ -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); }); diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 9bd96ba3..dee281e8 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -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]; + }); } /**