Generalize Transaction to express a Claim

If a Transaction doesn't have an existing address, it's being used
to create new funds.
This commit is contained in:
Greg Fitzgerald
2018-03-02 10:41:13 -07:00
parent 32d677787b
commit 3e2d6d9e8b
3 changed files with 6 additions and 6 deletions

View File

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

View File

@ -35,7 +35,7 @@ pub enum Event<T> {
sig: Signature,
},
Transaction {
from: PublicKey,
from: Option<PublicKey>,
to: PublicKey,
data: T,
sig: Signature,
@ -106,7 +106,7 @@ pub fn verify_event<T: Serialize>(event: &Event<T>) -> bool {
} = *event
{
let sign_data = serialize(&(&data, &to)).unwrap();
if !verify_signature(&from, &sign_data, &sig) {
if !verify_signature(&from.unwrap_or(to), &sign_data, &sig) {
return false;
}
}

View File

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