aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

Add require() functionality to BlockchainRuntime #333

Closed aionick closed 5 years ago

aionick commented 5 years ago

Solidity provides this idiom: require(boolean) that, if false, triggers a REVERT. This idiom proves very useful for a lot of contracts. We should provide the same support (ie. BlockchainRuntime.require(boolean))

aionick commented 5 years ago

Solidity also provides a similar function, assert(boolean). It behaves the same as require() except that require() will refund the caller any unused energy whereas assert() will use up all of the caller's energy.

I'm not sure if this distinction is worth carrying over into our world, assert() just feels like a cruder version of require().

(see this discussion on the matter).

aionick commented 5 years ago

Confirmed that a RevertException cannot be caught. This is desirable. If someone wants to evaluate a boolean and do some conditional logic then they can use a regular if block to do so.