Add BudgetExpr::new_cancelable_authorized_payment

This commit is contained in:
Greg Fitzgerald 2019-03-18 05:48:46 -06:00 committed by Grimes
parent dbd4176b97
commit 3369019943
2 changed files with 22 additions and 14 deletions

View File

@ -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,

View File

@ -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)