@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user