mirror of
https://github.com/mempool/mempool.git
synced 2025-02-25 15:10:12 +01:00
Merge pull request #1147 from mempool/simon/gettxout
Utilize gettxout to display spent/unspent
This commit is contained in:
commit
4133bf31c6
6 changed files with 33 additions and 6 deletions
|
@ -12,6 +12,7 @@ export interface AbstractBitcoinApi {
|
||||||
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
||||||
$getAddressPrefix(prefix: string): string[];
|
$getAddressPrefix(prefix: string): string[];
|
||||||
$sendRawTransaction(rawTransaction: string): Promise<string>;
|
$sendRawTransaction(rawTransaction: string): Promise<string>;
|
||||||
|
$getOutspends(txId: string): Promise<IEsploraApi.Outspend[]>;
|
||||||
}
|
}
|
||||||
export interface BitcoinRpcCredentials {
|
export interface BitcoinRpcCredentials {
|
||||||
host: string;
|
host: string;
|
||||||
|
|
|
@ -102,6 +102,18 @@ class BitcoinApi implements AbstractBitcoinApi {
|
||||||
return this.bitcoindClient.sendRawTransaction(rawTransaction);
|
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> {
|
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,
|
||||||
|
|
|
@ -113,9 +113,9 @@ export namespace IEsploraApi {
|
||||||
|
|
||||||
export interface Outspend {
|
export interface Outspend {
|
||||||
spent: boolean;
|
spent: boolean;
|
||||||
txid: string;
|
txid?: string;
|
||||||
vin: number;
|
vin?: number;
|
||||||
status: Status;
|
status?: Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Asset {
|
export interface Asset {
|
||||||
|
|
|
@ -60,6 +60,10 @@ class ElectrsApi implements AbstractBitcoinApi {
|
||||||
$sendRawTransaction(rawTransaction: string): Promise<string> {
|
$sendRawTransaction(rawTransaction: string): Promise<string> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$getOutspends(): Promise<IEsploraApi.Outspend[]> {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ElectrsApi;
|
export default ElectrsApi;
|
||||||
|
|
|
@ -716,8 +716,13 @@ class Routes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTransactionOutspends(req: Request, res: Response) {
|
public async getTransactionOutspends(req: Request, res: Response) {
|
||||||
res.status(501).send('Not implemented');
|
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) {
|
public getDifficultyChange(req: Request, res: Response) {
|
||||||
|
|
|
@ -189,9 +189,14 @@
|
||||||
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
|
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
|
||||||
</span>
|
</span>
|
||||||
<ng-template #spent>
|
<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>
|
<fa-icon [icon]="['fas', 'arrow-alt-circle-right']" [fixedWidth]="true"></fa-icon>
|
||||||
</a>
|
</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>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue