diff --git a/clients/js/src/generated/accounts/nonce.ts b/clients/js/src/generated/accounts/nonce.ts index ea233c9..1163ff3 100644 --- a/clients/js/src/generated/accounts/nonce.ts +++ b/clients/js/src/generated/accounts/nonce.ts @@ -24,13 +24,18 @@ import { getStructDecoder, getStructEncoder, } from '@solana/codecs-data-structures'; -import { - getU32Decoder, - getU32Encoder, - getU64Decoder, - getU64Encoder, -} from '@solana/codecs-numbers'; +import { getU64Decoder, getU64Encoder } from '@solana/codecs-numbers'; import { Context } from '../shared'; +import { + NonceState, + NonceStateArgs, + NonceVersion, + NonceVersionArgs, + getNonceStateDecoder, + getNonceStateEncoder, + getNonceVersionDecoder, + getNonceVersionEncoder, +} from '../types'; export type Nonce = Account< NonceAccountData, @@ -38,16 +43,16 @@ export type Nonce = Account< >; export type NonceAccountData = { - discriminator: number; - state: number; + version: NonceVersion; + state: NonceState; authority: Address; blockhash: Address; lamportsPerSignature: bigint; }; export type NonceAccountDataArgs = { - discriminator: number; - state: number; + version: NonceVersionArgs; + state: NonceStateArgs; authority: Address; blockhash: Address; lamportsPerSignature: number | bigint; @@ -55,8 +60,8 @@ export type NonceAccountDataArgs = { export function getNonceAccountDataEncoder() { return getStructEncoder([ - ['discriminator', getU32Encoder()], - ['state', getU32Encoder()], + ['version', getNonceVersionEncoder()], + ['state', getNonceStateEncoder()], ['authority', getAddressEncoder()], ['blockhash', getAddressEncoder()], ['lamportsPerSignature', getU64Encoder()], @@ -65,8 +70,8 @@ export function getNonceAccountDataEncoder() { export function getNonceAccountDataDecoder() { return getStructDecoder([ - ['discriminator', getU32Decoder()], - ['state', getU32Decoder()], + ['version', getNonceVersionDecoder()], + ['state', getNonceStateDecoder()], ['authority', getAddressDecoder()], ['blockhash', getAddressDecoder()], ['lamportsPerSignature', getU64Decoder()], diff --git a/clients/js/src/generated/index.ts b/clients/js/src/generated/index.ts index df6ca17..a377cc4 100644 --- a/clients/js/src/generated/index.ts +++ b/clients/js/src/generated/index.ts @@ -11,3 +11,4 @@ export * from './errors'; export * from './instructions'; export * from './programs'; export * from './shared'; +export * from './types'; diff --git a/clients/js/src/generated/types/index.ts b/clients/js/src/generated/types/index.ts new file mode 100644 index 0000000..575e4a0 --- /dev/null +++ b/clients/js/src/generated/types/index.ts @@ -0,0 +1,10 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/metaplex-foundation/kinobi + */ + +export * from './nonceState'; +export * from './nonceVersion'; diff --git a/clients/js/src/generated/types/nonceState.ts b/clients/js/src/generated/types/nonceState.ts new file mode 100644 index 0000000..079cd68 --- /dev/null +++ b/clients/js/src/generated/types/nonceState.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/metaplex-foundation/kinobi + */ + +import { Codec, Decoder, Encoder, combineCodec } from '@solana/codecs-core'; +import { + getScalarEnumDecoder, + getScalarEnumEncoder, +} from '@solana/codecs-data-structures'; +import { getU32Decoder, getU32Encoder } from '@solana/codecs-numbers'; + +export enum NonceState { + Uninitialized, + Initialized, +} + +export type NonceStateArgs = NonceState; + +export function getNonceStateEncoder() { + return getScalarEnumEncoder(NonceState, { + size: getU32Encoder(), + }) satisfies Encoder; +} + +export function getNonceStateDecoder() { + return getScalarEnumDecoder(NonceState, { + size: getU32Decoder(), + }) satisfies Decoder; +} + +export function getNonceStateCodec(): Codec { + return combineCodec(getNonceStateEncoder(), getNonceStateDecoder()); +} diff --git a/clients/js/src/generated/types/nonceVersion.ts b/clients/js/src/generated/types/nonceVersion.ts new file mode 100644 index 0000000..29807bb --- /dev/null +++ b/clients/js/src/generated/types/nonceVersion.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/metaplex-foundation/kinobi + */ + +import { Codec, Decoder, Encoder, combineCodec } from '@solana/codecs-core'; +import { + getScalarEnumDecoder, + getScalarEnumEncoder, +} from '@solana/codecs-data-structures'; +import { getU32Decoder, getU32Encoder } from '@solana/codecs-numbers'; + +export enum NonceVersion { + Legacy, + Current, +} + +export type NonceVersionArgs = NonceVersion; + +export function getNonceVersionEncoder() { + return getScalarEnumEncoder(NonceVersion, { + size: getU32Encoder(), + }) satisfies Encoder; +} + +export function getNonceVersionDecoder() { + return getScalarEnumDecoder(NonceVersion, { + size: getU32Decoder(), + }) satisfies Decoder; +} + +export function getNonceVersionCodec(): Codec { + return combineCodec(getNonceVersionEncoder(), getNonceVersionDecoder()); +} diff --git a/clients/js/test/_setup.ts b/clients/js/test/_setup.ts index 9899c9c..3b41d11 100644 --- a/clients/js/test/_setup.ts +++ b/clients/js/test/_setup.ts @@ -23,6 +23,8 @@ import { setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, } from '@solana/web3.js'; +import { fetchEncodedAccount, fetchEncodedAccounts } from '@solana/accounts'; +import { Context } from '../src'; type Client = { rpc: ReturnType; @@ -42,6 +44,13 @@ export const createClient = (): Client => { return { rpc, rpcSubscriptions }; }; +export const createContext = (client: Client): Context => ({ + fetchEncodedAccount: async (address, config) => + fetchEncodedAccount(client.rpc, address, config), + fetchEncodedAccounts: async (addresses, config) => + fetchEncodedAccounts(client.rpc, addresses, config), +}); + export const generateKeyPairSignerWithSol = async ( client: Client, putativeLamports: bigint = 1_000_000_000n diff --git a/clients/js/test/initializeNonceAccount.test.ts b/clients/js/test/initializeNonceAccount.test.ts index f99cd5b..4675bea 100644 --- a/clients/js/test/initializeNonceAccount.test.ts +++ b/clients/js/test/initializeNonceAccount.test.ts @@ -1,11 +1,11 @@ -import { fetchEncodedAccount } from '@solana/accounts'; import { pipe } from '@solana/functional'; import { generateKeyPairSigner } from '@solana/signers'; import { appendTransactionInstruction } from '@solana/web3.js'; import test from 'ava'; import { - Context, Nonce, + NonceState, + NonceVersion, SPL_SYSTEM_PROGRAM_ADDRESS, fetchNonce, getCreateAccountInstruction, @@ -13,18 +13,21 @@ import { } from '../src'; import { createClient, + createContext, createDefaultTransaction, generateKeyPairSignerWithSol, signAndSendTransaction, } from './_setup'; test('it can create and initialize a durable nonce account', async (t) => { - // Given + // Given some brand now payer, authority, and nonce KeyPairSigners. const client = createClient(); + const context = createContext(client); const payer = await generateKeyPairSignerWithSol(client); const nonce = await generateKeyPairSigner(); + const nonceAuthority = await generateKeyPairSigner(); - // When + // When we use them to create and initialize a nonce account. const rent = await client.rpc.getMinimumBalanceForRentExemption(80n).send(); const createAccount = getCreateAccountInstruction({ payer, @@ -35,7 +38,7 @@ test('it can create and initialize a durable nonce account', async (t) => { }); const initializeNonceAccount = getInitializeNonceAccountInstruction({ nonceAccount: nonce.address, - nonceAuthority: payer.address, + nonceAuthority: nonceAuthority.address, }); await pipe( await createDefaultTransaction(client, payer.address), @@ -44,22 +47,16 @@ test('it can create and initialize a durable nonce account', async (t) => { (tx) => signAndSendTransaction(client, tx) ); - // Then - const context = { - fetchEncodedAccount: ( - address: Parameters[1], - config: Parameters[2] - ) => fetchEncodedAccount(client.rpc, address, config), - } as Pick; - const account = await fetchNonce(context, nonce.address, { - commitment: 'confirmed', - }); - t.like(account, { - address: nonce.address, - data: { - discriminator: 1, - state: 1, - authority: payer.address, - }, - }); + // Then we expect the nonce account to exist with the following data. + t.like( + await fetchNonce(context, nonce.address, { commitment: 'confirmed' }), + { + address: nonce.address, + data: { + version: NonceVersion.Current, + state: NonceState.Initialized, + authority: nonceAuthority.address, + }, + } + ); }); diff --git a/clients/rust/src/generated/accounts/nonce.rs b/clients/rust/src/generated/accounts/nonce.rs index 10cb695..4e5a37d 100644 --- a/clients/rust/src/generated/accounts/nonce.rs +++ b/clients/rust/src/generated/accounts/nonce.rs @@ -5,6 +5,8 @@ //! [https://github.com/metaplex-foundation/kinobi] //! +use crate::generated::types::NonceState; +use crate::generated::types::NonceVersion; use borsh::BorshDeserialize; use borsh::BorshSerialize; use solana_program::pubkey::Pubkey; @@ -12,8 +14,8 @@ use solana_program::pubkey::Pubkey; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Nonce { - pub discriminator: u32, - pub state: u32, + pub version: NonceVersion, + pub state: NonceState, #[cfg_attr( feature = "serde", serde(with = "serde_with::As::") diff --git a/clients/rust/src/generated/mod.rs b/clients/rust/src/generated/mod.rs index b7833f1..1dc8fd1 100644 --- a/clients/rust/src/generated/mod.rs +++ b/clients/rust/src/generated/mod.rs @@ -9,5 +9,6 @@ pub mod accounts; pub mod errors; pub mod instructions; pub mod programs; +pub mod types; pub(crate) use programs::*; diff --git a/clients/rust/src/generated/types/mod.rs b/clients/rust/src/generated/types/mod.rs new file mode 100644 index 0000000..006b524 --- /dev/null +++ b/clients/rust/src/generated/types/mod.rs @@ -0,0 +1,12 @@ +//! This code was AUTOGENERATED using the kinobi library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun kinobi to update it. +//! +//! [https://github.com/metaplex-foundation/kinobi] +//! + +pub(crate) mod r#nonce_state; +pub(crate) mod r#nonce_version; + +pub use self::r#nonce_state::*; +pub use self::r#nonce_version::*; diff --git a/clients/rust/src/generated/types/nonce_state.rs b/clients/rust/src/generated/types/nonce_state.rs new file mode 100644 index 0000000..049b41a --- /dev/null +++ b/clients/rust/src/generated/types/nonce_state.rs @@ -0,0 +1,16 @@ +//! This code was AUTOGENERATED using the kinobi library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun kinobi to update it. +//! +//! [https://github.com/metaplex-foundation/kinobi] +//! + +use borsh::BorshDeserialize; +use borsh::BorshSerialize; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum NonceState { + Uninitialized, + Initialized, +} diff --git a/clients/rust/src/generated/types/nonce_version.rs b/clients/rust/src/generated/types/nonce_version.rs new file mode 100644 index 0000000..77fbccd --- /dev/null +++ b/clients/rust/src/generated/types/nonce_version.rs @@ -0,0 +1,16 @@ +//! This code was AUTOGENERATED using the kinobi library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun kinobi to update it. +//! +//! [https://github.com/metaplex-foundation/kinobi] +//! + +use borsh::BorshDeserialize; +use borsh::BorshSerialize; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum NonceVersion { + Legacy, + Current, +} diff --git a/idls/spl_system.json b/idls/spl_system.json index 9d4b719..e2b979b 100644 --- a/idls/spl_system.json +++ b/idls/spl_system.json @@ -8,12 +8,12 @@ "kind": "struct", "fields": [ { - "name": "discriminator", - "type": "u32" + "name": "version", + "type": { "defined": "NonceVersion" } }, { "name": "state", - "type": "u32" + "type": { "defined": "NonceState" } }, { "name": "authority", @@ -420,7 +420,24 @@ } } ], - "types": [], + "types": [ + { + "name": "NonceVersion", + "type": { + "kind": "enum", + "size": "u32", + "variants": [{ "name": "Legacy" }, { "name": "Current" }] + } + }, + { + "name": "NonceState", + "type": { + "kind": "enum", + "size": "u32", + "variants": [{ "name": "Uninitialized" }, { "name": "Initialized" }] + } + } + ], "errors": [ { "code": 0,