UNPKG

oken-waas

Version:
32 lines 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.contract = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const lodash_1 = __importDefault(require("lodash")); const typesAndMutability = v => ({ type: v.type, mutability: v.stateMutability }); const typeFunctions = v => v.type === 'function'; const buildApiUrls = (baseParams, api, abi) => (v, method) => { if (v.mutability === 'view') { return api.alchemyEnabled ? (params) => api.call(baseParams.contractAddress, abi, method, params) : (params) => api.get('/contracts/state', { ...baseParams, method, params }); } return (payload) => api.post('/transactions', { ...baseParams, method, params: payload }); }; const contract = (contractId, api, network, contractAddress) => { const abiPath = path_1.default.join(__dirname, '..', `abis/${contractId}.json`); const abi = JSON.parse(fs_1.default.readFileSync(abiPath).toString()); const contractApiServices = buildApiUrls({ network, contractId, contractAddress }, api, abi); return (0, lodash_1.default)(abi) .keyBy('name') .mapValues(typesAndMutability) .pickBy(typeFunctions) .mapValues(contractApiServices) .value(); }; exports.contract = contract; //# sourceMappingURL=helpers.js.map