Don't only look last output for commitments
This commit is contained in:
parent
9ffd5229fc
commit
a433400dd4
@ -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 };
|
let process_tip = if let Ok(tip) = process.get_process_tip() { tip } else { continue };
|
||||||
for input in &tx.input {
|
for input in &tx.input {
|
||||||
if process_tip == input.previous_output {
|
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
|
// 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 mut state_id = [0u8; 32];
|
let op_return_outputs: Vec<_> = tx.output.iter().filter(|o| o.script_pubkey.is_op_return()).collect();
|
||||||
if last_output.is_op_return() {
|
if op_return_outputs.len() != 1 {
|
||||||
if last_output.as_bytes().len() != 34 {
|
return Err(anyhow::Error::msg("Transaction must contain exactly one op_return output"));
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
let mut state_id = [0u8; 32];
|
||||||
|
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(data);
|
||||||
// Check if we know about the commited state
|
// Check if we know about the commited state
|
||||||
let new_state: ProcessState;
|
let new_state: ProcessState;
|
||||||
if let Ok(commited_state) = process.get_state_for_id(&state_id) {
|
if let Ok(commited_state) = process.get_state_for_id(&state_id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user