aboutsummaryrefslogtreecommitdiffstats
path: root/docs/solidity-by-example.rst
diff options
context:
space:
mode:
authorJim McDonald <Jim@mcdee.net>2017-12-13 02:47:30 +0800
committerJim McDonald <Jim@mcdee.net>2017-12-13 02:47:30 +0800
commit6e521d59b0a30fa0673aaf84559d5b74dbb1eed7 (patch)
tree618b00999c2de8432f222c7b990f51ef4de6b1f0 /docs/solidity-by-example.rst
parent7614b16dc9b2bb1e267e8f46834b40220fb9f9fb (diff)
downloaddexon-solidity-6e521d59b0a30fa0673aaf84559d5b74dbb1eed7.tar.gz
dexon-solidity-6e521d59b0a30fa0673aaf84559d5b74dbb1eed7.tar.zst
dexon-solidity-6e521d59b0a30fa0673aaf84559d5b74dbb1eed7.zip
Fix Solidity warnings
Diffstat (limited to 'docs/solidity-by-example.rst')
-rw-r--r--docs/solidity-by-example.rst42
1 files changed, 24 insertions, 18 deletions
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index 9489665e..6c01278a 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -36,7 +36,7 @@ of votes.
::
- pragma solidity ^0.4.11;
+ pragma solidity ^0.4.16;
/// @title Voting with delegation.
contract Ballot {
@@ -66,7 +66,7 @@ of votes.
Proposal[] public proposals;
/// Create a new ballot to choose one of `proposalNames`.
- function Ballot(bytes32[] proposalNames) {
+ function Ballot(bytes32[] proposalNames) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
@@ -86,7 +86,7 @@ of votes.
// Give `voter` the right to vote on this ballot.
// May only be called by `chairperson`.
- function giveRightToVote(address voter) {
+ function giveRightToVote(address voter) public {
// If the argument of `require` evaluates to `false`,
// it terminates and reverts all changes to
// the state and to Ether balances. It is often
@@ -99,7 +99,7 @@ of votes.
}
/// Delegate your vote to the voter `to`.
- function delegate(address to) {
+ function delegate(address to) public {
// assigns reference
Voter storage sender = voters[msg.sender];
require(!sender.voted);
@@ -140,7 +140,7 @@ of votes.
/// Give your vote (including votes delegated to you)
/// to proposal `proposals[proposal].name`.
- function vote(uint proposal) {
+ function vote(uint proposal) public {
Voter storage sender = voters[msg.sender];
require(!sender.voted);
sender.voted = true;
@@ -154,13 +154,13 @@ of votes.
/// @dev Computes the winning proposal taking all
/// previous votes into account.
- function winningProposal() constant
+ function winningProposal() public view
returns (uint winningProposal)
{
uint winningVoteCount = 0;
- for (uint p = 0; p < proposals.length; p++) {
- if (proposals[p].voteCount > winningVoteCount) {
- winningVoteCount = proposals[p].voteCount;
+ for (uint p = 0; p < winningProposals.length; p++) {
+ if (winningProposals[p].voteCount > winningVoteCount) {
+ winningVoteCount = winningProposals[p].voteCount;
winningProposal = p;
}
}
@@ -169,10 +169,10 @@ of votes.
// Calls winningProposal() function to get the index
// of the winner contained in the proposals array and then
// returns the name of the winner
- function winnerName() constant
+ function winnerName() public view
returns (bytes32 winnerName)
{
- winnerName = proposals[winningProposal()].name;
+ name = proposals[winningProposal()].name;
}
}
@@ -248,7 +248,7 @@ activate themselves.
function SimpleAuction(
uint _biddingTime,
address _beneficiary
- ) {
+ ) public {
beneficiary = _beneficiary;
auctionEnd = now + _biddingTime;
}
@@ -257,7 +257,7 @@ activate themselves.
/// together with this transaction.
/// The value will only be refunded if the
/// auction is not won.
- function bid() payable {
+ function bid() public payable {
// No arguments are necessary, all
// information is already part of
// the transaction. The keyword payable
@@ -286,7 +286,7 @@ activate themselves.
}
/// Withdraw a bid that was overbid.
- function withdraw() returns (bool) {
+ function withdraw() public returns (bool) {
uint amount = pendingReturns[msg.sender];
if (amount > 0) {
// It is important to set this to zero because the recipient
@@ -305,7 +305,7 @@ activate themselves.
/// End the auction and send the highest bid
/// to the beneficiary.
- function auctionEnd() {
+ function auctionEnd() public {
// It is a good guideline to structure functions that interact
// with other contracts (i.e. they call functions or send Ether)
// into three phases:
@@ -405,7 +405,7 @@ high or low invalid bids.
uint _biddingTime,
uint _revealTime,
address _beneficiary
- ) {
+ ) public {
beneficiary = _beneficiary;
biddingEnd = now + _biddingTime;
revealEnd = biddingEnd + _revealTime;
@@ -421,6 +421,7 @@ high or low invalid bids.
/// still make the required deposit. The same address can
/// place multiple bids.
function bid(bytes32 _blindedBid)
+ public
payable
onlyBefore(biddingEnd)
{
@@ -438,6 +439,7 @@ high or low invalid bids.
bool[] _fake,
bytes32[] _secret
)
+ public
onlyAfter(biddingEnd)
onlyBefore(revealEnd)
{
@@ -487,7 +489,7 @@ high or low invalid bids.
}
/// Withdraw a bid that was overbid.
- function withdraw() {
+ function withdraw() public {
uint amount = pendingReturns[msg.sender];
if (amount > 0) {
// It is important to set this to zero because the recipient
@@ -503,6 +505,7 @@ high or low invalid bids.
/// End the auction and send the highest bid
/// to the beneficiary.
function auctionEnd()
+ public
onlyAfter(revealEnd)
{
require(!ended);
@@ -533,7 +536,7 @@ Safe Remote Purchase
// Ensure that `msg.value` is an even number.
// Division will truncate if it is an odd number.
// Check via multiplication that it wasn't an odd number.
- function Purchase() payable {
+ function Purchase() public payable {
seller = msg.sender;
value = msg.value / 2;
require((2 * value) == msg.value);
@@ -567,6 +570,7 @@ Safe Remote Purchase
/// Can only be called by the seller before
/// the contract is locked.
function abort()
+ public
onlySeller
inState(State.Created)
{
@@ -580,6 +584,7 @@ Safe Remote Purchase
/// The ether will be locked until confirmReceived
/// is called.
function confirmPurchase()
+ public
inState(State.Created)
condition(msg.value == (2 * value))
payable
@@ -592,6 +597,7 @@ Safe Remote Purchase
/// Confirm that you (the buyer) received the item.
/// This will release the locked ether.
function confirmReceived()
+ public
onlyBuyer
inState(State.Locked)
{