Bitcoind: Use mempool as address index when doing address prefix search.

This commit is contained in:
softsimon 2021-01-11 01:51:57 +07:00
parent 38d534caee
commit 905ddbb363
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
5 changed files with 27 additions and 2 deletions

View File

@ -10,4 +10,5 @@ export interface AbstractBitcoinApi {
$getBlock(hash: string): Promise<IEsploraApi.Block>;
$getAddress(address: string): Promise<IEsploraApi.Address>;
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
$getAddressPrefix(prefix: string): string[];
}

View File

@ -90,6 +90,22 @@ class BitcoinApi implements AbstractBitcoinApi {
return this.bitcoindClient.getRawMemPool();
}
$getAddressPrefix(prefix: string): string[] {
const found: string[] = [];
const mp = mempool.getMempool();
for (const tx in mp) {
for (const vout of mp[tx].vout) {
if (vout.scriptpubkey_address.indexOf(prefix) === 0) {
found.push(vout.scriptpubkey_address);
if (found.length >= 10) {
return found;
}
}
}
}
return found;
}
protected async $convertTransaction(transaction: IBitcoinApi.Transaction, addPrevout: boolean): Promise<IEsploraApi.Transaction> {
let esploraTransaction: IEsploraApi.Transaction = {
txid: transaction.txid,

View File

@ -50,6 +50,9 @@ class ElectrsApi implements AbstractBitcoinApi {
.then((response) => response.data);
}
$getAddressPrefix(prefix: string): string[] {
throw new Error('Method not implemented.');
}
}
export default ElectrsApi;

View File

@ -660,7 +660,12 @@ class Routes {
}
public async getAddressPrefix(req: Request, res: Response) {
res.status(501).send('Not implemented');
try {
const blockHash = await bitcoinApi.$getAddressPrefix(req.params.prefix);
res.send(blockHash);
} catch (e) {
res.status(500).send(e.message || e);
}
}
public getTransactionOutspends(req: Request, res: Response) {

View File

@ -12,7 +12,7 @@
"severity": "warn"
},
"eofline": true,
"forin": true,
"forin": false,
"import-blacklist": [
true,
"rxjs",