Move Account into its own module
Also use default Default generator, since system program ID is [0; 32]. Bank should probably be the one to set this anyway.
This commit is contained in:
@@ -22,7 +22,7 @@ pub extern "C" fn process(infos: &mut Vec<KeyedAccount>, data: &[u8]) {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana::bank::Account;
|
use solana::account::Account;
|
||||||
use solana::signature::Pubkey;
|
use solana::signature::Pubkey;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
23
src/account.rs
Normal file
23
src/account.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use signature::Pubkey;
|
||||||
|
|
||||||
|
/// An Account with userdata that is stored on chain
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||||
|
pub struct Account {
|
||||||
|
/// tokens in the account
|
||||||
|
pub tokens: i64,
|
||||||
|
/// user data
|
||||||
|
/// A transaction can write to its userdata
|
||||||
|
pub userdata: Vec<u8>,
|
||||||
|
/// contract id this contract belongs to
|
||||||
|
pub program_id: Pubkey,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Account {
|
||||||
|
pub fn new(tokens: i64, space: usize, program_id: Pubkey) -> Account {
|
||||||
|
Account {
|
||||||
|
tokens,
|
||||||
|
userdata: vec![0u8; space],
|
||||||
|
program_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
src/bank.rs
31
src/bank.rs
@@ -3,6 +3,7 @@
|
|||||||
//! 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 account::Account;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use budget_program::BudgetState;
|
use budget_program::BudgetState;
|
||||||
@@ -31,36 +32,6 @@ use timing::{duration_as_us, timestamp};
|
|||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
use window::WINDOW_SIZE;
|
use window::WINDOW_SIZE;
|
||||||
|
|
||||||
/// An Account with userdata that is stored on chain
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct Account {
|
|
||||||
/// tokens in the account
|
|
||||||
pub tokens: i64,
|
|
||||||
/// user data
|
|
||||||
/// A transaction can write to its userdata
|
|
||||||
pub userdata: Vec<u8>,
|
|
||||||
/// contract id this contract belongs to
|
|
||||||
pub program_id: Pubkey,
|
|
||||||
}
|
|
||||||
impl Account {
|
|
||||||
pub fn new(tokens: i64, space: usize, program_id: Pubkey) -> Account {
|
|
||||||
Account {
|
|
||||||
tokens,
|
|
||||||
userdata: vec![0u8; space],
|
|
||||||
program_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Account {
|
|
||||||
fn default() -> Self {
|
|
||||||
Account {
|
|
||||||
tokens: 0,
|
|
||||||
userdata: vec![],
|
|
||||||
program_id: SystemProgram::id(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// The number of most recent `last_id` values that the bank will track the signatures
|
/// The number of most recent `last_id` values that the bank will track the signatures
|
||||||
/// of. Once the bank discards a `last_id`, it will reject any transactions that use
|
/// of. Once the bank discards a `last_id`, it will reject any transactions that use
|
||||||
/// that `last_id` in a transaction. Lowering this value reduces memory consumption,
|
/// that `last_id` in a transaction. Lowering this value reduces memory consumption,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
//! budget program
|
//! budget program
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::{self, deserialize, serialize_into, serialized_size};
|
use bincode::{self, deserialize, serialize_into, serialized_size};
|
||||||
use budget::Budget;
|
use budget::Budget;
|
||||||
use budget_instruction::Instruction;
|
use budget_instruction::Instruction;
|
||||||
@@ -265,7 +265,7 @@ impl BudgetState {
|
|||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use budget_program::{BudgetError, BudgetState};
|
use budget_program::{BudgetError, BudgetState};
|
||||||
use budget_transaction::BudgetTransaction;
|
use budget_transaction::BudgetTransaction;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
extern crate generic_array;
|
extern crate generic_array;
|
||||||
|
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use libc;
|
use libc;
|
||||||
use libloading;
|
use libloading;
|
||||||
use signature::Pubkey;
|
use signature::Pubkey;
|
||||||
@@ -105,7 +105,7 @@ impl DynamicProgram {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use signature::Pubkey;
|
use signature::Pubkey;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#![cfg_attr(feature = "unstable", feature(test))]
|
#![cfg_attr(feature = "unstable", feature(test))]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod counter;
|
pub mod counter;
|
||||||
|
pub mod account;
|
||||||
pub mod bank;
|
pub mod bank;
|
||||||
pub mod banking_stage;
|
pub mod banking_stage;
|
||||||
pub mod blob_fetch_stage;
|
pub mod blob_fetch_stage;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
//! The `request` module defines the messages for the thin client.
|
//! The `request` module defines the messages for the thin client.
|
||||||
|
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use signature::{Pubkey, Signature};
|
use signature::{Pubkey, Signature};
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
//! The `rpc` module implements the Solana RPC interface.
|
//! The `rpc` module implements the Solana RPC interface.
|
||||||
|
|
||||||
use bank::{Account, Bank, BankError};
|
use account::Account;
|
||||||
|
use bank::{Bank, BankError};
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use bs58;
|
use bs58;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
//! Receive mining proofs from miners, validate the answers
|
//! Receive mining proofs from miners, validate the answers
|
||||||
//! and give reward for good proofs.
|
//! and give reward for good proofs.
|
||||||
|
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use signature::Pubkey;
|
use signature::Pubkey;
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
//! system program
|
//! system program
|
||||||
|
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use dynamic_program::DynamicProgram;
|
use dynamic_program::DynamicProgram;
|
||||||
use signature::Pubkey;
|
use signature::Pubkey;
|
||||||
@@ -97,7 +97,7 @@ impl SystemProgram {
|
|||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use dynamic_program::KeyedAccount;
|
use dynamic_program::KeyedAccount;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
//! messages to the network directly. The binary encoding of its messages are
|
//! messages to the network directly. The binary encoding of its messages are
|
||||||
//! unstable and may change in future releases.
|
//! unstable and may change in future releases.
|
||||||
|
|
||||||
use bank::{Account, Bank};
|
use account::Account;
|
||||||
|
use bank::Bank;
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use crdt::{Crdt, CrdtError, NodeInfo};
|
use crdt::{Crdt, CrdtError, NodeInfo};
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
//! tic-tac-toe program
|
//! tic-tac-toe program
|
||||||
|
|
||||||
use bank::Account;
|
use account::Account;
|
||||||
use serde_cbor;
|
use serde_cbor;
|
||||||
use signature::Pubkey;
|
use signature::Pubkey;
|
||||||
use std;
|
use std;
|
||||||
|
Reference in New Issue
Block a user