Implement the same interface in all builtin programs
This commit is contained in:
36
src/bank.rs
36
src/bank.rs
@ -803,37 +803,17 @@ impl Bank {
|
|||||||
// Call the contract method
|
// Call the contract method
|
||||||
// It's up to the contract to implement its own rules on moving funds
|
// It's up to the contract to implement its own rules on moving funds
|
||||||
if system_program::check_id(&program_id) {
|
if system_program::check_id(&program_id) {
|
||||||
if let Err(err) =
|
system_program::process(&tx, instruction_index, program_accounts)
|
||||||
system_program::process_instruction(&tx, instruction_index, program_accounts)
|
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
||||||
{
|
|
||||||
let err = match err {
|
|
||||||
system_program::Error::ResultWithNegativeTokens => {
|
|
||||||
ProgramError::ResultWithNegativeTokens
|
|
||||||
}
|
|
||||||
_ => ProgramError::RuntimeError,
|
|
||||||
};
|
|
||||||
return Err(BankError::ProgramError(instruction_index as u8, err));
|
|
||||||
}
|
|
||||||
} else if budget_program::check_id(&program_id) {
|
} else if budget_program::check_id(&program_id) {
|
||||||
if budget_program::process_instruction(&tx, instruction_index, program_accounts)
|
budget_program::process(&tx, instruction_index, program_accounts)
|
||||||
.is_err()
|
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
||||||
{
|
|
||||||
let err = ProgramError::RuntimeError;
|
|
||||||
return Err(BankError::ProgramError(instruction_index as u8, err));
|
|
||||||
}
|
|
||||||
} else if storage_program::check_id(&program_id) {
|
} else if storage_program::check_id(&program_id) {
|
||||||
if storage_program::process_instruction(&tx, instruction_index, program_accounts)
|
storage_program::process(&tx, instruction_index, program_accounts)
|
||||||
.is_err()
|
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
||||||
{
|
|
||||||
let err = ProgramError::RuntimeError;
|
|
||||||
return Err(BankError::ProgramError(instruction_index as u8, err));
|
|
||||||
}
|
|
||||||
} else if vote_program::check_id(&program_id) {
|
} else if vote_program::check_id(&program_id) {
|
||||||
if vote_program::process_instruction(&tx, instruction_index, program_accounts).is_err()
|
vote_program::process(&tx, instruction_index, program_accounts)
|
||||||
{
|
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
||||||
let err = ProgramError::RuntimeError;
|
|
||||||
return Err(BankError::ProgramError(instruction_index as u8, err));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let mut accounts = self.load_executable_accounts(tx.program_ids[instruction_index])?;
|
let mut accounts = self.load_executable_accounts(tx.program_ids[instruction_index])?;
|
||||||
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
||||||
|
@ -4,6 +4,7 @@ use budget_expr::BudgetExpr;
|
|||||||
use budget_instruction::Instruction;
|
use budget_instruction::Instruction;
|
||||||
use chrono::prelude::{DateTime, Utc};
|
use chrono::prelude::{DateTime, Utc};
|
||||||
use payment_plan::Witness;
|
use payment_plan::Witness;
|
||||||
|
use program::ProgramError;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -133,6 +134,14 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process(
|
||||||
|
tx: &Transaction,
|
||||||
|
instruction_index: usize,
|
||||||
|
accounts: &mut [&mut Account],
|
||||||
|
) -> std::result::Result<(), ProgramError> {
|
||||||
|
process_instruction(&tx, instruction_index, accounts).map_err(|_| ProgramError::RuntimeError)
|
||||||
|
}
|
||||||
|
|
||||||
//TODO the contract needs to provide a "get_balance" introspection call of the userdata
|
//TODO the contract needs to provide a "get_balance" introspection call of the userdata
|
||||||
pub fn get_balance(account: &Account) -> u64 {
|
pub fn get_balance(account: &Account) -> u64 {
|
||||||
if let Ok(program) = deserialize(&account.userdata) {
|
if let Ok(program) = deserialize(&account.userdata) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//! and give reward for good proofs.
|
//! and give reward for good proofs.
|
||||||
|
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
|
use program::ProgramError;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
@ -51,6 +52,14 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process(
|
||||||
|
tx: &Transaction,
|
||||||
|
instruction_index: usize,
|
||||||
|
accounts: &mut [&mut Account],
|
||||||
|
) -> std::result::Result<(), ProgramError> {
|
||||||
|
process_instruction(&tx, instruction_index, accounts).map_err(|_| ProgramError::RuntimeError)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! system program
|
//! system program
|
||||||
|
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
|
use program::ProgramError;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
@ -99,6 +100,17 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process(
|
||||||
|
tx: &Transaction,
|
||||||
|
instruction_index: usize,
|
||||||
|
accounts: &mut [&mut Account],
|
||||||
|
) -> std::result::Result<(), ProgramError> {
|
||||||
|
process_instruction(&tx, instruction_index, accounts).map_err(|err| match err {
|
||||||
|
Error::ResultWithNegativeTokens => ProgramError::ResultWithNegativeTokens,
|
||||||
|
_ => ProgramError::RuntimeError,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
use program::ProgramError;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std;
|
use std;
|
||||||
@ -116,6 +117,14 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process(
|
||||||
|
tx: &Transaction,
|
||||||
|
instruction_index: usize,
|
||||||
|
accounts: &mut [&mut Account],
|
||||||
|
) -> std::result::Result<(), ProgramError> {
|
||||||
|
process_instruction(&tx, instruction_index, accounts).map_err(|_| ProgramError::RuntimeError)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_max_size() -> usize {
|
pub fn get_max_size() -> usize {
|
||||||
// Upper limit on the size of the Vote State. Equal to
|
// Upper limit on the size of the Vote State. Equal to
|
||||||
// sizeof(VoteProgram) + MAX_VOTE_HISTORY * sizeof(Vote) +
|
// sizeof(VoteProgram) + MAX_VOTE_HISTORY * sizeof(Vote) +
|
||||||
|
Reference in New Issue
Block a user