4 releases
0.0.4 | Feb 4, 2025 |
---|---|
0.0.3 | Feb 4, 2025 |
0.0.2 | Feb 4, 2025 |
0.0.1 | Jan 30, 2025 |
#284 in WebAssembly
316 downloads per month
145KB
3K
SLoC
Atlas rpcX Bindings
Wasm bindings for using rpcX on Atlas.
Program Parser
The program parser interface exposes functions for parsing atomic elements of a program such as individual accounts or instructions.
use atlas_rpcx_bindings::program_parser::*;
struct Package;
impl ProgramParserGuest for Package {
fn get_program_metadata(
idl: Option<bindings::AtlasAccount>,
) -> Option<bindings::ProgramMetadata> {
todo!()
}
fn parse_accounts(
idl: Option<bindings::AtlasAccount>,
accounts: Vec<bindings::AtlasAccount>,
params: String,
) -> Result<Vec<Result<bindings::AccountResponse, String>>, String> {
todo!()
}
fn parse_instructions(
idl: Option<bindings::AtlasAccount>,
instructions: Vec<bindings::AtlasInstruction>,
params: String,
) -> Result<Vec<Result<bindings::InstructionResponse, String>>, String> {
todo!()
}
fn parse_error(
idl: Option<bindings::AtlasAccount>,
error_code: u64,
params: String,
) -> Option<String> {
todo!()
}
fn parse_logs(
idl: Option<bindings::AtlasAccount>,
logs: Vec<String>,
params: String,
) -> Result<Vec<String>, String> {
todo!()
}
}
export_program_parser!(Package with_types_in bindings);
View Function
The view function interface exposes customizable functions for more involved
account parsing and aggregation. View functions are allowed to use the
get_account
and get_multiple_accounts
functions from the accounts_db
bindings.
use atlas_rpcx_bindings::view_function::{
bindings as view_function_bindings, export_view_function, ViewFunctionGuest,
};
struct Package;
impl ViewFunctionGuest for Package {
fn view_function(command: String, params: String) -> Result<String, String> {
todo!()
}
}
export_view_function!(Package with_types_in view_function_bindings);
Transaction Transformer
The transaction transformer interface exposes functions for parsing and enriching transactions.
use atlas_rpcx_bindings::transaction_transformer::{
bindings as transaction_transformer_bindings, export_transaction_transformer,
TransactionTransformerGuest,
};
struct Package;
impl TransactionTransformerGuest for Package {
fn transform_transaction(
transaction: String,
command: String,
params: String,
) -> Result<String, String> {
todo!()
}
}
export_transaction_transformer!(Package with_types_in transaction_transformer_bindings);
Account Setup and Transformer
The account setup and transformer interfaces are used together to enable fetching and subscribing to transformed accounts.
The account setup interface has access to stateful functions like get_account
and get_multiple_accounts
but the transformer interface does not. A "setup
call" can be used to seed the account transformer with some state that is
cumbersome to pass. One example of this is "seeding" an account transformer that
parses token balance with mint decimals.
Because the account transfomer interface is stateless, it supports subscriptions.
use atlas_rpcx_bindings::{
accounts_transformer::{
bindings as accounts_transformer_bindings, export_accounts_transformer,
AccountsTransformerGuest,
},
accounts_transformer_setup::{
bindings as accounts_transformer_setup_bindings, export_accounts_transformer_setup,
AccountsTransformerRequest, AccountsTransformerSetupGuest, WasmSeed,
},
};
struct Package;
impl AccountsTransformerSetupGuest for Package {
fn setup_accounts_transformer(
command: String,
params: String,
) -> Result<atlas_rpcx_bindings::accounts_transformer_setup::AccountsTransformerRequest, String>
{
todo!()
}
}
impl AccountsTransformerGuest for Package {
fn transform_accounts(
accounts: Vec<atlas_rpcx_bindings::bindings::accounts_transformer::AtlasAccount>,
command: String,
params: String,
) -> Result<String, String> {
Ok(String::new())
}
}
export_accounts_transformer!(Package with_types_in accounts_transformer_bindings);
export_accounts_transformer_setup!(Package with_types_in accounts_transformer_setup_bindings);
Dependencies
~1–2MB
~42K SLoC