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