Merge pull request #1147 from mempool/simon/gettxout
Utilize gettxout to display spent/unspent
This commit is contained in:
		
						commit
						4133bf31c6
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -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>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user