@yubing744/rooch-sdk
Version:
309 lines (267 loc) • 8.69 kB
text/typescript
// This file was generated by `yarn gen:client`. Please, do not modify it.
import { RequestManager, Client } from "@open-rpc/client-js";
import {
InscriptionFilterView,
IndexerStateID,
usize,
InscriptionStatePageView,
UTXOFilterView,
UTXOStatePageView,
ExecuteTransactionResponseView,
FunctionCallView,
AnnotatedFunctionResultView,
RoochAccountAddress,
RoochStructTag,
BalanceInfoView,
PageView_for_BalanceInfoView_and_String,
u64,
EventOptions,
EventPageView,
AccessPath,
StateOptions,
StateView,
primitive_types_H256,
TransactionWithInfoView,
TransactionWithInfoPageView,
StatePageView,
EventFilterView,
IndexerEventID,
PageView_for_IndexerEventView_and_IndexerEventID,
GlobalStateFilterView,
GlobalStateView,
TableStateFilterView,
TableStateView,
TransactionFilterView,
StateSyncFilterView,
PageView_for_IndexerTableChangeSetView_and_IndexerStateID,
} from "./types";
export class JsonRpcClient extends Client {
constructor(requestManager: RequestManager) {
super(requestManager);
}
async getRpcApiVersion(): Promise<string | undefined> {
const resp = await this.request({
method: "rpc.discover",
params: [],
});
return resp.info.version as string;
}
// Query the Inscription via global index by Inscription filter
async btc_queryInscriptions(
filter: InscriptionFilterView,
cursor: IndexerStateID,
limit: usize,
descending_order: boolean
): Promise<InscriptionStatePageView> {
const resp = await this.request({
method: "btc_queryInscriptions",
params: [filter, cursor, limit, descending_order],
});
return resp as InscriptionStatePageView;
}
// Query the UTXO via global index by UTXO filter
async btc_queryUTXOs(
filter: UTXOFilterView,
cursor: IndexerStateID,
limit: usize,
descending_order: boolean
): Promise<UTXOStatePageView> {
const resp = await this.request({
method: "btc_queryUTXOs",
params: [filter, cursor, limit, descending_order],
});
return resp as UTXOStatePageView;
}
// Send the signed transaction in bcs hex format This method blocks waiting for the transaction to be executed.
async rooch_executeRawTransaction(
tx_bcs_hex: Uint8Array
): Promise<ExecuteTransactionResponseView> {
const tx_bcs_hex_hex = tx_bcs_hex
? `0x${Array.from(tx_bcs_hex)
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("")}`
: null;
const resp = await this.request({
method: "rooch_executeRawTransaction",
params: [tx_bcs_hex_hex],
});
return resp as ExecuteTransactionResponseView;
}
// Execute a read-only function call The function do not change the state of Application
async rooch_executeViewFunction(
function_call: FunctionCallView
): Promise<AnnotatedFunctionResultView> {
const resp = await this.request({
method: "rooch_executeViewFunction",
params: [function_call],
});
return resp as AnnotatedFunctionResultView;
}
// get account balance by AccountAddress and CoinType
async rooch_getBalance(
account_addr: RoochAccountAddress,
coin_type: RoochStructTag
): Promise<BalanceInfoView> {
const resp = await this.request({
method: "rooch_getBalance",
params: [account_addr, coin_type],
});
return resp as BalanceInfoView;
}
// get account balances by AccountAddress
async rooch_getBalances(
account_addr: RoochAccountAddress,
cursor: string,
limit: usize
): Promise<PageView_for_BalanceInfoView_and_String> {
const resp = await this.request({
method: "rooch_getBalances",
params: [account_addr, cursor, limit],
});
return resp as PageView_for_BalanceInfoView_and_String;
}
async rooch_getChainID(): Promise<u64> {
const resp = await this.request({
method: "rooch_getChainID",
params: [],
});
return resp as u64;
}
// Get the events by event handle id
async rooch_getEventsByEventHandle(
event_handle_type: RoochStructTag,
cursor: u64,
limit: u64,
event_options: EventOptions
): Promise<EventPageView> {
const resp = await this.request({
method: "rooch_getEventsByEventHandle",
params: [event_handle_type, cursor, limit, event_options],
});
return resp as EventPageView;
}
// Get the states by access_path If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response.
async rooch_getStates(
access_path: AccessPath,
state_option: StateOptions
): Promise<StateView | null[]> {
const resp = await this.request({
method: "rooch_getStates",
params: [access_path, state_option],
});
return resp as StateView | null[];
}
async rooch_getTransactionsByHash(
tx_hashes: primitive_types_H256[]
): Promise<TransactionWithInfoView | null[]> {
const resp = await this.request({
method: "rooch_getTransactionsByHash",
params: [tx_hashes],
});
return resp as TransactionWithInfoView | null[];
}
async rooch_getTransactionsByOrder(
cursor: u64,
limit: u64
): Promise<TransactionWithInfoPageView> {
const resp = await this.request({
method: "rooch_getTransactionsByOrder",
params: [cursor, limit],
});
return resp as TransactionWithInfoPageView;
}
// List the states by access_path If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response.
async rooch_listStates(
access_path: AccessPath,
cursor: string,
limit: usize,
state_option: StateOptions
): Promise<StatePageView> {
const resp = await this.request({
method: "rooch_listStates",
params: [access_path, cursor, limit, state_option],
});
return resp as StatePageView;
}
// Query the events indexer by event filter
async rooch_queryEvents(
filter: EventFilterView,
cursor: IndexerEventID,
limit: usize,
descending_order: boolean
): Promise<PageView_for_IndexerEventView_and_IndexerEventID> {
const resp = await this.request({
method: "rooch_queryEvents",
params: [filter, cursor, limit, descending_order],
});
return resp as PageView_for_IndexerEventView_and_IndexerEventID;
}
// Query the global states indexer by state filter
async rooch_queryGlobalStates(
filter: GlobalStateFilterView,
cursor: IndexerStateID,
limit: usize,
descending_order: boolean
): Promise<GlobalStateView> {
const resp = await this.request({
method: "rooch_queryGlobalStates",
params: [filter, cursor, limit, descending_order],
});
return resp as GlobalStateView;
}
// Query the table states indexer by state filter
async rooch_queryTableStates(
filter: TableStateFilterView,
cursor: IndexerStateID,
limit: usize,
descending_order: boolean
): Promise<TableStateView> {
const resp = await this.request({
method: "rooch_queryTableStates",
params: [filter, cursor, limit, descending_order],
});
return resp as TableStateView;
}
// Query the transactions indexer by transaction filter
async rooch_queryTransactions(
filter: TransactionFilterView,
cursor: u64,
limit: usize,
descending_order: boolean
): Promise<TransactionWithInfoPageView> {
const resp = await this.request({
method: "rooch_queryTransactions",
params: [filter, cursor, limit, descending_order],
});
return resp as TransactionWithInfoPageView;
}
// Send the signed transaction in bcs hex format This method does not block waiting for the transaction to be executed.
async rooch_sendRawTransaction(
tx_bcs_hex: Uint8Array
): Promise<primitive_types_H256> {
const tx_bcs_hex_hex = tx_bcs_hex
? `0x${Array.from(tx_bcs_hex)
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("")}`
: null;
const resp = await this.request({
method: "rooch_sendRawTransaction",
params: [tx_bcs_hex_hex],
});
return resp as primitive_types_H256;
}
// Sync state change sets from indexer
async rooch_syncStates(
filter: StateSyncFilterView,
cursor: IndexerStateID,
limit: usize,
descending_order: boolean
): Promise<PageView_for_IndexerTableChangeSetView_and_IndexerStateID> {
const resp = await this.request({
method: "rooch_syncStates",
params: [filter, cursor, limit, descending_order],
});
return resp as PageView_for_IndexerTableChangeSetView_and_IndexerStateID;
}
}
// This file was generated by `yarn gen:client`. Please, do not modify it.