Check for duplicate signatures

TODO: have client add recent hash to each message
This commit is contained in:
Greg Fitzgerald
2018-03-01 14:07:23 -07:00
parent c9cc4b4369
commit 570e71f050
3 changed files with 26 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ use std::collections::HashMap;
pub struct Accountant {
pub historian: Historian<u64>,
pub balances: HashMap<PublicKey, u64>,
pub signatures: HashMap<Signature, bool>,
pub end_hash: Sha256Hash,
}
@@ -20,13 +21,19 @@ impl Accountant {
Accountant {
historian: hist,
balances: HashMap::new(),
signatures: HashMap::new(),
end_hash: *start_hash,
}
}
pub fn process_event(self: &mut Self, event: &Event<u64>) {
match *event {
Event::Claim { key, data, .. } => {
Event::Claim { key, data, sig } => {
if self.signatures.contains_key(&sig) {
return;
}
self.signatures.insert(sig, true);
if self.balances.contains_key(&key) {
if let Some(x) = self.balances.get_mut(&key) {
*x += data;
@@ -35,7 +42,16 @@ impl Accountant {
self.balances.insert(key, data);
}
}
Event::Transaction { from, to, data, .. } => {
Event::Transaction {
from,
to,
data,
sig,
} => {
if self.signatures.contains_key(&sig) {
return;
}
self.signatures.insert(sig, true);
if let Some(x) = self.balances.get_mut(&from) {
*x -= data;
}