@@ -108,24 +108,22 @@ export class Transaction {
|
||||
}
|
||||
|
||||
public isCoinbase(): boolean {
|
||||
// TODO: This definitely needs checking.
|
||||
// TODO: You're a moron Jim. outpointTransactionHash is 0x00 x 32 for Coinbase.
|
||||
|
||||
// A coinbase transaction MUST only have one input.
|
||||
if (this.getInputs().length > 1) {
|
||||
// A coinbase transaction MUST only have one input
|
||||
if (this.getInputs().length !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the input's unlocking bytecode.
|
||||
const unlockingBytecode = this.getInputs()[0].unlockingBytecode;
|
||||
const input = this.getInputs()[0];
|
||||
|
||||
// Get the firt byte.
|
||||
const firstByte = unlockingBytecode[0];
|
||||
// Check if the outpoint transaction hash is all zeros (32 bytes of 0x00)
|
||||
const isOutpointZero = input.outpointTransactionHash.every(
|
||||
(byte) => byte === 0x00
|
||||
);
|
||||
|
||||
if (firstByte >= 0x01 && firstByte <= 0x4b) {
|
||||
return true;
|
||||
}
|
||||
// Check if the outpoint index is 0xFFFFFFFF (or -1 in signed 32-bit integer representation)
|
||||
const isOutpointIndexMax = input.outpointIndex === 0xffffffff;
|
||||
|
||||
return false;
|
||||
// Both conditions must be true for a coinbase transaction
|
||||
return isOutpointZero && isOutpointIndexMax;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,21 +81,15 @@ export class BlockchainLocal implements IBlockchain {
|
||||
const utxoSet = this.deriveUtxoSet();
|
||||
|
||||
if (!opts.skipValidation) {
|
||||
console.log('utxoSet', utxoSet);
|
||||
|
||||
// Find the source outputs from our UTXO set so that we can make sure the transaction is valid.
|
||||
const sourceOutputs = tx.getInputs().map((input) => {
|
||||
const utxoId = `${binToHex(input.outpointTransactionHash)}:${
|
||||
input.outpointIndex
|
||||
}`;
|
||||
|
||||
console.log(utxoId);
|
||||
|
||||
return utxoSet[utxoId];
|
||||
});
|
||||
|
||||
console.log('sourceOutputs', sourceOutputs);
|
||||
|
||||
// Validate the transaction.
|
||||
BlockchainLocal.validateTransaction(tx, sourceOutputs);
|
||||
}
|
||||
@@ -333,9 +327,6 @@ export class BlockchainLocal implements IBlockchain {
|
||||
* @todo Consider moving this to Transaction Primitive. Trade-off is that it's probably big. Maybe standalone util?
|
||||
*/
|
||||
static validateTransaction(tx: Transaction, sourceOutputs: Array<Output>) {
|
||||
console.log(tx);
|
||||
console.log(sourceOutputs);
|
||||
|
||||
const virtualMachine = createVirtualMachineBCH();
|
||||
const virtualMachineResult = virtualMachine.verify({
|
||||
transaction: {
|
||||
|
||||
Reference in New Issue
Block a user