mint now uses the SystemContract instead of Budget

This commit is contained in:
Michael Vines 2018-09-17 15:38:10 -07:00
parent 8bae75a8a6
commit aac1571670
2 changed files with 21 additions and 17 deletions

View File

@ -3,17 +3,17 @@
//! on behalf of the caller, and a low-level API for when they have //! on behalf of the caller, and a low-level API for when they have
//! already been signed and verified. //! already been signed and verified.
use bincode::deserialize;
use bincode::serialize; use bincode::serialize;
use budget_contract::BudgetContract; use budget_contract::BudgetContract;
use counter::Counter; use counter::Counter;
use entry::Entry; use entry::Entry;
use hash::{hash, Hash}; use hash::{hash, Hash};
use instruction::Instruction;
use itertools::Itertools; use itertools::Itertools;
use ledger::Block; use ledger::Block;
use log::Level; use log::Level;
use mint::Mint; use mint::Mint;
use payment_plan::{Payment, PaymentPlan}; use payment_plan::Payment;
use signature::{Keypair, Pubkey, Signature}; use signature::{Keypair, Pubkey, Signature};
use std; use std;
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
@ -284,8 +284,11 @@ impl Bank {
} else { } else {
error_counters.account_not_found_leader += 1; error_counters.account_not_found_leader += 1;
} }
if let Some(Instruction::NewVote(_vote)) = tx.instruction() { if BudgetContract::check_id(&tx.contract_id) {
error_counters.account_not_found_vote += 1; use instruction::Instruction;
if let Some(Instruction::NewVote(_vote)) = tx.instruction() {
error_counters.account_not_found_vote += 1;
}
} }
Err(BankError::AccountNotFound(*tx.from())) Err(BankError::AccountNotFound(*tx.from()))
} else if accounts.get(&tx.keys[0]).unwrap().tokens < tx.fee { } 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"); .expect("invalid ledger: need at least 2 entries");
{ {
let tx = &entry1.transactions[0]; let tx = &entry1.transactions[0];
let instruction = tx.instruction(); assert!(SystemContract::check_id(&tx.contract_id), "Invalid ledger");
let deposit = if let Some(Instruction::NewContract(contract)) = instruction { let instruction: SystemContract = deserialize(&tx.userdata).unwrap();
contract.plan.final_payment() let deposit = if let SystemContract::Move { tokens } = instruction {
Some(tokens)
} else { } else {
None None
}.expect("invalid ledger, needs to start with a contract"); }.expect("invalid ledger, needs to start with a contract");
{ {
let mut accounts = self.accounts.write().unwrap(); let mut accounts = self.accounts.write().unwrap();
let entry = accounts.entry(tx.keys[0]).or_insert_with(Account::default); let account = accounts.entry(tx.keys[0]).or_insert_with(Account::default);
Self::apply_payment(&deposit, entry); account.tokens += deposit;
trace!("applied genesis payment {:?} {:?}", deposit, entry); trace!("applied genesis payment {:?} => {:?}", deposit, account);
} }
} }
self.register_entry_id(&entry0.id); self.register_entry_id(&entry0.id);

View File

@ -52,7 +52,7 @@ impl Mint {
pub fn create_transactions(&self) -> Vec<Transaction> { pub fn create_transactions(&self) -> Vec<Transaction> {
let keypair = self.keypair(); 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] vec![tx]
} }
@ -66,18 +66,18 @@ impl Mint {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use budget::Budget; use bincode::deserialize;
use instruction::{Instruction, Plan};
use ledger::Block; use ledger::Block;
use system_contract::SystemContract;
#[test] #[test]
fn test_create_transactions() { fn test_create_transactions() {
let mut transactions = Mint::new(100).create_transactions().into_iter(); let mut transactions = Mint::new(100).create_transactions().into_iter();
let tx = transactions.next().unwrap(); let tx = transactions.next().unwrap();
if let Some(Instruction::NewContract(contract)) = tx.instruction() { assert!(SystemContract::check_id(&tx.contract_id));
if let Plan::Budget(Budget::Pay(payment)) = contract.plan { let instruction: SystemContract = deserialize(&tx.userdata).unwrap();
assert_eq!(*tx.from(), payment.to); if let SystemContract::Move { tokens } = instruction {
} assert_eq!(tokens, 100);
} }
assert_eq!(transactions.next(), None); assert_eq!(transactions.next(), None);
} }