Utilize gettxout to display spent/outspent

fixes #1088
This commit is contained in:
softsimon 2022-01-15 22:09:04 +04:00
parent 20476e1366
commit 2a16dc5a7f
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
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;

View File

@ -716,8 +716,13 @@ class Routes {
}
}
public getTransactionOutspends(req: Request, res: Response) {
res.status(501).send('Not implemented');
public async getTransactionOutspends(req: Request, res: Response) {
try {
const result = await bitcoinApi.$getOutspends(req.params.txId);
res.json(result);
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
public getDifficultyChange(req: Request, res: Response) {

View File

@ -189,9 +189,14 @@
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
</span>
<ng-template #spent>
<a [routerLink]="['/tx/' | relativeUrl, outspends[i][vindex].txid]" class="red">
<a *ngIf="outspends[i][vindex].txid else outputNoTxId" [routerLink]="['/tx/' | relativeUrl, outspends[i][vindex].txid]" class="red">
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
</a>
<ng-template #outputNoTxId>
<span class="red">
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
</span>
</ng-template>
</ng-template>
</ng-template>
</td>