-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlienStarSystem.sol
77 lines (59 loc) · 2.34 KB
/
AlienStarSystem.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pragma solidity ^0.4.24;
contract AlienContract {
function onERC721Received(address, address, uint256, string) public;
}
contract StarsList {
uint256 starID;
uint256 starCount = 0;
mapping (uint256 => address) userAddress;
// Õðàíèëèùå äëÿ ïîêóïêè çâåçä è èõ íàèìåíîâàíèÿ
struct star {
address starOwner;
string starName;
string starColor;
}
mapping(uint256 => star) Stars;
event transfer(address from, address to, uint256 starID);
event changeColor(uint256 starID, string);
event changeName(uint256 starID, string);
function CreateStar(string _starName, string _starColor) public returns (bool){
starID = starCount++;
Stars[starID].starOwner = msg.sender;
Stars[starID].starName = _starName;
Stars[starID].starColor = _starColor;
return true;
}
function Transfer(address _to, uint256 _starID) public {
require(Stars[_starID].starOwner == msg.sender);
Stars[_starID].starOwner = _to;
emit transfer(msg.sender, _to, _starID);
}
function safeTransferFrom(address _from, address _to, uint256 _starID) public {
require(Stars[_starID].starOwner == msg.sender);
require(Stars[_starID].starOwner != _to);
require(starCount >= starID);
require(isContract(_to) == true);
AlienContract AlCont = AlienContract(_to);
AlCont.onERC721Received(_from, _to, _starID, "");
require(Stars[_starID].starOwner == msg.sender);
Stars[_starID].starOwner = _to;
emit transfer(msg.sender, _to, _starID);
}
function ChangeStarColor(uint256 _starID, string _starColor) public returns (bool) {
require(Stars[_starID].starOwner == msg.sender);
Stars[_starID].starColor = _starColor;
emit changeColor(_starID, _starColor);
return true;
}
function ChangeStarName(uint256 _starID, string _starName) public returns (bool) {
require(Stars[_starID].starOwner == msg.sender);
Stars[_starID].starName = _starName;
emit changeName(_starID, _starName);
return true;
}
function isContract(address addr) public view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}