Skip to content

Commit

Permalink
Rename stake state account
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Dec 4, 2024
1 parent b4065f7 commit 1582a27
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion clients/js/src/generated/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* @see https://github.com/codama-idl/codama
*/

export * from './stakeAccount';
export * from './stakeState';
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,71 @@ import {
type StakeStateV2Args,
} from '../types';

export type StakeAccount = { state: StakeStateV2 };
export type StakeState = { state: StakeStateV2 };

export type StakeAccountArgs = { state: StakeStateV2Args };
export type StakeStateArgs = { state: StakeStateV2Args };

export function getStakeAccountEncoder(): Encoder<StakeAccountArgs> {
export function getStakeStateEncoder(): Encoder<StakeStateArgs> {
return getStructEncoder([['state', getStakeStateV2Encoder()]]);
}

export function getStakeAccountDecoder(): Decoder<StakeAccount> {
export function getStakeStateDecoder(): Decoder<StakeState> {
return getStructDecoder([['state', getStakeStateV2Decoder()]]);
}

export function getStakeAccountCodec(): Codec<StakeAccountArgs, StakeAccount> {
return combineCodec(getStakeAccountEncoder(), getStakeAccountDecoder());
export function getStakeStateCodec(): Codec<StakeStateArgs, StakeState> {
return combineCodec(getStakeStateEncoder(), getStakeStateDecoder());
}

export function decodeStakeAccount<TAddress extends string = string>(
export function decodeStakeState<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>
): Account<StakeAccount, TAddress>;
export function decodeStakeAccount<TAddress extends string = string>(
): Account<StakeState, TAddress>;
export function decodeStakeState<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>
): MaybeAccount<StakeAccount, TAddress>;
export function decodeStakeAccount<TAddress extends string = string>(
): MaybeAccount<StakeState, TAddress>;
export function decodeStakeState<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
): Account<StakeAccount, TAddress> | MaybeAccount<StakeAccount, TAddress> {
): Account<StakeState, TAddress> | MaybeAccount<StakeState, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getStakeAccountDecoder()
getStakeStateDecoder()
);
}

export async function fetchStakeAccount<TAddress extends string = string>(
export async function fetchStakeState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<Account<StakeAccount, TAddress>> {
const maybeAccount = await fetchMaybeStakeAccount(rpc, address, config);
): Promise<Account<StakeState, TAddress>> {
const maybeAccount = await fetchMaybeStakeState(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}

export async function fetchMaybeStakeAccount<TAddress extends string = string>(
export async function fetchMaybeStakeState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<MaybeAccount<StakeAccount, TAddress>> {
): Promise<MaybeAccount<StakeState, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeStakeAccount(maybeAccount);
return decodeStakeState(maybeAccount);
}

export async function fetchAllStakeAccount(
export async function fetchAllStakeState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<Account<StakeAccount>[]> {
const maybeAccounts = await fetchAllMaybeStakeAccount(rpc, addresses, config);
): Promise<Account<StakeState>[]> {
const maybeAccounts = await fetchAllMaybeStakeState(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}

export async function fetchAllMaybeStakeAccount(
export async function fetchAllMaybeStakeState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<StakeAccount>[]> {
): Promise<MaybeAccount<StakeState>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeStakeAccount(maybeAccount));
return maybeAccounts.map((maybeAccount) => decodeStakeState(maybeAccount));
}
2 changes: 1 addition & 1 deletion clients/js/src/generated/programs/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const STAKE_PROGRAM_ADDRESS =
'Stake11111111111111111111111111111111111111' as Address<'Stake11111111111111111111111111111111111111'>;

export enum StakeAccount {
StakeAccount,
StakeState,
}

export enum StakeInstruction {
Expand Down
4 changes: 2 additions & 2 deletions clients/rust/src/hooked/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod stake_account;
pub use stake_account::*;
pub mod stake_state;
pub use stake_state::*;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use {
};

#[derive(Clone, Debug)]
pub struct StakeAccount {
pub struct StakeState {
state: StakeStateV2,
}

impl StakeAccount {
impl StakeState {
#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl StakeAccount {
}
}

impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for StakeAccount {
impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for StakeState {
type Error = std::io::Error;

fn try_from(
Expand All @@ -116,7 +116,7 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for StakeAccoun
}
}

impl BorshDeserialize for StakeAccount {
impl BorshDeserialize for StakeState {
fn deserialize_reader<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
let enum_value: u32 = BorshDeserialize::deserialize_reader(reader)?;
let state = match enum_value {
Expand All @@ -135,11 +135,11 @@ impl BorshDeserialize for StakeAccount {
_ => return Err(Error::new(ErrorKind::InvalidData, "Invalid enum value")),
};

Ok(StakeAccount { state })
Ok(StakeState { state })
}
}

impl BorshSerialize for StakeAccount {
impl BorshSerialize for StakeState {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
match self.state {
StakeStateV2::Uninitialized => writer.write_all(&0u32.to_le_bytes()),
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-clients.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ codama.update(
...node.accounts,
// stake account
c.accountNode({
name: 'stakeAccount',
name: 'stakeState',
data: c.structTypeNode([
c.structFieldTypeNode({
name: 'state',
Expand Down Expand Up @@ -190,7 +190,7 @@ codama.accept(
// provides its own implementation.
codama.update(
c.updateAccountsVisitor({
stakeAccount: { delete: true },
stakeState: { delete: true },
})
);

Expand Down

0 comments on commit 1582a27

Please sign in to comment.