diff --git a/contracts/split/src/events.rs b/contracts/split/src/events.rs index a4df1a2..76416aa 100644 --- a/contracts/split/src/events.rs +++ b/contracts/split/src/events.rs @@ -263,7 +263,7 @@ pub fn recipients_rebalanced( /// Emitted when an invoice is archived to instance storage. /// Topics: (split, archived, invoice_id) -/// Data: () +/// Data: (invoice_id, event_seq) pub fn invoice_archived(env: &Env, invoice_id: u64) { let event_seq = next_seq(env, invoice_id); env.events().publish( @@ -272,7 +272,7 @@ pub fn invoice_archived(env: &Env, invoice_id: u64) { symbol_short!("archived"), invoice_id, ), - (event_seq,), + (invoice_id, event_seq), ); } @@ -302,15 +302,16 @@ pub fn delegate_revoked(env: &Env, invoice_id: u64) { /// Emitted when an invoice is partially released. /// Topics: (split, part_rel, invoice_id) -/// Data: recipients +/// Data: (recipients, event_seq) pub fn invoice_partially_released(env: &Env, invoice_id: u64, recipients: &Vec
) { + let event_seq = next_seq(env, invoice_id); env.events().publish( ( symbol_short!("split"), symbol_short!("part_rel"), invoice_id, ), - recipients.clone(), + (recipients.clone(), event_seq), ); } diff --git a/contracts/split/src/types.rs b/contracts/split/src/types.rs index 3e12bfa..ccc2419 100644 --- a/contracts/split/src/types.rs +++ b/contracts/split/src/types.rs @@ -1236,6 +1236,11 @@ impl Invoice { ) -> Self { let bytes = &compact.data; + // Guard: require at least 25 bytes (1 status + 16 funded + 8 deadline). + if bytes.len() < 25 { + panic!("from_compact: data too short"); + } + // Unpack status (1 byte) let status_byte = bytes.get(0).expect("from_compact: byte 0 (status) missing"); let status = match status_byte { @@ -1563,9 +1568,11 @@ impl InvoiceStatus { } } - /// Decode from a single byte. Unknown values map to Pending. + /// Decode from a single byte. Unknown byte values panic to prevent + /// silent data corruption from masked migration errors (#616). pub fn from_u8(v: u8) -> Self { match v { + 0 => InvoiceStatus::Pending, 1 => InvoiceStatus::Released, 2 => InvoiceStatus::Refunded, 3 => InvoiceStatus::Cancelled, @@ -1574,7 +1581,7 @@ impl InvoiceStatus { 6 => InvoiceStatus::PartiallyReleased, 7 => InvoiceStatus::Finalised, 8 => InvoiceStatus::Deleted, - _ => InvoiceStatus::Pending, + _ => panic!("unknown InvoiceStatus byte: {v}"), } } }