import { AbiCoder } from '../abi/coder' ; import { AbiOutput } from '../Schema' ; import * as utils from '../utils/utils' ; import { bytesToHex } from '../utils/utils' ; const ethersAbiCoder = new AbiCoder ( ) ; /**
 * SolidityCoder prototype should be used to encode/decode solidity params of any type
 */ export namespace coder { method param { Array } types param { Array } params return { string } export function encodeParams ( types , params ) { return bytesToHex ( ethersAbiCoder . encode ( types , params ) ) ; } method param { Array } types param { string } bytes return { Array } export function decodeParams ( outputs , bytes ) { if ( outputs . length > 0 && ( ! bytes || bytes === '0x' || bytes === '0X' ) ) { throw new Error ( "Returned values aren't valid, did it run Out of Gas? " + 'You might also see this error if you are not using the ' + 'correct ABI for the contract you are retrieving data from, ' + 'requesting data from a block number that does not exist, ' + 'or querying a node which is not fully synced.' ) ; } return ethersAbiCoder . decode ( outputs , utils . hexToBytes ( '0x' + bytes . replace ( /0x/i , '' ) ) ) ; } }