Rename tokens to lamports in sdk/
This commit is contained in:
@ -5,8 +5,8 @@ use std::{cmp, fmt};
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Clone, Default, Eq, PartialEq)]
|
||||
pub struct Account {
|
||||
/// tokens in the account
|
||||
pub tokens: u64,
|
||||
/// lamports in the account
|
||||
pub lamports: u64,
|
||||
/// data held in this account
|
||||
pub userdata: Vec<u8>,
|
||||
/// the program that owns this account. If executable, the program that loads this account.
|
||||
@ -28,8 +28,8 @@ impl fmt::Debug for Account {
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"Account {{ tokens: {} userdata.len: {} owner: {} executable: {}{} }}",
|
||||
self.tokens,
|
||||
"Account {{ lamports: {} userdata.len: {} owner: {} executable: {}{} }}",
|
||||
self.lamports,
|
||||
self.userdata.len(),
|
||||
self.owner,
|
||||
self.executable,
|
||||
@ -40,9 +40,9 @@ impl fmt::Debug for Account {
|
||||
|
||||
impl Account {
|
||||
// TODO do we want to add executable and leader_owner even though they should always be false/default?
|
||||
pub fn new(tokens: u64, space: usize, owner: Pubkey) -> Account {
|
||||
pub fn new(lamports: u64, space: usize, owner: Pubkey) -> Account {
|
||||
Account {
|
||||
tokens,
|
||||
lamports,
|
||||
userdata: vec![0u8; space],
|
||||
owner,
|
||||
executable: false,
|
||||
|
@ -8,18 +8,18 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
// The default (and minimal) amount of tokens given to the bootstrap leader:
|
||||
// * 2 tokens for the bootstrap leader ID account to later setup another vote account
|
||||
// * 1 token for the bootstrap leader vote account
|
||||
pub const BOOTSTRAP_LEADER_TOKENS: u64 = 3;
|
||||
// The default (and minimal) amount of lamports given to the bootstrap leader:
|
||||
// * 2 lamports for the bootstrap leader ID account to later setup another vote account
|
||||
// * 1 lamport for the bootstrap leader vote account
|
||||
pub const BOOTSTRAP_LEADER_LAMPORTS: u64 = 3;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GenesisBlock {
|
||||
pub bootstrap_leader_id: Pubkey,
|
||||
pub bootstrap_leader_tokens: u64,
|
||||
pub bootstrap_leader_lamports: u64,
|
||||
pub bootstrap_leader_vote_account_id: Pubkey,
|
||||
pub mint_id: Pubkey,
|
||||
pub tokens: u64,
|
||||
pub lamports: u64,
|
||||
pub ticks_per_slot: u64,
|
||||
pub slots_per_epoch: u64,
|
||||
pub stakers_slot_offset: u64,
|
||||
@ -27,27 +27,27 @@ pub struct GenesisBlock {
|
||||
|
||||
impl GenesisBlock {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub fn new(tokens: u64) -> (Self, Keypair) {
|
||||
let tokens = tokens
|
||||
.checked_add(BOOTSTRAP_LEADER_TOKENS)
|
||||
.unwrap_or(tokens);
|
||||
Self::new_with_leader(tokens, Keypair::new().pubkey(), BOOTSTRAP_LEADER_TOKENS)
|
||||
pub fn new(lamports: u64) -> (Self, Keypair) {
|
||||
let lamports = lamports
|
||||
.checked_add(BOOTSTRAP_LEADER_LAMPORTS)
|
||||
.unwrap_or(lamports);
|
||||
Self::new_with_leader(lamports, Keypair::new().pubkey(), BOOTSTRAP_LEADER_LAMPORTS)
|
||||
}
|
||||
|
||||
pub fn new_with_leader(
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
bootstrap_leader_id: Pubkey,
|
||||
bootstrap_leader_tokens: u64,
|
||||
bootstrap_leader_lamports: u64,
|
||||
) -> (Self, Keypair) {
|
||||
let mint_keypair = Keypair::new();
|
||||
let bootstrap_leader_vote_account_keypair = Keypair::new();
|
||||
(
|
||||
Self {
|
||||
bootstrap_leader_id,
|
||||
bootstrap_leader_tokens,
|
||||
bootstrap_leader_lamports,
|
||||
bootstrap_leader_vote_account_id: bootstrap_leader_vote_account_keypair.pubkey(),
|
||||
mint_id: mint_keypair.pubkey(),
|
||||
tokens,
|
||||
lamports,
|
||||
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
|
||||
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
|
||||
stakers_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
|
||||
@ -81,13 +81,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_genesis_block_new() {
|
||||
let (genesis_block, mint) = GenesisBlock::new(10_000);
|
||||
assert_eq!(genesis_block.tokens, 10_000 + BOOTSTRAP_LEADER_TOKENS);
|
||||
assert_eq!(genesis_block.lamports, 10_000 + BOOTSTRAP_LEADER_LAMPORTS);
|
||||
assert_eq!(genesis_block.mint_id, mint.pubkey());
|
||||
assert!(genesis_block.bootstrap_leader_id != Pubkey::default());
|
||||
assert!(genesis_block.bootstrap_leader_vote_account_id != Pubkey::default());
|
||||
assert_eq!(
|
||||
genesis_block.bootstrap_leader_tokens,
|
||||
BOOTSTRAP_LEADER_TOKENS
|
||||
genesis_block.bootstrap_leader_lamports,
|
||||
BOOTSTRAP_LEADER_LAMPORTS
|
||||
);
|
||||
}
|
||||
|
||||
@ -97,9 +97,9 @@ mod tests {
|
||||
let (genesis_block, mint) =
|
||||
GenesisBlock::new_with_leader(20_000, leader_keypair.pubkey(), 123);
|
||||
|
||||
assert_eq!(genesis_block.tokens, 20_000);
|
||||
assert_eq!(genesis_block.lamports, 20_000);
|
||||
assert_eq!(genesis_block.mint_id, mint.pubkey());
|
||||
assert_eq!(genesis_block.bootstrap_leader_id, leader_keypair.pubkey());
|
||||
assert_eq!(genesis_block.bootstrap_leader_tokens, 123);
|
||||
assert_eq!(genesis_block.bootstrap_leader_lamports, 123);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub fn check_id(program_id: &Pubkey) -> bool {
|
||||
/// Create an executable account with the given shared object name.
|
||||
pub fn create_program_account(name: &str) -> Account {
|
||||
Account {
|
||||
tokens: 1,
|
||||
lamports: 1,
|
||||
owner: id(),
|
||||
userdata: name.as_bytes().to_vec(),
|
||||
executable: true,
|
||||
|
@ -14,16 +14,16 @@ pub enum ProgramError {
|
||||
/// An instruction resulted in an account with a negative balance
|
||||
/// The difference from InsufficientFundsForFee is that the transaction was executed by the
|
||||
/// contract
|
||||
ResultWithNegativeTokens,
|
||||
ResultWithNegativeLamports,
|
||||
|
||||
/// Program's instruction token balance does not equal the balance after the instruction
|
||||
/// Program's instruction lamport balance does not equal the balance after the instruction
|
||||
UnbalancedInstruction,
|
||||
|
||||
/// Program modified an account's program id
|
||||
ModifiedProgramId,
|
||||
|
||||
/// Program spent the tokens of an account that doesn't belong to it
|
||||
ExternalAccountTokenSpend,
|
||||
/// Program spent the lamports of an account that doesn't belong to it
|
||||
ExternalAccountLamportSpend,
|
||||
|
||||
/// Program modified the userdata of an account that doesn't belong to it
|
||||
ExternalAccountUserdataModified,
|
||||
|
@ -7,35 +7,35 @@ pub enum SystemInstruction {
|
||||
/// Create a new account
|
||||
/// * Transaction::keys[0] - source
|
||||
/// * Transaction::keys[1] - new account key
|
||||
/// * tokens - number of tokens to transfer to the new account
|
||||
/// * lamports - number of lamports to transfer to the new account
|
||||
/// * space - memory to allocate if greater then zero
|
||||
/// * program_id - the program id of the new account
|
||||
CreateAccount {
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
space: u64,
|
||||
program_id: Pubkey,
|
||||
},
|
||||
/// Assign account to a program
|
||||
/// * Transaction::keys[0] - account to assign
|
||||
Assign { program_id: Pubkey },
|
||||
/// Move tokens
|
||||
/// Move lamports
|
||||
/// * Transaction::keys[0] - source
|
||||
/// * Transaction::keys[1] - destination
|
||||
Move { tokens: u64 },
|
||||
Move { lamports: u64 },
|
||||
}
|
||||
|
||||
impl SystemInstruction {
|
||||
pub fn new_program_account(
|
||||
from_id: Pubkey,
|
||||
to_id: Pubkey,
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
space: u64,
|
||||
program_id: Pubkey,
|
||||
) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
system_program::id(),
|
||||
&SystemInstruction::CreateAccount {
|
||||
tokens,
|
||||
lamports,
|
||||
space,
|
||||
program_id,
|
||||
},
|
||||
@ -43,10 +43,10 @@ impl SystemInstruction {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_move(from_id: Pubkey, to_id: Pubkey, tokens: u64) -> BuilderInstruction {
|
||||
pub fn new_move(from_id: Pubkey, to_id: Pubkey, lamports: u64) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
system_program::id(),
|
||||
&SystemInstruction::Move { tokens },
|
||||
&SystemInstruction::Move { lamports },
|
||||
vec![(from_id, true), (to_id, false)],
|
||||
)
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ impl SystemTransaction {
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
space: u64,
|
||||
program_id: Pubkey,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let create = SystemInstruction::CreateAccount {
|
||||
tokens, //TODO, the tokens to allocate might need to be higher then 0 in the future
|
||||
lamports, //TODO, the lamports to allocate might need to be higher then 0 in the future
|
||||
space,
|
||||
program_id,
|
||||
};
|
||||
@ -39,7 +39,7 @@ impl SystemTransaction {
|
||||
pub fn new_account(
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
@ -48,7 +48,7 @@ impl SystemTransaction {
|
||||
from_keypair,
|
||||
to,
|
||||
recent_blockhash,
|
||||
tokens,
|
||||
lamports,
|
||||
0,
|
||||
program_id,
|
||||
fee,
|
||||
@ -75,16 +75,16 @@ impl SystemTransaction {
|
||||
pub fn new_move(
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let move_tokens = SystemInstruction::Move { tokens };
|
||||
let move_lamports = SystemInstruction::Move { lamports };
|
||||
Transaction::new(
|
||||
from_keypair,
|
||||
&[to],
|
||||
system_program::id(),
|
||||
&move_tokens,
|
||||
&move_lamports,
|
||||
recent_blockhash,
|
||||
fee,
|
||||
)
|
||||
@ -100,7 +100,7 @@ impl SystemTransaction {
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, (_, amount))| {
|
||||
let spend = SystemInstruction::Move { tokens: *amount };
|
||||
let spend = SystemInstruction::Move { lamports: *amount };
|
||||
Instruction::new(0, &spend, vec![0, i as u8 + 1])
|
||||
})
|
||||
.collect();
|
||||
|
@ -86,7 +86,7 @@ pub struct Transaction {
|
||||
pub account_keys: Vec<Pubkey>,
|
||||
/// The id of a recent ledger entry.
|
||||
pub recent_blockhash: Hash,
|
||||
/// The number of tokens paid for processing and storing of this transaction.
|
||||
/// The number of lamports paid for processing and storing of this transaction.
|
||||
pub fee: u64,
|
||||
/// All the program id keys used to execute this transaction's instructions
|
||||
pub program_ids: Vec<Pubkey>,
|
||||
@ -141,7 +141,7 @@ impl Transaction {
|
||||
/// Create a signed transaction
|
||||
/// * `from_keypair` - The key used to sign the transaction. This key is stored as keys[0]
|
||||
/// * `account_keys` - The keys for the transaction. These are the program state
|
||||
/// instances or token recipient keys.
|
||||
/// instances or lamport recipient keys.
|
||||
/// * `recent_blockhash` - The PoH hash.
|
||||
/// * `fee` - The transaction fee.
|
||||
/// * `program_ids` - The keys that identify programs used in the `instruction` vector.
|
||||
|
Reference in New Issue
Block a user