Add BudgetExpr::new_cancelable_authorized_payment
This commit is contained in:
parent
dbd4176b97
commit
3369019943
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue