/** * This code was GENERATED using the solita package. * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. * * See: https://github.com/metaplex-foundation/solita */ import * as web3 from '@solana/web3.js'; import * as beet from '@metaplex-foundation/beet'; import * as beetSolana from '@metaplex-foundation/beet-solana'; /** * Arguments used to create {@link BidReceipt} * @category Accounts * @category generated */ export type BidReceiptArgs = { tradeState: web3.PublicKey; bookkeeper: web3.PublicKey; auctionHouse: web3.PublicKey; buyer: web3.PublicKey; metadata: web3.PublicKey; tokenAccount: beet.COption; purchaseReceipt: beet.COption; price: beet.bignum; tokenSize: beet.bignum; bump: number; tradeStateBump: number; createdAt: beet.bignum; canceledAt: beet.COption; }; const bidReceiptDiscriminator = [186, 150, 141, 135, 59, 122, 39, 99]; /** * Holds the data for the {@link BidReceipt} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ export class BidReceipt implements BidReceiptArgs { private constructor( readonly tradeState: web3.PublicKey, readonly bookkeeper: web3.PublicKey, readonly auctionHouse: web3.PublicKey, readonly buyer: web3.PublicKey, readonly metadata: web3.PublicKey, readonly tokenAccount: beet.COption, readonly purchaseReceipt: beet.COption, readonly price: beet.bignum, readonly tokenSize: beet.bignum, readonly bump: number, readonly tradeStateBump: number, readonly createdAt: beet.bignum, readonly canceledAt: beet.COption, ) {} /** * Creates a {@link BidReceipt} instance from the provided args. */ static fromArgs(args: BidReceiptArgs) { return new BidReceipt( args.tradeState, args.bookkeeper, args.auctionHouse, args.buyer, args.metadata, args.tokenAccount, args.purchaseReceipt, args.price, args.tokenSize, args.bump, args.tradeStateBump, args.createdAt, args.canceledAt, ); } /** * Deserializes the {@link BidReceipt} from the data of the provided {@link web3.AccountInfo}. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static fromAccountInfo(accountInfo: web3.AccountInfo, offset = 0): [BidReceipt, number] { return BidReceipt.deserialize(accountInfo.data, offset); } /** * Retrieves the account info from the provided address and deserializes * the {@link BidReceipt} from its data. * * @throws Error if no account info is found at the address or if deserialization fails */ static async fromAccountAddress( connection: web3.Connection, address: web3.PublicKey, ): Promise { const accountInfo = await connection.getAccountInfo(address); if (accountInfo == null) { throw new Error(`Unable to find BidReceipt account at ${address}`); } return BidReceipt.fromAccountInfo(accountInfo, 0)[0]; } /** * Deserializes the {@link BidReceipt} from the provided data Buffer. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static deserialize(buf: Buffer, offset = 0): [BidReceipt, number] { return bidReceiptBeet.deserialize(buf, offset); } /** * Serializes the {@link BidReceipt} into a Buffer. * @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it. */ serialize(): [Buffer, number] { return bidReceiptBeet.serialize({ accountDiscriminator: bidReceiptDiscriminator, ...this, }); } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link BidReceipt} for the provided args. * * @param args need to be provided since the byte size for this account * depends on them */ static byteSize(args: BidReceiptArgs) { const instance = BidReceipt.fromArgs(args); return bidReceiptBeet.toFixedFromValue({ accountDiscriminator: bidReceiptDiscriminator, ...instance, }).byteSize; } /** * Fetches the minimum balance needed to exempt an account holding * {@link BidReceipt} data from rent * * @param args need to be provided since the byte size for this account * depends on them * @param connection used to retrieve the rent exemption information */ static async getMinimumBalanceForRentExemption( args: BidReceiptArgs, connection: web3.Connection, commitment?: web3.Commitment, ): Promise { return connection.getMinimumBalanceForRentExemption(BidReceipt.byteSize(args), commitment); } /** * Returns a readable version of {@link BidReceipt} properties * and can be used to convert to JSON and/or logging */ pretty() { return { tradeState: this.tradeState.toBase58(), bookkeeper: this.bookkeeper.toBase58(), auctionHouse: this.auctionHouse.toBase58(), buyer: this.buyer.toBase58(), metadata: this.metadata.toBase58(), tokenAccount: this.tokenAccount, purchaseReceipt: this.purchaseReceipt, price: (() => { const x = <{ toNumber: () => number }>this.price; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), tokenSize: (() => { const x = <{ toNumber: () => number }>this.tokenSize; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), bump: this.bump, tradeStateBump: this.tradeStateBump, createdAt: (() => { const x = <{ toNumber: () => number }>this.createdAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), canceledAt: this.canceledAt, }; } } /** * @category Accounts * @category generated */ export const bidReceiptBeet = new beet.FixableBeetStruct< BidReceipt, BidReceiptArgs & { accountDiscriminator: number[] /* size: 8 */; } >( [ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['tradeState', beetSolana.publicKey], ['bookkeeper', beetSolana.publicKey], ['auctionHouse', beetSolana.publicKey], ['buyer', beetSolana.publicKey], ['metadata', beetSolana.publicKey], ['tokenAccount', beet.coption(beetSolana.publicKey)], ['purchaseReceipt', beet.coption(beetSolana.publicKey)], ['price', beet.u64], ['tokenSize', beet.u64], ['bump', beet.u8], ['tradeStateBump', beet.u8], ['createdAt', beet.i64], ['canceledAt', beet.coption(beet.i64)], ], BidReceipt.fromArgs, 'BidReceipt', );