@archwayhq/arch3-core
Version:
Core library to interact with Archway Network
91 lines • 4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArchwayClient = void 0;
const cosmwasm_stargate_1 = require("@cosmjs/cosmwasm-stargate");
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
const queryclient_1 = require("./queryclient");
const utils_1 = require("./utils");
/**
* Extension to the {@link CosmWasmClient } with queries for Archway's modules.
*/
class ArchwayClient extends cosmwasm_stargate_1.CosmWasmClient {
constructor(cometClient) {
super(cometClient);
this.archwayQueryClient = (0, queryclient_1.createArchwayQueryClient)(cometClient);
}
/**
* Creates an instance by connecting to the given Tendermint/Comet RPC endpoint.
*
* @param endpoint - String URL of the RPC endpoint to connect or an {@link HttpEndpoint} object.
* @returns An {@link ArchwayClient} connected to the endpoint.
*
* @see Use {@link ArchwayClient.create} if you need to support a specific CometBFT version.
*/
static async connect(endpoint) {
const cometClient = await (0, tendermint_rpc_1.connectComet)(endpoint);
return ArchwayClient.create(cometClient);
}
/**
* Creates an instance by connecting to the given Tendermint/CometBFT RPC endpoint using an HttpBatchClient to batch
* multiple requests and reduce queries to the server.
*
* @param endpoint - String URL of the RPC endpoint to connect or an {@link HttpEndpoint} object.
* @param options - Optional configuration to control how the HttpBatchClient will batch requests.
* @returns An {@link ArchwayClient} connected to the endpoint.
*
* @remarks This factory method doesn't support WebSocket endpoints.
*/
static async connectWithBatchClient(endpoint, options) {
const cometBatchClient = await (0, utils_1.connectCometWithBatchClient)(endpoint, options);
return ArchwayClient.create(cometBatchClient);
}
/**
* Creates an instance from a manually created Comet client.
*
* @param cometClient - A Comet client for a given endpoint.
* @returns An {@link ArchwayClient} connected to the endpoint.
*/
/* eslint-disable-next-line @typescript-eslint/require-await */
static async create(cometClient) {
return new ArchwayClient(cometClient);
}
async getBlockRewardsTracking() {
return await this.archwayQueryClient.getBlockRewardsTracking();
}
async getContractMetadata(contractAddress) {
return await this.archwayQueryClient.getContractMetadata(contractAddress);
}
async getContractPremium(contractAddress) {
return await this.archwayQueryClient.getContractPremium(contractAddress);
}
async getEstimateTxFees(gasLimit, contractAddress) {
return await this.archwayQueryClient.getEstimateTxFees(gasLimit, contractAddress);
}
async getOutstandingRewards(rewardsAddress) {
return await this.archwayQueryClient.getOutstandingRewards(rewardsAddress);
}
async getRewardsPool() {
return await this.archwayQueryClient.getRewardsPool();
}
async getAllRewardsRecords(rewardsAddress) {
return await this.archwayQueryClient.getAllRewardsRecords(rewardsAddress);
}
async simulateTx(messages, memo, signer, sequence, granter, payer) {
return await this.archwayQueryClient.simulateTx(messages, memo, signer, sequence, granter, payer);
}
/**
* Queries all balances for all denoms that belong to this address.
*
* Uses the grpc queries (which iterates over the store internally), and we cannot get
* proofs from such a method.
*
* @param address - Address to query balances for.
*
* @returns All balances for all denoms that belong to this address.
*/
async getAllBalances(address) {
return this.forceGetQueryClient().bank.allBalances(address);
}
}
exports.ArchwayClient = ArchwayClient;
//# sourceMappingURL=archwayclient.js.map