From aac1571670a73df40ff43222a4dc648e20de01df Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 17 Sep 2018 15:38:10 -0700 Subject: [PATCH] mint now uses the SystemContract instead of Budget --- src/bank.rs | 24 ++++++++++++++---------- src/mint.rs | 14 +++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index 09126e5601..668b1c5d43 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -3,17 +3,17 @@ //! on behalf of the caller, and a low-level API for when they have //! already been signed and verified. +use bincode::deserialize; use bincode::serialize; use budget_contract::BudgetContract; use counter::Counter; use entry::Entry; use hash::{hash, Hash}; -use instruction::Instruction; use itertools::Itertools; use ledger::Block; use log::Level; use mint::Mint; -use payment_plan::{Payment, PaymentPlan}; +use payment_plan::Payment; use signature::{Keypair, Pubkey, Signature}; use std; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; @@ -284,8 +284,11 @@ impl Bank { } else { error_counters.account_not_found_leader += 1; } - if let Some(Instruction::NewVote(_vote)) = tx.instruction() { - error_counters.account_not_found_vote += 1; + if BudgetContract::check_id(&tx.contract_id) { + use instruction::Instruction; + if let Some(Instruction::NewVote(_vote)) = tx.instruction() { + error_counters.account_not_found_vote += 1; + } } Err(BankError::AccountNotFound(*tx.from())) } else if accounts.get(&tx.keys[0]).unwrap().tokens < tx.fee { @@ -557,17 +560,18 @@ impl Bank { .expect("invalid ledger: need at least 2 entries"); { let tx = &entry1.transactions[0]; - let instruction = tx.instruction(); - let deposit = if let Some(Instruction::NewContract(contract)) = instruction { - contract.plan.final_payment() + assert!(SystemContract::check_id(&tx.contract_id), "Invalid ledger"); + let instruction: SystemContract = deserialize(&tx.userdata).unwrap(); + let deposit = if let SystemContract::Move { tokens } = instruction { + Some(tokens) } else { None }.expect("invalid ledger, needs to start with a contract"); { let mut accounts = self.accounts.write().unwrap(); - let entry = accounts.entry(tx.keys[0]).or_insert_with(Account::default); - Self::apply_payment(&deposit, entry); - trace!("applied genesis payment {:?} {:?}", deposit, entry); + let account = accounts.entry(tx.keys[0]).or_insert_with(Account::default); + account.tokens += deposit; + trace!("applied genesis payment {:?} => {:?}", deposit, account); } } self.register_entry_id(&entry0.id); diff --git a/src/mint.rs b/src/mint.rs index 346d1bb082..1f18e81d07 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -52,7 +52,7 @@ impl Mint { pub fn create_transactions(&self) -> Vec { let keypair = self.keypair(); - let tx = Transaction::budget_new(&keypair, self.pubkey(), self.tokens, self.seed()); + let tx = Transaction::system_move(&keypair, self.pubkey(), self.tokens, self.seed(), 0); vec![tx] } @@ -66,18 +66,18 @@ impl Mint { #[cfg(test)] mod tests { use super::*; - use budget::Budget; - use instruction::{Instruction, Plan}; + use bincode::deserialize; use ledger::Block; + use system_contract::SystemContract; #[test] fn test_create_transactions() { let mut transactions = Mint::new(100).create_transactions().into_iter(); let tx = transactions.next().unwrap(); - if let Some(Instruction::NewContract(contract)) = tx.instruction() { - if let Plan::Budget(Budget::Pay(payment)) = contract.plan { - assert_eq!(*tx.from(), payment.to); - } + assert!(SystemContract::check_id(&tx.contract_id)); + let instruction: SystemContract = deserialize(&tx.userdata).unwrap(); + if let SystemContract::Move { tokens } = instruction { + assert_eq!(tokens, 100); } assert_eq!(transactions.next(), None); }