Skip to content

Commit

Permalink
frontend fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Jun 12, 2024
1 parent 58dc439 commit 607b890
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion wasm/utils/solana-extra/src/program/spl_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn ui_amount_to_amount(ui_amount: f64, decimals: u8) -> u64 {

/// Convert a raw amount to its UI representation (using the decimals field defined in its mint)
pub fn amount_to_ui_amount(amount: u64, decimals: u8) -> f64 {
amount as f64 / 10_usize.pow(decimals as u32) as f64
amount as f64 / 10f64.powf(decimals as f64)
}

/// Convert a raw amount to its UI representation (using the decimals field defined in its mint)
Expand Down
34 changes: 15 additions & 19 deletions wasm/utils/solana-extra/src/program/vote/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,15 +1212,15 @@ pub fn authorize<S: std::hash::BuildHasher>(
}
}

vote_account.set_state(&VoteStateVersions::new_current(vote_state), feature_set)
vote_account.set_state(&VoteStateVersions::new_current(vote_state))
}

/// Update the node_pubkey, requires signature of the authorized voter
pub fn update_validator_identity<S: std::hash::BuildHasher>(
vote_account: &mut BorrowedAccount,
node_pubkey: &Pubkey,
signers: &HashSet<Pubkey, S>,
feature_set: &FeatureSet,
_feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
let mut vote_state: VoteState = vote_account
.get_state::<VoteStateVersions>()?
Expand All @@ -1234,15 +1234,15 @@ pub fn update_validator_identity<S: std::hash::BuildHasher>(

vote_state.node_pubkey = *node_pubkey;

vote_account.set_state(&VoteStateVersions::new_current(vote_state), feature_set)
vote_account.set_state(&VoteStateVersions::new_current(vote_state))
}

/// Update the vote account's commission
pub fn update_commission<S: std::hash::BuildHasher>(
vote_account: &mut BorrowedAccount,
commission: u8,
signers: &HashSet<Pubkey, S>,
feature_set: &FeatureSet,
_feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
let mut vote_state: VoteState = vote_account
.get_state::<VoteStateVersions>()?
Expand All @@ -1253,7 +1253,7 @@ pub fn update_commission<S: std::hash::BuildHasher>(

vote_state.commission = commission;

vote_account.set_state(&VoteStateVersions::new_current(vote_state), feature_set)
vote_account.set_state(&VoteStateVersions::new_current(vote_state))
}

fn verify_authorized_signer<S: std::hash::BuildHasher>(
Expand All @@ -1278,7 +1278,7 @@ pub fn withdraw<S: std::hash::BuildHasher>(
signers: &HashSet<Pubkey, S>,
rent_sysvar: Option<&Rent>,
clock: Option<&Clock>,
feature_set: &FeatureSet,
_feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
// NOTE: solana-sdk 1.11 `try_borrow_account` is private(this lib was written in 1.10.29)
// We use `try_borrow_instruction_account` to fix it.
Expand Down Expand Up @@ -1315,10 +1315,7 @@ pub fn withdraw<S: std::hash::BuildHasher>(
// Deinitialize upon zero-balance
// TODO:
// datapoint_debug!("vote-account-close", ("allow", 1, i64));
vote_account.set_state(
&VoteStateVersions::new_current(VoteState::default()),
feature_set,
)?;
vote_account.set_state(&VoteStateVersions::new_current(VoteState::default()))?;
}
} else if let Some(rent_sysvar) = rent_sysvar {
let min_rent_exempt_balance = rent_sysvar.minimum_balance(vote_account.get_data().len());
Expand All @@ -1327,13 +1324,13 @@ pub fn withdraw<S: std::hash::BuildHasher>(
}
}

vote_account.checked_sub_lamports(lamports, feature_set)?;
vote_account.checked_sub_lamports(lamports)?;
drop(vote_account);
// NOTE: solana-sdk 1.11 `try_borrow_account` is private(this lib was written in 1.10.29)
// We use `try_borrow_instruction_account` to fix it.
let mut to_account = instruction_context
.try_borrow_instruction_account(transaction_context, to_account_index)?;
to_account.checked_add_lamports(lamports, feature_set)?;
to_account.checked_add_lamports(lamports)?;
Ok(())
}

Expand All @@ -1345,7 +1342,7 @@ pub fn initialize_account<S: std::hash::BuildHasher>(
vote_init: &VoteInit,
signers: &HashSet<Pubkey, S>,
clock: &Clock,
feature_set: &FeatureSet,
_feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
if vote_account.get_data().len() != VoteState::size_of() {
return Err(InstructionError::InvalidAccountData);
Expand All @@ -1359,10 +1356,9 @@ pub fn initialize_account<S: std::hash::BuildHasher>(
// node must agree to accept this vote account
verify_authorized_signer(&vote_init.node_pubkey, signers)?;

vote_account.set_state(
&VoteStateVersions::new_current(VoteState::new(vote_init, clock)),
feature_set,
)
vote_account.set_state(&VoteStateVersions::new_current(VoteState::new(
vote_init, clock,
)))
}

fn verify_and_get_vote_state<S: std::hash::BuildHasher>(
Expand Down Expand Up @@ -1401,7 +1397,7 @@ pub fn process_vote<S: std::hash::BuildHasher>(
.ok_or(VoteError::EmptySlots)
.and_then(|slot| vote_state.process_timestamp(*slot, timestamp))?;
}
vote_account.set_state(&VoteStateVersions::new_current(vote_state), feature_set)
vote_account.set_state(&VoteStateVersions::new_current(vote_state))
}

pub fn process_vote_state_update<S: std::hash::BuildHasher>(
Expand All @@ -1421,7 +1417,7 @@ pub fn process_vote_state_update<S: std::hash::BuildHasher>(
clock.epoch,
Some(feature_set),
)?;
vote_account.set_state(&VoteStateVersions::new_current(vote_state), feature_set)
vote_account.set_state(&VoteStateVersions::new_current(vote_state))
}

pub fn create_account_with_authorized(
Expand Down

0 comments on commit 607b890

Please sign in to comment.