I am trying to decode data from accounts.
This is the IDL for the data I want to decode:
{
"name": "deployment",
"type": {
"kind": "struct",
"fields": [
{
"name": "creator",
"type": "publicKey"
},
{
"name": "limitPerMint",
"type": "u64"
},
{
"name": "maxNumberOfTokens",
"type": "u64"
},
{
"name": "numberOfTokensIssued",
"type": "u64"
},
{
"name": "decimals",
"type": "u8"
},
{
"name": "useInscriptions",
"type": "bool"
},
{
"name": "deploymentType",
"type": "u8"
},
{
"name": "requireCreatorCosign",
"type": "bool"
},
{
"name": "migratedFromLegacy",
"type": "bool"
},
{
"name": "escrowNonFungibleCount",
"type": "u64"
},
{
"name": "ticker",
"type": "string"
},
{
"name": "deploymentTemplate",
"type": "string"
},
{
"name": "mintTemplate",
"type": "string"
},
{
"name": "fungibleMint",
"type": "publicKey"
},
{
"name": "offchainUrl",
"type": "string"
}
]
}
},
This is how my code looks like:
import { publicKey, u64, bool } from '@solana/buffer-layout-utils';
import { u32, u8, struct} from '@solana/buffer-layout';
import {Connection,PublicKey,} from "@solana/web3.js";
interface DeploymentAccount{
discriminator: BN;
creator: PublicKey;
limitPerMint: BN;
maxNumberOfTokens: BN;
numberOfTokensIssued: BN;
decimals: number;
useInscriptions: boolean;
deploymentType:number;
requireCreatorCosign:boolean;
migratedFromLegacy:boolean;
escrowNonFungibleCount:BN;
ticker: string;
deploymentTemplate:string;
mintTemplate:string;
fungibleMint: PublicKey;
offchainUrl:string;
}
const DeploymentAccountLayout = struct<DeploymentAccount>([
u64("discriminator"),
publicKey("creator"),
u64("limitPerMint"),
u64("maxNumberOfTokens"),
u64("numberOfTokensIssued"),
u8("decimals"),
bool("useInscriptions"),
u8("deploymentType"),
bool("requireCreatorCosign"),
bool("migratedFromLegacy"),
u64("escrowNonFungibleCount"),
u8("ticker"),
u32("deploymentTemplate"),
u32("mintTemplate"),
publicKey("fungibleMint"),
u64("offchainUrl"),
])
const connection = new Connection(rpc)
const accounts = await connection.getAccountInfo(new PublicKey('CDoPzZWsuZQ2GrJ4xWSkqomQLkXxK1FM7HUd2jSRTQKn'), "processed" )
const d = DeploymentAccountLayout.decode(accounts.data)
So far everything seems to work but I do not know what kind of bytes an string represent so I do no know what to assign for ticker, deployTemplate, mintTemplate, offchainUrl
This are the limits set on the contract:
pub const TICKER_LIMIT: usize = 200;
pub const TEMPLATE_LIMIT: usize = 1200;
pub const OFFCHAIN_URL_LIMIT: usize = 1200;