Remove optional 'from' field

This commit is contained in:
Greg Fitzgerald 2018-03-03 20:41:05 -07:00
parent ce60b960c0
commit 7cf0d55546
5 changed files with 10 additions and 10 deletions

View File

@ -87,7 +87,7 @@ impl Accountant {
}
let event = Event::Transaction {
from: Some(from),
from,
to,
data,
sig,

View File

@ -45,7 +45,7 @@ fn main() {
let now = Instant::now();
for &(k, s) in &sigs {
let e = Event::Transaction {
from: Some(alice_pubkey),
from: alice_pubkey,
to: k,
data: one,
sig: s,

View File

@ -30,7 +30,7 @@ pub type Signature = GenericArray<u8, U64>;
pub enum Event<T> {
Tick,
Transaction {
from: Option<PublicKey>,
from: PublicKey,
to: PublicKey,
data: T,
sig: Signature,
@ -40,7 +40,7 @@ pub enum Event<T> {
impl<T> Event<T> {
pub fn new_claim(to: PublicKey, data: T, sig: Signature) -> Self {
Event::Transaction {
from: Some(to),
from: to,
to,
data,
sig,
@ -75,7 +75,7 @@ pub fn sign_transaction_data<T: Serialize>(
keypair: &Ed25519KeyPair,
to: &PublicKey,
) -> Signature {
let from = &Some(get_pubkey(keypair));
let from = &get_pubkey(keypair);
sign_serialized(&(from, to, data), keypair)
}
@ -111,7 +111,7 @@ pub fn verify_event<T: Serialize>(event: &Event<T>) -> bool {
} = *event
{
let sign_data = serialize(&(&from, &to, &data)).unwrap();
if !verify_signature(&from.unwrap_or(to), &sign_data, &sig) {
if !verify_signature(&from, &sign_data, &sig) {
return false;
}
}

View File

@ -22,7 +22,7 @@ impl Creator {
}
pub fn create_transaction(&self, keypair: &Ed25519KeyPair) -> Event<u64> {
let from = Some(get_pubkey(keypair));
let from = get_pubkey(keypair);
let to = self.pubkey;
let data = self.tokens;
let sig = sign_transaction_data(&data, keypair, &to);

View File

@ -255,7 +255,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world");
let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)),
from: get_pubkey(&keypair0),
to: pubkey1,
data,
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
@ -272,7 +272,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world");
let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)),
from: get_pubkey(&keypair0),
to: pubkey1,
data: hash(b"goodbye cruel world"), // <-- attack!
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
@ -290,7 +290,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world");
let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)),
from: get_pubkey(&keypair0),
to: get_pubkey(&thief_keypair), // <-- attack!
data: hash(b"goodbye cruel world"),
sig: sign_transaction_data(&data, &keypair0, &pubkey1),