I’m currently in the process of constructing a predicate that utilizes the tx_id() (transaction identifier), and during the developmental stage, I have implemented it successfully within a script. However, when I integrate the predicate into the system, it appears that the tx_id() is yielding a different value that remains unidentified.
By substituting the tx_id() within the predicate with a hardcoded value encoded in b256, I am able to successfully validate all the conditions.
fn main() -> bool {
// Works with I turn the predicate into a script but not works on predicate
// let tx_id_hash = tx_id();
// Hardcode value that works on predicate
let tx_id_hash = 0x0000000000000000000000000000000000000000000000000000000000000001;
let tx_hash = b256_to_ascii_bytes(tx_id_hash).sha256();
return check_signature(0, tx_hash);
}
fn check_signature(index: u64, tx_hash: b256) -> u64 {
// If the index is bigger than the witness count
// return false because the signature does not exist
// and if we try to access it, it will panic
if (index >= tx_witnesses_count()) {
return 0;
}
// Get the singature from the witness field
let signature = tx_witness_data::<B512>(index);
// Check if the signature is valid and if the address
// is one of the signers list
if let Result::Ok(pub_key_sig) = ec_recover_address(signature, tx_hash) {
let address = pub_key_sig.value;
if (address == signer_configurable {
log(address);
return 1;
}
}
return 0;
}