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 {
|
let event = Event::Transaction {
|
||||||
from,
|
from: Some(from),
|
||||||
to,
|
to,
|
||||||
data,
|
data,
|
||||||
sig,
|
sig,
|
||||||
|
@ -35,7 +35,7 @@ pub enum Event<T> {
|
|||||||
sig: Signature,
|
sig: Signature,
|
||||||
},
|
},
|
||||||
Transaction {
|
Transaction {
|
||||||
from: PublicKey,
|
from: Option<PublicKey>,
|
||||||
to: PublicKey,
|
to: PublicKey,
|
||||||
data: T,
|
data: T,
|
||||||
sig: Signature,
|
sig: Signature,
|
||||||
@ -106,7 +106,7 @@ pub fn verify_event<T: Serialize>(event: &Event<T>) -> bool {
|
|||||||
} = *event
|
} = *event
|
||||||
{
|
{
|
||||||
let sign_data = serialize(&(&data, &to)).unwrap();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ mod tests {
|
|||||||
let pubkey1 = get_pubkey(&keypair1);
|
let pubkey1 = get_pubkey(&keypair1);
|
||||||
let data = hash(b"hello, world");
|
let data = hash(b"hello, world");
|
||||||
let event0 = Event::Transaction {
|
let event0 = Event::Transaction {
|
||||||
from: get_pubkey(&keypair0),
|
from: Some(get_pubkey(&keypair0)),
|
||||||
to: pubkey1,
|
to: pubkey1,
|
||||||
data,
|
data,
|
||||||
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
||||||
@ -285,7 +285,7 @@ mod tests {
|
|||||||
let pubkey1 = get_pubkey(&keypair1);
|
let pubkey1 = get_pubkey(&keypair1);
|
||||||
let data = hash(b"hello, world");
|
let data = hash(b"hello, world");
|
||||||
let event0 = Event::Transaction {
|
let event0 = Event::Transaction {
|
||||||
from: get_pubkey(&keypair0),
|
from: Some(get_pubkey(&keypair0)),
|
||||||
to: pubkey1,
|
to: pubkey1,
|
||||||
data: hash(b"goodbye cruel world"), // <-- attack!
|
data: hash(b"goodbye cruel world"), // <-- attack!
|
||||||
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
||||||
@ -303,7 +303,7 @@ mod tests {
|
|||||||
let pubkey1 = get_pubkey(&keypair1);
|
let pubkey1 = get_pubkey(&keypair1);
|
||||||
let data = hash(b"hello, world");
|
let data = hash(b"hello, world");
|
||||||
let event0 = Event::Transaction {
|
let event0 = Event::Transaction {
|
||||||
from: get_pubkey(&keypair0),
|
from: Some(get_pubkey(&keypair0)),
|
||||||
to: get_pubkey(&thief_keypair), // <-- attack!
|
to: get_pubkey(&thief_keypair), // <-- attack!
|
||||||
data: hash(b"goodbye cruel world"),
|
data: hash(b"goodbye cruel world"),
|
||||||
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
sig: sign_transaction_data(&data, &keypair0, &pubkey1),
|
||||||
|
Reference in New Issue
Block a user