-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGreeterV8.sol
65 lines (49 loc) · 1.9 KB
/
GreeterV8.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
pragma solidity ^0.4.18;
contract GreeterV8 {
struct Greeting {
string hello;
string goodbye;
}
mapping (uint => Greeting) countryToGreeting;
mapping (uint => string) countryToHello;
mapping (uint => string) countryToGoodbye;
mapping (string => uint) countryToEnum;
enum Country { Global, Korea, Usa }
address owner;
function GreeterV3() public {
owner = msg.sender;
countryToHello[0] = "Hello";
countryToGreeting[uint(Country.Global)] = Greeting("Hello","Goodbye");
Greeting memory korean = Greeting({goodbye:"안녕!",hello:"안녕?"});
countryToGreeting[uint(Country.Korea)] = korean;
Greeting memory usa;
usa.hello = "Hi";
usa.goodbye = "Bye";
countryToGreeting[uint(Country.Usa)] = usa;
countryToEnum[""] = uint(Country.Global);
countryToEnum["Korea"] = uint(Country.Korea);
countryToEnum["Usa"] = uint(Country.Usa);
}
function sayHello1(uint country) external view returns (string) {
return countryToHello[0];
}
function sayHello(uint country) external view returns (string) {
return countryToGreeting[country].hello;
}
function sayHello(string country) external view returns (string) {
return countryToGreeting[countryToEnum[country]].hello;
}
function changeHello(string country,string hello) external {
countryToGreeting[countryToEnum[country]].hello = hello;
}
function sayGoodbye(string country) external view returns (string) {
return countryToGreeting[countryToEnum[country]].goodbye;
}
function changeGoodbye(string country,string goodbye) external {
countryToGreeting[countryToEnum[country]].goodbye = goodbye;
}
function kill() external {
if ( msg.sender == owner )
selfdestruct(owner);
}
}