2018-05-29 13:08:59 -06:00
|
|
|
//! The `plan` module provides a domain-specific language for payment plans. Users create Budget objects that
|
2018-05-25 15:51:41 -06:00
|
|
|
//! are given to an interpreter. The interpreter listens for `Witness` transactions,
|
2018-03-20 15:52:46 -06:00
|
|
|
//! which it uses to reduce the payment plan. When the plan is reduced to a
|
|
|
|
//! `Payment`, the payment is executed.
|
2018-03-17 14:42:43 -06:00
|
|
|
|
|
|
|
use chrono::prelude::*;
|
2018-03-26 22:03:26 -06:00
|
|
|
use signature::PublicKey;
|
2018-03-17 14:42:43 -06:00
|
|
|
|
2018-05-22 21:42:04 -06:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
2018-03-20 15:31:28 -06:00
|
|
|
pub enum Witness {
|
2018-03-17 14:42:43 -06:00
|
|
|
Timestamp(DateTime<Utc>),
|
|
|
|
Signature(PublicKey),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
2018-03-17 14:42:50 -06:00
|
|
|
pub struct Payment {
|
2018-03-19 10:03:41 -06:00
|
|
|
pub tokens: i64,
|
2018-03-17 14:42:43 -06:00
|
|
|
pub to: PublicKey,
|
|
|
|
}
|
|
|
|
|
2018-05-29 13:00:44 -06:00
|
|
|
pub trait PaymentPlan {
|
2018-05-29 17:11:24 -06:00
|
|
|
/// Return Payment if the payment plan requires no additional Witnesses.
|
2018-05-29 13:00:44 -06:00
|
|
|
fn final_payment(&self) -> Option<Payment>;
|
|
|
|
|
|
|
|
/// Return true if the plan spends exactly `spendable_tokens`.
|
|
|
|
fn verify(&self, spendable_tokens: i64) -> bool;
|
|
|
|
|
2018-05-29 17:11:24 -06:00
|
|
|
/// Apply a witness to the payment plan to see if the plan can be reduced.
|
2018-05-29 13:00:44 -06:00
|
|
|
/// If so, modify the plan in-place.
|
|
|
|
fn apply_witness(&mut self, witness: &Witness);
|
|
|
|
}
|