Skip to content

Instantly share code, notes, and snippets.

@alexroan
Last active June 10, 2018 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexroan/f8dbf980b7a57c0e96481386afd3589d to your computer and use it in GitHub Desktop.
Save alexroan/f8dbf980b7a57c0e96481386afd3589d 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.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.0;
//Interface
interface Regulator{
//Methods to implement
function checkValue(uint amount) returns(bool);
function loan() returns(bool);
}
//Extension of Rregulator interface
contract Bank is Regulator{
//Datatype before access
//<type> <access> <name>
uint private value;
//Address on the blockchain
address private owner;
//Access modifier
//requiring that the owner of the contract
//is the initial sender
modifier ownerFunc{
require(owner == msg.sender);
_;
}
//Constructor
function Bank(uint amount){
value = amount;
owner = msg.sender;
}
//Applying the access modifier to this function means
//that performing the function must satisfy the modifier.
//If the account address is changed after the initial send then
//deposits and withdrawals cannot be made because the modifier
//will fail (see ownerFunc).
function deposit(uint amount) ownerFunc{
value += amount;
}
function withdraw(uint amount) ownerFunc{
if (checkValue(amount)){
value -= amount;
}
}
//define return types within definition
function balance() returns(uint){
return value;
}
function checkValue(uint amount) returns(bool){
return amount <= value;
}
function loan() returns(bool){
return value > 0;
}
}
//extension with constructor parameter injection
contract MyFirstContract is Bank(10){
string private name;
uint private age;
function getName() returns(string){
return name;
}
function setName(string newName){
name = newName;
}
function getAge() returns(uint){
return age;
}
function setAge(uint newAge){
age = newAge;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment