[#7] Refactor common.CheckAlphabetWitness()
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
d8530284fd
commit
b9be2ac036
8 changed files with 27 additions and 43 deletions
|
@ -178,8 +178,7 @@ func Vote(epoch int, candidates []interop.PublicKey) {
|
||||||
index := index(ctx)
|
index := index(ctx)
|
||||||
name := name(ctx)
|
name := name(ctx)
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
curEpoch := currentEpoch(ctx)
|
curEpoch := currentEpoch(ctx)
|
||||||
if epoch != curEpoch {
|
if epoch != curEpoch {
|
||||||
|
|
|
@ -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) {
|
func TransferX(from, to interop.Hash160, amount int, details []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
result := token.transfer(ctx, from, to, amount, true, details)
|
result := token.transfer(ctx, from, to, amount, true, details)
|
||||||
if !result {
|
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) {
|
func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
details := common.LockTransferDetails(txDetails)
|
details := common.LockTransferDetails(txDetails)
|
||||||
|
|
||||||
|
@ -197,8 +195,7 @@ func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) {
|
||||||
func NewEpoch(epochNum int) {
|
func NewEpoch(epochNum int) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
|
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
|
||||||
for iterator.Next(it) {
|
for iterator.Next(it) {
|
||||||
|
@ -232,8 +229,7 @@ func NewEpoch(epochNum int) {
|
||||||
func Mint(to interop.Hash160, amount int, txDetails []byte) {
|
func Mint(to interop.Hash160, amount int, txDetails []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
details := common.MintTransferDetails(txDetails)
|
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) {
|
func Burn(from interop.Hash160, amount int, txDetails []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
details := common.BurnTransferDetails(txDetails)
|
details := common.BurnTransferDetails(txDetails)
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ var (
|
||||||
|
|
||||||
// CheckAlphabetWitness checks witness of the passed caller.
|
// CheckAlphabetWitness checks witness of the passed caller.
|
||||||
// It panics with ErrAlphabetWitnessFailed message on fail.
|
// It panics with ErrAlphabetWitnessFailed message on fail.
|
||||||
func CheckAlphabetWitness(caller []byte) {
|
func CheckAlphabetWitness() {
|
||||||
checkWitnessWithPanic(caller, ErrAlphabetWitnessFailed)
|
checkWitnessWithPanic(AlphabetAddress(), ErrAlphabetWitnessFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckOwnerWitness checks witness of the passed caller.
|
// CheckOwnerWitness checks witness of the passed caller.
|
||||||
|
|
|
@ -234,8 +234,7 @@ func PutNamed(container []byte, signature interop.Signature,
|
||||||
panic("insufficient balance to create container")
|
panic("insufficient balance to create container")
|
||||||
}
|
}
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
// todo: check if new container with unique container id
|
// todo: check if new container with unique container id
|
||||||
|
|
||||||
details := common.ContainerFeeTransferDetails(containerID)
|
details := common.ContainerFeeTransferDetails(containerID)
|
||||||
|
@ -320,8 +319,7 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
key := append([]byte(nnsHasAliasKey), containerID...)
|
key := append([]byte(nnsHasAliasKey), containerID...)
|
||||||
domain := storage.Get(ctx, key).(string)
|
domain := storage.Get(ctx, key).(string)
|
||||||
|
@ -433,8 +431,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK
|
||||||
panic(NotFoundError)
|
panic(NotFoundError)
|
||||||
}
|
}
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
rule := ExtendedACL{
|
rule := ExtendedACL{
|
||||||
value: eACL,
|
value: eACL,
|
||||||
|
@ -567,8 +564,7 @@ func IterateContainerSizes(epoch int) iterator.Iterator {
|
||||||
func NewEpoch(epochNum int) {
|
func NewEpoch(epochNum int) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
cleanupContainers(ctx, epochNum)
|
cleanupContainers(ctx, epochNum)
|
||||||
}
|
}
|
||||||
|
@ -576,8 +572,7 @@ func NewEpoch(epochNum int) {
|
||||||
// StartContainerEstimation method produces StartEstimation notification.
|
// StartContainerEstimation method produces StartEstimation notification.
|
||||||
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
||||||
func StartContainerEstimation(epoch int) {
|
func StartContainerEstimation(epoch int) {
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
runtime.Notify("StartEstimation", epoch)
|
runtime.Notify("StartEstimation", epoch)
|
||||||
runtime.Log("notification has been produced")
|
runtime.Log("notification has been produced")
|
||||||
|
@ -586,8 +581,7 @@ func StartContainerEstimation(epoch int) {
|
||||||
// StopContainerEstimation method produces StopEstimation notification.
|
// StopContainerEstimation method produces StopEstimation notification.
|
||||||
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
// It can be invoked only by Alphabet nodes of the Inner Ring.
|
||||||
func StopContainerEstimation(epoch int) {
|
func StopContainerEstimation(epoch int) {
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
runtime.Notify("StopEstimation", epoch)
|
runtime.Notify("StopEstimation", epoch)
|
||||||
runtime.Log("notification has been produced")
|
runtime.Log("notification has been produced")
|
||||||
|
|
|
@ -105,7 +105,9 @@ func Update(script []byte, manifest []byte, data interface{}) {
|
||||||
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
||||||
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
||||||
|
|
||||||
common.CheckAlphabetWitness(alphabetCommittee)
|
if !runtime.CheckWitness(alphabetCommittee) {
|
||||||
|
panic(common.ErrAlphabetWitnessFailed)
|
||||||
|
}
|
||||||
|
|
||||||
contract.Call(interop.Hash160(management.Hash), "update",
|
contract.Call(interop.Hash160(management.Hash), "update",
|
||||||
contract.All, script, manifest, common.AppendVersion(data))
|
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.
|
// This method produces Cheque notification to burn assets in sidechain.
|
||||||
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) {
|
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) {
|
||||||
multiaddr := AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
from := runtime.GetExecutingScriptHash()
|
from := runtime.GetExecutingScriptHash()
|
||||||
|
|
||||||
|
@ -331,8 +332,7 @@ func Config(key []byte) interface{} {
|
||||||
func SetConfig(id, key, val []byte) {
|
func SetConfig(id, key, val []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
setConfig(ctx, key, val)
|
setConfig(ctx, key, val)
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,7 @@ func AddKey(owner []byte, keys []interop.PublicKey) {
|
||||||
|
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
ownerKey := append([]byte{ownerKeysPrefix}, owner...)
|
ownerKey := append([]byte{ownerKeysPrefix}, owner...)
|
||||||
for i := range keys {
|
for i := range keys {
|
||||||
|
|
|
@ -140,7 +140,7 @@ func Update(script []byte, manifest []byte, data interface{}) {
|
||||||
func AddPeerIR(nodeInfo []byte) {
|
func AddPeerIR(nodeInfo []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.CheckAlphabetWitness(common.AlphabetAddress())
|
common.CheckAlphabetWitness()
|
||||||
|
|
||||||
publicKey := nodeInfo[2:35] // V2 format: offset:2, len:33
|
publicKey := nodeInfo[2:35] // V2 format: offset:2, len:33
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.CheckWitness(publicKey)
|
common.CheckWitness(publicKey)
|
||||||
common.CheckAlphabetWitness(common.AlphabetAddress())
|
common.CheckAlphabetWitness()
|
||||||
|
|
||||||
updateCandidateState(ctx, publicKey, state)
|
updateCandidateState(ctx, publicKey, state)
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) {
|
||||||
func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
|
func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.CheckAlphabetWitness(common.AlphabetAddress())
|
common.CheckAlphabetWitness()
|
||||||
|
|
||||||
updateCandidateState(ctx, publicKey, state)
|
updateCandidateState(ctx, publicKey, state)
|
||||||
}
|
}
|
||||||
|
@ -244,8 +244,7 @@ func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
|
||||||
func NewEpoch(epochNum int) {
|
func NewEpoch(epochNum int) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
currentEpoch := storage.Get(ctx, snapshotEpoch).(int)
|
currentEpoch := storage.Get(ctx, snapshotEpoch).(int)
|
||||||
if epochNum <= currentEpoch {
|
if epochNum <= currentEpoch {
|
||||||
|
@ -343,7 +342,7 @@ func getSnapshotCount(ctx storage.Context) int {
|
||||||
//
|
//
|
||||||
// Count MUST NOT be negative.
|
// Count MUST NOT be negative.
|
||||||
func UpdateSnapshotCount(count int) {
|
func UpdateSnapshotCount(count int) {
|
||||||
common.CheckAlphabetWitness(common.AlphabetAddress())
|
common.CheckAlphabetWitness()
|
||||||
if count < 0 {
|
if count < 0 {
|
||||||
panic("count must be positive")
|
panic("count must be positive")
|
||||||
}
|
}
|
||||||
|
@ -443,8 +442,7 @@ func Config(key []byte) interface{} {
|
||||||
func SetConfig(id, key, val []byte) {
|
func SetConfig(id, key, val []byte) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
setConfig(ctx, key, val)
|
setConfig(ctx, key, val)
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,7 @@ func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
|
||||||
|
|
||||||
common.CheckOwnerWitness(ownerKey)
|
common.CheckOwnerWitness(ownerKey)
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
common.CheckAlphabetWitness()
|
||||||
common.CheckAlphabetWitness(multiaddr)
|
|
||||||
|
|
||||||
storage.Put(ctx, stKey, ownerKey)
|
storage.Put(ctx, stKey, ownerKey)
|
||||||
stKey[0] = infoPrefix
|
stKey[0] = infoPrefix
|
||||||
|
|
Loading…
Reference in a new issue