3 个版本 (破坏性更新)
0.3.0 | 2024 年 7 月 17 日 |
---|---|
0.2.0 | 2024 年 6 月 19 日 |
0.1.0 | 2024 年 3 月 5 日 |
#17 in #deserializing
每月 158 次下载
105KB
2.5K SLoC
chainparser
使用它们的 progam IDL 反序列化 Solana 账户
use chainparser::{ChainparserDeserializer, IdlProvider, SerializationOpts};
let opts = SerializationOpts {
pubkey_as_base58: true,
n64_as_string: false,
n128_as_string: true,
};
let mut chainparser = ChainparserDeserializer::new(&opts);
// 1. Add IDLS
// Candy Machine IDL
let cndy_program_id = "cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ";
{
let idl_json = read_idl_json(&cndy_program_id);
chainparser
.add_idl_json(cndy_program_id.to_string(), &idl_json, IdlProvider::Anchor)
.expect("failed adding IDL JSON");
}
// Staking Program IDL
let stake_program_id = "StakeSSzfxn391k3LvdKbZP5WVwWd6AsY1DNiXHjQfK";
{
let idl_json = read_idl_json(&stake_program_id);
chainparser
.add_idl_json(stake_program_id.to_string(), &idl_json, IdlProvider::Anchor)
.expect("failed adding IDL JSON");
}
// 2. Read Accounts Data
// Stake Account
let stake_acc_data = read_account(
&stake_program_id,
"EscrowHistory",
"5AEHnKRonYWeXWQTCqbfaEY6jHy38ifutWsriVsxsgbL",
);
// Candy Machine Account
let cndy_acc_data = read_account(
&cndy_program_id,
"CollectionPDA",
"4gt6YPtgZp2MYJUP7cAH8E3UiL6mUruYaPprEiyJytQ4",
);
// 3. Deserialize Accounts
// Stake Account
{
let mut acc_json = String::new();
chainparser
.deserialize_account(
&stake_program_id,
&mut stake_acc_data.as_slice(),
&mut acc_json,
)
.expect("failed to deserialize account");
assert!(acc_json.contains("{\"escrow\":\"4uj6fRJzqoNRPktmYqGX1nBkjAJBsimJ4ug77S3Tzj7y\""));
}
// Candy Machine Account
{
let mut acc_json = String::new();
chainparser
.deserialize_account(
&cndy_program_id,
&mut cndy_acc_data.as_slice(),
&mut acc_json,
)
.expect("failed to deserialize account");
assert_eq!(acc_json, "{\"mint\":\"BrqNo3sQFTaq9JevoWYhgagJEjE3MmTgYonfaHV5Mf3E\",\"candyMachine\":\"DpBwktkJsEPTtsRpD8kCFGwEUjwTkXARSGSTQ7MJr4kE\"}");
}
许可
MIT
依赖项
~18–27MB
~467K SLoC