[#185] *: Cast args of _deploy method to struct

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-29 19:34:11 +03:00 committed by Alex Vanin
parent b2559857f6
commit f78a0e32b8
10 changed files with 114 additions and 104 deletions

View file

@ -37,34 +37,35 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrNetmap := args[1].(interop.Hash160)
addrProxy := args[2].(interop.Hash160)
name := args[3].(string)
index := args[4].(int)
total := args[5].(int)
args := data.(struct {
notaryDisabled bool
addrNetmap interop.Hash160
addrProxy interop.Hash160
name string
index int
total int
})
ctx := storage.GetContext()
if len(addrNetmap) != 20 || !notaryDisabled && len(addrProxy) != 20 {
if len(args.addrNetmap) != 20 || !args.notaryDisabled && len(args.addrProxy) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapKey, addrNetmap)
storage.Put(ctx, proxyKey, addrProxy)
storage.Put(ctx, nameKey, name)
storage.Put(ctx, indexKey, index)
storage.Put(ctx, totalKey, total)
storage.Put(ctx, netmapKey, args.addrNetmap)
storage.Put(ctx, proxyKey, args.addrProxy)
storage.Put(ctx, nameKey, args.name)
storage.Put(ctx, indexKey, args.index)
storage.Put(ctx, totalKey, args.total)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log(name + " notary disabled")
runtime.Log(args.name + " notary disabled")
}
runtime.Log(name + " contract initialized")
runtime.Log(args.name + " contract initialized")
}
// Update method updates contract source code and manifest. Can be invoked

View file

@ -47,21 +47,22 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrNetmap := args[1].(interop.Hash160)
args := data.(struct {
notaryDisabled bool
addrNetmap interop.Hash160
})
ctx := storage.GetContext()
if len(addrNetmap) != 20 {
if len(args.addrNetmap) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapContractKey, addrNetmap)
storage.Put(ctx, netmapContractKey, args.addrNetmap)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
runtime.Log("audit contract notary disabled")
}

View file

@ -63,23 +63,24 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrNetmap := args[1].(interop.Hash160)
addrContainer := args[2].(interop.Hash160)
args := data.(struct {
notaryDisabled bool
addrNetmap interop.Hash160
addrContainer interop.Hash160
})
ctx := storage.GetContext()
if len(addrNetmap) != 20 || len(addrContainer) != 20 {
if len(args.addrNetmap) != 20 || len(args.addrContainer) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapContractKey, addrNetmap)
storage.Put(ctx, containerContractKey, addrContainer)
storage.Put(ctx, netmapContractKey, args.addrNetmap)
storage.Put(ctx, containerContractKey, args.addrContainer)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log("balance contract notary disabled")
}

View file

@ -84,40 +84,41 @@ func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) {
func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrNetmap := args[1].(interop.Hash160)
addrBalance := args[2].(interop.Hash160)
addrID := args[3].(interop.Hash160)
addrNNS := args[4].(interop.Hash160)
nnsRoot := args[5].(string)
args := data.(struct {
notaryDisabled bool
addrNetmap interop.Hash160
addrBalance interop.Hash160
addrID interop.Hash160
addrNNS interop.Hash160
nnsRoot string
})
if isUpdate {
storage.Put(ctx, nnsContractKey, addrNNS)
storage.Put(ctx, nnsRootKey, nnsRoot)
registerNiceNameTLD(addrNNS, nnsRoot)
storage.Put(ctx, nnsContractKey, args.addrNNS)
storage.Put(ctx, nnsRootKey, args.nnsRoot)
registerNiceNameTLD(args.addrNNS, args.nnsRoot)
return
}
if len(addrNetmap) != 20 || len(addrBalance) != 20 || len(addrID) != 20 {
if len(args.addrNetmap) != 20 || len(args.addrBalance) != 20 || len(args.addrID) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapContractKey, addrNetmap)
storage.Put(ctx, balanceContractKey, addrBalance)
storage.Put(ctx, neofsIDContractKey, addrID)
storage.Put(ctx, nnsContractKey, addrNNS)
storage.Put(ctx, nnsRootKey, nnsRoot)
storage.Put(ctx, netmapContractKey, args.addrNetmap)
storage.Put(ctx, balanceContractKey, args.addrBalance)
storage.Put(ctx, neofsIDContractKey, args.addrID)
storage.Put(ctx, nnsContractKey, args.addrNNS)
storage.Put(ctx, nnsRootKey, args.nnsRoot)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log("container contract notary disabled")
}
// add NNS root for container alias domains
registerNiceNameTLD(addrNNS, nnsRoot)
registerNiceNameTLD(args.addrNNS, args.nnsRoot)
runtime.Log("container contract initialized")
}

View file

@ -60,26 +60,27 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrProc := args[1].(interop.Hash160)
keys := args[2].([]interop.PublicKey)
config := args[3].([][]byte)
args := data.(struct {
notaryDisabled bool
addrProc interop.Hash160
keys []interop.PublicKey
config [][]byte
})
ctx := storage.GetContext()
var irList []common.IRNode
if len(keys) == 0 {
if len(args.keys) == 0 {
panic("at least one alphabet key must be provided")
}
if len(addrProc) != 20 {
if len(args.addrProc) != 20 {
panic("incorrect length of contract script hash")
}
for i := 0; i < len(keys); i++ {
pub := keys[i]
for i := 0; i < len(args.keys); i++ {
pub := args.keys[i]
if len(pub) != publicKeySize {
panic("incorrect public key length")
}
@ -89,23 +90,23 @@ func _deploy(data interface{}, isUpdate bool) {
// initialize all storage slices
common.SetSerialized(ctx, alphabetKey, irList)
storage.Put(ctx, processingContractKey, addrProc)
storage.Put(ctx, processingContractKey, args.addrProc)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log("neofs contract notary disabled")
}
ln := len(config)
ln := len(args.config)
if ln%2 != 0 {
panic("bad configuration")
}
for i := 0; i < ln/2; i++ {
key := config[i*2]
val := config[i*2+1]
key := args.config[i*2]
val := args.config[i*2+1]
setConfig(ctx, key, val)
}

View file

@ -45,21 +45,22 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrNetmap := args[1].(interop.Hash160)
addrContainer := args[2].(interop.Hash160)
args := data.(struct {
notaryDisabled bool
addrNetmap interop.Hash160
addrContainer interop.Hash160
})
if len(addrNetmap) != 20 || len(addrContainer) != 20 {
if len(args.addrNetmap) != 20 || len(args.addrContainer) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapContractKey, addrNetmap)
storage.Put(ctx, containerContractKey, addrContainer)
storage.Put(ctx, netmapContractKey, args.addrNetmap)
storage.Put(ctx, containerContractKey, args.addrContainer)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log("neofsid contract notary disabled")
}

View file

@ -62,21 +62,22 @@ var (
func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
args := data.([]interface{})
notaryDisabled := args[0].(bool)
addrBalance := args[1].(interop.Hash160)
addrContainer := args[2].(interop.Hash160)
keys := args[3].([]interop.PublicKey)
config := args[4].([][]byte)
var args = data.(struct {
notaryDisabled bool
addrBalance interop.Hash160
addrContainer interop.Hash160
keys []interop.PublicKey
config [][]byte
})
ln := len(config)
ln := len(args.config)
if ln%2 != 0 {
panic("bad configuration")
}
for i := 0; i < ln/2; i++ {
key := config[i*2]
val := config[i*2+1]
key := args.config[i*2]
val := args.config[i*2+1]
setConfig(ctx, key, val)
}
@ -85,7 +86,7 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
if len(addrBalance) != 20 || len(addrContainer) != 20 {
if len(args.addrBalance) != 20 || len(args.addrContainer) != 20 {
panic("incorrect length of contract script hash")
}
@ -96,16 +97,16 @@ func _deploy(data interface{}, isUpdate bool) {
common.SetSerialized(ctx, snapshot0Key, []netmapNode{})
common.SetSerialized(ctx, snapshot1Key, []netmapNode{})
storage.Put(ctx, balanceContractKey, addrBalance)
storage.Put(ctx, containerContractKey, addrContainer)
storage.Put(ctx, balanceContractKey, args.addrBalance)
storage.Put(ctx, containerContractKey, args.addrContainer)
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
var irList []common.IRNode
for i := 0; i < len(keys); i++ {
key := keys[i]
for i := 0; i < len(args.keys); i++ {
key := args.keys[i]
irList = append(irList, common.IRNode{PublicKey: key})
}

View file

@ -31,16 +31,17 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
arr := data.([]interop.Hash160)
addrNeoFS := arr[0]
args := data.(struct {
addrNeoFS interop.Hash160
})
ctx := storage.GetContext()
if len(addrNeoFS) != 20 {
if len(args.addrNeoFS) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, neofsContractKey, addrNeoFS)
storage.Put(ctx, neofsContractKey, args.addrNeoFS)
runtime.Log("processing contract initialized")
}

View file

@ -28,16 +28,17 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
addrNetmap := args[0].(interop.Hash160)
args := data.(struct {
addrNetmap interop.Hash160
})
ctx := storage.GetContext()
if len(addrNetmap) != 20 {
if len(args.addrNetmap) != 20 {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, netmapContractKey, addrNetmap)
storage.Put(ctx, netmapContractKey, args.addrNetmap)
runtime.Log("proxy contract initialized")
}

View file

@ -43,12 +43,13 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
args := data.([]interface{})
notaryDisabled := args[0].(bool)
args := data.(struct {
notaryDisabled bool
})
// initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled {
storage.Put(ctx, notaryDisabledKey, args.notaryDisabled)
if args.notaryDisabled {
common.InitVote(ctx)
runtime.Log("reputation contract notary disabled")
}