container: register NNS root on update
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
80d599b65b
commit
18ff4ea116
1 changed files with 17 additions and 5 deletions
|
@ -71,10 +71,6 @@ func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) {
|
|||
func _deploy(data interface{}, isUpdate bool) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if isUpdate {
|
||||
return
|
||||
}
|
||||
|
||||
args := data.([]interface{})
|
||||
notaryDisabled := args[0].(bool)
|
||||
addrNetmap := args[1].(interop.Hash160)
|
||||
|
@ -83,6 +79,11 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
addrNNS := args[4].(interop.Hash160)
|
||||
nnsRoot := args[5].(string)
|
||||
|
||||
if isUpdate {
|
||||
registerNiceNameTLD(addrNNS, nnsRoot)
|
||||
return
|
||||
}
|
||||
|
||||
if len(addrNetmap) != 20 || len(addrBalance) != 20 || len(addrID) != 20 {
|
||||
panic("incorrect length of contract script hash")
|
||||
}
|
||||
|
@ -101,11 +102,22 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
}
|
||||
|
||||
// add NNS root for container alias domains
|
||||
contract.Call(addrNNS, "addRoot", contract.All, nnsRoot)
|
||||
registerNiceNameTLD(addrNNS, nnsRoot)
|
||||
|
||||
runtime.Log("container contract initialized")
|
||||
}
|
||||
|
||||
func registerNiceNameTLD(addrNNS interop.Hash160, nnsRoot string) {
|
||||
iter := contract.Call(addrNNS, "roots", contract.ReadStates).(iterator.Iterator)
|
||||
for iterator.Next(iter) {
|
||||
if iterator.Value(iter).(string) == nnsRoot {
|
||||
runtime.Log("NNS root is already registered: " + nnsRoot)
|
||||
return
|
||||
}
|
||||
}
|
||||
contract.Call(addrNNS, "addRoot", contract.All, nnsRoot)
|
||||
}
|
||||
|
||||
// Update method updates contract source code and manifest. Can be invoked
|
||||
// only by committee.
|
||||
func Update(script []byte, manifest []byte, data interface{}) {
|
||||
|
|
Loading…
Reference in a new issue