Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.19;
- contract Adoption {
- address ceoAddress = 0xFc3B4137Bf7d53aB44A0FB39b31CC3F18EA6F959;
- struct Pet {
- address owner;
- uint256 price;
- }
- Pet[16] data;
- function Adoption() public {
- for (uint i = 0; i < 16; i++) {
- data[i].price = 100000000;
- data[i].owner = msg.sender;
- }
- }
- function returnEth(address oldOwner, uint256 price) public payable {
- ceoAddress.transfer(price);
- }
- // Adopting a pet
- function adopt(uint petId) public payable returns (uint, uint) {
- require(petId >= 0 && petId <= 15);
- if ( data[petId].price == 0 ) {
- data[petId].price = 100000000;
- } else {
- data[petId].price = data[petId].price * 2;
- }
- require(msg.value >= data[petId].price * uint256(1));
- returnEth(data[petId].owner, (data[petId].price / 2));
- data[petId].owner = msg.sender;
- return (petId, data[petId].price);
- //return value;
- }
- function getAdopters() external view returns (address[], uint256[]) {
- address[] memory owners = new address[](16);
- uint256[] memory prices = new uint256[](16);
- for (uint i=0; i<16; i++) {
- owners[i] = (data[i].owner);
- prices[i] = (data[i].price);
- }
- return (owners,prices);
- }
- }
Add Comment
Please, Sign In to add comment