[#136] nns: Move CheckCommittee to common package

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-12-10 17:05:55 +03:00
parent 762d7f9f9f
commit 40b12fbb35
Signed by: achuprov
GPG key ID: 2D916FFD803B0EDD
2 changed files with 21 additions and 18 deletions

View file

@ -1,6 +1,10 @@
package common package common
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" import (
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
)
var ( var (
// ErrAlphabetWitnessFailed appears when the method must be // ErrAlphabetWitnessFailed appears when the method must be
@ -37,3 +41,16 @@ func checkWitnessWithPanic(caller []byte, panicMsg string) {
panic(panicMsg) panic(panicMsg)
} }
} }
// CheckCommittee panics if the script container is not signed by the committee.
func CheckCommittee() {
committee := neo.GetCommittee()
if committee == nil {
panic("failed to get committee")
}
l := len(committee)
committeeMultisig := contract.CreateMultisigAccount(l-(l-1)/2, committee)
if committeeMultisig == nil || !runtime.CheckWitness(committeeMultisig) {
panic("not witnessed by committee")
}
}

View file

@ -15,7 +15,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/interop/iterator" "github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto" "github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"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" "github.com/nspcc-dev/neo-go/pkg/interop/storage"
@ -93,7 +92,7 @@ type RecordState struct {
// Update updates NameService contract. // Update updates NameService contract.
func Update(nef []byte, manifest string, data any) { func Update(nef []byte, manifest string, data any) {
checkCommittee() common.CheckCommittee()
// Calculating keys and serializing requires calling // Calculating keys and serializing requires calling
// std and crypto contracts. This can be helpful on update // std and crypto contracts. This can be helpful on update
// thus we provide `AllowCall` to management.Update. // thus we provide `AllowCall` to management.Update.
@ -219,7 +218,7 @@ func Roots() iterator.Iterator {
// SetPrice sets the domain registration price. // SetPrice sets the domain registration price.
func SetPrice(price int64) { func SetPrice(price int64) {
checkCommittee() common.CheckCommittee()
if price < 0 || price > maxRegisterPrice { if price < 0 || price > maxRegisterPrice {
panic("The price is out of range.") panic("The price is out of range.")
} }
@ -928,20 +927,7 @@ func isValid(address interop.Hash160) bool {
// or if the owner does not have permission in FrostfsID. // or if the owner does not have permission in FrostfsID.
func checkCommitteeAndFrostfsID(ctx storage.Context, owner interop.Hash160) { func checkCommitteeAndFrostfsID(ctx storage.Context, owner interop.Hash160) {
if !checkFrostfsID(ctx, owner) { if !checkFrostfsID(ctx, owner) {
checkCommittee() common.CheckCommittee()
}
}
// checkCommittee panics if the script container is not signed by the committee.
func checkCommittee() {
committee := neo.GetCommittee()
if committee == nil {
panic("failed to get committee")
}
l := len(committee)
committeeMultisig := contract.CreateMultisigAccount(l-(l-1)/2, committee)
if committeeMultisig == nil || !runtime.CheckWitness(committeeMultisig) {
panic("not witnessed by committee")
} }
} }