Fix example contract modifiers

pull/754/head
Dominik Muhs 6 years ago
parent d226755ae9
commit a047f564b3
  1. 8
      solidity_examples/BECToken.sol
  2. 8
      solidity_examples/WalletLibrary.sol
  3. 16
      solidity_examples/exceptions.sol
  4. 16
      solidity_examples/rubixi.sol
  5. 2
      solidity_examples/token.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;

@ -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;

@ -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];
}

@ -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;

@ -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];
}
}
Loading…
Cancel
Save