Skip to content
Open
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
2 changes: 2 additions & 0 deletions contracts/invoice-escrow/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ pub enum Error {
InvalidDueDate = 17,
/// Caller is not on the buyer whitelist and cannot fund escrows.
NotWhitelisted = 18,
/// No fee schedule has been configured for the requested invoice category.
CategoryFeeNotFound = 19,
}
29 changes: 24 additions & 5 deletions contracts/invoice-escrow/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

use soroban_sdk::{Address, Env, Symbol};

use crate::types::EscrowStatus;
use crate::types::{EscrowStatus, InvoiceCategory};

/// Publish a lifecycle transition event carrying the new status and ledger
/// timestamp, in addition to the narrower per-action events below. Lets
/// off-chain indexers reconstruct full escrow lifecycle history/metadata
/// from a single event stream instead of correlating five separate events.
/// timestamp. Lets off-chain indexers reconstruct full escrow lifecycle
/// history from a single event stream instead of correlating multiple events.
pub fn escrow_status_changed(env: &Env, inv_id: Symbol, status: EscrowStatus, timestamp: u64) {
env.events().publish(
(Symbol::new(env, "escrow_status_changed"),),
Expand All @@ -27,6 +26,8 @@ pub fn escrow_created(
token: &Address,
inv_token: &Address,
commitment: &soroban_sdk::BytesN<32>,
category: InvoiceCategory,
effective_fee_bps: u32,
) {
env.events().publish(
(Symbol::new(env, "escrow_created"),),
Expand All @@ -40,6 +41,8 @@ pub fn escrow_created(
token,
inv_token,
commitment,
category as u32,
effective_fee_bps,
),
);
}
Expand Down Expand Up @@ -93,7 +96,7 @@ pub fn platform_fee_updated(env: &Env, old_fee_bps: u32, new_fee_bps: u32) {
);
}

/// Publish payment distributor update event with previous and new distributor addresses.
/// Publish payment distributor update event.
pub fn payment_distributor_updated(
env: &Env,
had_previous_distributor: bool,
Expand All @@ -115,3 +118,19 @@ pub fn paused_updated(env: &Env, old_paused: bool, new_paused: bool) {
(old_paused, new_paused),
);
}

/// Publish category fee schedule set/updated event.
///
/// `old_fee_bps` is `None` when this is the first time a schedule is set for
/// this category, `Some(old)` when overwriting an existing schedule.
pub fn category_fee_set(
env: &Env,
category: InvoiceCategory,
old_fee_bps: Option<u32>,
new_fee_bps: u32,
) {
env.events().publish(
(Symbol::new(env, "cat_fee_set"),),
(category as u32, old_fee_bps, new_fee_bps),
);
}
3 changes: 3 additions & 0 deletions contracts/invoice-escrow/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn test_integration_escrow_lifecycle_happy_path() {
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
&InvoiceCategory::Standard,
);

// 8. Fund Escrow (Buyer buys the invoice)
Expand Down Expand Up @@ -160,6 +161,7 @@ fn test_integration_refund_lifecycle() {
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
&InvoiceCategory::Standard,
);

escrow_client.fund_escrow(&invoice_id, &buyer, &amount);
Expand Down Expand Up @@ -231,6 +233,7 @@ fn test_integration_token_locked_during_active_escrow() {
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
&InvoiceCategory::Standard,
);

// Token is locked even before funding (initialized locked)
Expand Down
Loading
Loading