Created
July 30, 2018 21:22
-
-
Save aquafemi/2c263db0021cbf0142e68820a630dacd to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25-nightly.2018.7.23+commit.79ddcc76.js&optimize=true&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
library IntExtended { | |
function increment(uint _self) public pure returns (uint) { | |
return _self + 1; | |
} | |
function decrement(uint _self) public pure returns (uint) { | |
return _self - 1; | |
} | |
function incrementValue(uint _self, uint _value) public pure returns (uint) { | |
return _self + _value; | |
} | |
function decrementValue(uint _self, uint _value) public pure returns (uint) { | |
return _self - _value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
interface Regulator { | |
function checkValue(uint amount) external returns (bool); | |
function loan() external returns (bool); | |
} | |
contract Bank is Regulator { | |
uint private Value; | |
address private Owner; | |
modifier ownerAccess { | |
require(Owner == msg.sender); | |
_; | |
} | |
constructor(uint amount) public { | |
Value = amount; | |
Owner = msg.sender; | |
} | |
function deposit(uint amount) public ownerAccess { | |
Value += amount; | |
} | |
function withdraw(uint amount) public ownerAccess { | |
if (checkValue(amount)){ | |
Value -= amount; | |
} | |
} | |
function balance() public view returns (uint) { | |
return Value; | |
} | |
function checkValue(uint amount) public view returns (bool) { | |
return Value >= amount; | |
} | |
function loan() public view returns (bool) { | |
return Value > 0; | |
} | |
} | |
contract MyFirstContract is Bank(10) { | |
string private Name; | |
uint private Age; | |
function setName(string newName) public { | |
Name = newName; | |
} | |
function getName() public view returns (string) { | |
return Name; | |
} | |
function setAge(uint newAge) public { | |
Age = newAge; | |
} | |
function getAge() public view returns (uint) { | |
return Age; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
import "browser/library.sol"; | |
contract TestLibrary { | |
using IntExtended for uint; | |
function testIncrement(uint _base) public pure returns (uint) { | |
return _base.increment(); | |
} | |
function testDecrement(uint _base) public pure returns (uint) { | |
return _base.decrement(); | |
} | |
function testIncrementValue(uint _base, uint _value) public pure returns (uint) { | |
return _base.incrementValue(_value); | |
} | |
function testDecrementValue(uint _base, uint _value) public pure returns (uint) { | |
return _base.decrementValue(_value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment