Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions contracts/split/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -272,7 +272,7 @@ pub fn invoice_archived(env: &Env, invoice_id: u64) {
symbol_short!("archived"),
invoice_id,
),
(event_seq,),
(invoice_id, event_seq),
);
}

Expand Down Expand Up @@ -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<Address>) {
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),
);
}

Expand Down
11 changes: 9 additions & 2 deletions contracts/split/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -1574,7 +1581,7 @@ impl InvoiceStatus {
6 => InvoiceStatus::PartiallyReleased,
7 => InvoiceStatus::Finalised,
8 => InvoiceStatus::Deleted,
_ => InvoiceStatus::Pending,
_ => panic!("unknown InvoiceStatus byte: {v}"),
}
}
}
Expand Down