From 86dc705415abcb1411a405ea4fe8cfeb964213d8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 12 Nov 2020 14:03:02 +0100 Subject: [PATCH] ensure payable and stateMutability have correct value is constant is true in the abi --- libs/remix-solidity/src/compiler/compiler.ts | 17 ++++++++++++++--- libs/remix-solidity/src/compiler/types.ts | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index 7541b98c78..95e1f92195 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -7,7 +7,8 @@ import EventManager from '../lib/eventManager' import { default as txHelper } from './txHelper'; import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, - gatherImportsCallbackInterface } from './types' + gatherImportsCallbackInterface, + isFunctionDescription } from './types' /* trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration @@ -335,8 +336,18 @@ export class Compiler { 'type': 'fallback' }) } - if(data && data.contracts && this.state.currentVersion) - data.contracts[contract.file][contract.name].abi = update(this.truncateVersion(this.state.currentVersion), contract.object.abi) + if(data && data.contracts && this.state.currentVersion) { + const version = this.truncateVersion(this.state.currentVersion) + data.contracts[contract.file][contract.name].abi = update(version, contract.object.abi) + // if "constant" , payable must not be true and stateMutability must be view. + // see https://github.com/ethereum/solc-js/issues/500 + for (const item of data.contracts[contract.file][contract.name].abi) { + if (isFunctionDescription(item) && item.constant) { + item.payable = false + item.stateMutability = 'view'; + } + } + } }) return data } diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index bbbd9624f1..b3f06e6e4c 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -354,6 +354,12 @@ export interface CompilationResult { ///////// export type ABIDescription = FunctionDescription | EventDescription + export const isFunctionDescription = (item: ABIDescription): item is FunctionDescription => + (item as FunctionDescription).stateMutability !== undefined; + + export const isEventDescription = (item: ABIDescription): item is EventDescription => + (item as EventDescription).type === 'event'; + export interface FunctionDescription { /** Type of the method. default is 'function' */ type?: 'function' | 'constructor' | 'fallback' | 'receive'