[#107] common: Check committee witness for contract update

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-09-20 18:05:49 +03:00 committed by Alex Vanin
parent edd4864e39
commit 378e69c015
2 changed files with 10 additions and 21 deletions

View file

@ -55,6 +55,12 @@ func AlphabetAddress() []byte {
return Multiaddress(alphabet, false) return Multiaddress(alphabet, false)
} }
// CommitteeAddress returns multi address of committee.
func CommitteeAddress() []byte {
committee := neo.GetCommittee()
return Multiaddress(committee, true)
}
// Multiaddress returns default multi signature account address for N keys. // Multiaddress returns default multi signature account address for N keys.
// If committee set to true, then it is `M = N/2+1` committee account. // If committee set to true, then it is `M = N/2+1` committee account.
func Multiaddress(n []interop.PublicKey, committee bool) []byte { func Multiaddress(n []interop.PublicKey, committee bool) []byte {
@ -63,12 +69,7 @@ func Multiaddress(n []interop.PublicKey, committee bool) []byte {
threshold = len(n)/2 + 1 threshold = len(n)/2 + 1
} }
keys := []interop.PublicKey{} return contract.CreateMultisigAccount(threshold, n)
for _, key := range n {
keys = append(keys, key)
}
return contract.CreateMultisigAccount(threshold, keys)
} }
func keysToNodes(list []interop.PublicKey) []IRNode { func keysToNodes(list []interop.PublicKey) []IRNode {

View file

@ -1,22 +1,10 @@
package common package common
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
) )
const OwnerKey = "contractOwner" // HasUpdateAccess returns true if contract can be updated.
func HasUpdateAccess() bool {
// HasUpdateAccess returns true if contract can be initialized, re-initialized return runtime.CheckWitness(CommitteeAddress())
// or migrated.
func HasUpdateAccess(ctx storage.Context) bool {
data := storage.Get(ctx, OwnerKey)
if data == nil { // contract has not been initialized yet, return true
return true
}
owner := data.(interop.Hash160)
return runtime.CheckWitness(owner)
} }