addrindexer: minor.
* allocate one buffer istead of concat. * return results instead of mutating array.
This commit is contained in:
parent
0f6ef910b0
commit
cdca51a844
@ -211,8 +211,6 @@ class AddrIndexer extends Indexer {
|
||||
*/
|
||||
|
||||
async getHashesByAddress(addr, options = {}) {
|
||||
const txs = [];
|
||||
|
||||
const {after, reverse} = options;
|
||||
let {limit} = options;
|
||||
|
||||
@ -230,7 +228,7 @@ class AddrIndexer extends Indexer {
|
||||
reverse,
|
||||
parse: (key) => {
|
||||
const [,, height, index] = layout.A.decode(key);
|
||||
txs.push([height, index]);
|
||||
return [height, index];
|
||||
}
|
||||
};
|
||||
|
||||
@ -265,8 +263,7 @@ class AddrIndexer extends Indexer {
|
||||
opts.lte = layout.A.max(prefix, hash);
|
||||
}
|
||||
|
||||
await this.db.keys(opts);
|
||||
|
||||
const txs = await this.db.keys(opts);
|
||||
const hashes = [];
|
||||
|
||||
for (const [height, index] of txs)
|
||||
|
||||
@ -44,10 +44,15 @@ class AddrIndexer {
|
||||
if (prefix < 0)
|
||||
return null;
|
||||
|
||||
const raw = Buffer.allocUnsafe(1);
|
||||
raw.writeUInt8(prefix);
|
||||
const hash = addr.getHash();
|
||||
const size = hash.length + 1;
|
||||
const raw = Buffer.allocUnsafe(size);
|
||||
|
||||
return Buffer.concat([raw, addr.getHash()]);
|
||||
let written = raw.writeUInt8(prefix);
|
||||
written += hash.copy(raw, 1);
|
||||
assert(written === size);
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user