Migrate from Event to Transaction Timestramp/Signature

This commit is contained in:
Greg Fitzgerald
2018-05-23 23:26:55 -06:00
parent 7f647a93da
commit 73d3c17507
2 changed files with 8 additions and 19 deletions

View File

@ -4,7 +4,7 @@
use bincode::serialize; use bincode::serialize;
use chrono::prelude::*; use chrono::prelude::*;
use hash::Hash; use hash::Hash;
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil}; use signature::{KeyPair, PublicKey, Signature, SignatureUtil};
use transaction::Transaction; use transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
@ -34,24 +34,15 @@ impl Event {
} }
/// Create and sign a new Witness Timestamp. Used for unit-testing. /// Create and sign a new Witness Timestamp. Used for unit-testing.
pub fn new_timestamp(from: &KeyPair, dt: DateTime<Utc>, _last_id: Hash) -> Self { pub fn new_timestamp(from: &KeyPair, dt: DateTime<Utc>, last_id: Hash) -> Self {
let sign_data = serialize(&dt).expect("serialize 'dt' in pub fn new_timestamp"); let tr = Transaction::new_timestamp(from, dt, last_id);
let sig = Signature::clone_from_slice(from.sign(&sign_data).as_ref()); Event::Transaction(tr)
Event::Timestamp {
from: from.pubkey(),
dt,
sig,
}
} }
/// Create and sign a new Witness Signature. Used for unit-testing. /// Create and sign a new Witness Signature. Used for unit-testing.
pub fn new_signature(from: &KeyPair, tx_sig: Signature, _last_id: Hash) -> Self { pub fn new_signature(from: &KeyPair, tx_sig: Signature, last_id: Hash) -> Self {
let sig = Signature::clone_from_slice(from.sign(&tx_sig).as_ref()); let tr = Transaction::new_signature(from, tx_sig, last_id);
Event::Signature { Event::Transaction(tr)
from: from.pubkey(),
tx_sig,
sig,
}
} }
/// Verify the Event's signature's are valid and if a transaction, that its /// Verify the Event's signature's are valid and if a transaction, that its

View File

@ -154,7 +154,6 @@ pub fn test_node() -> (ReplicatedData, UdpSocket, UdpSocket, UdpSocket, UdpSocke
pub mod tests { pub mod tests {
use bank::Bank; use bank::Bank;
use bincode::serialize; use bincode::serialize;
use chrono::prelude::*;
use crdt::Crdt; use crdt::Crdt;
use crdt::ReplicatedData; use crdt::ReplicatedData;
use entry::Entry; use entry::Entry;
@ -249,8 +248,7 @@ pub mod tests {
w.set_index(i).unwrap(); w.set_index(i).unwrap();
w.set_id(leader_id).unwrap(); w.set_id(leader_id).unwrap();
let tr0 = Event::new_timestamp(&bob_keypair, Utc::now(), cur_hash); let entry0 = Entry::new(&cur_hash, i, vec![]);
let entry0 = Entry::new(&cur_hash, i, vec![tr0]);
bank.register_entry_id(&cur_hash); bank.register_entry_id(&cur_hash);
cur_hash = hash(&cur_hash); cur_hash = hash(&cur_hash);