Skip to content

Instantly share code, notes, and snippets.

@MunhozThiago
Created May 10, 2019 14:29
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 MunhozThiago/579102a19b6503b81c3167c19785e469 to your computer and use it in GitHub Desktop.
Save MunhozThiago/579102a19b6503b81c3167c19785e469 to your computer and use it in GitHub Desktop.
This is the Smart Contract used in the paper "Regulating Blockchain Smart Contracts WithAgent-Based Markets"
pragma solidity >=0.4.4 <0.6.0;
contract BuyItemContract {
string item = "myItemKey";
uint price;
address payable seller;
event Sell(address seller, string item);
event Sold(address buyer, string item, uint value);
event Received(address seller, uint price);
constructor() public payable {
}
function() external payable {}
function setSeller() public {
seller = msg.sender;
emit Sell(seller, item);
}
function payHalf(uint value) public payable returns (bool) {
if (msg.value != 0) {
value = msg.value;
}
if (value < 100) {
revert();
} else {
price += value;
emit Sold(msg.sender, item, price);
}
return true;
}
function payOtherHalf(uint value) public payable {
if (msg.value != 0) {
value = msg.value;
}
if (value != 2 * price) {
revert();
} else {
seller.transfer(2 * price);
emit Received(seller, 2 * price);
}
}
function expectedOtherHalf() public view returns (uint) {
return (2 * price);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment