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
|
/// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s
|
||||||
pub fn new_2_2_multisig_payment(
|
pub fn new_2_2_multisig_payment(
|
||||||
from0: &Pubkey,
|
from0: &Pubkey,
|
||||||
|
|
|
@ -74,21 +74,9 @@ impl BudgetScript {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Script {
|
) -> Script {
|
||||||
let expr = if let Some(from) = cancelable {
|
let expr = if let Some(from) = cancelable {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, &from)
|
||||||
(
|
|
||||||
Condition::Signature(*witness),
|
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Condition::Signature(from),
|
|
||||||
Box::new(BudgetExpr::new_payment(lamports, &from)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
BudgetExpr::After(
|
BudgetExpr::new_authorized_payment(witness, lamports, to)
|
||||||
Condition::Signature(*witness),
|
|
||||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::new_account(from, contract, lamports, expr)
|
Self::new_account(from, contract, lamports, expr)
|
||||||
|
|
Loading…
Reference in New Issue