Rename tokens to lamports in sdk/

This commit is contained in:
Michael Vines
2019-03-05 16:28:14 -08:00
parent bd237a2d6f
commit 53f09c44f3
33 changed files with 324 additions and 306 deletions

View File

@@ -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);
}
}