Check for duplicate signatures
TODO: have client add recent hash to each message
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user