Skip to content

Instantly share code, notes, and snippets.

@aquafemi
Created July 30, 2018 21:22
Show Gist options
  • Save aquafemi/2c263db0021cbf0142e68820a630dacd to your computer and use it in GitHub Desktop.
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=
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;
}
}
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;
}
}
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