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:
@ -92,7 +92,7 @@ impl Accountant {
|
||||
}
|
||||
|
||||
let event = Event::Transaction {
|
||||
from,
|
||||
from: Some(from),
|
||||
to,
|
||||
data,
|
||||
sig,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
|
Reference in New Issue
Block a user