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
22 changes: 22 additions & 0 deletions contracts/split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl SplitContract {
)
}

#[allow(clippy::too_many_arguments)]
fn _create_invoice_inner(
env: &Env,
creator: Address,
Expand Down Expand Up @@ -645,6 +646,7 @@ impl SplitContract {
///
/// For tranche invoices, only distributes tranches whose timestamp ≤ now.
/// Blocks with "prerequisite not released" until the prerequisite invoice is Released.
/// If an approver is set, requires the invoice to be approved first (issue #25).
pub fn release(env: Env, invoice_id: u64) {
require_not_paused(&env);
let caller = env.current_contract_address();
Expand All @@ -659,6 +661,11 @@ impl SplitContract {
let total: i128 = invoice.amounts.iter().sum();
assert!(invoice.funded >= total, "invoice not fully funded");

// Approval check (issue #25).
if invoice.approver.is_some() && !invoice.approved {
panic!("awaiting approval");
}

// Prerequisite check (issue #22).
if let Some(prereq_id) = invoice.prerequisite_id {
let prereq = load_invoice(&env, prereq_id);
Expand Down Expand Up @@ -696,6 +703,21 @@ impl SplitContract {
}
}

/// Approve an invoice if it has an approver set (issue #25).
///
/// Requires authentication from the approver address.
pub fn approve_invoice(env: Env, invoice_id: u64) {
require_not_paused(&env);
let mut invoice = load_invoice(&env, invoice_id);

let approver = invoice.approver.as_ref().expect("no approver set on this invoice");
approver.require_auth();

invoice.approved = true;
save_invoice(&env, invoice_id, &invoice);
append_audit_entry(&env, invoice_id, symbol_short!("aprv"), approver);
}

/// Distribute tranches unlocked by the current ledger time (issue #23).
fn _release_tranches(env: &Env, invoice_id: u64, invoice: &mut Invoice, actor: &Address) {
let now = env.ledger().timestamp();
Expand Down
Loading