Skip to content

Commit

Permalink
Fix name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Dec 4, 2024
1 parent 1582a27 commit cc6bf35
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 39 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 './stakeState';
export * from './stakeStateAccount';
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,87 @@ import {
type StakeStateV2Args,
} from '../types';

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

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

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

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

export function getStakeStateCodec(): Codec<StakeStateArgs, StakeState> {
return combineCodec(getStakeStateEncoder(), getStakeStateDecoder());
export function getStakeStateAccountCodec(): Codec<
StakeStateAccountArgs,
StakeStateAccount
> {
return combineCodec(
getStakeStateAccountEncoder(),
getStakeStateAccountDecoder()
);
}

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

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

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

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

export async function fetchAllMaybeStakeState(
export async function fetchAllMaybeStakeStateAccount(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<StakeState>[]> {
): Promise<MaybeAccount<StakeStateAccount>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeStakeState(maybeAccount));
return maybeAccounts.map((maybeAccount) =>
decodeStakeStateAccount(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 {
StakeState,
StakeStateAccount,
}

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_state;
pub use stake_state::*;
pub mod stake_state_account;
pub use stake_state_account::*;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use {
};

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

impl StakeState {
impl StakeStateAccount {
#[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 StakeState {
}
}

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

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

impl BorshDeserialize for StakeState {
impl BorshDeserialize for StakeStateAccount {
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 StakeState {
_ => return Err(Error::new(ErrorKind::InvalidData, "Invalid enum value")),
};

Ok(StakeState { state })
Ok(StakeStateAccount { state })
}
}

impl BorshSerialize for StakeState {
impl BorshSerialize for StakeStateAccount {
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 clients/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod generated;
pub mod hooked;
mod hooked;

pub use {
generated::{programs::STAKE_ID as ID, *},
hooked as accounts,
hooked::StakeStateAccount,
};
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: 'stakeState',
name: 'stakeStateAccount',
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({
stakeState: { delete: true },
stakeStateAccount: { delete: true },
})
);

Expand Down

0 comments on commit cc6bf35

Please sign in to comment.