User Cli Interface

This documentation organizes the three core data query interfaces implemented by RpcProvider (QTreeDataStoreReaderSync<F>, QMetaDataStoreReaderSync<F>, and QEDComboDataStoreReaderSync<F>). It includes interface functions, method details, parameter descriptions, and return value types, focusing on core data query capabilities for blockchain scenarios such as users, contracts, and checkpoints.

Basic Information

  • Core Dependent Types:
    • F = GoldilocksField: A prime field type based on Plonky2, used for blockchain data verification and hash calculation.
    • QHashOut<F>: Hash output result type, storing raw data after hash calculation.
    • MerkleProofCore<QHashOut<F>>: Core Merkle proof type, containing information such as the root, value, and sibling nodes required for proof.

Core Structures

RpcProvider

The foundational component for RPC communication, responsible for interacting with Realm nodes (user-specific data) and Coordinator nodes (global public data, e.g., contracts, checkpoints). It supports cross-environment use (non-WASM like servers, WASM like browser extensions).

Structure Definition

#![allow(unused)]
fn main() {
#[derive(Debug, Clone)]
pub struct RpcProvider {
    pub client: Arc<Client>,               // HTTP client (for RPC requests)
    pub realm_configs: HashMap<u64, Vec<String>>,  // Realm node config: {Realm ID → List of RPC URLs}
    pub coordinator_configs: HashMap<u64, Vec<String>>,  // Coordinator node config: {Coordinator ID → List of RPC URLs}
    pub users_per_realm: u64,              // Number of users assigned to each Realm (for user-to-Realm routing)
    pub current_user_id: u64,              // ID of the currently active user (for default data requests)
}
}

Key Methods

RpcProvider provides methods for node routing, user/contract/data queries, and transaction submission. Core methods are categorized below:

CategoryMethod NameParametersReturn ValueFunction Description
Node Routingget_realm_iduser_id: u64u64Calculate the Realm ID for a user (via user_id / users_per_realm).
get_realm_urluser_id: u64anyhow::Result<&String>Get a random RPC URL of the Realm node corresponding to the user (for load balancing).
get_coordinator_urlNoneanyhow::Result<&String>Get a random RPC URL of the Coordinator node (for global data requests).
User Operationsregister_userreq: QRegisterUserRPCRequest<F>anyhow::Result<()>Submit a user registration request to the Coordinator node.
get_user_idpublic_key: QHashOut<F>anyhow::Result<u64>Query the user ID corresponding to a public key from the Coordinator node.
Contract Operationsdeploy_contractreq: QDeployContractRPCRequest<F>anyhow::Result<()>Submit a contract deployment request to the Coordinator node.
Data Queriesget_realm_latest_l2_block_stateNoneanyhow::Result<QEDL2BlockState>Query the latest L2 block state from the current user’s Realm node.
get_claim_amountcheckpoint_id: u64, user_id: u64, claim_user_id: u64anyhow::Result<u64>Calculate the available claim amount for a user by querying contract state tree leaves.
check_tx_is_confirmedcheckpoint_id: u64, user_id: u64, tx_hash: QHashOut<GoldilocksField>anyhow::Result<bool>Verify if a transaction is confirmed by comparing the user leaf hash with the transaction hash.
Batch Proof Queryget_job_proofsjob_infos: Vec<JobInfo>anyhow::Result<Vec<(QProvingJobDataID, VariableHeightRewardMerkleProof)>>Batch query reward Merkle proofs for multiple jobs (routes to Realm/Coordinator based on job location).

Auxiliary Structures

RpcConfig & NetworkConfig

Configuration structures for node networks and proxy services, loaded from external config files:

#![allow(unused)]
fn main() {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RpcConfig {
    pub users_per_realm: u64,                // Number of users per Realm
    pub global_user_tree_height: u8,         // Height of the global user Merkle tree
    pub realm_user_tree_height: u8,          // Height of the Realm-specific user Merkle tree
    pub realm_configs: Vec<RealmRpcConfig>,  // List of Realm node configs
    pub coordinator_configs: Vec<CoordinatorRpcConfig>,  // List of Coordinator node configs
    pub prove_proxy_url: Vec<String>,        // List of proof proxy service URLs
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkConfig {  // Extended config for blockchain network
    pub users_per_realm: u64,
    pub global_user_tree_height: u8,
    pub realm_user_tree_height: u8,
    pub realm_configs: Vec<RealmConfig>,     // Same as RealmRpcConfig
    pub coordinator_configs: Vec<CoordinatorConfig>,  // Same as CoordinatorRpcConfig
    pub prover_url: Option<String>,          // Optional prover service URL
    pub prove_proxy_url: Vec<String>,
    pub native_currency: String,             // Native currency symbol (e.g., "PSY")
}
}

Merkle Tree Data Query

This interface focuses on querying roots, leaf hashes, and Merkle proofs of various Merkle trees in the blockchain, covering core scenarios such as users, contracts, checkpoints, deposits, and withdrawals.

(1) User Contract State Tree Queries (User-Contract Internal State)

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_user_contract_state_tree_root- checkpoint_id: u64: Unique identifier for the checkpoint
- user_id: u64: Unique identifier for the user
- contract_id: u32: Unique identifier for the contract
QHashOut<F>Queries the root hash of a user's contract state tree under a specified checkpointRealm Node
get_user_contract_state_tree_leaf_hash- Same as above
- height: u8: Height of the state tree
- leaf_id: u64: Unique identifier for the leaf node
QHashOut<F>Queries the hash of a specified leaf node in the state treeRealm Node
get_user_contract_state_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a specified leaf node in the state tree (including verification logic)Realm Node

(2) User Contract Tree Queries (User-Contract Association)

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_user_contract_tree_root- checkpoint_id: u64: Unique identifier for the checkpoint
- user_id: u64: Unique identifier for the user
QHashOut<F>Queries the root hash of a user's contract tree under a specified checkpointRealm Node
get_user_contract_tree_leaf_hash- Same as above
- contract_id: u32: Unique identifier for the contract
QHashOut<F>Queries the hash of the leaf node corresponding to a contract in the user's contract treeRealm Node
get_user_contract_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a contract in the user's contract treeRealm Node

(3) User Registration Tree Queries (Global User Registration State)

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_user_registration_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of the global user registration tree under a specified checkpointCoordinator Node
get_user_registration_tree_leaf_hash- Same as above
- leaf_index: u64: Leaf index
QHashOut<F>Queries the hash of a leaf node at a specified index in the user registration treeCoordinator Node
get_user_registration_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a leaf node at a specified index in the user registration treeCoordinator Node

(4) User Tree Queries (Global User State)

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_user_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of the global user tree under a specified checkpointCoordinator Node
get_user_tree_leaf_hash- Same as above
- user_id: u64: Unique identifier for the user
QHashOut<F>Queries the hash of the leaf node corresponding to a user in the user treeRealm Node
get_user_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a user in the user tree (automatically merges subtree proofs)Coordinator & Realm Node
get_user_sub_tree_merkle_proof- checkpoint_id: u64: Unique identifier for the checkpoint
- root_level: u8: Root level
- leaf_level: u8: Leaf level
- leaf_index: u64: Leaf index
MerkleProofCore<QHashOut<F>>Queries the Merkle proof of a specified level in the user subtreeCoordinator & Realm Node
Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_contract_function_tree_root- checkpoint_id: u64: Unique identifier for the checkpoint
- contract_id: u32: Unique identifier for the contract
QHashOut<F>Queries the root hash of a contract's function tree under a specified checkpointCoordinator Node
get_contract_function_tree_leaf_hash- Same as above
- function_id: u32: Unique identifier for the function
QHashOut<F>Queries the hash of a function's leaf node in the contract function treeCoordinator Node
get_contract_function_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a function in the contract function treeCoordinator Node
get_contract_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of the global contract tree under a specified checkpointCoordinator Node
get_contract_tree_leaf_hash- Same as above
- contract_id: u32: Unique identifier for the contract
QHashOut<F>Queries the hash of a contract's leaf node in the contract treeCoordinator Node
get_contract_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a contract in the contract treeCoordinator Node

(1) Deposit Tree Queries

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_deposit_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of the global deposit tree under a specified checkpointCoordinator Node
get_deposit_tree_leaf_hash- Same as above
- deposit_id: u32: Unique identifier for the deposit
QHashOut<F>Queries the hash of a deposit's leaf node in the deposit treeCoordinator Node
get_deposit_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a deposit in the deposit treeCoordinator Node

(2) Withdrawal Tree Queries

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_withdrawal_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of the global withdrawal tree under a specified checkpointCoordinator Node
get_withdrawal_tree_leaf_hash- Same as above
- withdrawal_id: u32: Unique identifier for the withdrawal
QHashOut<F>Queries the hash of a withdrawal's leaf node in the withdrawal treeCoordinator Node
get_withdrawal_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a withdrawal in the withdrawal treeCoordinator Node
Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_latest_checkpoint_tree_rootNo parametersQHashOut<F>Queries the root hash of the latest checkpoint treeCoordinator Node
get_checkpoint_tree_root- checkpoint_id: u64: Unique identifier for the checkpointQHashOut<F>Queries the root hash of a specified checkpoint treeCoordinator Node
get_checkpoint_tree_leaf_hash- Same as above
- leaf_checkpoint_id: u64: Leaf checkpoint ID
QHashOut<F>Queries the hash of a leaf node in the checkpoint treeCoordinator Node
get_checkpoint_tree_merkle_proofSame parameters as aboveMerkleProofCore<QHashOut<F>>Queries the Merkle proof of a leaf node in the checkpoint treeCoordinator Node

Metadata Query

This interface focuses on querying core blockchain metadata, including complete leaf data for users, contracts, and checkpoints, as well as L2 block states.

1. User Metadata Queries

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_user_leaf_data- checkpoint_id: u64: Unique identifier for the checkpoint
- user_id: u64: Unique identifier for the user
QEDUserLeaf<F>Queries complete leaf data for a user under a specified checkpoint (including user state, hash, etc.)Realm Node

2. Contract Metadata Queries

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_contract_leaf_data- contract_id: u64: Unique identifier for the contractQEDContractLeaf<F>Queries complete leaf data for a contract (including basic contract information, state, etc.)Coordinator Node
get_contract_code_definition- contract_id: u64: Unique identifier for the contractContractCodeDefinitionQueries the code definition of a contract (including bytecode, function list, etc.)Coordinator Node

3. Checkpoint and L2 Block State Queries

Method NameParameter DescriptionReturn ValueFunction DescriptionCalled Node
get_checkpoint_leaf_data- checkpoint_id: u64: Unique identifier for the checkpointQEDCheckpointLeaf<F>Queries complete leaf data for a specified checkpoint (including global state root, block information, etc.)Coordinator Node
get_latest_l2_block_stateNo parametersQEDL2BlockStateQueries the complete state of the latest L2 block (including block height, transaction count, etc.)Coordinator Node
get_l2_block_state- checkpoint_id: u64: Unique identifier for the checkpointQEDL2BlockStateQueries the L2 block state corresponding to a specified checkpointCoordinator Node