Let's say I have a decentralized application that allows people to buy some object at an arbitrary price.
User 1 purchases the object for 1 eth. A few moments later, user 2 purchases the same item. How can I monitor for this event and automatically return the appropriate amount of etherium to user 2? Here's what I have so far:
contract Adoption {
address[16] public adopters;
function returnEth() public payable {
msg.sender.transfer(msg.value);
}
// Adopting a pet
function adopt(uint petId) public payable returns (uint) {
require(petId >= 0 && petId <= 15);
//require(msg.value == 1 ether);
adopters[petId] = msg.sender;
returnEth();
return petId;
//return value;
}
// Retrieving the adopters
function getAdopters() public view returns (address[16]) {
return adopters;
}
}