-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
4,367 additions
and
52 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
templates/product-program/clients/js/src/generated/accounts/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
export * from './programAccount'; |
156 changes: 156 additions & 0 deletions
156
templates/product-program/clients/js/src/generated/accounts/programAccount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
import { | ||
assertAccountExists, | ||
assertAccountsExist, | ||
combineCodec, | ||
decodeAccount, | ||
fetchEncodedAccount, | ||
fetchEncodedAccounts, | ||
getAddressDecoder, | ||
getAddressEncoder, | ||
getStructDecoder, | ||
getStructEncoder, | ||
transformEncoder, | ||
type Account, | ||
type Address, | ||
type Codec, | ||
type Decoder, | ||
type EncodedAccount, | ||
type Encoder, | ||
type FetchAccountConfig, | ||
type FetchAccountsConfig, | ||
type MaybeAccount, | ||
type MaybeEncodedAccount, | ||
} from '@solana/web3.js'; | ||
import { ProgramAccountSeeds, findProgramAccountPda } from '../pdas'; | ||
import { Key, getKeyDecoder, getKeyEncoder } from '../types'; | ||
|
||
export type ProgramAccount = { | ||
key: Key; | ||
authority: Address; | ||
productMint: Address; | ||
}; | ||
|
||
export type ProgramAccountArgs = { authority: Address; productMint: Address }; | ||
|
||
export function getProgramAccountEncoder(): Encoder<ProgramAccountArgs> { | ||
return transformEncoder( | ||
getStructEncoder([ | ||
['key', getKeyEncoder()], | ||
['authority', getAddressEncoder()], | ||
['productMint', getAddressEncoder()], | ||
]), | ||
(value) => ({ ...value, key: Key.ProgramAccount }) | ||
); | ||
} | ||
|
||
export function getProgramAccountDecoder(): Decoder<ProgramAccount> { | ||
return getStructDecoder([ | ||
['key', getKeyDecoder()], | ||
['authority', getAddressDecoder()], | ||
['productMint', getAddressDecoder()], | ||
]); | ||
} | ||
|
||
export function getProgramAccountCodec(): Codec< | ||
ProgramAccountArgs, | ||
ProgramAccount | ||
> { | ||
return combineCodec(getProgramAccountEncoder(), getProgramAccountDecoder()); | ||
} | ||
|
||
export function decodeProgramAccount<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | ||
): Account<ProgramAccount, TAddress>; | ||
export function decodeProgramAccount<TAddress extends string = string>( | ||
encodedAccount: MaybeEncodedAccount<TAddress> | ||
): MaybeAccount<ProgramAccount, TAddress>; | ||
export function decodeProgramAccount<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress> | ||
): Account<ProgramAccount, TAddress> | MaybeAccount<ProgramAccount, TAddress> { | ||
return decodeAccount( | ||
encodedAccount as MaybeEncodedAccount<TAddress>, | ||
getProgramAccountDecoder() | ||
); | ||
} | ||
|
||
export async function fetchProgramAccount<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<Account<ProgramAccount, TAddress>> { | ||
const maybeAccount = await fetchMaybeProgramAccount(rpc, address, config); | ||
assertAccountExists(maybeAccount); | ||
return maybeAccount; | ||
} | ||
|
||
export async function fetchMaybeProgramAccount< | ||
TAddress extends string = string, | ||
>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<MaybeAccount<ProgramAccount, TAddress>> { | ||
const maybeAccount = await fetchEncodedAccount(rpc, address, config); | ||
return decodeProgramAccount(maybeAccount); | ||
} | ||
|
||
export async function fetchAllProgramAccount( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<Account<ProgramAccount>[]> { | ||
const maybeAccounts = await fetchAllMaybeProgramAccount( | ||
rpc, | ||
addresses, | ||
config | ||
); | ||
assertAccountsExist(maybeAccounts); | ||
return maybeAccounts; | ||
} | ||
|
||
export async function fetchAllMaybeProgramAccount( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<MaybeAccount<ProgramAccount>[]> { | ||
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); | ||
return maybeAccounts.map((maybeAccount) => | ||
decodeProgramAccount(maybeAccount) | ||
); | ||
} | ||
|
||
export function getProgramAccountSize(): number { | ||
return 65; | ||
} | ||
|
||
export async function fetchProgramAccountFromSeeds( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
seeds: ProgramAccountSeeds, | ||
config: FetchAccountConfig & { programAddress?: Address } = {} | ||
): Promise<Account<ProgramAccount>> { | ||
const maybeAccount = await fetchMaybeProgramAccountFromSeeds( | ||
rpc, | ||
seeds, | ||
config | ||
); | ||
assertAccountExists(maybeAccount); | ||
return maybeAccount; | ||
} | ||
|
||
export async function fetchMaybeProgramAccountFromSeeds( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
seeds: ProgramAccountSeeds, | ||
config: FetchAccountConfig & { programAddress?: Address } = {} | ||
): Promise<MaybeAccount<ProgramAccount>> { | ||
const { programAddress, ...fetchConfig } = config; | ||
const [address] = await findProgramAccountPda(seeds, { programAddress }); | ||
return await fetchMaybeProgramAccount(rpc, address, fetchConfig); | ||
} |
9 changes: 9 additions & 0 deletions
9
templates/product-program/clients/js/src/generated/errors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
export * from './productProgram'; |
74 changes: 74 additions & 0 deletions
74
templates/product-program/clients/js/src/generated/errors/productProgram.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
/** DeserializationError: Error deserializing an account */ | ||
export const PRODUCT_PROGRAM_ERROR__DESERIALIZATION_ERROR = 0x0; // 0 | ||
/** SerializationError: Error serializing an account */ | ||
export const PRODUCT_PROGRAM_ERROR__SERIALIZATION_ERROR = 0x1; // 1 | ||
/** InvalidProgramOwner: Invalid program owner. This likely mean the provided account does not exist */ | ||
export const PRODUCT_PROGRAM_ERROR__INVALID_PROGRAM_OWNER = 0x2; // 2 | ||
/** InvalidPda: Invalid PDA derivation */ | ||
export const PRODUCT_PROGRAM_ERROR__INVALID_PDA = 0x3; // 3 | ||
/** ExpectedEmptyAccount: Expected empty account */ | ||
export const PRODUCT_PROGRAM_ERROR__EXPECTED_EMPTY_ACCOUNT = 0x4; // 4 | ||
/** ExpectedNonEmptyAccount: Expected non empty account */ | ||
export const PRODUCT_PROGRAM_ERROR__EXPECTED_NON_EMPTY_ACCOUNT = 0x5; // 5 | ||
/** ExpectedSignerAccount: Expected signer account */ | ||
export const PRODUCT_PROGRAM_ERROR__EXPECTED_SIGNER_ACCOUNT = 0x6; // 6 | ||
/** ExpectedWritableAccount: Expected writable account */ | ||
export const PRODUCT_PROGRAM_ERROR__EXPECTED_WRITABLE_ACCOUNT = 0x7; // 7 | ||
/** AccountMismatch: Account mismatch */ | ||
export const PRODUCT_PROGRAM_ERROR__ACCOUNT_MISMATCH = 0x8; // 8 | ||
/** InvalidAccountKey: Invalid account key */ | ||
export const PRODUCT_PROGRAM_ERROR__INVALID_ACCOUNT_KEY = 0x9; // 9 | ||
/** NumericalOverflow: Numerical overflow */ | ||
export const PRODUCT_PROGRAM_ERROR__NUMERICAL_OVERFLOW = 0xa; // 10 | ||
|
||
export type ProductProgramError = | ||
| typeof PRODUCT_PROGRAM_ERROR__ACCOUNT_MISMATCH | ||
| typeof PRODUCT_PROGRAM_ERROR__DESERIALIZATION_ERROR | ||
| typeof PRODUCT_PROGRAM_ERROR__EXPECTED_EMPTY_ACCOUNT | ||
| typeof PRODUCT_PROGRAM_ERROR__EXPECTED_NON_EMPTY_ACCOUNT | ||
| typeof PRODUCT_PROGRAM_ERROR__EXPECTED_SIGNER_ACCOUNT | ||
| typeof PRODUCT_PROGRAM_ERROR__EXPECTED_WRITABLE_ACCOUNT | ||
| typeof PRODUCT_PROGRAM_ERROR__INVALID_ACCOUNT_KEY | ||
| typeof PRODUCT_PROGRAM_ERROR__INVALID_PDA | ||
| typeof PRODUCT_PROGRAM_ERROR__INVALID_PROGRAM_OWNER | ||
| typeof PRODUCT_PROGRAM_ERROR__NUMERICAL_OVERFLOW | ||
| typeof PRODUCT_PROGRAM_ERROR__SERIALIZATION_ERROR; | ||
|
||
let productProgramErrorMessages: | ||
| Record<ProductProgramError, string> | ||
| undefined; | ||
if (__DEV__) { | ||
productProgramErrorMessages = { | ||
[PRODUCT_PROGRAM_ERROR__ACCOUNT_MISMATCH]: `Account mismatch`, | ||
[PRODUCT_PROGRAM_ERROR__DESERIALIZATION_ERROR]: `Error deserializing an account`, | ||
[PRODUCT_PROGRAM_ERROR__EXPECTED_EMPTY_ACCOUNT]: `Expected empty account`, | ||
[PRODUCT_PROGRAM_ERROR__EXPECTED_NON_EMPTY_ACCOUNT]: `Expected non empty account`, | ||
[PRODUCT_PROGRAM_ERROR__EXPECTED_SIGNER_ACCOUNT]: `Expected signer account`, | ||
[PRODUCT_PROGRAM_ERROR__EXPECTED_WRITABLE_ACCOUNT]: `Expected writable account`, | ||
[PRODUCT_PROGRAM_ERROR__INVALID_ACCOUNT_KEY]: `Invalid account key`, | ||
[PRODUCT_PROGRAM_ERROR__INVALID_PDA]: `Invalid PDA derivation`, | ||
[PRODUCT_PROGRAM_ERROR__INVALID_PROGRAM_OWNER]: `Invalid program owner. This likely mean the provided account does not exist`, | ||
[PRODUCT_PROGRAM_ERROR__NUMERICAL_OVERFLOW]: `Numerical overflow`, | ||
[PRODUCT_PROGRAM_ERROR__SERIALIZATION_ERROR]: `Error serializing an account`, | ||
}; | ||
} | ||
|
||
export function getProductProgramErrorMessage( | ||
code: ProductProgramError | ||
): string { | ||
if (__DEV__) { | ||
return (productProgramErrorMessages as Record<ProductProgramError, string>)[ | ||
code | ||
]; | ||
} | ||
|
||
return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.'; | ||
} |
11 changes: 11 additions & 0 deletions
11
templates/product-program/clients/js/src/generated/global.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
/** Global variable provided by bundlers telling us if we are building for production or not. */ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
declare const __DEV__: boolean; |
14 changes: 14 additions & 0 deletions
14
templates/product-program/clients/js/src/generated/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* 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/kinobi-so/kinobi | ||
*/ | ||
|
||
export * from './accounts'; | ||
export * from './errors'; | ||
export * from './instructions'; | ||
export * from './pdas'; | ||
export * from './programs'; | ||
export * from './types'; |
Oops, something went wrong.