forked from TrueCloudLab/frostfs-contract
[#7] Refactor common.CheckAlphabetWitness()
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
7acc5ecaf1
commit
3aa936df5c
8 changed files with 27 additions and 43 deletions
|
@ -182,8 +182,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 {
|
||||
|
|
|
@ -148,8 +148,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 {
|
||||
|
@ -170,8 +169,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)
|
||||
|
||||
|
@ -201,8 +199,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) {
|
||||
|
@ -236,8 +233,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)
|
||||
|
||||
|
@ -267,8 +263,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)
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -238,8 +238,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)
|
||||
|
@ -324,8 +323,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)
|
||||
|
@ -437,8 +435,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,
|
||||
|
@ -571,8 +568,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)
|
||||
}
|
||||
|
@ -580,8 +576,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")
|
||||
|
@ -590,8 +585,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")
|
||||
|
|
|
@ -109,7 +109,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))
|
||||
|
@ -269,8 +271,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()
|
||||
|
||||
|
@ -335,8 +336,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)
|
||||
|
||||
|
|
|
@ -90,8 +90,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 {
|
||||
|
|
|
@ -144,7 +144,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
|
||||
|
||||
|
@ -217,7 +217,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) {
|
|||
ctx := storage.GetContext()
|
||||
|
||||
common.CheckWitness(publicKey)
|
||||
common.CheckAlphabetWitness(common.AlphabetAddress())
|
||||
common.CheckAlphabetWitness()
|
||||
|
||||
updateCandidateState(ctx, publicKey, state)
|
||||
}
|
||||
|
@ -231,7 +231,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)
|
||||
}
|
||||
|
@ -248,8 +248,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 {
|
||||
|
@ -347,7 +346,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")
|
||||
}
|
||||
|
@ -447,8 +446,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)
|
||||
|
||||
|
|
|
@ -92,8 +92,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
|
||||
|
|
Loading…
Reference in a new issue