Skip to content

Commit 011eb3a

Browse files
Update docs
1 parent c712103 commit 011eb3a

10 files changed

+27
-0
lines changed

docs/050-breaking-changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ New version:
501501
// To increase clarity, we suggest the use of a library for
502502
// the conversion (provided after the contract in this example).
503503
address payable addr = unknownContract.makePayable();
504+
// This will report a warning
504505
require(addr.send(1 ether));
505506
506507
// Since uint32 (4 bytes) is smaller than bytes8 (8 bytes),

docs/common-patterns.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ you receive the funds of the person who is now the richest.
5757
// Remember to zero the pending refund before
5858
// sending to prevent reentrancy attacks
5959
pendingWithdrawals[msg.sender] = 0;
60+
// This will report a warning
6061
payable(msg.sender).transfer(amount);
6162
}
6263
}
@@ -84,6 +85,7 @@ This is as opposed to the more intuitive sending pattern:
8485
function becomeRichest() public payable {
8586
if (msg.value <= mostSent) revert NotEnoughEther();
8687
// This line can cause problems (explained below).
88+
// This will report a warning
8789
richest.transfer(msg.value);
8890
richest = payable(msg.sender);
8991
mostSent = msg.value;
@@ -211,6 +213,7 @@ restrictions highly readable.
211213
212214
_;
213215
if (msg.value > amount)
216+
// This will report a warning
214217
payable(msg.sender).transfer(msg.value - amount);
215218
}
216219

docs/contracts/functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ operations as long as there is enough gas passed on to it.
440440
441441
// If someone sends Ether to that contract,
442442
// the transfer will fail, i.e. this returns false here.
443+
// This will report a warning
443444
return testPayable.send(2 ether);
444445
}
445446

docs/contracts/inheritance.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ and the ``override`` keyword must be used in the overriding modifier:
392392
393393
contract Base
394394
{
395+
// This will report a warning
395396
modifier foo() virtual {_;}
396397
}
397398
@@ -411,11 +412,13 @@ explicitly:
411412
412413
contract Base1
413414
{
415+
// This will report a warning
414416
modifier foo() virtual {_;}
415417
}
416418
417419
contract Base2
418420
{
421+
// This will report a warning
419422
modifier foo() virtual {_;}
420423
}
421424

docs/control-structures.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ and ``assert`` for internal error checking.
698698
function sendHalf(address payable addr) public payable returns (uint balance) {
699699
require(msg.value % 2 == 0, "Even value required.");
700700
uint balanceBeforeTransfer = address(this).balance;
701+
// This will report a warning
701702
addr.transfer(msg.value / 2);
702703
// Since transfer throws an exception on failure and
703704
// cannot call back here, there should be no way for us to
@@ -775,6 +776,7 @@ together with ``revert`` and the equivalent ``require``:
775776
if (msg.sender != owner)
776777
revert Unauthorized();
777778
779+
// This will report a warning
778780
payable(msg.sender).transfer(address(this).balance);
779781
}
780782
}

docs/examples/blind-auction.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ to receive their Ether - contracts cannot activate themselves.
124124
// msg.sender is not of type `address payable` and must be
125125
// explicitly converted using `payable(msg.sender)` in order
126126
// use the member function `send()`.
127+
// This will report a warning
127128
if (!payable(msg.sender).send(amount)) {
128129
// No need to call throw here, just reset the amount owing
129130
pendingReturns[msg.sender] = amount;
@@ -160,6 +161,7 @@ to receive their Ether - contracts cannot activate themselves.
160161
emit AuctionEnded(highestBidder, highestBid);
161162
162163
// 3. Interaction
164+
// This will report a warning
163165
beneficiary.transfer(highestBid);
164166
}
165167
}
@@ -310,6 +312,7 @@ invalid bids.
310312
// the same deposit.
311313
bidToCheck.blindedBid = bytes32(0);
312314
}
315+
// This will report a warning
313316
payable(msg.sender).transfer(refund);
314317
}
315318
@@ -323,6 +326,7 @@ invalid bids.
323326
// conditions -> effects -> interaction).
324327
pendingReturns[msg.sender] = 0;
325328
329+
// This will report a warning
326330
payable(msg.sender).transfer(amount);
327331
}
328332
}
@@ -336,6 +340,7 @@ invalid bids.
336340
if (ended) revert AuctionEndAlreadyCalled();
337341
emit AuctionEnded(highestBidder, highestBid);
338342
ended = true;
343+
// This will report a warning
339344
beneficiary.transfer(highestBid);
340345
}
341346

docs/examples/micropayment.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ The full contract
185185
// this recreates the message that was signed on the client
186186
bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));
187187
require(recoverSigner(message, signature) == owner);
188+
// This will report a warning
188189
payable(msg.sender).transfer(amount);
189190
}
190191
@@ -195,6 +196,7 @@ The full contract
195196
{
196197
require(msg.sender == owner);
197198
freeze();
199+
// This will report a warning
198200
payable(msg.sender).transfer(address(this).balance);
199201
}
200202
@@ -406,8 +408,10 @@ The full contract
406408
require(msg.sender == recipient);
407409
require(isValidSignature(amount, signature));
408410
411+
// This will report a warning
409412
recipient.transfer(amount);
410413
freeze();
414+
// This will report a warning
411415
sender.transfer(address(this).balance);
412416
}
413417
@@ -430,6 +434,7 @@ The full contract
430434
{
431435
require(block.timestamp >= expiration);
432436
freeze();
437+
// This will report a warning
433438
sender.transfer(address(this).balance);
434439
}
435440

docs/examples/safe-remote.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ you can use state machine-like constructs inside a contract.
9797
// reentrancy-safe, because it is the
9898
// last call in this function and we
9999
// already changed the state.
100+
// This will report a warning.
100101
seller.transfer(address(this).balance);
101102
}
102103
@@ -128,6 +129,7 @@ you can use state machine-like constructs inside a contract.
128129
// can call in again here.
129130
state = State.Release;
130131
132+
// This will report a warning
131133
buyer.transfer(value);
132134
}
133135
@@ -144,6 +146,7 @@ you can use state machine-like constructs inside a contract.
144146
// can call in again here.
145147
state = State.Inactive;
146148
149+
// This will report a warning
147150
seller.transfer(3 * value);
148151
}
149152
}

docs/security-considerations.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ To give an example, the following code contains a bug (it is just a snippet and
6565
mapping(address => uint) shares;
6666
/// Withdraw your share.
6767
function withdraw() public {
68+
// This will report a warning
6869
if (payable(msg.sender).send(shares[msg.sender]))
6970
shares[msg.sender] = 0;
7071
}
@@ -109,6 +110,7 @@ To avoid reentrancy, you can use the Checks-Effects-Interactions pattern as demo
109110
function withdraw() public {
110111
uint share = shares[msg.sender];
111112
shares[msg.sender] = 0;
113+
// This will report a warning
112114
payable(msg.sender).transfer(share);
113115
}
114116
}
@@ -255,6 +257,7 @@ Let's say you have a wallet contract like this:
255257
function transferTo(address payable dest, uint amount) public {
256258
// THE BUG IS RIGHT HERE, you must use msg.sender instead of tx.origin
257259
require(tx.origin == owner);
260+
// This will report a warning
258261
dest.transfer(amount);
259262
}
260263
}

docs/types/reference-types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ shown in the following example:
729729
return false;
730730
uint amount = c.amount;
731731
c.amount = 0;
732+
// This will report a warning
732733
c.beneficiary.transfer(amount);
733734
return true;
734735
}

0 commit comments

Comments
 (0)