diff --git a/programs/budget_api/src/budget_expr.rs b/programs/budget_api/src/budget_expr.rs index ad20de3f8a..124faa1e91 100644 --- a/programs/budget_api/src/budget_expr.rs +++ b/programs/budget_api/src/budget_expr.rs @@ -64,6 +64,26 @@ impl BudgetExpr { ) } + /// Create a budget that pays `lamports` to `to` after being witnessed by `witness` unless + /// canceled with a signature from `from`. + pub fn new_cancelable_authorized_payment( + witness: &Pubkey, + lamports: u64, + to: &Pubkey, + from: &Pubkey, + ) -> Self { + BudgetExpr::Or( + ( + Condition::Signature(*witness), + Box::new(BudgetExpr::new_payment(lamports, to)), + ), + ( + Condition::Signature(*from), + Box::new(BudgetExpr::new_payment(lamports, from)), + ), + ) + } + /// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s pub fn new_2_2_multisig_payment( from0: &Pubkey, diff --git a/programs/budget_api/src/budget_script.rs b/programs/budget_api/src/budget_script.rs index ce6321d13f..8c1865014b 100644 --- a/programs/budget_api/src/budget_script.rs +++ b/programs/budget_api/src/budget_script.rs @@ -74,21 +74,9 @@ impl BudgetScript { lamports: u64, ) -> Script { let expr = if let Some(from) = cancelable { - BudgetExpr::Or( - ( - Condition::Signature(*witness), - Box::new(BudgetExpr::new_payment(lamports, to)), - ), - ( - Condition::Signature(from), - Box::new(BudgetExpr::new_payment(lamports, &from)), - ), - ) + BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, &from) } else { - BudgetExpr::After( - Condition::Signature(*witness), - Box::new(BudgetExpr::new_payment(lamports, to)), - ) + BudgetExpr::new_authorized_payment(witness, lamports, to) }; Self::new_account(from, contract, lamports, expr)