@nosana/kit
Version:
Nosana KIT
87 lines • 2.62 kB
JavaScript
/**
* 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 { AccountRole, isProgramDerivedAddress, isTransactionSigner as kitIsTransactionSigner, upgradeRoleToSigner, } from '@solana/kit';
/**
* Asserts that the given value is not null or undefined.
* @internal
*/
export function expectSome(value) {
if (value === null || value === undefined) {
throw new Error('Expected a value but received null or undefined.');
}
return value;
}
/**
* Asserts that the given value is a PublicKey.
* @internal
*/
export function expectAddress(value) {
if (!value) {
throw new Error('Expected a Address.');
}
if (typeof value === 'object' && 'address' in value) {
return value.address;
}
if (Array.isArray(value)) {
return value[0];
}
return value;
}
/**
* Asserts that the given value is a PDA.
* @internal
*/
export function expectProgramDerivedAddress(value) {
if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) {
throw new Error('Expected a ProgramDerivedAddress.');
}
return value;
}
/**
* Asserts that the given value is a TransactionSigner.
* @internal
*/
export function expectTransactionSigner(value) {
if (!value || !isTransactionSigner(value)) {
throw new Error('Expected a TransactionSigner.');
}
return value;
}
/**
* Get account metas and signers from resolved accounts.
* @internal
*/
export function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
return (account) => {
if (!account.value) {
if (optionalAccountStrategy === 'omitted')
return;
return Object.freeze({
address: programAddress,
role: AccountRole.READONLY,
});
}
const writableRole = account.isWritable
? AccountRole.WRITABLE
: AccountRole.READONLY;
return Object.freeze({
address: expectAddress(account.value),
role: isTransactionSigner(account.value)
? upgradeRoleToSigner(writableRole)
: writableRole,
...(isTransactionSigner(account.value) ? { signer: account.value } : {}),
});
};
}
export function isTransactionSigner(value) {
return (!!value &&
typeof value === 'object' &&
'address' in value &&
kitIsTransactionSigner(value));
}
//# sourceMappingURL=index.js.map