Skip to content

Instantly share code, notes, and snippets.

@ripter
Created July 18, 2018 19:41
Show Gist options
  • Save ripter/65c18af0dad2da9d4b4dc742c78b565c to your computer and use it in GitHub Desktop.
Save ripter/65c18af0dad2da9d4b4dc742c78b565c 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.24;
contract BankContract {
uint balane;
function deposit() public payable {
balane += msg.value;
}
function getBalance() public view returns (uint) {
return balane;
}
}
pragma solidity ^0.4.0;
contract Dog {
string name = "Unnamed Dog";
function Bark() view returns (string) {
return name;
}
function setName(string _name) {
name = _name;
}
}
pragma solidity ^0.4.24;
import "./Ownable.sol";
contract DogContract is Ownable {
struct Dog {
string name;
uint8 age;
}
mapping(address => Dog) ownedDogs;
event addedDog(address owner, string name, uint age);
function addDog(string _name, uint8 _age) public {
address owner = msg.sender;
ownedDogs[owner] = Dog(_name, _age);
emit addedDog(owner, _name, _age);
}
function getDogName() public view returns (string) {
return ownedDogs[msg.sender].name;
}
}
pragma solidity ^0.4.0;
contract Hangout {
Person[] people;
function addPerson(string _name, uint _age) public {
people.push(Person(_name, _age));
}
function averageAge() public view returns (uint) {
uint sum = 0;
for(uint i=0; i < people.length; i++) {
sum += people[i].age;
}
return sum / people.length;
}
struct Person {
string name;
uint age;
}
}
pragma solidity ^0.4.24;
import './DogContract.sol';
contract BankInterface {
function deposit() public payable;
function getBalance() public view returns (uint);
}
contract Kennel is DogContract {
BankInterface bankContract;
function initBank(address _bankAddress) public onlyOwner {
bankContract = BankInterface(_bankAddress);
}
function transferDog(address _newOwner) public payable costs(100) {
address owner = msg.sender;
require(_newOwner != owner, "Owner already owns the Dog");
ownedDogs[_newOwner] = ownedDogs[owner];
delete(ownedDogs[owner]);
bankContract.deposit.value(msg.value)();
}
function getBankBalance() public view returns (uint) {
return bankContract.getBalance();
}
modifier costs(uint _value) {
require(msg.value >= _value, "Value does not cover the costs");
_;
}
}
pragma solidity ^0.4.24;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment