From 6286947697e87f961406ac09834eb065ef777146 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Sat, 23 Mar 2019 06:18:10 -0600 Subject: [PATCH] Inline payment_plan This module predates Accounts. That was a separate module because it used to be part of Bank and those types could be sent to any smart contract. Now each instruction processor defines for itself what instructions it accepts. --- programs/budget_api/src/budget_expr.rs | 21 +++++++++++++++- programs/budget_api/src/budget_processor.rs | 2 +- programs/budget_api/src/lib.rs | 1 - programs/budget_api/src/payment_plan.rs | 28 --------------------- programs/vote_api/src/vote_instruction.rs | 1 - 5 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 programs/budget_api/src/payment_plan.rs diff --git a/programs/budget_api/src/budget_expr.rs b/programs/budget_api/src/budget_expr.rs index 1e45ae82e0..b0534433c6 100644 --- a/programs/budget_api/src/budget_expr.rs +++ b/programs/budget_api/src/budget_expr.rs @@ -3,12 +3,31 @@ //! which it uses to reduce the payment plan. When the budget is reduced to a //! `Payment`, the payment is executed. -use crate::payment_plan::{Payment, Witness}; use chrono::prelude::*; use serde_derive::{Deserialize, Serialize}; use solana_sdk::pubkey::Pubkey; use std::mem; +/// The types of events a payment plan can process. +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +pub enum Witness { + /// The current time. + Timestamp(DateTime), + + /// A signature from Pubkey. + Signature, +} + +/// Some amount of lamports that should be sent to the `to` `Pubkey`. +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +pub struct Payment { + /// Amount to be paid. + pub lamports: u64, + + /// The `Pubkey` that `lamports` should be paid to. + pub to: Pubkey, +} + /// A data type representing a `Witness` that the payment plan is waiting on. #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum Condition { diff --git a/programs/budget_api/src/budget_processor.rs b/programs/budget_api/src/budget_processor.rs index f0edfdb4f0..fd89376c05 100644 --- a/programs/budget_api/src/budget_processor.rs +++ b/programs/budget_api/src/budget_processor.rs @@ -1,7 +1,7 @@ //! budget program +use crate::budget_expr::Witness; use crate::budget_instruction::BudgetInstruction; use crate::budget_state::{BudgetError, BudgetState}; -use crate::payment_plan::Witness; use bincode::{deserialize, serialize}; use chrono::prelude::{DateTime, Utc}; use log::*; diff --git a/programs/budget_api/src/lib.rs b/programs/budget_api/src/lib.rs index 05bf85f169..7af7bbbe36 100644 --- a/programs/budget_api/src/lib.rs +++ b/programs/budget_api/src/lib.rs @@ -2,7 +2,6 @@ pub mod budget_expr; pub mod budget_instruction; pub mod budget_processor; pub mod budget_state; -pub mod payment_plan; use solana_sdk::pubkey::Pubkey; diff --git a/programs/budget_api/src/payment_plan.rs b/programs/budget_api/src/payment_plan.rs deleted file mode 100644 index ba4e166dd8..0000000000 --- a/programs/budget_api/src/payment_plan.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! The `plan` module provides a domain-specific language for payment plans. Users create BudgetExpr objects that -//! are given to an interpreter. The interpreter listens for `Witness` transactions, -//! which it uses to reduce the payment plan. When the plan is reduced to a -//! `Payment`, the payment is executed. - -use chrono::prelude::*; -use serde_derive::{Deserialize, Serialize}; -use solana_sdk::pubkey::Pubkey; - -/// The types of events a payment plan can process. -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] -pub enum Witness { - /// The current time. - Timestamp(DateTime), - - /// A signature from Pubkey. - Signature, -} - -/// Some amount of lamports that should be sent to the `to` `Pubkey`. -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct Payment { - /// Amount to be paid. - pub lamports: u64, - - /// The `Pubkey` that `lamports` should be paid to. - pub to: Pubkey, -} diff --git a/programs/vote_api/src/vote_instruction.rs b/programs/vote_api/src/vote_instruction.rs index 82c73a6cc3..610701aabf 100644 --- a/programs/vote_api/src/vote_instruction.rs +++ b/programs/vote_api/src/vote_instruction.rs @@ -4,7 +4,6 @@ use serde_derive::{Deserialize, Serialize}; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::pubkey::Pubkey; use solana_sdk::system_instruction::SystemInstruction; -use solana_sdk::transaction::{AccountMeta, Instruction}; #[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Vote {