diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 2ab2024f..310f6202 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -307,7 +307,9 @@ function Block(data) { var self = this; Object.keys(data).forEach(function(key) { - self[key] = data[key]; + if (!self[key]) { + self[key] = data[key]; + } }); } @@ -334,9 +336,17 @@ function Transaction(data) { this.vout = data.vout || []; this.nLockTime = data.nLockTime || data.locktime || 0; + if (data.hex) { + this._hex = data.hex; + } + Object.keys(data).forEach(function(key) { - self[key] = data[key]; + if (!self[key]) { + self[key] = data[key]; + } }); + + this.toHex(); } Transaction.prototype.getSerializeSize = function() { @@ -614,6 +624,15 @@ utils.varint = function(arr, value, off) { } }; +utils.copy = function copy(src, dst, off, force) { + var len = src.length; + if (!force) + len = Math.min(dst.length - off, len); + for (var i = 0; i < len; i++) + dst[i + off] = src[i]; + return i; +}; + utils.NOOP = function() {}; /** diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 7d40fefc..30607565 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -1213,7 +1213,11 @@ cblock_to_js(const CBlock& block, const CBlockIndex* blockindex, Local o static inline void ctx_to_js(const CTransaction& tx, uint256 hashBlock, Local entry) { - // entry->Set(NanNew("hex"), NanNew(strHex)); + CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); + ssTx << tx; + string strHex = HexStr(ssTx.begin(), ssTx.end()); + entry->Set(NanNew("hex"), NanNew(strHex)); + entry->Set(NanNew("txid"), NanNew(tx.GetHash().GetHex())); entry->Set(NanNew("version"), NanNew(tx.nVersion)); entry->Set(NanNew("locktime"), NanNew(tx.nLockTime));