@yubing744/rooch-sdk
Version:
161 lines (160 loc) • 5.57 kB
JavaScript
import { Client } from "@open-rpc/client-js";
class JsonRpcClient extends Client {
constructor(requestManager) {
super(requestManager);
}
async getRpcApiVersion() {
const resp = await this.request({
method: "rpc.discover",
params: []
});
return resp.info.version;
}
// Query the Inscription via global index by Inscription filter
async btc_queryInscriptions(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "btc_queryInscriptions",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// Query the UTXO via global index by UTXO filter
async btc_queryUTXOs(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "btc_queryUTXOs",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// Send the signed transaction in bcs hex format This method blocks waiting for the transaction to be executed.
async rooch_executeRawTransaction(tx_bcs_hex) {
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;
}
// Execute a read-only function call The function do not change the state of Application
async rooch_executeViewFunction(function_call) {
const resp = await this.request({
method: "rooch_executeViewFunction",
params: [function_call]
});
return resp;
}
// get account balance by AccountAddress and CoinType
async rooch_getBalance(account_addr, coin_type) {
const resp = await this.request({
method: "rooch_getBalance",
params: [account_addr, coin_type]
});
return resp;
}
// get account balances by AccountAddress
async rooch_getBalances(account_addr, cursor, limit) {
const resp = await this.request({
method: "rooch_getBalances",
params: [account_addr, cursor, limit]
});
return resp;
}
async rooch_getChainID() {
const resp = await this.request({
method: "rooch_getChainID",
params: []
});
return resp;
}
// Get the events by event handle id
async rooch_getEventsByEventHandle(event_handle_type, cursor, limit, event_options) {
const resp = await this.request({
method: "rooch_getEventsByEventHandle",
params: [event_handle_type, cursor, limit, event_options]
});
return resp;
}
// 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, state_option) {
const resp = await this.request({
method: "rooch_getStates",
params: [access_path, state_option]
});
return resp;
}
async rooch_getTransactionsByHash(tx_hashes) {
const resp = await this.request({
method: "rooch_getTransactionsByHash",
params: [tx_hashes]
});
return resp;
}
async rooch_getTransactionsByOrder(cursor, limit) {
const resp = await this.request({
method: "rooch_getTransactionsByOrder",
params: [cursor, limit]
});
return resp;
}
// 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, cursor, limit, state_option) {
const resp = await this.request({
method: "rooch_listStates",
params: [access_path, cursor, limit, state_option]
});
return resp;
}
// Query the events indexer by event filter
async rooch_queryEvents(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "rooch_queryEvents",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// Query the global states indexer by state filter
async rooch_queryGlobalStates(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "rooch_queryGlobalStates",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// Query the table states indexer by state filter
async rooch_queryTableStates(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "rooch_queryTableStates",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// Query the transactions indexer by transaction filter
async rooch_queryTransactions(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "rooch_queryTransactions",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
// 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) {
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;
}
// Sync state change sets from indexer
async rooch_syncStates(filter, cursor, limit, descending_order) {
const resp = await this.request({
method: "rooch_syncStates",
params: [filter, cursor, limit, descending_order]
});
return resp;
}
}
export {
JsonRpcClient
};
//# sourceMappingURL=client.js.map