zeriontech / Web3Swift

Ethereum Web3 library implementation for Swift
https://web3swift.io
Apache License 2.0
107 stars 32 forks source link

Missing convenient constructor for EthNumber #212

Open rockfridrich opened 5 years ago

rockfridrich commented 5 years ago

It is often needed to construct primitives like EthNumber with pure bytes.

 try EthNumber(
            hex: SimpleBytes(
                bytes: DecodedABINumber(
                    abiMessage: message,
                    index: index
                ).value()
            )
        )
abdulowork commented 5 years ago

In your example initialization can be simplified to:

try EthNumber(
    hex: DecodedABINumber(
        abiMessage: message,
        index: index
    )
)

as hex and DecodedABINumber are both BytesScalar

rockfridrich commented 5 years ago

For ABIMessage it is right but if we get it remotely then the call will be executed only when we check EthNumber.value(). Also I don't want to parse ABIMessage each time I need EthNumber value.

rockfridrich commented 5 years ago

@biboran so what is the best way to precompute the value of DecodeABINumber to pass into EthNumber in your opinion? There are also cases when we don't want lazy computations or overuse of CachedBytes