solana-with-rpc-optimizations/sdk/src/budget_instruction.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

2018-12-14 20:39:10 -08:00
use crate::budget_expr::BudgetExpr;
2019-02-28 03:48:44 -08:00
use crate::budget_program;
use crate::pubkey::Pubkey;
use crate::transaction_builder::BuilderInstruction;
use chrono::prelude::{DateTime, Utc};
/// A smart contract.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Contract {
2018-11-02 19:13:33 -07:00
/// The number of tokens allocated to the `BudgetExpr` and any transaction fees.
pub tokens: u64,
2018-11-02 19:13:33 -07:00
pub budget_expr: BudgetExpr,
}
/// An instruction to progress the smart contract.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub enum Instruction {
2018-11-02 19:13:33 -07:00
/// Declare and instantiate `BudgetExpr`.
NewBudget(BudgetExpr),
/// Tell a payment plan acknowledge the given `DateTime` has past.
ApplyTimestamp(DateTime<Utc>),
/// Tell the budget that the `NewBudget` with `Signature` has been
/// signed by the containing transaction's `Pubkey`.
2018-09-18 18:45:44 -07:00
ApplySignature,
}
2019-02-28 03:48:44 -08:00
impl Instruction {
pub fn new_budget(contract: Pubkey, expr: BudgetExpr) -> BuilderInstruction {
BuilderInstruction::new(
budget_program::id(),
&Instruction::NewBudget(expr),
vec![(contract, false)],
)
}
}