forked from wy/examples-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDomain.java
More file actions
42 lines (34 loc) · 1.43 KB
/
Copy pathDomain.java
File metadata and controls
42 lines (34 loc) · 1.43 KB
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
import org.neo.smartcontract.framework.SmartContract;
import org.neo.smartcontract.framework.services.neo.Storage;
public class Domain extends SmartContract {
public static Object Main(String operation, Object... args){
if (operation == "query") return Query((String) args[0]);
if (operation == "register") return Register((String)args[0], (byte[])args[1]);
if (operation == "transfer") return Transfer((String) args[0], (byte[])args[1]);
if (operation == "delete") return Delete((String) args[0]);
return false;
}
private static byte[] Query(String domain){
return Storage.get(Storage.currentContext(),domain);
}
private static boolean Register(String domain, byte[] owner) {
byte[] value = Storage.get(Storage.currentContext(), domain);
if (value!= null) return false;
Storage.put(Storage.currentContext(),domain,owner);
return true;
}
private static boolean Transfer(String domain, byte[] to)
{
byte[] from = Storage.get(Storage.currentContext(), domain);
if (from == null) return false;
Storage.put(Storage.currentContext(), domain, to);
return true;
}
private static boolean Delete(String domain)
{
byte[] owner = Storage.get(Storage.currentContext(), domain);
if (owner == null) return false;
Storage.delete(Storage.currentContext(), domain);
return true;
}
}