UNPKG

@yubing744/rooch-sdk

Version:
88 lines (87 loc) 2.43 kB
"use strict"; 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 filtered_client_exports = {}; __export(filtered_client_exports, { FilteredProvider: () => FilteredProvider, FuncFilter: () => FuncFilter }); module.exports = __toCommonJS(filtered_client_exports); class FuncFilter { constructor(func) { this.func = func; } init() { } destroy() { } async doFilter(request, chain) { return await this.func(request, chain); } } class FilteredProvider { constructor(target, filters) { this.target = target; this.filters = filters; for (const filter of this.filters) { filter.init(); } } getRpcApiVersion() { return this.target.getRpcApiVersion(); } getChainId() { return this.target.getChainId(); } executeViewFunction(params) { return this.target.executeViewFunction(params); } getStates(accessPath) { return this.target.getStates(accessPath); } listStates(params) { return this.target.listStates(params); } sendRawTransaction(playload) { let index = 0; const chain = { doFilter: async (req) => { if (index < this.filters.length) { const filter = this.filters[index++]; return await filter.doFilter(req, chain); } else { return await this.target.sendRawTransaction(req); } } }; return new Promise(async (resolve, reject) => { try { let response = await chain.doFilter(playload); resolve(response); } catch (error) { reject(error); } }); } destroy() { for (const filter of this.filters) { filter.destroy(); } } } //# sourceMappingURL=filtered-client.js.map