| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /**
- * This code was AUTOGENERATED using the Codama library.
- * Please DO NOT EDIT THIS FILE, instead use visitors
- * to add features, then rerun Codama to update it.
- *
- * @see https://github.com/codama-idl/codama
- */
- import {
- assertAccountExists,
- assertAccountsExist,
- combineCodec,
- decodeAccount,
- fetchEncodedAccount,
- fetchEncodedAccounts,
- getAddressDecoder,
- getAddressEncoder,
- getStructDecoder,
- getStructEncoder,
- getU64Decoder,
- getU64Encoder,
- type Account,
- type Address,
- type EncodedAccount,
- type FetchAccountConfig,
- type FetchAccountsConfig,
- type FixedSizeCodec,
- type FixedSizeDecoder,
- type FixedSizeEncoder,
- type MaybeAccount,
- type MaybeEncodedAccount,
- } from '@solana/kit';
- import {
- getNonceStateDecoder,
- getNonceStateEncoder,
- getNonceVersionDecoder,
- getNonceVersionEncoder,
- type NonceState,
- type NonceStateArgs,
- type NonceVersion,
- type NonceVersionArgs,
- } from '../types';
- export type Nonce = {
- version: NonceVersion;
- state: NonceState;
- authority: Address;
- blockhash: Address;
- lamportsPerSignature: bigint;
- };
- export type NonceArgs = {
- version: NonceVersionArgs;
- state: NonceStateArgs;
- authority: Address;
- blockhash: Address;
- lamportsPerSignature: number | bigint;
- };
- export function getNonceEncoder(): FixedSizeEncoder<NonceArgs> {
- return getStructEncoder([
- ['version', getNonceVersionEncoder()],
- ['state', getNonceStateEncoder()],
- ['authority', getAddressEncoder()],
- ['blockhash', getAddressEncoder()],
- ['lamportsPerSignature', getU64Encoder()],
- ]);
- }
- export function getNonceDecoder(): FixedSizeDecoder<Nonce> {
- return getStructDecoder([
- ['version', getNonceVersionDecoder()],
- ['state', getNonceStateDecoder()],
- ['authority', getAddressDecoder()],
- ['blockhash', getAddressDecoder()],
- ['lamportsPerSignature', getU64Decoder()],
- ]);
- }
- export function getNonceCodec(): FixedSizeCodec<NonceArgs, Nonce> {
- return combineCodec(getNonceEncoder(), getNonceDecoder());
- }
- export function decodeNonce<TAddress extends string = string>(
- encodedAccount: EncodedAccount<TAddress>
- ): Account<Nonce, TAddress>;
- export function decodeNonce<TAddress extends string = string>(
- encodedAccount: MaybeEncodedAccount<TAddress>
- ): MaybeAccount<Nonce, TAddress>;
- export function decodeNonce<TAddress extends string = string>(
- encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
- ): Account<Nonce, TAddress> | MaybeAccount<Nonce, TAddress> {
- return decodeAccount(
- encodedAccount as MaybeEncodedAccount<TAddress>,
- getNonceDecoder()
- );
- }
- export async function fetchNonce<TAddress extends string = string>(
- rpc: Parameters<typeof fetchEncodedAccount>[0],
- address: Address<TAddress>,
- config?: FetchAccountConfig
- ): Promise<Account<Nonce, TAddress>> {
- const maybeAccount = await fetchMaybeNonce(rpc, address, config);
- assertAccountExists(maybeAccount);
- return maybeAccount;
- }
- export async function fetchMaybeNonce<TAddress extends string = string>(
- rpc: Parameters<typeof fetchEncodedAccount>[0],
- address: Address<TAddress>,
- config?: FetchAccountConfig
- ): Promise<MaybeAccount<Nonce, TAddress>> {
- const maybeAccount = await fetchEncodedAccount(rpc, address, config);
- return decodeNonce(maybeAccount);
- }
- export async function fetchAllNonce(
- rpc: Parameters<typeof fetchEncodedAccounts>[0],
- addresses: Array<Address>,
- config?: FetchAccountsConfig
- ): Promise<Account<Nonce>[]> {
- const maybeAccounts = await fetchAllMaybeNonce(rpc, addresses, config);
- assertAccountsExist(maybeAccounts);
- return maybeAccounts;
- }
- export async function fetchAllMaybeNonce(
- rpc: Parameters<typeof fetchEncodedAccounts>[0],
- addresses: Array<Address>,
- config?: FetchAccountsConfig
- ): Promise<MaybeAccount<Nonce>[]> {
- const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
- return maybeAccounts.map((maybeAccount) => decodeNonce(maybeAccount));
- }
- export function getNonceSize(): number {
- return 80;
- }
|