[#7] Refactor common.CheckAlphabetWitness()

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-02-10 18:07:44 +03:00
parent 2a889c316c
commit 8e75fa1285
8 changed files with 27 additions and 43 deletions

View file

@ -178,8 +178,7 @@ func Vote(epoch int, candidates []interop.PublicKey) {
index := index(ctx)
name := name(ctx)
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
curEpoch := currentEpoch(ctx)
if epoch != curEpoch {

View file

@ -144,8 +144,7 @@ func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
func TransferX(from, to interop.Hash160, amount int, details []byte) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
result := token.transfer(ctx, from, to, amount, true, details)
if !result {
@ -166,8 +165,7 @@ func TransferX(from, to interop.Hash160, amount int, details []byte) {
func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
details := common.LockTransferDetails(txDetails)
@ -197,8 +195,7 @@ func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) {
func NewEpoch(epochNum int) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
for iterator.Next(it) {
@ -232,8 +229,7 @@ func NewEpoch(epochNum int) {
func Mint(to interop.Hash160, amount int, txDetails []byte) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
details := common.MintTransferDetails(txDetails)
@ -263,8 +259,7 @@ func Mint(to interop.Hash160, amount int, txDetails []byte) {
func Burn(from interop.Hash160, amount int, txDetails []byte) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
details := common.BurnTransferDetails(txDetails)

View file

@ -16,8 +16,8 @@ var (
// CheckAlphabetWitness checks witness of the passed caller.
// It panics with ErrAlphabetWitnessFailed message on fail.
func CheckAlphabetWitness(caller []byte) {
checkWitnessWithPanic(caller, ErrAlphabetWitnessFailed)
func CheckAlphabetWitness() {
checkWitnessWithPanic(AlphabetAddress(), ErrAlphabetWitnessFailed)
}
// CheckOwnerWitness checks witness of the passed caller.

View file

@ -234,8 +234,7 @@ func PutNamed(container []byte, signature interop.Signature,
panic("insufficient balance to create container")
}
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
// todo: check if new container with unique container id
details := common.ContainerFeeTransferDetails(containerID)
@ -320,8 +319,7 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) {
return
}
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
key := append([]byte(nnsHasAliasKey), containerID...)
domain := storage.Get(ctx, key).(string)
@ -433,8 +431,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK
panic(NotFoundError)
}
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
rule := ExtendedACL{
value: eACL,
@ -567,8 +564,7 @@ func IterateContainerSizes(epoch int) iterator.Iterator {
func NewEpoch(epochNum int) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
cleanupContainers(ctx, epochNum)
}
@ -576,8 +572,7 @@ func NewEpoch(epochNum int) {
// StartContainerEstimation method produces StartEstimation notification.
// It can be invoked only by Alphabet nodes of the Inner Ring.
func StartContainerEstimation(epoch int) {
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
runtime.Notify("StartEstimation", epoch)
runtime.Log("notification has been produced")
@ -586,8 +581,7 @@ func StartContainerEstimation(epoch int) {
// StopContainerEstimation method produces StopEstimation notification.
// It can be invoked only by Alphabet nodes of the Inner Ring.
func StopContainerEstimation(epoch int) {
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
runtime.Notify("StopEstimation", epoch)
runtime.Log("notification has been produced")

View file

@ -105,7 +105,9 @@ func Update(script []byte, manifest []byte, data interface{}) {
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
common.CheckAlphabetWitness(alphabetCommittee)
if !runtime.CheckWitness(alphabetCommittee) {
panic(common.ErrAlphabetWitnessFailed)
}
contract.Call(interop.Hash160(management.Hash), "update",
contract.All, script, manifest, common.AppendVersion(data))
@ -265,8 +267,7 @@ func Withdraw(user interop.Hash160, amount int) {
//
// This method produces Cheque notification to burn assets in sidechain.
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) {
multiaddr := AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
from := runtime.GetExecutingScriptHash()
@ -331,8 +332,7 @@ func Config(key []byte) interface{} {
func SetConfig(id, key, val []byte) {
ctx := storage.GetContext()
multiaddr := AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
setConfig(ctx, key, val)

View file

@ -86,8 +86,7 @@ func AddKey(owner []byte, keys []interop.PublicKey) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
ownerKey := append([]byte{ownerKeysPrefix}, owner...)
for i := range keys {

View file

@ -140,7 +140,7 @@ func Update(script []byte, manifest []byte, data interface{}) {
func AddPeerIR(nodeInfo []byte) {
ctx := storage.GetContext()
common.CheckAlphabetWitness(common.AlphabetAddress())
common.CheckAlphabetWitness()
publicKey := nodeInfo[2:35] // V2 format: offset:2, len:33
@ -213,7 +213,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) {
ctx := storage.GetContext()
common.CheckWitness(publicKey)
common.CheckAlphabetWitness(common.AlphabetAddress())
common.CheckAlphabetWitness()
updateCandidateState(ctx, publicKey, state)
}
@ -227,7 +227,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) {
func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
ctx := storage.GetContext()
common.CheckAlphabetWitness(common.AlphabetAddress())
common.CheckAlphabetWitness()
updateCandidateState(ctx, publicKey, state)
}
@ -244,8 +244,7 @@ func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
func NewEpoch(epochNum int) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
currentEpoch := storage.Get(ctx, snapshotEpoch).(int)
if epochNum <= currentEpoch {
@ -343,7 +342,7 @@ func getSnapshotCount(ctx storage.Context) int {
//
// Count MUST NOT be negative.
func UpdateSnapshotCount(count int) {
common.CheckAlphabetWitness(common.AlphabetAddress())
common.CheckAlphabetWitness()
if count < 0 {
panic("count must be positive")
}
@ -443,8 +442,7 @@ func Config(key []byte) interface{} {
func SetConfig(id, key, val []byte) {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
setConfig(ctx, key, val)

View file

@ -88,8 +88,7 @@ func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
common.CheckOwnerWitness(ownerKey)
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()
storage.Put(ctx, stKey, ownerKey)
stKey[0] = infoPrefix