From a047f564b3b0f8fa0c2bf127c6f6bf5f64d591bf Mon Sep 17 00:00:00 2001 From: Dominik Muhs Date: Mon, 26 Nov 2018 13:57:34 +0100 Subject: [PATCH] Fix example contract modifiers --- solidity_examples/BECToken.sol | 8 ++++---- solidity_examples/WalletLibrary.sol | 8 ++++---- solidity_examples/exceptions.sol | 16 ++++++++-------- solidity_examples/rubixi.sol | 16 ++++++++-------- solidity_examples/token.sol | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/solidity_examples/BECToken.sol b/solidity_examples/BECToken.sol index bc4b9db4..3a14fd12 100644 --- a/solidity_examples/BECToken.sol +++ b/solidity_examples/BECToken.sol @@ -5,25 +5,25 @@ pragma solidity 0.5.0; * @dev Math operations with safety checks that throw on error */ library SafeMath { - function mul(uint256 a, uint256 b) internal returns (uint256) { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } - function div(uint256 a, uint256 b) internal returns (uint256) { + function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } - function sub(uint256 a, uint256 b) internal returns (uint256) { + function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } - function add(uint256 a, uint256 b) internal returns (uint256) { + function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; diff --git a/solidity_examples/WalletLibrary.sol b/solidity_examples/WalletLibrary.sol index 204de6a1..d972cdd6 100644 --- a/solidity_examples/WalletLibrary.sol +++ b/solidity_examples/WalletLibrary.sol @@ -177,15 +177,15 @@ contract WalletLibrary is WalletEvents { } // Gets an owner by 0-indexed position (using numOwners as the count) - function getOwner(uint ownerIndex) external returns (address) { + function getOwner(uint ownerIndex) external view returns (address) { return address(m_owners[ownerIndex + 1]); } - function isOwner(address _addr) public returns (bool) { + function isOwner(address _addr) public view returns (bool) { return m_ownerIndex[uint(_addr)] > 0; } - function hasConfirmed(bytes32 _operation, address _owner) external returns (bool) { + function hasConfirmed(bytes32 _operation, address _owner) external view returns (bool) { PendingState memory pending = m_pending[_operation]; uint ownerIndex = m_ownerIndex[uint(_owner)]; @@ -356,7 +356,7 @@ contract WalletLibrary is WalletEvents { } // determines today's index. - function today() private returns (uint) { return now / 1 days; } + function today() private view returns (uint) { return now / 1 days; } function clearPending() internal { uint length = m_pendingIndex.length; diff --git a/solidity_examples/exceptions.sol b/solidity_examples/exceptions.sol index 6e2632f6..aa925603 100644 --- a/solidity_examples/exceptions.sol +++ b/solidity_examples/exceptions.sol @@ -5,39 +5,39 @@ contract Exceptions { uint256[8] myarray; - function assert1() public { + function assert1() public pure { uint256 i = 1; assert(i == 0); } - function assert2() public { + function assert2() public pure { uint256 i = 1; assert(i > 0); } - function assert3(uint256 input) public { + function assert3(uint256 input) public pure { assert(input != 23); } - function requireisfine(uint256 input) public { + function requireisfine(uint256 input) public pure { require(input != 23); } - function divisionby0(uint256 input) public { + function divisionby0(uint256 input) public pure { uint256 i = 1/input; } - function thisisfine(uint256 input) public { + function thisisfine(uint256 input) public pure { if (input > 0) { uint256 i = 1/input; } } - function arrayaccess(uint256 index) public { + function arrayaccess(uint256 index) public view { uint256 i = myarray[index]; } - function thisisalsofind(uint256 index) public { + function thisisalsofind(uint256 index) public view { if (index < 8) { uint256 i = myarray[index]; } diff --git a/solidity_examples/rubixi.sol b/solidity_examples/rubixi.sol index c8aa2c77..8e1567c6 100644 --- a/solidity_examples/rubixi.sol +++ b/solidity_examples/rubixi.sol @@ -73,38 +73,38 @@ contract Rubixi { } //Functions to provide information to end-user using JSON interface or other interfaces - function currentMultiplier() public returns (uint multiplier, string memory info) { + function currentMultiplier() public view returns (uint multiplier, string memory info) { multiplier = pyramidMultiplier; info = "This multiplier applies to you as soon as transaction is received, may be lowered to hasten payouts or increased if payouts are fast enough. Due to no float or decimals, multiplier is x100 for a fractional multiplier e.g. 250 is actually a 2.5x multiplier. Capped at 3x max and 1.2x min."; } - function currentFeePercentage() public returns (uint fee, string memory info) { + function currentFeePercentage() public view returns (uint fee, string memory info) { fee = feePercent; info = "Shown in % form. Fee is halved(50%) for amounts equal or greater than 50 ethers. (Fee may change, but is capped to a maximum of 10%)"; } - function currentPyramidBalanceApproximately() public returns (uint pyramidBalance, string memory info) { + function currentPyramidBalanceApproximately() public view returns (uint pyramidBalance, string memory info) { pyramidBalance = balance / 1 ether; info = "All balance values are measured in Ethers, note that due to no decimal placing, these values show up as integers only, within the contract itself you will get the exact decimal value you are supposed to"; } - function nextPayoutWhenPyramidBalanceTotalsApproximately() public returns (uint balancePayout) { + function nextPayoutWhenPyramidBalanceTotalsApproximately() public view returns (uint balancePayout) { balancePayout = participants[payoutOrder].payout / 1 ether; } - function feesSeperateFromBalanceApproximately() public returns (uint fees) { + function feesSeperateFromBalanceApproximately() public view returns (uint fees) { fees = collectedFees / 1 ether; } - function totalParticipants() public returns (uint count) { + function totalParticipants() public view returns (uint count) { count = participants.length; } - function numberOfParticipantsWaitingForPayout() public returns (uint count) { + function numberOfParticipantsWaitingForPayout() public view returns (uint count) { count = participants.length - payoutOrder; } - function participantDetails(uint orderInPyramid) public returns (address addr, uint payout) { + function participantDetails(uint orderInPyramid) public view returns (address addr, uint payout) { if (orderInPyramid <= participants.length) { addr = participants[orderInPyramid].etherAddress; payout = participants[orderInPyramid].payout / 1 ether; diff --git a/solidity_examples/token.sol b/solidity_examples/token.sol index 0e03d9ee..30eeb963 100644 --- a/solidity_examples/token.sol +++ b/solidity_examples/token.sol @@ -17,7 +17,7 @@ contract Token { return true; } - function balanceOf(address _owner) public returns (uint balance) { + function balanceOf(address _owner) public view returns (uint balance) { return balances[_owner]; } } \ No newline at end of file