Skip to content

Commit

Permalink
force using old acount discriminator for VoterWeightRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
crypt0miester committed Aug 5, 2024
1 parent 45dac13 commit 632b789
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions programs/voter-stake-registry/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ macro_rules! vote_weight_record {
#[cfg(feature = "idl-build")]
impl anchor_lang::IdlBuild for VoterWeightRecord {}

#[cfg(feature = "idl-build")]
impl anchor_lang::Discriminator for VoterWeightRecord {
const DISCRIMINATOR: [u8; 8] = [0; 8];
fn discriminator() -> [u8; 8] {
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR
// legacy discriminator which is not compatible with Anchor but is used by older plugins
*b"2ef99b4b"
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::error::*;
use crate::state::*;
use anchor_lang::prelude::*;
use anchor_lang::solana_program::sysvar::instructions as tx_instructions;
use anchor_lang::Discriminator;
use std::mem::size_of;

#[derive(Accounts)]
Expand Down Expand Up @@ -82,8 +83,7 @@ pub fn create_voter(
voter.registrar = ctx.accounts.registrar.key();

let voter_weight_record = &mut ctx.accounts.voter_weight_record;
voter_weight_record.account_discriminator =
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR;
voter_weight_record.account_discriminator = VoterWeightRecord::discriminator();
voter_weight_record.realm = registrar.realm;
voter_weight_record.governing_token_mint = registrar.realm_governing_token_mint;
voter_weight_record.governing_token_owner = voter_authority;
Expand Down
4 changes: 2 additions & 2 deletions programs/voter-stake-registry/src/instructions/grant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::*;
use crate::state::*;
use anchor_lang::prelude::*;
use anchor_lang::Discriminator;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{self, Mint, Token, TokenAccount};
use std::convert::TryFrom;
Expand Down Expand Up @@ -145,8 +146,7 @@ pub fn grant(
// Note that vote_weight_record is not an Anchor account, is_freshly_initialized()
// would not work.
let voter_weight_record = &mut ctx.accounts.voter_weight_record;
voter_weight_record.account_discriminator =
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR;
voter_weight_record.account_discriminator = VoterWeightRecord::discriminator();
voter_weight_record.realm = registrar.realm;
voter_weight_record.governing_token_mint = registrar.realm_governing_token_mint;
voter_weight_record.governing_token_owner = voter_authority;
Expand Down
4 changes: 2 additions & 2 deletions programs/voter-stake-registry/tests/test_grants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ async fn test_grants() -> Result<(), TransportError> {
.get_account::<voter_stake_registry::state::Voter>(voter.address)
.await;
let deposit = &voter_data.deposits[1];
assert_eq!(deposit.is_used, true.into());
assert_eq!(deposit.is_used, true);
let amount_deposited_native = deposit.amount_deposited_native;
let amount_initially_locked_native = deposit.amount_initially_locked_native;
assert_eq!(amount_deposited_native, 12000);
assert_eq!(amount_initially_locked_native, 12000);
assert_eq!(deposit.allow_clawback, true.into());
assert_eq!(deposit.allow_clawback, true);
assert_eq!(deposit.lockup.kind, LockupKind::Monthly);
assert_eq!(deposit.lockup.periods_total().unwrap(), 12);

Expand Down

0 comments on commit 632b789

Please sign in to comment.