bcoin: use util.revHex again.

This commit is contained in:
Christopher Jeffrey 2017-11-17 00:00:36 -08:00
parent f2abdf68cb
commit 3c82ac0486
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
34 changed files with 122 additions and 118 deletions

View File

@ -12,7 +12,6 @@ const path = require('path');
const AsyncEmitter = require('bevent');
const Logger = require('blgr');
const {Lock} = require('bmutex');
const {encoding} = require('bufio');
const Network = require('../protocol/network');
const ChainDB = require('./chaindb');
const common = require('./common');
@ -1562,7 +1561,7 @@ class Chain extends AsyncEmitter {
if (hash === checkpoint) {
this.logger.debug('Hit checkpoint block %s (%d).',
encoding.revHex(hash), height);
util.revHex(hash), height);
this.emit('checkpoint', hash, height);
return true;
}
@ -1574,8 +1573,8 @@ class Chain extends AsyncEmitter {
this.logger.warning(
'Checkpoint mismatch at height %d: expected=%s received=%s',
height,
encoding.revHex(checkpoint),
encoding.revHex(hash)
util.revHex(checkpoint),
util.revHex(hash)
);
this.purgeOrphans();

View File

@ -16,6 +16,7 @@ const CoinView = require('../coins/coinview');
const UndoCoins = require('../coins/undocoins');
const layout = require('./layout');
const LRU = require('../utils/lru');
const util = require('../utils/util');
const Block = require('../primitives/block');
const Outpoint = require('../primitives/outpoint');
const Address = require('../primitives/address');
@ -1275,7 +1276,7 @@ class ChainDB {
if (typeof start === 'number')
this.logger.info('Scanning from height %d.', start);
else
this.logger.info('Scanning from block %s.', encoding.revHex(start));
this.logger.info('Scanning from block %s.', util.revHex(start));
let entry = await this.getEntry(start);
@ -2135,7 +2136,7 @@ class ChainState {
}
rhash() {
return encoding.revHex(this.tip);
return util.revHex(this.tip);
}
clone() {

View File

@ -12,6 +12,7 @@ const bio = require('bufio');
const BN = require('bcrypto/lib/bn');
const consensus = require('../protocol/consensus');
const hash256 = require('bcrypto/lib/hash256');
const util = require('../utils/util');
const Headers = require('../primitives/headers');
const InvItem = require('../primitives/invitem');
const {encoding} = bio;
@ -177,7 +178,7 @@ class ChainEntry {
*/
rhash() {
return encoding.revHex(this.hash);
return util.revHex(this.hash);
}
/**
@ -274,10 +275,10 @@ class ChainEntry {
toJSON() {
return {
hash: encoding.revHex(this.hash),
hash: util.revHex(this.hash),
version: this.version,
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce,
@ -303,10 +304,10 @@ class ChainEntry {
assert((json.nonce >>> 0) === json.nonce);
assert(typeof json.chainwork === 'string');
this.hash = encoding.revHex(json.hash);
this.hash = util.revHex(json.hash);
this.version = json.version;
this.prevBlock = encoding.revHex(json.prevBlock);
this.merkleRoot = encoding.revHex(json.merkleRoot);
this.prevBlock = util.revHex(json.prevBlock);
this.merkleRoot = util.revHex(json.merkleRoot);
this.time = json.time;
this.bits = json.bits;
this.nonce = json.nonce;

View File

@ -11,6 +11,7 @@
const assert = require('assert');
const bio = require('bufio');
const Logger = require('blgr');
const util = require('../utils/util');
const binary = require('../utils/binary');
const consensus = require('../protocol/consensus');
const policy = require('../protocol/policy');
@ -488,7 +489,7 @@ class PolicyEstimator {
const item = this.map.get(hash);
if (!item) {
this.logger.spam('Mempool tx %s not found.', encoding.revHex(hash));
this.logger.spam('Mempool tx %s not found.', util.revHex(hash));
return;
}

View File

@ -1661,7 +1661,7 @@ class Mempool extends EventEmitter {
assert(hash);
this.logger.debug('Removing orphan %s from mempool.',
encoding.revHex(hash));
util.revHex(hash));
this.removeOrphan(hash);
@ -2518,7 +2518,7 @@ class MempoolCache {
this.logger.info(
'Mempool cache is empty. Writing tip %s.',
encoding.revHex(tip));
util.revHex(tip));
await this.init(tip);
}
@ -2538,7 +2538,7 @@ class MempoolCache {
if (tip !== this.chain.tip.hash) {
this.logger.warning(
'Mempool tip not consistent with chain tip (%s != %s)!',
encoding.revHex(tip),
util.revHex(tip),
this.chain.tip.rhash());
this.logger.warning('Invalidating mempool cache.');
await this.wipe();

View File

@ -9,7 +9,6 @@
const assert = require('assert');
const EventEmitter = require('events');
const {encoding} = require('bufio');
const {Lock} = require('bmutex');
const util = require('../utils/util');
const mine = require('./mine');
@ -402,7 +401,7 @@ class CPUMiner extends EventEmitter {
sendStatus(job, nonce) {
const attempt = job.attempt;
const tip = encoding.revHex(attempt.prevBlock);
const tip = util.revHex(attempt.prevBlock);
const hashes = job.getHashes(nonce);
const hashrate = job.getRate(nonce);

View File

@ -11,6 +11,7 @@ const assert = require('assert');
const bio = require('bufio');
const hash256 = require('bcrypto/lib/hash256');
const merkle = require('bcrypto/lib/merkle');
const util = require('../utils/util');
const Address = require('../primitives/address');
const TX = require('../primitives/tx');
const Block = require('../primitives/block');
@ -677,7 +678,7 @@ class BlockProof {
}
rhash() {
return encoding.revHex(this.hash.toString('hex'));
return util.revHex(this.hash.toString('hex'));
}
verify(target) {

View File

@ -1557,7 +1557,7 @@ class RejectPacket extends Packet {
*/
rhash() {
return this.hash ? encoding.revHex(this.hash) : null;
return this.hash ? util.revHex(this.hash) : null;
}
/**
@ -1741,7 +1741,7 @@ class RejectPacket extends Packet {
inspect() {
const code = RejectPacket.codesByVal[this.code] || this.code;
const hash = this.hash ? encoding.revHex(this.hash) : null;
const hash = this.hash ? util.revHex(this.hash) : null;
return '<Reject:'
+ ` msg=${this.message}`
+ ` code=${code}`

View File

@ -13,8 +13,8 @@ const {Lock} = require('bmutex');
const {format} = require('util');
const tcp = require('btcp');
const Logger = require('blgr');
const {encoding} = require('bufio');
const {RollingFilter} = require('bfilter');
const util = require('../utils/util');
const Parser = require('./parser');
const Framer = require('./framer');
const packets = require('./packets');
@ -1923,11 +1923,11 @@ class Peer extends EventEmitter {
let hash = null;
if (packet.locator.length > 0)
hash = encoding.revHex(packet.locator[0]);
hash = util.revHex(packet.locator[0]);
let end = null;
if (stop)
end = encoding.revHex(stop);
end = util.revHex(stop);
this.logger.debug(
'Requesting headers packet from peer with getheaders (%s).',
@ -1951,11 +1951,11 @@ class Peer extends EventEmitter {
let hash = null;
if (packet.locator.length > 0)
hash = encoding.revHex(packet.locator[0]);
hash = util.revHex(packet.locator[0]);
let end = null;
if (stop)
end = encoding.revHex(stop);
end = util.revHex(stop);
this.logger.debug(
'Requesting inv packet from peer with getblocks (%s).',
@ -2003,7 +2003,7 @@ class Peer extends EventEmitter {
if (msg) {
this.logger.debug('Rejecting %s %s (%s): code=%s reason=%s.',
msg, encoding.revHex(hash), this.hostname(), code, reason);
msg, util.revHex(hash), this.hostname(), code, reason);
} else {
this.logger.debug('Rejecting packet from %s: code=%s reason=%s.',
this.hostname(), code, reason);

View File

@ -9,7 +9,6 @@
const assert = require('assert');
const EventEmitter = require('events');
const {encoding} = require('bufio');
const {Lock} = require('bmutex');
const IP = require('binet');
const dns = require('bdns');
@ -227,7 +226,7 @@ class Pool extends EventEmitter {
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
this.logger.info(
'Initialized header chain to height %d (checkpoint=%s).',
tip.height, encoding.revHex(this.headerTip.hash));
tip.height, util.revHex(this.headerTip.hash));
}
}
@ -2285,8 +2284,8 @@ class Pool extends EventEmitter {
if (hash !== node.hash) {
this.logger.warning(
'Header hash mismatch %s != %s (%s).',
encoding.revHex(hash),
encoding.revHex(node.hash),
util.revHex(hash),
util.revHex(node.hash),
peer.hostname());
peer.destroy();
@ -2298,7 +2297,7 @@ class Pool extends EventEmitter {
if (node.height === this.headerTip.height) {
this.logger.info(
'Received checkpoint %s (%d).',
encoding.revHex(node.hash), node.height);
util.revHex(node.hash), node.height);
this.headerTip = this.getNextTip(node.height);
@ -2355,7 +2354,7 @@ class Pool extends EventEmitter {
if (!peer) {
this.logger.warning(
'Could not find offending peer for orphan: %s (%d).',
encoding.revHex(err.hash), id);
util.revHex(err.hash), id);
return;
}
@ -3443,7 +3442,7 @@ class Pool extends EventEmitter {
// If we recently rejected this item. Ignore.
if (this.mempool.hasReject(hash)) {
this.logger.spam('Saw known reject of %s.', encoding.revHex(hash));
this.logger.spam('Saw known reject of %s.', util.revHex(hash));
return true;
}
}
@ -4336,7 +4335,7 @@ class BroadcastItem extends EventEmitter {
inspect() {
const type = this.type === invTypes.TX ? 'tx' : 'block';
const hash = encoding.revHex(this.hash);
const hash = util.revHex(this.hash);
return `<BroadcastItem: type=${type} hash=${hash}>`;
}
}

View File

@ -12,7 +12,6 @@ const path = require('path');
const {Server} = require('bweb');
const Validator = require('bval');
const {base58} = require('bstring');
const {encoding} = require('bufio');
const {BloomFilter} = require('bfilter');
const sha256 = require('bcrypto/lib/sha256');
const random = require('bcrypto/lib/random');
@ -296,7 +295,7 @@ class HTTP extends Server {
const result = [];
for (const hash of hashes)
result.push(encoding.revHex(hash));
result.push(util.revHex(hash));
res.json(200, result);
});

View File

@ -464,7 +464,7 @@ class RPC extends RPCBase {
offset = 0;
for (const hash in peer.blockMap.keys()) {
const str = encoding.revHex(hash);
const str = util.revHex(hash);
hashes.push(str);
}
@ -490,7 +490,7 @@ class RPC extends RPCBase {
subver: peer.agent,
inbound: !peer.outbound,
startingheight: peer.height,
besthash: peer.bestHash ? encoding.revHex(peer.bestHash) : null,
besthash: peer.bestHash ? util.revHex(peer.bestHash) : null,
bestheight: peer.bestHeight,
banscore: peer.banScore,
inflight: hashes,
@ -694,7 +694,7 @@ class RPC extends RPCBase {
if (!hash)
throw new RPCError(errs.MISC_ERROR, 'Not found.');
return encoding.revHex(hash);
return util.revHex(hash);
}
async getBlockHeader(args, help) {
@ -878,7 +878,7 @@ class RPC extends RPCBase {
const hashes = this.mempool.getSnapshot();
return hashes.map(encoding.revHex);
return hashes.map(util.revHex);
}
async getTXOut(args, help) {
@ -1017,7 +1017,7 @@ class RPC extends RPCBase {
const out = [];
for (const hash of tree.matches)
out.push(encoding.revHex(hash.toString('hex')));
out.push(util.revHex(hash.toString('hex')));
return out;
}
@ -1461,8 +1461,8 @@ class RPC extends RPCBase {
vbavailable: vbavailable,
vbrequired: 0,
height: attempt.height,
previousblockhash: encoding.revHex(attempt.prevBlock),
target: encoding.revHex(attempt.target.toString('hex')),
previousblockhash: util.revHex(attempt.prevBlock),
target: util.revHex(attempt.target.toString('hex')),
bits: hex32(attempt.bits),
noncerange: '00000000ffffffff',
curtime: attempt.time,
@ -2286,7 +2286,7 @@ class RPC extends RPCBase {
if ((lastTX >>> 0) !== lastTX)
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid longpoll ID.');
const hash = encoding.revHex(watched);
const hash = util.revHex(watched);
if (this.chain.tip.hash !== hash)
return;
@ -2699,16 +2699,16 @@ class RPC extends RPCBase {
height: entry.height,
version: entry.version,
versionHex: hex32(entry.version),
merkleroot: encoding.revHex(entry.merkleRoot),
merkleroot: util.revHex(entry.merkleRoot),
time: entry.time,
mediantime: mtp,
bits: entry.bits,
difficulty: toDifficulty(entry.bits),
chainwork: entry.chainwork.toString('hex', 64),
previousblockhash: entry.prevBlock !== encoding.NULL_HASH
? encoding.revHex(entry.prevBlock)
? util.revHex(entry.prevBlock)
: null,
nextblockhash: next ? encoding.revHex(next) : null
nextblockhash: next ? util.revHex(next) : null
};
}
@ -2735,7 +2735,7 @@ class RPC extends RPCBase {
height: entry.height,
version: entry.version,
versionHex: hex32(entry.version),
merkleroot: encoding.revHex(entry.merkleRoot),
merkleroot: util.revHex(entry.merkleRoot),
coinbase: block.txs[0].inputs[0].script.toJSON(),
tx: txs,
time: entry.time,
@ -2744,9 +2744,9 @@ class RPC extends RPCBase {
difficulty: toDifficulty(entry.bits),
chainwork: entry.chainwork.toString('hex', 64),
previousblockhash: entry.prevBlock !== encoding.NULL_HASH
? encoding.revHex(entry.prevBlock)
? util.revHex(entry.prevBlock)
: null,
nextblockhash: next ? encoding.revHex(next) : null
nextblockhash: next ? util.revHex(next) : null
};
}
@ -2765,7 +2765,7 @@ class RPC extends RPCBase {
ancestorcount: this.mempool.countAncestors(entry),
ancestorsize: 0,
ancestorfees: 0,
depends: this.mempool.getDepends(entry.tx).map(encoding.revHex)
depends: this.mempool.getDepends(entry.tx).map(util.revHex)
};
}
}

View File

@ -10,6 +10,7 @@
const assert = require('assert');
const hash256 = require('bcrypto/lib/hash256');
const bio = require('bufio');
const util = require('../utils/util');
const InvItem = require('./invitem');
const consensus = require('../protocol/consensus');
const {encoding} = bio;
@ -93,8 +94,8 @@ class AbstractBlock {
assert((json.nonce >>> 0) === json.nonce);
this.version = json.version;
this.prevBlock = encoding.revHex(json.prevBlock);
this.merkleRoot = encoding.revHex(json.merkleRoot);
this.prevBlock = util.revHex(json.prevBlock);
this.merkleRoot = util.revHex(json.merkleRoot);
this.time = json.time;
this.bits = json.bits;
this.nonce = json.nonce;
@ -244,7 +245,7 @@ class AbstractBlock {
*/
rhash() {
return encoding.revHex(this.hash('hex'));
return util.revHex(this.hash('hex'));
}
/**

View File

@ -540,10 +540,10 @@ class Block extends AbstractBlock {
virtualSize: this.getVirtualSize(),
date: util.date(this.time),
version: this.version.toString(16),
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
commitmentHash: commitmentHash
? encoding.revHex(commitmentHash)
? util.revHex(commitmentHash)
: null,
time: this.time,
bits: this.bits,
@ -583,8 +583,8 @@ class Block extends AbstractBlock {
height: height,
depth: depth,
version: this.version,
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce,

View File

@ -9,6 +9,7 @@
const assert = require('assert');
const bio = require('bufio');
const util = require('../utils/util');
const Amount = require('../btc/amount');
const Output = require('./output');
const Network = require('../protocol/network');
@ -184,7 +185,7 @@ class Coin extends Output {
*/
rhash() {
return encoding.revHex(this.hash);
return util.revHex(this.hash);
}
/**
@ -209,7 +210,7 @@ class Coin extends Output {
value: Amount.btc(this.value),
script: this.script,
coinbase: this.coinbase,
hash: this.hash ? encoding.revHex(this.hash) : null,
hash: this.hash ? util.revHex(this.hash) : null,
index: this.index,
address: this.getAddress()
};
@ -280,7 +281,7 @@ class Coin extends Output {
assert(typeof json.hash === 'string', 'Hash must be a string.');
assert(json.hash.length === 64, 'Hash must be a string.');
assert((json.index >>> 0) === json.index, 'Index must be a uint32.');
this.hash = encoding.revHex(json.hash);
this.hash = util.revHex(json.hash);
this.index = json.index;
}

View File

@ -10,7 +10,6 @@
const bio = require('bufio');
const util = require('../utils/util');
const AbstractBlock = require('./abstractblock');
const {encoding} = bio;
/**
* Headers
@ -199,8 +198,8 @@ class Headers extends AbstractBlock {
hash: this.rhash(),
height: height,
version: this.version,
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce
@ -252,8 +251,8 @@ class Headers extends AbstractBlock {
height: height != null ? height : -1,
date: util.date(this.time),
version: this.version.toString(16),
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce

View File

@ -8,7 +8,7 @@
'use strict';
const bio = require('bufio');
const {encoding} = bio;
const util = require('../utils/util');
/**
* Inv Item
@ -152,7 +152,7 @@ class InvItem {
*/
rhash() {
return encoding.revHex(this.hash);
return util.revHex(this.hash);
}
}

View File

@ -306,8 +306,8 @@ class MerkleBlock extends AbstractBlock {
height: height != null ? height : -1,
date: util.date(this.time),
version: this.version.toString(16),
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce,
@ -448,14 +448,14 @@ class MerkleBlock extends AbstractBlock {
hash: this.rhash(),
height: height,
version: this.version,
prevBlock: encoding.revHex(this.prevBlock),
merkleRoot: encoding.revHex(this.merkleRoot),
prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot),
time: this.time,
bits: this.bits,
nonce: this.nonce,
totalTX: this.totalTX,
hashes: this.hashes.map((hash) => {
return encoding.revHex(hash.toString('hex'));
return util.revHex(hash.toString('hex'));
}),
flags: this.flags.toString('hex')
};
@ -476,7 +476,7 @@ class MerkleBlock extends AbstractBlock {
this.parseJSON(json);
for (let hash of json.hashes) {
hash = encoding.revHex(hash);
hash = util.revHex(hash);
this.hashes.push(Buffer.from(hash, 'hex'));
}

View File

@ -8,6 +8,7 @@
const assert = require('assert');
const bio = require('bufio');
const util = require('../utils/util');
const {encoding} = bio;
/**
@ -120,7 +121,7 @@ class Outpoint {
*/
rhash() {
return encoding.revHex(this.hash);
return util.revHex(this.hash);
}
/**
@ -247,7 +248,7 @@ class Outpoint {
assert(json, 'Outpoint data is required.');
assert(typeof json.hash === 'string', 'Hash must be a string.');
assert((json.index >>> 0) === json.index, 'Index must be a uint32.');
this.hash = encoding.revHex(json.hash);
this.hash = util.revHex(json.hash);
this.index = json.index;
return this;
}
@ -262,7 +263,7 @@ class Outpoint {
toJSON() {
return {
hash: encoding.revHex(this.hash),
hash: util.revHex(this.hash),
index: this.index
};
}

View File

@ -2012,7 +2012,7 @@ class TX {
*/
rhash() {
return encoding.revHex(this.hash('hex'));
return util.revHex(this.hash('hex'));
}
/**
@ -2021,7 +2021,7 @@ class TX {
*/
rwhash() {
return encoding.revHex(this.witnessHash('hex'));
return util.revHex(this.witnessHash('hex'));
}
/**
@ -2089,7 +2089,7 @@ class TX {
if (entry) {
height = entry.height;
block = encoding.revHex(entry.hash);
block = util.revHex(entry.hash);
time = entry.time;
date = util.date(time);
}
@ -2157,7 +2157,7 @@ class TX {
if (entry) {
height = entry.height;
block = encoding.revHex(entry.hash);
block = util.revHex(entry.hash);
time = entry.time;
date = util.date(time);
}

View File

@ -10,7 +10,6 @@ const assert = require('assert');
const bio = require('bufio');
const util = require('../utils/util');
const TX = require('./tx');
const {encoding} = bio;
/**
* TXMeta
@ -132,7 +131,7 @@ class TXMeta {
const data = this.tx.format(view, null, this.index);
data.mtime = this.mtime;
data.height = this.height;
data.block = this.block ? encoding.revHex(this.block) : null;
data.block = this.block ? util.revHex(this.block) : null;
data.time = this.time;
return data;
}
@ -158,7 +157,7 @@ class TXMeta {
const json = this.tx.getJSON(network, view, null, this.index);
json.mtime = this.mtime;
json.height = this.height;
json.block = this.block ? encoding.revHex(this.block) : null;
json.block = this.block ? util.revHex(this.block) : null;
json.time = this.time;
json.confirmations = 0;
@ -185,7 +184,7 @@ class TXMeta {
this.mtime = json.mtime;
this.height = json.height;
this.block = encoding.revHex(json.block);
this.block = util.revHex(json.block);
this.index = json.index;
return this;

View File

@ -14,7 +14,6 @@ const sha1 = require('bcrypto/lib/sha1');
const sha256 = require('bcrypto/lib/sha256');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
const merkle = require('bcrypto/lib/merkle');
const secp256k1 = require('bcrypto/lib/secp256k1');
const consensus = require('../protocol/consensus');
const policy = require('../protocol/policy');

View File

@ -7,6 +7,8 @@
'use strict';
const assert = require('assert');
/**
* @exports utils/util
*/

View File

@ -8,8 +8,8 @@
'use strict';
const assert = require('assert');
const {encoding} = require('bufio');
const {NodeClient} = require('bclient');
const util = require('../utils/util');
const TX = require('../primitives/tx');
const hash256 = require('bcrypto/lib/hash256');
@ -58,7 +58,7 @@ class WalletClient extends NodeClient {
async getEntry(block) {
if (typeof block === 'string')
block = encoding.revHex(block);
block = util.revHex(block);
return parseEntry(await super.getEntry(block));
}
@ -73,7 +73,7 @@ class WalletClient extends NodeClient {
async rescan(start) {
if (typeof start === 'string')
start = encoding.revHex(start);
start = util.revHex(start);
return super.rescan(start);
}

View File

@ -149,7 +149,7 @@ class BlockMeta {
*/
fromJSON(json) {
this.hash = encoding.revHex(json.hash);
this.hash = util.revHex(json.hash);
this.height = json.height;
this.time = json.time;
return this;
@ -220,7 +220,7 @@ class BlockMeta {
toJSON() {
return {
hash: encoding.revHex(this.hash),
hash: util.revHex(this.hash),
height: this.height,
time: this.time
};

View File

@ -316,7 +316,7 @@ class RPC extends RPCBase {
format('# Wallet Dump created by Bcoin %s', pkg.version),
format('# * Created on %s', time),
format('# * Best block at time of backup was %d (%s).',
tip.height, encoding.revHex(tip.hash)),
tip.height, util.revHex(tip.hash)),
format('# * File: %s', file),
''
];
@ -632,10 +632,10 @@ class RPC extends RPCBase {
return {
amount: Amount.btc(receive ? received : -sent, true),
confirmations: details.confirmations,
blockhash: details.block ? encoding.revHex(details.block) : null,
blockhash: details.block ? util.revHex(details.block) : null,
blockindex: details.index,
blocktime: details.time,
txid: encoding.revHex(details.hash),
txid: util.revHex(details.hash),
walletconflicts: [],
time: details.mtime,
timereceived: details.mtime,
@ -1063,7 +1063,7 @@ class RPC extends RPCBase {
return {
transactions: out,
lastblock: highest && highest.block
? encoding.revHex(highest.block)
? util.revHex(highest.block)
: encoding.NULL_HASH
};
}
@ -1129,10 +1129,10 @@ class RPC extends RPCBase {
label: member.path ? member.path.name : undefined,
vout: index,
confirmations: details.getDepth(),
blockhash: details.block ? encoding.revHex(details.block) : null,
blockhash: details.block ? util.revHex(details.block) : null,
blockindex: details.index,
blocktime: details.time,
txid: encoding.revHex(details.hash),
txid: util.revHex(details.hash),
walletconflicts: [],
time: details.mtime,
timereceived: details.mtime,

View File

@ -2525,9 +2525,9 @@ class Details {
const rate = this.getRate(fee);
return {
hash: encoding.revHex(this.hash),
hash: util.revHex(this.hash),
height: this.height,
block: this.block ? encoding.revHex(this.block) : null,
block: this.block ? util.revHex(this.block) : null,
time: this.time,
mtime: this.mtime,
date: util.date(this.time),
@ -2723,10 +2723,10 @@ class BlockRecord {
toJSON() {
return {
hash: encoding.revHex(this.hash),
hash: util.revHex(this.hash),
height: this.height,
time: this.time,
hashes: this.toArray().map(encoding.revHex)
hashes: this.toArray().map(util.revHex)
};
}

View File

@ -17,6 +17,7 @@ const BDB = require('bdb');
const Logger = require('blgr');
const ccmp = require('bcrypto/lib/ccmp');
const aes = require('bcrypto/lib/aes');
const util = require('../utils/util');
const Network = require('../protocol/network');
const Path = require('./path');
const common = require('./common');
@ -1748,7 +1749,7 @@ class WalletDB extends EventEmitter {
if (total > 0) {
this.logger.info('Connected WalletDB block %s (tx=%d).',
encoding.revHex(tip.hash), total);
util.revHex(tip.hash), total);
}
return total;
@ -1816,7 +1817,7 @@ class WalletDB extends EventEmitter {
await this.setTip(prev);
this.logger.warning('Disconnected wallet block %s (tx=%d).',
encoding.revHex(tip.hash), total);
util.revHex(tip.hash), total);
return total;
}

View File

@ -20,6 +20,7 @@ const BDB = require('bdb');
const hash256 = require('bcrypto/lib/hash256');
const BN = require('bcrypto/lib/bn');
const bio = require('bufio');
const util = require('../lib/utils/util');
const OldCoins = require('./coins/coins');
const OldUndoCoins = require('./coins/undocoins');
const CoinEntry = require('../lib/coins/coinentry');
@ -131,7 +132,7 @@ async function reserializeUndo(hash) {
tip = await getEntry(hash);
console.log('Reserializing undo coins from tip %s.',
encoding.revHex(tip.hash));
util.revHex(tip.hash));
let batch = db.batch();
let pruning = false;
@ -142,7 +143,7 @@ async function reserializeUndo(hash) {
if (shouldPrune) {
if (tip.height < height - 288) {
console.log('Pruning block %s (%d).',
encoding.revHex(tip.hash), tip.height);
util.revHex(tip.hash), tip.height);
batch.del(pair('u', tip.hash));
batch.del(pair('b', tip.hash));
@ -185,7 +186,7 @@ async function reserializeUndo(hash) {
console.log(
'Reserializing coins for block %s (%d).',
encoding.revHex(tip.hash), tip.height);
util.revHex(tip.hash), tip.height);
for (let i = block.txs.length - 1; i >= 1; i--) {
const tx = block.txs[i];
@ -313,7 +314,7 @@ async function reserializeCoins(hash) {
start = false;
}
console.log('Reserializing coins from %s.', encoding.revHex(hash));
console.log('Reserializing coins from %s.', util.revHex(hash));
let batch = db.batch();
let total = 0;
@ -388,7 +389,7 @@ async function reserializeEntries(hash) {
assert(item.key.equals(pair('e', hash)));
}
console.log('Reserializing entries from %s.', encoding.revHex(hash));
console.log('Reserializing entries from %s.', util.revHex(hash));
const tip = await getTipHash();

View File

@ -5,6 +5,7 @@ const BDB = require('bdb');
const bio = require('bufio');
const hash256 = require('bcrypto/lib/hash256');
const BN = require('bcrypto/lib/bn');
const util = require('../lib/utils/util');
const {encoding} = bio;
const DUMMY = Buffer.from([0]);
@ -114,7 +115,7 @@ async function indexTips() {
for (let i = 0; i < tips.length; i++) {
const tip = tips[i];
console.log('Indexing chain tip: %s.', encoding.revHex(tip));
console.log('Indexing chain tip: %s.', util.revHex(tip));
batch.put(pair('p', tip), DUMMY);
}
}

View File

@ -5,7 +5,6 @@
const assert = require('./util/assert');
const consensus = require('../lib/protocol/consensus');
const {encoding} = require('bufio');
const Coin = require('../lib/primitives/coin');
const Script = require('../lib/script/script');
const Chain = require('../lib/blockchain/chain');

View File

@ -4,10 +4,10 @@
'use strict';
const bio = require('bufio');
const util = require('../lib/utils/util');
const Input = require('../lib/primitives/input');
const assert = require('./util/assert');
const common = require('./util/common');
const {encoding} = bio;
// Take input rawbytes from the raw data format
// p2pkh
@ -236,7 +236,7 @@ describe('Input', function() {
const inputs = test.inputs.map((prevout, i) => {
const input = Input.fromOptions({
prevout: {
hash: encoding.revHex(prevout.txId),
hash: util.revHex(prevout.txId),
index: prevout.vout
}
});

View File

@ -4,7 +4,6 @@
'use strict';
const assert = require('./util/assert');
const {encoding} = require('bufio');
const random = require('bcrypto/lib/random');
const MempoolEntry = require('../lib/mempool/mempoolentry');
const Mempool = require('../lib/mempool/mempool');

View File

@ -7,6 +7,7 @@ const {inspect} = require('util');
const {encoding} = require('bufio');
const assert = require('./util/assert');
const random = require('bcrypto/lib/random');
const util = require('../lib/utils/util');
const consensus = require('../lib/protocol/consensus');
const TX = require('../lib/primitives/tx');
const Output = require('../lib/primitives/output');
@ -65,7 +66,7 @@ function parseTXTest(data) {
const view = new CoinView();
for (const [txid, index, str, amount] of coins) {
const hash = encoding.revHex(txid);
const hash = util.revHex(txid);
const script = Script.fromString(str);
const value = parseInt(amount || '0', 10);
@ -102,7 +103,7 @@ function parseSighashTest(data) {
const tx = TX.fromRaw(txHex, 'hex');
const script = Script.fromRaw(scriptHex, 'hex');
const expected = encoding.revHex(hash);
const expected = util.revHex(hash);
let hex = type & 3;