@yubing744/rooch-sdk
Version:
181 lines (180 loc) • 6.51 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var client_exports = {};
__export(client_exports, {
JsonRpcClient: () => JsonRpcClient
});
module.exports = __toCommonJS(client_exports);
var import_client_js = require("@open-rpc/client-js");
class JsonRpcClient extends import_client_js.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;
}
}
//# sourceMappingURL=client.js.map