chore(Docs): Replaced instances if - throw to require() where applicable.#2134
chore(Docs): Replaced instances if - throw to require() where applicable.#2134InfamousVague wants to merge 21 commits intoargotorg:developfrom InfamousVague:develop
Conversation
chore(Docs): Replaced instances if - throw to require() where applicable.
|
Looks like the test is failing because of a broken function trying to convert a line ending, is this my fault? |
docs/common-patterns.rst
Outdated
| if (!richest.send(msg.value)) { | ||
| throw; | ||
| } | ||
| require(richest.send(msg.value)); |
There was a problem hiding this comment.
I think this should be assert() here.
Perhaps we could also have a comment to say that the use of richest.transfer(msg.value) is preferred instead.
docs/contracts.rst
Outdated
| // "instance" will be the current contract. | ||
| if (!Set.insert(knownValues, value)) | ||
| throw; | ||
| require(Set.insert(knownValues, value)); |
There was a problem hiding this comment.
I think this should be assert.
| shares[msg.sender] = 0; | ||
| if (!msg.sender.send(share)) | ||
| throw; | ||
| require(msg.sender.send(share)); |
There was a problem hiding this comment.
This is the withdraw pattern, in here probably we should prefer transfer() instead.
| if (tx.origin != owner) { throw; } | ||
| if (!dest.call.value(amount)()) throw; | ||
| require(tx.origin == owner); | ||
| require(dest.call.value(amount)()); |
There was a problem hiding this comment.
Could be replaced with .transfer().
There was a problem hiding this comment.
@axic 125 - 130 will need to be updated to reflect this change, I am not confident that I understand deeply enough to replace this paragraph; would you mind taking a look and if we still want to switch to transfer() let me know what you'd like me to replace that paragraph with.
|
I guess no point to repeat the same. Where the code explains why Note, that by moving to |
docs/types.rst
Outdated
| c.amount = 0; | ||
| if (!c.beneficiary.send(amount)) | ||
| throw; | ||
| require(c.beneficiary.transfer(amount)); |
There was a problem hiding this comment.
transfer() will abort if it failed, no need for require() here
| @@ -86,9 +86,7 @@ This is as opposed to the more intuitive sending pattern: | |||
| // Check if call succeeds to prevent an attacker | |||
There was a problem hiding this comment.
This comment is not relevant anymore. If you are not confident with making the relevant changes, then please just keep send and we will go over it in another iteration.
There was a problem hiding this comment.
Okay I'll leave that in for now.
docs/common-patterns.rst
Outdated
|
|
||
| modifier onlyAfter(uint _time) { | ||
| if (now < _time) throw; | ||
| require(now > _time); |
There was a problem hiding this comment.
Should be >= to have identical semantics.
There was a problem hiding this comment.
Changing now but wouldn't that signify it allows something to happen also at a given time and not just after a given time.
docs/common-patterns.rst
Outdated
| modifier costs(uint _amount) { | ||
| if (msg.value < _amount) | ||
| throw; | ||
| require(msg.value > _amount); |
| // "instance" will be the current contract. | ||
| if (!Set.insert(knownValues, value)) | ||
| throw; | ||
| assert(Set.insert(knownValues, value)); |
There was a problem hiding this comment.
I think even here, we should use require because it is not an internal error if this fails - it is still invalid usage of contract C.
There was a problem hiding this comment.
Wasn't the definition that require() is for input validation, while assert() is for everything else?
There was a problem hiding this comment.
The definition was that it is impossible to get a contract to trigger an assert unless it has a bug.
|
Replaced this by #2207 |
#2118