UNPKG

jcc-ethereum-abi

Version:

Decoder and encoder for the ethereum ABI and decode events from ethereum transactions

90 lines (89 loc) 2.39 kB
import { Contract } from "web3-eth-contract"; import { IABIItem, IDecoded, IDecodedLog, ILog } from "./model"; import { ContractAbi } from "web3-types"; /** * decoder and encoder for Ether * * @export * @class EthereumABI */ export default class EthereumABI { /** * Ether contract instance * * @private * @type {Contract} * @memberof EthereumABI */ private _contract; /** * Ether abi * * @private * @type {IABIItem[]} * @memberof EthereumABI */ private _abi; /** * Creates an instance of EthereumABI. * @param {Contract} contract Ether contract instance * @memberof EthereumABI */ constructor(contract: Contract<ContractAbi>); /** * get item of function meta data * * @param {string} name defined function name in the abi * @param {*} args parameters according to the defined inputs * @returns {IABIItem} * @memberof EthereumABI */ getAbiItem: (name: string, ...args: any[]) => IABIItem; /** * encode the input value by function name * * @param {string} name defined function name in the abi * @param {*} args parameters according to the defined inputs * @returns {string} * @memberof EthereumABI */ encode: (name: string, ...args: any[]) => string; /** * decode the input value * * @static * @param {string} data * @returns {IDecoded[]} * @memberof EthereumABI */ static decode(data: string): IDecoded[]; /** * decode Ether transaction logs * * [Reference](https://github.com/ConsenSys/abi-decoder/blob/master/index.js#L130) * * @static * @param {ILog[]} logs * @returns {IDecodedLog[]} if event is defined and decode succeed, return log that contains * events as input arguments and name as event's name, otherwise return itself. * @memberof EthereumABI */ static decodeLogs(logs: ILog[]): IDecodedLog[]; /** * add abi to abiDecoder * * @static * @param {IABIItem[]} abi * @memberof EthereumABI */ static addABI(abi: IABIItem[]): void; /** * remove ABIs and methodIDs from abiDecoder * * @static * @param {IABIItem[]} abi * @memberof EthereumABI */ static removeABI(abi: IABIItem[]): void; } export { EthereumABI };