Stop accesing ethers private methods

This commit is contained in:
Leonid Logvinov 2018-10-09 15:46:13 +02:00
parent d21e6f3aaf
commit f93774f855
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
3 changed files with 7 additions and 9 deletions

View File

@ -12,13 +12,12 @@ import {
TxDataPayable, TxDataPayable,
} from 'ethereum-types'; } from 'ethereum-types';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
import { Interface } from 'ethers/utils/interface';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { formatABIDataItem } from './utils'; import { formatABIDataItem } from './utils';
export interface EthersInterfaceByFunctionSignature { export interface EthersInterfaceByFunctionSignature {
[key: string]: Interface; [key: string]: ethers.utils.Interface;
} }
const REVERT_ERROR_SELECTOR = '08c379a0'; const REVERT_ERROR_SELECTOR = '08c379a0';
@ -118,7 +117,7 @@ export class BaseContract {
} }
} }
} }
protected _lookupEthersInterface(functionSignature: string): Interface { protected _lookupEthersInterface(functionSignature: string): ethers.utils.Interface {
const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature]; const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature];
if (_.isUndefined(ethersInterface)) { if (_.isUndefined(ethersInterface)) {
throw new Error(`Failed to lookup method with function signature '${functionSignature}'`); throw new Error(`Failed to lookup method with function signature '${functionSignature}'`);
@ -155,7 +154,7 @@ export class BaseContract {
this._ethersInterfacesByFunctionSignature = {}; this._ethersInterfacesByFunctionSignature = {};
_.each(methodAbis, methodAbi => { _.each(methodAbis, methodAbi => {
const functionSignature = abiUtils.getFunctionSignature(methodAbi); const functionSignature = abiUtils.getFunctionSignature(methodAbi);
this._ethersInterfacesByFunctionSignature[functionSignature] = new Interface([methodAbi]); this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.utils.Interface([methodAbi]);
}); });
} }
} }

View File

@ -5,7 +5,7 @@ import { BaseContract } from '@0xproject/base-contract';
import { BlockParam, BlockParamLiteral, CallData, ContractAbi, ContractArtifact, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types'; import { BlockParam, BlockParamLiteral, CallData, ContractAbi, ContractArtifact, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types';
import { BigNumber, classUtils, logUtils } from '@0xproject/utils'; import { BigNumber, classUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Interface } from 'ethers/utils/interface'; import * as ethers from 'ethers';
import * as _ from 'lodash'; import * as _ from 'lodash';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
@ -65,7 +65,7 @@ export class {{contractName}}Contract extends BaseContract {
[{{> params inputs=ctor.inputs}}], [{{> params inputs=ctor.inputs}}],
BaseContract._bigNumberToString, BaseContract._bigNumberToString,
); );
const iface = new Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, [{{> params inputs=ctor.inputs}}]); const txData = deployInfo.encode(bytecode, [{{> params inputs=ctor.inputs}}]);
const web3Wrapper = new Web3Wrapper(provider); const web3Wrapper = new Web3Wrapper(provider);

View File

@ -10,7 +10,6 @@ import {
SolidityTypes, SolidityTypes,
} from 'ethereum-types'; } from 'ethereum-types';
import { ethers } from 'ethers'; import { ethers } from 'ethers';
import { Interface } from 'ethers/utils/interface';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { addressUtils } from './address_utils'; import { addressUtils } from './address_utils';
@ -42,7 +41,7 @@ export class AbiDecoder {
return log; return log;
} }
const event = this._methodIds[methodId][numIndexedArgs]; const event = this._methodIds[methodId][numIndexedArgs];
const ethersInterface = new Interface([event]); const ethersInterface = new ethers.utils.Interface([event]);
const decodedParams: DecodedLogArgs = {}; const decodedParams: DecodedLogArgs = {};
let topicsIndex = 1; let topicsIndex = 1;
@ -97,7 +96,7 @@ export class AbiDecoder {
if (_.isUndefined(abiArray)) { if (_.isUndefined(abiArray)) {
return; return;
} }
const ethersInterface = new Interface(abiArray); const ethersInterface = new ethers.utils.Interface(abiArray);
_.map(abiArray, (abi: AbiDefinition) => { _.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) { if (abi.type === AbiType.Event) {
const topic = ethersInterface.events[abi.name].topic; const topic = ethersInterface.events[abi.name].topic;