Cleanup naming
This commit is contained in:
@ -141,7 +141,7 @@ impl Accountant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut plan = tr.plan.clone();
|
let mut plan = tr.plan.clone();
|
||||||
plan.process_witness(Witness::Timestamp(self.last_time));
|
plan.apply_witness(Witness::Timestamp(self.last_time));
|
||||||
|
|
||||||
if plan.is_complete() {
|
if plan.is_complete() {
|
||||||
self.complete_transaction(&plan);
|
self.complete_transaction(&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_witness(Witness::Signature(from));
|
plan.apply_witness(Witness::Signature(from));
|
||||||
plan.is_complete()
|
plan.is_complete()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@ -187,7 +187,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 {
|
||||||
plan.process_witness(Witness::Timestamp(self.last_time));
|
plan.apply_witness(Witness::Timestamp(self.last_time));
|
||||||
if plan.is_complete() {
|
if plan.is_complete() {
|
||||||
completed.push(key.clone());
|
completed.push(key.clone());
|
||||||
}
|
}
|
||||||
|
20
src/plan.rs
20
src/plan.rs
@ -19,8 +19,8 @@ pub enum Condition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Condition {
|
impl Condition {
|
||||||
pub fn is_satisfied(&self, event: &Witness) -> bool {
|
pub fn is_satisfied(&self, witness: &Witness) -> bool {
|
||||||
match (self, event) {
|
match (self, witness) {
|
||||||
(&Condition::Signature(ref pubkey), &Witness::Signature(ref from)) => pubkey == from,
|
(&Condition::Signature(ref pubkey), &Witness::Signature(ref from)) => pubkey == from,
|
||||||
(&Condition::Timestamp(ref dt), &Witness::Timestamp(ref last_time)) => dt <= last_time,
|
(&Condition::Timestamp(ref dt), &Witness::Timestamp(ref last_time)) => dt <= last_time,
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -83,19 +83,19 @@ impl Plan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_witness(&mut self, event: Witness) {
|
pub fn apply_witness(&mut self, witness: Witness) {
|
||||||
let mut new_payment = None;
|
let mut new_payment = None;
|
||||||
match *self {
|
match *self {
|
||||||
Plan::Pay(_) => (),
|
Plan::Pay(_) => (),
|
||||||
Plan::After(ref cond, ref payment) => {
|
Plan::After(ref cond, ref payment) => {
|
||||||
if cond.is_satisfied(&event) {
|
if cond.is_satisfied(&witness) {
|
||||||
new_payment = Some(payment.clone());
|
new_payment = Some(payment.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Plan::Race(ref a, ref b) => {
|
Plan::Race(ref a, ref b) => {
|
||||||
if a.0.is_satisfied(&event) {
|
if a.0.is_satisfied(&witness) {
|
||||||
new_payment = Some(a.1.clone());
|
new_payment = Some(a.1.clone());
|
||||||
} else if b.0.is_satisfied(&event) {
|
} else if b.0.is_satisfied(&witness) {
|
||||||
new_payment = Some(b.1.clone());
|
new_payment = Some(b.1.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +143,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);
|
||||||
plan.process_witness(Witness::Signature(from));
|
plan.apply_witness(Witness::Signature(from));
|
||||||
assert_eq!(plan, Plan::new_payment(42, to));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,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);
|
||||||
plan.process_witness(Witness::Timestamp(dt));
|
plan.apply_witness(Witness::Timestamp(dt));
|
||||||
assert_eq!(plan, Plan::new_payment(42, to));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,11 +164,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);
|
||||||
plan.process_witness(Witness::Timestamp(dt));
|
plan.apply_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);
|
||||||
plan.process_witness(Witness::Signature(from));
|
plan.apply_witness(Witness::Signature(from));
|
||||||
assert_eq!(plan, Plan::new_payment(42, from));
|
assert_eq!(plan, Plan::new_payment(42, from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user