Skip to content

Commit

Permalink
display opreturn as text (#65)
Browse files Browse the repository at this point in the history
* display opretun as text

* parse opreturn

* convert opreturn to ascii
  • Loading branch information
dangershony authored Sep 9, 2022
1 parent a2232fb commit 5a435ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,22 @@ <h3>Outputs ({{transaction.outputs.length}})</h3>
<span>ScriptPubKey (HEX)</span>
<span class="breakable">{{item.scriptPubKey}}</span>
</div>
<div *ngIf="item.outputType == 'TX_NULL_DATA'">
<span>Data</span>
<span class="breakable">{{parseOpreturn(item.scriptPubKey)}}</span>
</div>
<div>
<span>Spending TX</span>
<span class="breakable">
<div *ngIf="item.spentInTransaction == null">Unspent</div>
<div *ngIf="item.spentInTransaction != null">Spent by <a
[routerLink]="['../../transaction', item.spentInTransaction]"
title="Spent">{{item.spentInTransaction}}</a></div>
<div *ngIf="item.spentInTransaction != null">
Spent by <a [routerLink]="['../../transaction', item.spentInTransaction]"
title="Spent">{{item.spentInTransaction}}</a>
</div>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
this.transaction.hasContract = true;
}


this.error = null;
} catch (e) {
this.error = e;
Expand All @@ -67,6 +68,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
});
}


async ngOnInit() {

}
Expand All @@ -78,5 +80,31 @@ export class TransactionComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {

}

parseOpreturn(data) {

// the buffer of the OP_RETURN has the first 2 char for the opcode opreturn=6a
// and the next 2 char for the pushdata opcode we sktip the first 4 chars
const dataParsed = data.substring(4);

const buffer = Uint8Array.from(dataParsed).buffer;
//return this.hex2text(buffer);
return this.hex2a(dataParsed);
}

hex2text(buffer) { // buffer is an ArrayBuffer
return [...new Uint8Array(buffer)]
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}

hex2a(hexx) {
var hex = hexx.toString();//force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}

}

0 comments on commit 5a435ac

Please sign in to comment.