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 = {}) {
|
async getHashesByAddress(addr, options = {}) {
|
||||||
const txs = [];
|
|
||||||
|
|
||||||
const {after, reverse} = options;
|
const {after, reverse} = options;
|
||||||
let {limit} = options;
|
let {limit} = options;
|
||||||
|
|
||||||
@ -230,7 +228,7 @@ class AddrIndexer extends Indexer {
|
|||||||
reverse,
|
reverse,
|
||||||
parse: (key) => {
|
parse: (key) => {
|
||||||
const [,, height, index] = layout.A.decode(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);
|
opts.lte = layout.A.max(prefix, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.db.keys(opts);
|
const txs = await this.db.keys(opts);
|
||||||
|
|
||||||
const hashes = [];
|
const hashes = [];
|
||||||
|
|
||||||
for (const [height, index] of txs)
|
for (const [height, index] of txs)
|
||||||
|
|||||||
@ -44,10 +44,15 @@ class AddrIndexer {
|
|||||||
if (prefix < 0)
|
if (prefix < 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
const raw = Buffer.allocUnsafe(1);
|
const hash = addr.getHash();
|
||||||
raw.writeUInt8(prefix);
|
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