display transactions with vins/vouts

This commit is contained in:
Darren Nelsen 2017-07-28 17:05:25 -04:00
parent 6f99a2f881
commit 583139ca2c
4 changed files with 65 additions and 9 deletions

View File

@ -1,3 +1,48 @@
<div>
Put Transactions here
<div *ngFor="let tx of transactions.txs" style="border: 1px solid purple">
<p>{{ tx.txid }}</p>
<div [hidden]="!tx.firstSeenTs">
<span translate>first seen at</span>
<time>{{tx.firstSeenTs * 1000 | date:'medium'}}</time>
</div>
<div [hidden]="!tx.blocktime && tx.firstSeenTs">
<span translate>mined</span>
<time>{{tx.time * 1000 | date:'medium'}}</time>
</div>
<div [hidden]="!tx.isCoinBase">
<div *ngFor="let vin of tx.vin">
<div>
<span translate>No Inputs (Newly Generated Coins)</span>
</div>
</div>
<div>
&gt;
</div>
<div *ngFor="let vout of tx.vout">
<div>
<p>{{ getAddress(vout) }} {{ vout.value + ' BTC' }} <span [hidden]="!vout.spentTxId">(S)</span><span [hidden]="vout.spentTxId">(U)</span></p>
</div>
</div>
</div>
<div [hidden]="tx.isCoinBase">
<div *ngFor="let vin of tx.vin">
<div>{{ vin.addr }}</div>
<p>{{ vin.value + ' BTC' }}</p>
</div>
<div>
&gt;
</div>
<div *ngFor="let vout of tx.vout">
<div>
<p>{{ getAddress(vout) }} {{ vout.value + ' BTC' }} <span [hidden]="!vout.spentTxId">(S)</span><span [hidden]="vout.spentTxId">(U)</span></p>
</div>
</div>
</div>
</div>
</div>

View File

@ -15,24 +15,36 @@ import { Http } from '@angular/http';
export class TransactionsComponent {
public loading: boolean = true;
@Input() private blockHash: string;
@Input() public blockHash: string;
public transactions: any = [];
constructor(private http: Http) {
}
private ngOnInit(): void {
let apiPrefix: string = 'http://localhost:3001/insight-api/';
this.http.get(apiPrefix + 'txs/' + this.blockHash).subscribe(
this.http.get(apiPrefix + 'txs?block=' + this.blockHash).subscribe(
(data) => {
console.log('hey, got data');
this.transactions = JSON.parse(data['_body']);
this.loading = false;
this.transactions.txs.forEach((tx) => {
console.log('tx is', tx);
});
},
(err) => {
console.log('err is', err);
},
() => {
this.loading = false;
}
);
}
public getAddress(vout: any): string {
if (vout.scriptPubKey && vout.scriptPubKey.addresses) {
return vout.scriptPubKey.addresses[0];
} else {
return 'Unparsed address';
}
}
}

View File

@ -33,7 +33,7 @@
<p>Next Block <a (click)="goToNextBlock()">{{ block.height + 1 }}</a></p>
<h3>Transactions</h3>
<transactions blockHash="block.hash"></transactions>
<transactions [blockHash]="block.hash"></transactions>
</div>
<div *ngIf="loading">
<p>Loading...</p>

View File

@ -32,11 +32,10 @@ export class BlockDetailPage {
this.http.get(apiPrefix + 'block/' + this.blockHash).subscribe(
(data) => {
this.block = JSON.parse(data['_body']);
this.loading = false;
},
(err) => {
console.log('err is', err);
},
() => {
this.loading = false;
}
);