Skip to main content

rpcX Interfaces

In order for an rpcX package to be used by an RPC node it must implement one of the required interfaces. Each interface corresponds with a set of RPC endpoints and determines what data the rpcX package can parse.

This page contains a list of rpcX interfaces and their corresponding RPC endpoints. All rpcX interfaces can be imported from the atlas-rpcx-bindings crate. A single rpcX package can implement multiple interfaces.

warning

Note that most interfaces return a String type. These return strings must be valid JSON. We recommend using the serde_json crate.

Program Parser

The program parser interface exposes functions for parsing atomic elements of a program such as individual accounts or instructions.

Corresponding RPC methods:

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.

Corresponding RPC methods:

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.

Corresponding RPC methods:

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.

Corresponding RPC methods:

use atlas_wasm_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);