Hoist last_id
First step in unifying Witness processing and Transaction processing
This commit is contained in:
parent
abfd7d6951
commit
207b6686d1
|
@ -170,7 +170,7 @@ impl Bank {
|
||||||
return Err(BankError::AccountNotFound);
|
return Err(BankError::AccountNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.reserve_signature_with_last_id(&tr.sig, &tr.data.last_id) {
|
if !self.reserve_signature_with_last_id(&tr.sig, &tr.last_id) {
|
||||||
return Err(BankError::InvalidTransferSignature);
|
return Err(BankError::InvalidTransferSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ impl Bank {
|
||||||
let current = bal.load(Ordering::Relaxed) as i64;
|
let current = bal.load(Ordering::Relaxed) as i64;
|
||||||
|
|
||||||
if current < tr.data.tokens {
|
if current < tr.data.tokens {
|
||||||
self.forget_signature_with_last_id(&tr.sig, &tr.data.last_id);
|
self.forget_signature_with_last_id(&tr.sig, &tr.last_id);
|
||||||
return Err(BankError::InsufficientFunds);
|
return Err(BankError::InsufficientFunds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ pub const PUB_KEY_OFFSET: usize = 80;
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct TransactionData {
|
pub struct TransactionData {
|
||||||
pub tokens: i64,
|
pub tokens: i64,
|
||||||
pub last_id: Hash,
|
|
||||||
pub plan: Plan,
|
pub plan: Plan,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +22,7 @@ pub struct Transaction {
|
||||||
pub sig: Signature,
|
pub sig: Signature,
|
||||||
pub from: PublicKey,
|
pub from: PublicKey,
|
||||||
pub data: TransactionData,
|
pub data: TransactionData,
|
||||||
|
pub last_id: Hash,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
|
@ -32,12 +32,9 @@ impl Transaction {
|
||||||
let plan = Plan::Pay(Payment { tokens, to });
|
let plan = Plan::Pay(Payment { tokens, to });
|
||||||
let mut tr = Transaction {
|
let mut tr = Transaction {
|
||||||
sig: Signature::default(),
|
sig: Signature::default(),
|
||||||
data: TransactionData {
|
data: TransactionData { plan, tokens },
|
||||||
plan,
|
last_id,
|
||||||
tokens,
|
from,
|
||||||
last_id,
|
|
||||||
},
|
|
||||||
from: from,
|
|
||||||
};
|
};
|
||||||
tr.sign(from_keypair);
|
tr.sign(from_keypair);
|
||||||
tr
|
tr
|
||||||
|
@ -57,12 +54,9 @@ impl Transaction {
|
||||||
(Condition::Signature(from), Payment { tokens, to: from }),
|
(Condition::Signature(from), Payment { tokens, to: from }),
|
||||||
);
|
);
|
||||||
let mut tr = Transaction {
|
let mut tr = Transaction {
|
||||||
data: TransactionData {
|
data: TransactionData { plan, tokens },
|
||||||
plan,
|
from,
|
||||||
tokens,
|
last_id,
|
||||||
last_id,
|
|
||||||
},
|
|
||||||
from: from,
|
|
||||||
sig: Signature::default(),
|
sig: Signature::default(),
|
||||||
};
|
};
|
||||||
tr.sign(from_keypair);
|
tr.sign(from_keypair);
|
||||||
|
@ -70,7 +64,10 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_sign_data(&self) -> Vec<u8> {
|
fn get_sign_data(&self) -> Vec<u8> {
|
||||||
serialize(&(&self.data)).expect("serialize TransactionData in fn get_sign_data")
|
let mut data = serialize(&(&self.data)).expect("serialize TransactionData");
|
||||||
|
let last_id_data = serialize(&(&self.last_id)).expect("serialize last_id");
|
||||||
|
data.extend_from_slice(&last_id_data);
|
||||||
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign this transaction.
|
/// Sign this transaction.
|
||||||
|
@ -153,12 +150,9 @@ mod tests {
|
||||||
to: Default::default(),
|
to: Default::default(),
|
||||||
});
|
});
|
||||||
let claim0 = Transaction {
|
let claim0 = Transaction {
|
||||||
data: TransactionData {
|
data: TransactionData { plan, tokens: 0 },
|
||||||
plan,
|
|
||||||
tokens: 0,
|
|
||||||
last_id: Default::default(),
|
|
||||||
},
|
|
||||||
from: Default::default(),
|
from: Default::default(),
|
||||||
|
last_id: Default::default(),
|
||||||
sig: Default::default(),
|
sig: Default::default(),
|
||||||
};
|
};
|
||||||
let buf = serialize(&claim0).unwrap();
|
let buf = serialize(&claim0).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue