addrindexer: minor.

* allocate one buffer istead of concat.
* return results instead of mutating array.
This commit is contained in:
Nodar Chkuaselidze 2019-05-17 20:35:21 +04:00
parent 0f6ef910b0
commit cdca51a844
No known key found for this signature in database
GPG Key ID: 8E1B4DC29040BD90
2 changed files with 10 additions and 8 deletions

View File

@ -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)

View File

@ -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;
}
/**