Bitcoind: Use mempool as address index when doing address prefix search.
This commit is contained in:
parent
38d534caee
commit
905ddbb363
@ -10,4 +10,5 @@ export interface AbstractBitcoinApi {
|
|||||||
$getBlock(hash: string): Promise<IEsploraApi.Block>;
|
$getBlock(hash: string): Promise<IEsploraApi.Block>;
|
||||||
$getAddress(address: string): Promise<IEsploraApi.Address>;
|
$getAddress(address: string): Promise<IEsploraApi.Address>;
|
||||||
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
||||||
|
$getAddressPrefix(prefix: string): string[];
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,22 @@ class BitcoinApi implements AbstractBitcoinApi {
|
|||||||
return this.bitcoindClient.getRawMemPool();
|
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> {
|
protected async $convertTransaction(transaction: IBitcoinApi.Transaction, addPrevout: boolean): Promise<IEsploraApi.Transaction> {
|
||||||
let esploraTransaction: IEsploraApi.Transaction = {
|
let esploraTransaction: IEsploraApi.Transaction = {
|
||||||
txid: transaction.txid,
|
txid: transaction.txid,
|
||||||
|
@ -50,6 +50,9 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$getAddressPrefix(prefix: string): string[] {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ElectrsApi;
|
export default ElectrsApi;
|
||||||
|
@ -660,7 +660,12 @@ class Routes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getAddressPrefix(req: Request, res: Response) {
|
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) {
|
public getTransactionOutspends(req: Request, res: Response) {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
"severity": "warn"
|
"severity": "warn"
|
||||||
},
|
},
|
||||||
"eofline": true,
|
"eofline": true,
|
||||||
"forin": true,
|
"forin": false,
|
||||||
"import-blacklist": [
|
"import-blacklist": [
|
||||||
true,
|
true,
|
||||||
"rxjs",
|
"rxjs",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user