xf00f / web3x

Ethereum TypeScript Client Library - for perfect types and tiny builds.
211 stars 27 forks source link

Why checking for outputs to define if a function is constant ? #63

Closed megaturbo closed 4 years ago

megaturbo commented 5 years ago

Why checking for outputs to define if a function is constant ?

web3x-codegen defines here a function constant if there are outputs. Why not rather checking for:

if (definition.constant)

A function can be state-modifying even if it has output, right ? I just wanted to understand why. I can do a PR if that makes sense to use the constant keyword of the ABI.

I know it doesn't change anything since the solidity compiler outputs the stateMutability parameters, but the vyper compiler doesn't. So that would help to be vyper-compatible.

xf00f commented 5 years ago

I think this is incorrect, perhaps an incorrect assumption at some point on my part around return values not being accessible on transactions. There is no way to read a return value from a transaction, only events. However it is possible for a state modifying call to return a value which could be read by another smart contract. I'll accept a PR. Thanks.

alcuadrado commented 5 years ago

use the constant keyword of the ABI.

I know it doesn't change anything since the solidity compiler outputs the stateMutability parameters, but the vyper compiler doesn't. So that would help to be vyper-compatible.

I think you should check both of them. Something like abi.constant || abi.stateMutability === 'payable' || abi.stateMutability === 'nonpayable', since acording to solidity's doc constant will be removed in the future.

megaturbo commented 5 years ago

@alcuadrado I think that the case when stateMutability is set is already handled here

Btw I did a PR, feel free to review it

xf00f commented 4 years ago

Should be fixed in v4.0.6