Unverified Commit 3a57efd3 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #574 from ethereum/fixAbi

Ensure "payable" and "stateMutability" have correct value if "constant" is true
parents 828ee0bf 86dc7054
...@@ -7,7 +7,8 @@ import EventManager from '../lib/eventManager' ...@@ -7,7 +7,8 @@ import EventManager from '../lib/eventManager'
import { default as txHelper } from './txHelper'; import { default as txHelper } from './txHelper';
import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult,
visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError,
gatherImportsCallbackInterface } from './types' gatherImportsCallbackInterface,
isFunctionDescription } from './types'
/* /*
trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration
...@@ -335,8 +336,18 @@ export class Compiler { ...@@ -335,8 +336,18 @@ export class Compiler {
'type': 'fallback' 'type': 'fallback'
}) })
} }
if(data && data.contracts && this.state.currentVersion) if(data && data.contracts && this.state.currentVersion) {
data.contracts[contract.file][contract.name].abi = update(this.truncateVersion(this.state.currentVersion), contract.object.abi) 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 return data
} }
......
...@@ -354,6 +354,12 @@ export interface CompilationResult { ...@@ -354,6 +354,12 @@ export interface CompilationResult {
///////// /////////
export type ABIDescription = FunctionDescription | EventDescription 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 { export interface FunctionDescription {
/** Type of the method. default is 'function' */ /** Type of the method. default is 'function' */
type?: 'function' | 'constructor' | 'fallback' | 'receive' type?: 'function' | 'constructor' | 'fallback' | 'receive'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment