From 5d8332c710e0fe2ce06a966325f984c51a09153f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 23 Oct 2014 16:22:39 -0700 Subject: [PATCH] convenience for fromHex. --- example/index.js | 11 ++--------- lib/bitcoind.js | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/example/index.js b/example/index.js index 0b00c7eb..4d508dba 100755 --- a/example/index.js +++ b/example/index.js @@ -142,13 +142,6 @@ bitcoind.on('open', function(status) { return getBlocks(bitcoind); } - if (argv['test-tx']) { - var tx = bitcoind.tx.fromHex(testTx); - bitcoind.log(tx); - bitcoind.log(tx.txid === tx.getHash('hex')); - return; - } - function assertHex(obj) { // Hash if (obj.txid) { @@ -200,12 +193,12 @@ bitcoind.on('open', function(status) { // Test fromHex: if (argv['from-hex']) { - var block = bitcoind.block.fromHex(testBlock); + var block = bitcoind.block(testBlock); assert.equal(block.hash, '0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af'); assert.equal(block.merkleroot, '2fda58e5959b0ee53c5253da9b9f3c0c739422ae04946966991cf55895287552'); bitcoind.log('Block:'); bitcoind.log(block); - var tx = bitcoind.tx.fromHex(testTx); + var tx = bitcoind.tx(testTx); assert.equal(tx.txid, 'b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b'); bitcoind.log('Transaction:'); bitcoind.log(tx); diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 60493f05..7f882264 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -395,6 +395,10 @@ function Block(data) { return new Block(data); } + if (typeof data === 'string') { + return Block.fromHex(data); + } + if (data instanceof Block) { return data; } @@ -478,6 +482,10 @@ function Transaction(data) { return new Transaction(data); } + if (typeof data === 'string') { + return Transaction.fromHex(data); + } + if (data instanceof Transaction) { return data; }