-
Notifications
You must be signed in to change notification settings - Fork 5
/
4-domain.go
90 lines (72 loc) · 2.15 KB
/
4-domain.go
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
78
79
80
81
82
83
84
85
86
87
88
89
90
package domain
import (
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
var ctx storage.Context
func init() {
ctx = storage.GetContext()
}
// Query returns the owner of the domain with the specified name.
func Query(domainName []byte) interface{} {
message := "QueryDomain: " + string(domainName)
runtime.Log(message)
owner := storage.Get(ctx, domainName)
if owner != nil {
runtime.Log("Domain is already registered")
return owner
}
runtime.Log("Domain is not yet registered")
return false
}
// Delete deletes domain with the specified name.
func Delete(domainName []byte) bool {
message := "DeleteDomain: " + string(domainName)
runtime.Log(message)
owner := storage.Get(ctx, domainName)
if owner == nil {
runtime.Log("Domain is not yet registered")
return false
}
if !runtime.CheckWitness(owner.([]byte)) {
runtime.Log("Sender is not the owner, cannot delete")
return false
}
storage.Delete(ctx, domainName)
runtime.Notify("deleted", owner.([]byte), domainName)
return true
}
// Register registers new domain with specified name and owner.
func Register(domainName []byte, owner []byte) bool {
message := "RegisterDomain: " + string(domainName)
runtime.Log(message)
if !runtime.CheckWitness(owner) {
runtime.Log("Owner argument is not the same as the sender")
return false
}
if storage.Get(ctx, domainName) != nil {
runtime.Log("Domain is already registered")
return false
}
storage.Put(ctx, domainName, owner)
runtime.Notify("registered", owner, domainName)
return true
}
// Transfer transfers domain from owner to the specified address.
func Transfer(domainName []byte, toAddress []byte) bool {
message := "TransferDomain: " + string(domainName)
runtime.Log(message)
owner := storage.Get(ctx, domainName)
if owner == nil {
runtime.Log("Domain is not yet registered")
return false
}
if !runtime.CheckWitness(owner.([]byte)) {
runtime.Log("Not co-signed by an owner, cannot transfer")
return false
}
storage.Put(ctx, domainName, toAddress)
runtime.Notify("deleted", owner.([]byte), domainName)
runtime.Notify("registered", toAddress, domainName)
return true
}