Migrate from Event to Transaction Timestramp/Signature
This commit is contained in:
23
src/event.rs
23
src/event.rs
@ -4,7 +4,7 @@
|
||||
use bincode::serialize;
|
||||
use chrono::prelude::*;
|
||||
use hash::Hash;
|
||||
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil};
|
||||
use signature::{KeyPair, PublicKey, Signature, SignatureUtil};
|
||||
use transaction::Transaction;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
@ -34,24 +34,15 @@ impl Event {
|
||||
}
|
||||
|
||||
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
||||
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 sig = Signature::clone_from_slice(from.sign(&sign_data).as_ref());
|
||||
Event::Timestamp {
|
||||
from: from.pubkey(),
|
||||
dt,
|
||||
sig,
|
||||
}
|
||||
pub fn new_timestamp(from: &KeyPair, dt: DateTime<Utc>, last_id: Hash) -> Self {
|
||||
let tr = Transaction::new_timestamp(from, dt, last_id);
|
||||
Event::Transaction(tr)
|
||||
}
|
||||
|
||||
/// Create and sign a new Witness Signature. Used for unit-testing.
|
||||
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());
|
||||
Event::Signature {
|
||||
from: from.pubkey(),
|
||||
tx_sig,
|
||||
sig,
|
||||
}
|
||||
pub fn new_signature(from: &KeyPair, tx_sig: Signature, last_id: Hash) -> Self {
|
||||
let tr = Transaction::new_signature(from, tx_sig, last_id);
|
||||
Event::Transaction(tr)
|
||||
}
|
||||
|
||||
/// Verify the Event's signature's are valid and if a transaction, that its
|
||||
|
@ -154,7 +154,6 @@ pub fn test_node() -> (ReplicatedData, UdpSocket, UdpSocket, UdpSocket, UdpSocke
|
||||
pub mod tests {
|
||||
use bank::Bank;
|
||||
use bincode::serialize;
|
||||
use chrono::prelude::*;
|
||||
use crdt::Crdt;
|
||||
use crdt::ReplicatedData;
|
||||
use entry::Entry;
|
||||
@ -249,8 +248,7 @@ pub mod tests {
|
||||
w.set_index(i).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![tr0]);
|
||||
let entry0 = Entry::new(&cur_hash, i, vec![]);
|
||||
bank.register_entry_id(&cur_hash);
|
||||
cur_hash = hash(&cur_hash);
|
||||
|
||||
|
Reference in New Issue
Block a user