Utilize gettxout to display spent/outspent

fixes #1088
This commit is contained in:
softsimon
2022-01-15 22:09:04 +04:00
parent 6e951f0c04
commit 3450ff97ff
6 changed files with 33 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ export interface AbstractBitcoinApi {
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
$getAddressPrefix(prefix: string): string[];
$sendRawTransaction(rawTransaction: string): Promise<string>;
$getOutspends(txId: string): Promise<IEsploraApi.Outspend[]>;
}
export interface BitcoinRpcCredentials {
host: string;

View File

@@ -102,6 +102,18 @@ class BitcoinApi implements AbstractBitcoinApi {
return this.bitcoindClient.sendRawTransaction(rawTransaction);
}
async $getOutspends(txId: string): Promise<IEsploraApi.Outspend[]> {
const outSpends: IEsploraApi.Outspend[] = [];
const tx = await this.$getRawTransaction(txId, true, false);
for (let i = 0; i < tx.vout.length; i++) {
const txOut = await this.bitcoindClient.getTxOut(txId, i);
outSpends.push({
spent: txOut === null,
});
}
return outSpends;
}
protected async $convertTransaction(transaction: IBitcoinApi.Transaction, addPrevout: boolean): Promise<IEsploraApi.Transaction> {
let esploraTransaction: IEsploraApi.Transaction = {
txid: transaction.txid,

View File

@@ -113,9 +113,9 @@ export namespace IEsploraApi {
export interface Outspend {
spent: boolean;
txid: string;
vin: number;
status: Status;
txid?: string;
vin?: number;
status?: Status;
}
export interface Asset {

View File

@@ -60,6 +60,10 @@ class ElectrsApi implements AbstractBitcoinApi {
$sendRawTransaction(rawTransaction: string): Promise<string> {
throw new Error('Method not implemented.');
}
$getOutspends(): Promise<IEsploraApi.Outspend[]> {
throw new Error('Method not implemented.');
}
}
export default ElectrsApi;