-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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