PlanEvent -> Witness
The term used by the Simplicity smart contract language
This commit is contained in:
parent
6b66e1a077
commit
4379fabf16
|
@ -5,7 +5,7 @@
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use event::Event;
|
use event::Event;
|
||||||
use plan::{Action, Plan, PlanEvent};
|
use plan::{Action, Plan, Witness};
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
use signature::{KeyPair, PublicKey, Signature};
|
use signature::{KeyPair, PublicKey, Signature};
|
||||||
use mint::Mint;
|
use mint::Mint;
|
||||||
|
@ -141,7 +141,7 @@ impl Accountant {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut plan = tr.plan.clone();
|
let mut plan = tr.plan.clone();
|
||||||
let actionable = plan.process_event(PlanEvent::Timestamp(self.last_time));
|
let actionable = plan.process_witness(Witness::Timestamp(self.last_time));
|
||||||
|
|
||||||
if !actionable {
|
if !actionable {
|
||||||
self.pending.insert(tr.sig, plan);
|
self.pending.insert(tr.sig, plan);
|
||||||
|
@ -154,7 +154,7 @@ impl Accountant {
|
||||||
|
|
||||||
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
||||||
let actionable = if let Some(plan) = self.pending.get_mut(&tx_sig) {
|
let actionable = if let Some(plan) = self.pending.get_mut(&tx_sig) {
|
||||||
plan.process_event(PlanEvent::Signature(from))
|
plan.process_witness(Witness::Signature(from))
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
@ -186,7 +186,7 @@ impl Accountant {
|
||||||
// Check to see if any timelocked transactions can be completed.
|
// Check to see if any timelocked transactions can be completed.
|
||||||
let mut completed = vec![];
|
let mut completed = vec![];
|
||||||
for (key, plan) in &mut self.pending {
|
for (key, plan) in &mut self.pending {
|
||||||
if plan.process_event(PlanEvent::Timestamp(self.last_time)) {
|
if plan.process_witness(Witness::Timestamp(self.last_time)) {
|
||||||
completed.push(key.clone());
|
completed.push(key.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/plan.rs
28
src/plan.rs
|
@ -10,18 +10,16 @@ pub enum Condition {
|
||||||
Signature(PublicKey),
|
Signature(PublicKey),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum PlanEvent {
|
pub enum Witness {
|
||||||
Timestamp(DateTime<Utc>),
|
Timestamp(DateTime<Utc>),
|
||||||
Signature(PublicKey),
|
Signature(PublicKey),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Condition {
|
impl Condition {
|
||||||
pub fn is_satisfied(&self, event: &PlanEvent) -> bool {
|
pub fn is_satisfied(&self, event: &Witness) -> bool {
|
||||||
match (self, event) {
|
match (self, event) {
|
||||||
(&Condition::Signature(ref pubkey), &PlanEvent::Signature(ref from)) => pubkey == from,
|
(&Condition::Signature(ref pubkey), &Witness::Signature(ref from)) => pubkey == from,
|
||||||
(&Condition::Timestamp(ref dt), &PlanEvent::Timestamp(ref last_time)) => {
|
(&Condition::Timestamp(ref dt), &Witness::Timestamp(ref last_time)) => dt <= last_time,
|
||||||
dt <= last_time
|
|
||||||
}
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +98,7 @@ impl Plan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_event(&mut self, event: PlanEvent) -> bool {
|
pub fn process_witness(&mut self, event: Witness) -> bool {
|
||||||
let mut new_action = None;
|
let mut new_action = None;
|
||||||
match *self {
|
match *self {
|
||||||
Plan::Action(_) => return true,
|
Plan::Action(_) => return true,
|
||||||
|
@ -134,16 +132,16 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signature_satisfied() {
|
fn test_signature_satisfied() {
|
||||||
let sig = PublicKey::default();
|
let sig = PublicKey::default();
|
||||||
assert!(Condition::Signature(sig).is_satisfied(&PlanEvent::Signature(sig)));
|
assert!(Condition::Signature(sig).is_satisfied(&Witness::Signature(sig)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_timestamp_satisfied() {
|
fn test_timestamp_satisfied() {
|
||||||
let dt1 = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
let dt1 = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
||||||
let dt2 = Utc.ymd(2014, 11, 14).and_hms(10, 9, 8);
|
let dt2 = Utc.ymd(2014, 11, 14).and_hms(10, 9, 8);
|
||||||
assert!(Condition::Timestamp(dt1).is_satisfied(&PlanEvent::Timestamp(dt1)));
|
assert!(Condition::Timestamp(dt1).is_satisfied(&Witness::Timestamp(dt1)));
|
||||||
assert!(Condition::Timestamp(dt1).is_satisfied(&PlanEvent::Timestamp(dt2)));
|
assert!(Condition::Timestamp(dt1).is_satisfied(&Witness::Timestamp(dt2)));
|
||||||
assert!(!Condition::Timestamp(dt2).is_satisfied(&PlanEvent::Timestamp(dt1)));
|
assert!(!Condition::Timestamp(dt2).is_satisfied(&Witness::Timestamp(dt1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -163,7 +161,7 @@ mod tests {
|
||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_authorized_payment(from, 42, to);
|
let mut plan = Plan::new_authorized_payment(from, 42, to);
|
||||||
assert!(plan.process_event(PlanEvent::Signature(from)));
|
assert!(plan.process_witness(Witness::Signature(from)));
|
||||||
assert_eq!(plan, Plan::new_payment(42, to));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +171,7 @@ mod tests {
|
||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_future_payment(dt, 42, to);
|
let mut plan = Plan::new_future_payment(dt, 42, to);
|
||||||
assert!(plan.process_event(PlanEvent::Timestamp(dt)));
|
assert!(plan.process_witness(Witness::Timestamp(dt)));
|
||||||
assert_eq!(plan, Plan::new_payment(42, to));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,11 +182,11 @@ mod tests {
|
||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
||||||
assert!(plan.process_event(PlanEvent::Timestamp(dt)));
|
assert!(plan.process_witness(Witness::Timestamp(dt)));
|
||||||
assert_eq!(plan, Plan::new_payment(42, to));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
|
|
||||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
||||||
assert!(plan.process_event(PlanEvent::Signature(from)));
|
assert!(plan.process_witness(Witness::Signature(from)));
|
||||||
assert_eq!(plan, Plan::new_payment(42, from));
|
assert_eq!(plan, Plan::new_payment(42, from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue