From 3e9309c003fd441fb28ed598544db3e51547a90d Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Tue, 7 Apr 2020 23:12:01 -0400 Subject: [PATCH] `@0x/sol-compiler`: Strip `receive` functions from 0.6 ABI output --- packages/sol-compiler/CHANGELOG.json | 4 +++ packages/sol-compiler/src/solc_wrapper_v05.ts | 27 ++++++++++--------- packages/sol-compiler/src/solc_wrapper_v06.ts | 11 ++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index 469e9b554b..9f3dca62a9 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Refactor + add solidity 0.6 support", "pr": 2532 + }, + { + "note": "Filter `receive` functions from 0.6 ABIs", + "pr": 2540 } ] }, diff --git a/packages/sol-compiler/src/solc_wrapper_v05.ts b/packages/sol-compiler/src/solc_wrapper_v05.ts index 17184dbec0..ba19d939cf 100644 --- a/packages/sol-compiler/src/solc_wrapper_v05.ts +++ b/packages/sol-compiler/src/solc_wrapper_v05.ts @@ -32,18 +32,6 @@ export const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = { export class SolcWrapperV05 extends SolcWrapper { protected readonly _compilerSettings: solc.CompilerSettings; - public static normalizeOutput(output: StandardOutput): StandardOutput { - const _output = _.cloneDeep(output); - // tslint:disable-next-line forin - for (const contractPath in _output.contracts) { - // tslint:disable-next-line forin - for (const contract of Object.values(_output.contracts[contractPath])) { - addHexPrefixToContractBytecode(contract); - } - } - return _output; - } - constructor(protected readonly _solcVersion: string, protected readonly _opts: CompilerOptions) { super(); this._compilerSettings = { @@ -88,7 +76,7 @@ export class SolcWrapperV05 extends SolcWrapper { } return { input, - output: SolcWrapperV05.normalizeOutput(output), + output: this._normalizeOutput(output), }; } @@ -99,4 +87,17 @@ export class SolcWrapperV05 extends SolcWrapper { const solcInstance = await getSolcJSAsync(this.solidityVersion, !!this._opts.isOfflineMode); return compileSolcJSAsync(solcInstance, input); } + + // tslint:disable-next-line: prefer-function-over-method + protected _normalizeOutput(output: StandardOutput): StandardOutput { + const _output = _.cloneDeep(output); + // tslint:disable-next-line forin + for (const contractPath in _output.contracts) { + // tslint:disable-next-line forin + for (const contract of Object.values(_output.contracts[contractPath])) { + addHexPrefixToContractBytecode(contract); + } + } + return _output; + } } diff --git a/packages/sol-compiler/src/solc_wrapper_v06.ts b/packages/sol-compiler/src/solc_wrapper_v06.ts index f69b77e5b6..625c76b1eb 100644 --- a/packages/sol-compiler/src/solc_wrapper_v06.ts +++ b/packages/sol-compiler/src/solc_wrapper_v06.ts @@ -22,4 +22,15 @@ export class SolcWrapperV06 extends SolcWrapperV05 { solcInstance.compileStandardWrapper = solcInstance.compile; return compileSolcJSAsync(solcInstance, input); } + + protected _normalizeOutput(output: StandardOutput): StandardOutput { + const _output = super._normalizeOutput(output); + // Filter out 'receive' ABI item types until ethers supports it. + for (const contracts of Object.values(_output.contracts)) { + for (const contract of Object.values(contracts)) { + contract.abi = contract.abi.filter(v => v.type !== 'receive'); + } + } + return _output; + } }