-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adoption.sol
35 lines (25 loc) · 977 Bytes
/
Adoption.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pragma solidity ^0.4.4; // The minimum version of Solidity required
contract Adoption {
address[16] public adopters; // fixed array of 16 ethereum addresses
// public member variables have automatic getter methods
// array public variables require and id, so like
// function getAdopter(index) { return adopters[index];}
// adopt a pet
function adopt(uint petId) public returns (uint) {
require(petId >= 0 && petId <= 15); //we only have 16 pets
// msg.sender is the senders address (person or smart contract)
adopters[petId] = msg.sender;
return petId;
}
//return all the adopters, unlike the auto-magic getter
function getAdopters() public returns (address[16]) {
return adopters;
}
function disown(uint petId) public returns (uint) {
require(petId >= 0 && petId <= 15);
// make sure this owner owns the pet
require(adopters[petId] == msg.sender);
adopters[petId] = 0x0;
return petId;
}
}