Skip to content

Instantly share code, notes, and snippets.

@paxthemax
Created October 16, 2020 11:14
Show Gist options
  • Save paxthemax/ef9719ed367bf4776b7df62f843aa0cb to your computer and use it in GitHub Desktop.
Save paxthemax/ef9719ed367bf4776b7df62f843aa0cb 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.7.3+commit.9bfce1f6.js&optimize=false&gist=
// "SPDX-License-Identifier: UNLICENSED"
pragma solidity 0.7.3;
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
contract AgreementStore is Ownable {
struct AgreementData{
uint256 kind;
string uuid;
string user1;
string user2;
}
uint256 private cnt;
mapping (uint256 => AgreementData) private _agreements;
event AgreementCreated(uint256 indexed id, uint256 kind, string uuid, string user1, string user2);
function createAgreement(uint256 _kind, string calldata _uuid, string calldata _user1, string calldata _user2) external {
require (_kind != 0, "Agreement kind cannot be zero");
uint256 id = cnt;
_agreements[id] = AgreementData(_kind, _uuid, _user1, _user2);
cnt++;
emit AgreementCreated(id, _kind, _uuid, _user1, _user2);
}
function getAgreement(uint256 id) external view returns (uint256 kind, string memory uuid, string memory user1, string memory user2) {
return (_agreements[id].kind, _agreements[id].uuid, _agreements[id].user1, _agreements[id].user2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment