diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 98d64772..78c3f1ec 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -122,8 +122,8 @@ Chain.prototype._init = function _init() { entry.height, self.tip.height, entry.height, - self.tip.rhash, - entry.rhash, + self.tip.rhash(), + entry.rhash(), self.tip.chainwork.toString(), entry.chainwork.toString(), self.tip.chainwork.sub(entry.chainwork).toString()); @@ -131,7 +131,7 @@ Chain.prototype._init = function _init() { this.on('resolved', function(block, entry) { self.logger.debug('Orphan %s (%d) was resolved.', - block.rhash, entry.height); + block.rhash(), entry.height); }); this.on('checkpoint', function(hash, height) { @@ -153,21 +153,21 @@ Chain.prototype._init = function _init() { 'Reorg at height %d: old=%s new=%s', height, util.revHex(expected), - block.rhash + block.rhash() ); }); this.on('invalid', function(block, height) { self.logger.warning('Invalid block at height %d: hash=%s', - height, block.rhash); + height, block.rhash()); }); this.on('exists', function(block, height) { - self.logger.debug('Already have block %s (%d).', block.rhash, height); + self.logger.debug('Already have block %s (%d).', block.rhash(), height); }); this.on('orphan', function(block, height) { - self.logger.debug('Handled orphan %s (%d).', block.rhash, height); + self.logger.debug('Handled orphan %s (%d).', block.rhash(), height); }); this.on('purge', function(count, size) { @@ -1406,7 +1406,7 @@ Chain.prototype.finish = function finish(block, entry) { this.logger.info( 'Block %s (%d) added to chain (size=%d txs=%d time=%d).', - entry.rhash, + entry.rhash(), entry.height, block.getSize(), block.txs.length, diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 9a314f2d..6a248953 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -148,7 +148,7 @@ ChainDB.prototype._open = co(function* open() { this.logger.info( 'Chain State: hash=%s tx=%d coin=%d value=%s.', - this.state.rhash, + this.state.rhash(), this.state.tx, this.state.coin, Amount.btc(this.state.value)); @@ -500,7 +500,7 @@ ChainDB.prototype.hasEntry = co(function* hasEntry(block) { */ ChainDB.prototype.getTip = function getTip() { - return this.getEntry(this.state.hash); + return this.getEntry(this.state.hash()); }; /** @@ -1243,7 +1243,7 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) { this.logger.info( 'Scanning block %s (%d).', - entry.rhash, entry.height); + entry.rhash(), entry.height); for (i = 0; i < block.txs.length; i++) { tx = block.txs[i]; @@ -1510,7 +1510,7 @@ ChainDB.prototype.reset = co(function* reset(block) { tip = yield this.getTip(); assert(tip); - this.logger.debug('Resetting main chain to: %s', entry.rhash); + this.logger.debug('Resetting main chain to: %s', entry.rhash()); for (;;) { this.start(); @@ -1596,7 +1596,7 @@ ChainDB.prototype._removeChain = co(function* removeChain(hash) { if (!tip) throw new Error('Alternate chain tip not found.'); - this.logger.debug('Removing alternate chain: %s.', tip.rhash); + this.logger.debug('Removing alternate chain: %s.', tip.rhash()); for (;;) { if (yield tip.isMainChain()) @@ -2092,13 +2092,13 @@ function ChainState() { this.committed = false; } -ChainState.prototype.__defineGetter__('hash', function() { +ChainState.prototype.hash = function() { return this.tip.toString('hex'); -}); +}; -ChainState.prototype.__defineGetter__('rhash', function() { - return util.revHex(this.hash); -}); +ChainState.prototype.rhash = function() { + return util.revHex(this.hash()); +}; ChainState.prototype.clone = function clone() { var state = new ChainState(); diff --git a/lib/blockchain/chainentry.js b/lib/blockchain/chainentry.js index 38b8383d..585f64d5 100644 --- a/lib/blockchain/chainentry.js +++ b/lib/blockchain/chainentry.js @@ -383,9 +383,14 @@ ChainEntry.prototype.hasBit = function hasBit(bit) { return (bits >>> 0) === topBits && (this.version & mask) !== 0; }; -ChainEntry.prototype.__defineGetter__('rhash', function() { +/** + * Get little-endian block hash. + * @returns {Hash} + */ + +ChainEntry.prototype.rhash = function() { return util.revHex(this.hash); -}); +}; /** * Inject properties from block. diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 0f911779..0a897ff1 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -711,7 +711,7 @@ RPC.prototype.getbestblockhash = function getbestblockhash(args) { if (args.help || args.length !== 0) return Promise.reject(new RPCError('getbestblockhash')); - return Promise.resolve(this.chain.tip.rhash); + return Promise.resolve(this.chain.tip.rhash()); }; RPC.prototype.getblockcount = function getblockcount(args) { @@ -763,8 +763,8 @@ RPC.prototype.getblock = co(function* getblock(args) { RPC.prototype._txToJSON = function _txToJSON(tx) { var self = this; return { - txid: tx.txid, - hash: tx.wtxid, + txid: tx.txid(), + hash: tx.wtxid(), size: tx.getSize(), vsize: tx.getVirtualSize(), version: tx.version, @@ -840,7 +840,7 @@ RPC.prototype.getblockhash = co(function* getblockhash(args) { if (!entry) throw new RPCError('Not found.'); - return entry.rhash; + return entry.rhash(); }); RPC.prototype.getblockheader = co(function* getblockheader(args) { @@ -909,7 +909,7 @@ RPC.prototype._blockToJSON = co(function* _blockToJSON(entry, block, txDetails) tx: block.txs.map(function(tx) { if (txDetails) return self._txToJSON(tx); - return tx.rhash; + return tx.txid(); }), time: entry.ts, mediantime: medianTime, @@ -942,7 +942,7 @@ RPC.prototype.getchaintips = co(function* getchaintips(args) { result.push({ height: entry.height, - hash: entry.rhash, + hash: entry.rhash(), branchlen: entry.height - fork.height, status: main ? 'active' : 'valid-headers' }); @@ -1012,7 +1012,7 @@ RPC.prototype.getmempoolancestors = function getmempoolancestors(args) { entries[i] = this._entryToJSON(entries[i]); } else { for (i = 0; i < entries.length; i++) - entries[i] = entries[i].tx.rhash; + entries[i] = entries[i].tx.txid(); } return Promise.resolve(entries); @@ -1047,7 +1047,7 @@ RPC.prototype.getmempooldescendants = function getmempooldescendants(args) { entries[i] = this._entryToJSON(entries[i]); } else { for (i = 0; i < entries.length; i++) - entries[i] = entries[i].tx.rhash; + entries[i] = entries[i].tx.txid(); } return Promise.resolve(entries); @@ -1103,7 +1103,7 @@ RPC.prototype._mempoolToJSON = function _mempoolToJSON(verbose) { if (!entry) continue; - out[entry.tx.rhash] = this._entryToJSON(entry); + out[entry.tx.txid()] = this._entryToJSON(entry); } return out; @@ -1166,7 +1166,7 @@ RPC.prototype.gettxout = co(function* gettxout(args) { return null; return { - bestblock: this.chain.tip.rhash, + bestblock: this.chain.tip.rhash(), confirmations: coin.getConfirmations(this.chain.height), value: Amount.btc(coin.value, true), scriptPubKey: this._scriptToJSON(coin.script, true), @@ -1274,7 +1274,7 @@ RPC.prototype.gettxoutsetinfo = function gettxoutsetinfo(args) { return Promise.resolve({ height: this.chain.height, - bestblock: this.chain.tip.rhash, + bestblock: this.chain.tip.rhash(), transactions: this.chain.db.state.tx, txouts: this.chain.db.state.coin, bytes_serialized: 0, @@ -1560,8 +1560,8 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { txs.push({ data: tx.toRaw().toString('hex'), - txid: tx.rhash, - hash: tx.rwhash, + txid: tx.txid(), + hash: tx.rwhash(), depends: deps, fee: tx.getFee(), sigops: tx.getSigops(), @@ -1615,7 +1615,7 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { vbrequired: 0, previousblockhash: util.revHex(block.prevBlock), transactions: txs, - longpollid: this.chain.tip.rhash + util.pad32(this._totalTX()), + longpollid: this.chain.tip.rhash() + util.pad32(this._totalTX()), target: util.revHex(attempt.target.toString('hex')), submitold: false, mintime: block.ts, @@ -1641,16 +1641,16 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { output = tx.outputs.pop(); assert(output.script.isCommitment()); raw = tx.toRaw(); - rwhash = tx.rwhash; + rwhash = tx.rwhash(); tx.outputs.push(output); } else { raw = tx.toRaw(); - rwhash = tx.rwhash; + rwhash = tx.rwhash(); } template.coinbasetxn = { data: raw.toString('hex'), - txid: tx.rhash, + txid: tx.txid(), hash: rwhash, depends: [], fee: 0, @@ -1933,7 +1933,7 @@ RPC.prototype._generateBlocks = co(function* _generateBlocks(blocks, address) { for (i = 0; i < blocks; i++) { block = yield this.miner.mineBlock(null, address); - hashes.push(block.rhash); + hashes.push(block.rhash()); yield this.chain.add(block); } @@ -2141,7 +2141,7 @@ RPC.prototype.sendrawtransaction = function sendrawtransaction(args) { this.node.sendTX(tx); - return tx.rhash; + return tx.txid(); }; RPC.prototype.signrawtransaction = co(function* signrawtransaction(args) { @@ -2658,7 +2658,7 @@ RPC.prototype.resendwallettransactions = co(function* resendwallettransactions(a for (i = 0; i < txs.length; i++) { tx = txs[i]; - hashes.push(tx.rhash); + hashes.push(tx.txid()); } return hashes; @@ -2730,7 +2730,7 @@ RPC.prototype.dumpwallet = co(function* dumpwallet(args) { util.fmt('# Wallet Dump created by BCoin %s', constants.USER_VERSION), util.fmt('# * Created on %s', time), util.fmt('# * Best block at time of backup was %d (%s),', - this.chain.height, this.chain.tip.rhash), + this.chain.height, this.chain.tip.rhash()), util.fmt('# mined on %s', util.date(this.chain.tip.ts)), util.fmt('# * File: %s', file), '' @@ -3767,7 +3767,7 @@ RPC.prototype.lockunspent = function lockunspent(args) { outpoint.hash = toHash(output.txid); outpoint.index = toNumber(output.vout); - if (!outpoint.txid) + if (!outpoint.hash) return Promise.reject(new RPCError('Invalid paremeter.')); if (outpoint.index < 0) @@ -3802,7 +3802,7 @@ RPC.prototype._send = co(function* _send(account, address, amount, subtractFee) tx = yield this.wallet.send(options); - return tx.rhash; + return tx.txid(); }); RPC.prototype.sendfrom = function sendfrom(args) { @@ -3884,7 +3884,7 @@ RPC.prototype.sendmany = co(function* sendmany(args) { tx = yield this.wallet.send(options); - return tx.rhash; + return tx.txid(); }); RPC.prototype.sendtoaddress = function sendtoaddress(args) { diff --git a/lib/http/server.js b/lib/http/server.js index ac70f68c..75c59244 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -579,7 +579,7 @@ HTTPServer.prototype._init = function _init() { services: this.pool.services.toString(2), network: this.network.type, height: this.chain.height, - tip: this.chain.tip.rhash, + tip: this.chain.tip.rhash(), outbound: this.pool.peers.outbound.length + loader, pending: this.pool.peers.pending.length, inbound: this.pool.peers.inbound.length, diff --git a/lib/mempool/fees.js b/lib/mempool/fees.js index 72d2bc9e..5c5dcfe6 100644 --- a/lib/mempool/fees.js +++ b/lib/mempool/fees.js @@ -560,7 +560,7 @@ PolicyEstimator.prototype.processTX = function processTX(entry, current) { if (this.map[hash]) { this.logger.debug( 'estimatefee: Mempool tx %s already tracked.', - entry.tx.rhash); + entry.tx.txid()); return; } @@ -580,7 +580,7 @@ PolicyEstimator.prototype.processTX = function processTX(entry, current) { rate = entry.getRate(); priority = entry.getPriority(height); - this.logger.spam('estimatefee: Processing mempool tx %s.', entry.tx.rhash); + this.logger.spam('estimatefee: Processing mempool tx %s.', entry.tx.txid()); if (fee === 0 || this.isPriPoint(rate, priority)) { item = new StatEntry(); @@ -593,7 +593,7 @@ PolicyEstimator.prototype.processTX = function processTX(entry, current) { } if (!item) { - this.logger.spam('estimatefee: Not adding tx %s.', entry.tx.rhash); + this.logger.spam('estimatefee: Not adding tx %s.', entry.tx.txid()); return; } @@ -618,7 +618,7 @@ PolicyEstimator.prototype.processBlockTX = function processBlockTX(height, entry if (blocks <= 0) { this.logger.debug( 'estimatefee: Block tx %s had negative blocks to confirm (%d, %d).', - entry.tx.rhash, + entry.tx.txid(), height, entry.height); return; diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index b271d670..39bffa6b 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -803,7 +803,7 @@ Mempool.prototype._addUnchecked = co(function* addUnchecked(entry) { if (this.fees) this.fees.processTX(entry, this.chain.isFull()); - this.logger.debug('Added tx %s to mempool.', entry.tx.rhash); + this.logger.debug('Added tx %s to mempool.', entry.tx.txid()); resolved = this.resolveOrphans(entry.tx); @@ -816,7 +816,7 @@ Mempool.prototype._addUnchecked = co(function* addUnchecked(entry) { } catch (err) { if (err.type === 'VerifyError') { this.logger.debug('Could not resolve orphan %s: %s.', - tx.rhash, + tx.txid(), err.message); if (!tx.hasWitness() && !err.malleated) @@ -835,7 +835,7 @@ Mempool.prototype._addUnchecked = co(function* addUnchecked(entry) { continue; } - this.logger.spam('Resolved orphan %s in mempool.', tx.rhash); + this.logger.spam('Resolved orphan %s in mempool.', tx.txid()); } }); @@ -858,9 +858,9 @@ Mempool.prototype.removeUnchecked = function removeUnchecked(entry, limit) { // now exist on the blockchain). if (limit) { this.removeSpenders(entry); - this.logger.debug('Evicting %s from the mempool.', tx.rhash); + this.logger.debug('Evicting %s from the mempool.', tx.txid()); } else { - this.logger.spam('Removing block tx %s from mempool.', tx.rhash); + this.logger.spam('Removing block tx %s from mempool.', tx.txid()); } this.untrackEntry(entry); @@ -1275,7 +1275,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx) { var i, hash, input, prev; if (tx.getWeight() > constants.tx.MAX_WEIGHT) { - this.logger.debug('Ignoring large orphan: %s', tx.rhash); + this.logger.debug('Ignoring large orphan: %s', tx.txid()); if (!tx.hasWitness()) this.rejects.add(tx.hash()); return; @@ -1288,7 +1288,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx) { continue; if (this.hasReject(input.prevout.hash)) { - this.logger.debug('Not storing orphan %s (rejected parents).', tx.rhash); + this.logger.debug('Not storing orphan %s (rejected parents).', tx.txid()); this.rejects.add(tx.hash()); return; } @@ -1313,7 +1313,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx) { this.orphans[hash] = tx.toExtended(true); this.totalOrphans++; - this.logger.debug('Added orphan %s to mempool.', tx.rhash); + this.logger.debug('Added orphan %s to mempool.', tx.txid()); this.emit('add orphan', tx); diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 9c4bd6cc..775b9f58 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -138,7 +138,7 @@ Miner.prototype._init = function _init() { this.on('block', function(block) { // Emit the block hex as a failsafe (in case we can't send it) - self.logger.info('Found block: %d (%s).', block.height, block.rhash); + self.logger.info('Found block: %d (%s).', block.height, block.rhash()); self.logger.debug('Raw: %s', block.toRaw().toString('hex')); }); diff --git a/lib/mining/minerblock.js b/lib/mining/minerblock.js index 5d0add6c..2db42560 100644 --- a/lib/mining/minerblock.js +++ b/lib/mining/minerblock.js @@ -88,13 +88,23 @@ util.inherits(MinerBlock, EventEmitter); MinerBlock.INTERVAL = 0xffffffff / 1500 | 0; -MinerBlock.prototype.__defineGetter__('hashes', function() { - return this.iterations * 0xffffffff + this.block.nonce; -}); +/** + * Calculate number of hashes. + * @returns {Number} + */ -MinerBlock.prototype.__defineGetter__('rate', function() { +MinerBlock.prototype.getHashes = function() { + return this.iterations * 0xffffffff + this.block.nonce; +}; + +/** + * Calculate hashrate. + * @returns {Number} + */ + +MinerBlock.prototype.getRate = function() { return (this.block.nonce / (util.now() - this.begin)) | 0; -}); +}; /** * Initialize the block. @@ -487,8 +497,8 @@ MinerBlock.prototype.sendStatus = function sendStatus() { this.emit('status', { block: this.block, target: this.block.bits, - hashes: this.hashes, - hashrate: this.rate, + hashes: this.getHashes(), + hashrate: this.getRate(), height: this.height, best: util.revHex(this.tip.hash) }); diff --git a/lib/net/peer.js b/lib/net/peer.js index e0834a13..74e737d4 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -2304,7 +2304,7 @@ Peer.prototype._handleCmpctBlock = co(function* _handleCmpctBlock(packet) { this.fire('block', block.toBlock()); this.logger.debug( 'Received full compact block %s (%s).', - block.rhash, this.hostname); + block.rhash(), this.hostname); return; } @@ -2314,14 +2314,14 @@ Peer.prototype._handleCmpctBlock = co(function* _handleCmpctBlock(packet) { this.logger.debug( 'Received semi-full compact block %s (%s).', - block.rhash, this.hostname); + block.rhash(), this.hostname); try { yield block.wait(10000); } catch (e) { this.logger.debug( 'Compact block timed out: %s (%s).', - block.rhash, this.hostname); + block.rhash(), this.hostname); delete this.compactBlocks[hash]; } @@ -2399,7 +2399,7 @@ Peer.prototype._handleBlockTxn = function _handleBlockTxn(packet) { this.logger.debug( 'Filled compact block %s (%s).', - block.rhash, this.hostname); + block.rhash(), this.hostname); this.fire('block', block.toBlock()); this.fire('getblocktxn', res); @@ -2512,7 +2512,7 @@ Peer.prototype.sendReject = function sendReject(code, reason, obj) { if (obj) { this.logger.debug('Rejecting %s %s (%s): ccode=%s reason=%s.', - reject.message, obj.rhash, this.hostname, code, reason); + reject.message, obj.rhash(), this.hostname, code, reason); } else { this.logger.debug('Rejecting packet from %s: ccode=%s reason=%s.', this.hostname, code, reason); diff --git a/lib/net/pool.js b/lib/net/pool.js index ed170437..2d73262f 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -946,7 +946,7 @@ Pool.prototype._handleBlock = co(function* _handleBlock(block, peer) { peer.invFilter.add(block.hash()); this.logger.warning( 'Received unrequested block: %s (%s).', - block.rhash, peer.hostname); + block.rhash(), peer.hostname); return yield co.wait(); } @@ -1004,7 +1004,7 @@ Pool.prototype._handleBlock = co(function* _handleBlock(block, peer) { this.logger.info( 'Received 2000 more blocks (height=%d, hash=%s).', this.chain.height, - block.rhash); + block.rhash()); } }); @@ -1363,7 +1363,7 @@ Pool.prototype._handleTX = co(function* _handleTX(tx, peer) { this.txFilter.add(tx.hash()); this.logger.warning('Peer sent unrequested tx: %s (%s).', - tx.rhash, peer.hostname); + tx.txid(), peer.hostname); if (this.hasReject(tx.hash())) { throw new VerifyError(tx, diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index a3124885..768e8364 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -316,7 +316,7 @@ FullNode.prototype.sendTX = co(function* sendTX(tx) { } catch (err) { if (err.type === 'VerifyError') { this._error(err); - this.logger.warning('Verification failed for tx: %s.', tx.rhash); + this.logger.warning('Verification failed for tx: %s.', tx.txid()); this.logger.warning('Attempting to broadcast anyway...'); yield this.pool.broadcast(tx); return; diff --git a/lib/primitives/abstractblock.js b/lib/primitives/abstractblock.js index ebf7dc79..6a4d32f6 100644 --- a/lib/primitives/abstractblock.js +++ b/lib/primitives/abstractblock.js @@ -282,9 +282,14 @@ AbstractBlock.prototype.setHeight = function setHeight(height) { this.txs[i].height = height; }; -AbstractBlock.prototype.__defineGetter__('rhash', function() { +/** + * Get little-endian block hash. + * @returns {Hash} + */ + +AbstractBlock.prototype.rhash = function() { return util.revHex(this.hash('hex')); -}); +}; /** * Convert the block to an inv item. diff --git a/lib/primitives/block.js b/lib/primitives/block.js index 9f302829..9abc2182 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -604,7 +604,7 @@ Block.prototype.getPrevout = function getPrevout() { Block.prototype.inspect = function inspect() { var commitmentHash = this.getCommitmentHash('hex'); return { - hash: this.rhash, + hash: this.rhash(), height: this.height, size: this.getSize(), virtualSize: this.getVirtualSize(), @@ -633,7 +633,7 @@ Block.prototype.inspect = function inspect() { Block.prototype.toJSON = function toJSON(network) { network = Network.get(network); return { - hash: this.rhash, + hash: this.rhash(), height: this.height, version: this.version, prevBlock: util.revHex(this.prevBlock), diff --git a/lib/primitives/headers.js b/lib/primitives/headers.js index c09bd017..d3bd09d6 100644 --- a/lib/primitives/headers.js +++ b/lib/primitives/headers.js @@ -61,7 +61,7 @@ Headers.prototype.getSize = function getSize() { Headers.prototype.inspect = function inspect() { return { type: 'headers', - hash: this.rhash, + hash: this.rhash(), height: this.height, date: util.date(this.ts), version: util.hex32(this.version), diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index d470b518..836f3a18 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -318,7 +318,7 @@ MerkleBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() { MerkleBlock.prototype.inspect = function inspect() { return { type: 'merkleblock', - hash: this.rhash, + hash: this.rhash(), height: this.height, date: util.date(this.ts), version: util.hex32(this.version), @@ -420,7 +420,7 @@ MerkleBlock.fromRaw = function fromRaw(data, enc) { MerkleBlock.prototype.toJSON = function toJSON() { return { type: 'merkleblock', - hash: this.rhash, + hash: this.rhash(), height: this.height, version: this.version, prevBlock: util.revHex(this.prevBlock), diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 23b11f95..1b07984a 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -1992,27 +1992,52 @@ TX.prototype.isWatched = function isWatched(filter) { return false; }; -TX.prototype.__defineGetter__('rblock', function() { +/** + * Get little-endian block hash. + * @returns {Hash|null} + */ + +TX.prototype.rblock = function() { return this.block ? util.revHex(this.block) : null; -}); +}; -TX.prototype.__defineGetter__('rhash', function() { +/** + * Get little-endian tx hash. + * @returns {Hash} + */ + +TX.prototype.rhash = function() { return util.revHex(this.hash('hex')); -}); +}; -TX.prototype.__defineGetter__('rwhash', function() { +/** + * Get little-endian wtx hash. + * @returns {Hash} + */ + +TX.prototype.rwhash = function() { return util.revHex(this.witnessHash('hex')); -}); +}; -TX.prototype.__defineGetter__('txid', function() { - return this.rhash; -}); +/** + * Get little-endian tx hash. + * @returns {Hash} + */ -TX.prototype.__defineGetter__('wtxid', function() { - return this.rwhash; -}); +TX.prototype.txid = function() { + return this.rhash(); +}; + +/** + * Get little-endian wtx hash. + * @returns {Hash} + */ + +TX.prototype.wtxid = function() { + return this.rwhash(); +}; /** * Convert the tx to an inv item. @@ -2037,8 +2062,8 @@ TX.prototype.inspect = function inspect() { rate = 0; return { - hash: this.rhash, - witnessHash: this.rwhash, + hash: this.rhash(), + witnessHash: this.rwhash(), size: this.getSize(), virtualSize: this.maxSize(), height: this.height, diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 0388350f..da3d08c4 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -1683,7 +1683,7 @@ TXDB.prototype.disconnect = co(function* disconnect(tx) { TXDB.prototype.removeConflict = co(function* removeConflict(tx) { var details; - this.logger.warning('Handling conflicting tx: %s.', tx.rhash); + this.logger.warning('Handling conflicting tx: %s.', tx.txid()); this.drop(); @@ -1691,7 +1691,7 @@ TXDB.prototype.removeConflict = co(function* removeConflict(tx) { this.start(); - this.logger.warning('Removed conflict: %s.', tx.rhash); + this.logger.warning('Removed conflict: %s.', tx.txid()); // Emit the _removed_ transaction. this.emit('conflict', tx, details); diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index a437c272..6e79190b 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -1541,7 +1541,7 @@ Wallet.prototype._send = co(function* send(options, passphrase) { yield this.db.addTX(tx); - this.logger.debug('Sending wallet tx (%s): %s', this.id, tx.rhash); + this.logger.debug('Sending wallet tx (%s): %s', this.id, tx.txid()); yield this.db.send(tx); @@ -1633,7 +1633,7 @@ Wallet.prototype.increaseFee = co(function* increaseFee(hash, rate, passphrase) tx = tx.toTX(); - this.logger.debug('Increasing fee for wallet tx (%s): %s', this.id, tx.rhash); + this.logger.debug('Increasing fee for wallet tx (%s): %s', this.id, tx.txid()); yield this.db.addTX(tx); yield this.db.send(tx); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 96d4d0ae..7de6909a 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -2114,7 +2114,7 @@ WalletDB.prototype._insert = co(function* insert(tx, block) { this.logger.info( 'Incoming transaction for %d wallets in WalletDB (%s).', - wids.length, tx.rhash); + wids.length, tx.txid()); // If this is our first transaction // in a block, set the start block here. diff --git a/test/block-test.js b/test/block-test.js index af97b1a7..56510f0a 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -67,7 +67,7 @@ describe('Block', function() { assert.equal(mblock.matches.length, 2); assert.equal(mblock.hash('hex'), '8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000'); - assert.equal(mblock.rhash, + assert.equal(mblock.rhash(), '0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c'); assert.equal( mblock.matches[0].toString('hex'), @@ -124,7 +124,7 @@ describe('Block', function() { block = bcoin.block.fromJSON(block300025); assert.equal(block.hash('hex'), '8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000'); - assert.equal(block.rhash, + assert.equal(block.rhash(), '0000000000000000821c4e0acc40f88bedbce3b73ba2358b5ade58a9022cc78c'); assert.equal(block.merkleRoot, block.createMerkleRoot('hex')); }); diff --git a/test/http-test.js b/test/http-test.js index 174de940..08a492e9 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -112,7 +112,7 @@ describe('HTTP', function() { assert.equal(Amount.value(balance.confirmed), 0); assert.equal(Amount.value(balance.unconfirmed), 201840); assert(details); - assert.equal(details.hash, t1.rhash); + assert.equal(details.hash, t1.rhash()); })); it('should get balance', cob(function* () {