forked from TrueCloudLab/frostfs-contract
[#107] common: Check committee witness for contract update
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
edd4864e39
commit
378e69c015
2 changed files with 10 additions and 21 deletions
13
common/ir.go
13
common/ir.go
|
@ -55,6 +55,12 @@ func AlphabetAddress() []byte {
|
|||
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.
|
||||
// If committee set to true, then it is `M = N/2+1` committee account.
|
||||
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
|
||||
}
|
||||
|
||||
keys := []interop.PublicKey{}
|
||||
for _, key := range n {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
return contract.CreateMultisigAccount(threshold, keys)
|
||||
return contract.CreateMultisigAccount(threshold, n)
|
||||
}
|
||||
|
||||
func keysToNodes(list []interop.PublicKey) []IRNode {
|
||||
|
|
|
@ -1,22 +1,10 @@
|
|||
package common
|
||||
|
||||
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/storage"
|
||||
)
|
||||
|
||||
const OwnerKey = "contractOwner"
|
||||
|
||||
// HasUpdateAccess returns true if contract can be initialized, re-initialized
|
||||
// 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)
|
||||
// HasUpdateAccess returns true if contract can be updated.
|
||||
func HasUpdateAccess() bool {
|
||||
return runtime.CheckWitness(CommitteeAddress())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue