UNPKG

@wuwei-labs/srsly

Version:
140 lines 6.17 kB
/** * 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 { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { expectAddress, getAccountMetaFactory } from '../shared'; export const INVALIDATE_RENTAL_DISCRIMINATOR = new Uint8Array([ 180, 183, 106, 153, 255, 8, 232, 178, ]); export function getInvalidateRentalDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INVALIDATE_RENTAL_DISCRIMINATOR); } export function getInvalidateRentalInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: INVALIDATE_RENTAL_DISCRIMINATOR })); } export function getInvalidateRentalInstructionDataDecoder() { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getInvalidateRentalInstructionDataCodec() { return combineCodec(getInvalidateRentalInstructionDataEncoder(), getInvalidateRentalInstructionDataDecoder()); } export async function getInvalidateRentalInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { signer: { value: input.signer ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: false }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.contract.value) { accounts.contract.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([114, 101, 110, 116, 97, 108, 95, 99, 111, 110, 116, 114, 97, 99, 116])), getAddressEncoder().encode(expectAddress(accounts.fleet.value)), ], }); } if (!accounts.rentalAuthority.value) { accounts.rentalAuthority.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([ 114, 101, 110, 116, 97, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121, ])), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.signer), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), ], data: getInvalidateRentalInstructionDataEncoder().encode({}), programAddress, }); } export function getInvalidateRentalInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { signer: { value: input.signer ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: false }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.signer), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), ], data: getInvalidateRentalInstructionDataEncoder().encode({}), programAddress, }); } export function parseInvalidateRentalInstruction(instruction) { if (instruction.accounts.length < 8) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { signer: getNextAccount(), fleet: getNextAccount(), gameId: getNextAccount(), starbase: getNextAccount(), starbasePlayer: getNextAccount(), contract: getNextAccount(), rentalAuthority: getNextAccount(), sageProgram: getNextAccount(), }, data: getInvalidateRentalInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=invalidateRental.js.map