Don't only look last output for commitments

This commit is contained in:
NicolasCantu 2025-04-08 15:59:49 +02:00 committed by Nicolas Cantu
parent 9ffd5229fc
commit a433400dd4

View File

@ -546,18 +546,19 @@ pub fn check_tx_for_process_updates(tx: &Transaction) -> anyhow::Result<OutPoint
let process_tip = if let Ok(tip) = process.get_process_tip() { tip } else { continue };
for input in &tx.input {
if process_tip == input.previous_output {
log::debug!("Find a match for process tip {}", process_tip);
log::debug!("Found a match for process tip {}", process_tip);
// This transaction commits a new state
let last_output = &tx.output.get(tx.output.len()-1).unwrap().script_pubkey;
// Look for the op_return
let op_return_outputs: Vec<_> = tx.output.iter().filter(|o| o.script_pubkey.is_op_return()).collect();
if op_return_outputs.len() != 1 {
return Err(anyhow::Error::msg("Transaction must contain exactly one op_return output"));
}
let mut state_id = [0u8; 32];
if last_output.is_op_return() {
if last_output.as_bytes().len() != 34 {
let data = &op_return_outputs.into_iter().next().unwrap().script_pubkey.as_bytes()[2..];
if data.len() != 32 {
return Err(anyhow::Error::msg("commited data is not 32B long"));
}
state_id.clone_from_slice(&last_output.as_bytes()[2..]);
} else {
return Err(anyhow::Error::msg("last output must be op_return"));
}
state_id.clone_from_slice(data);
// Check if we know about the commited state
let new_state: ProcessState;
if let Ok(commited_state) = process.get_state_for_id(&state_id) {