Skip to content

Commit

Permalink
*: simplify common.CheckAlphabetWitness()
Browse files Browse the repository at this point in the history
It uses alphabet multiaddress and it's well-known, no need to repeat the
getter.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Nov 19, 2024
1 parent 36adb10 commit c4a3bf0
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 67 deletions.
6 changes: 3 additions & 3 deletions common/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var (
ErrWitnessFailed = "witness check failed"
)

// CheckAlphabetWitness checks witness of the passed caller.
// CheckAlphabetWitness checks witness of the alphabet multiaddress.
// 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.
Expand Down
3 changes: 1 addition & 2 deletions contracts/alphabet/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,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 {
Expand Down
Binary file modified contracts/alphabet/contract.nef
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/alphabet/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NeoFS Alphabet","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":35,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"emit","offset":2827,"parameters":[],"returntype":"Void","safe":false},{"name":"gas","offset":2648,"parameters":[],"returntype":"Integer","safe":true},{"name":"name","offset":3458,"parameters":[],"returntype":"String","safe":true},{"name":"neo","offset":2662,"parameters":[],"returntype":"Integer","safe":true},{"name":"onNEP17Payment","offset":1160,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":2516,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":3478,"parameters":[],"returntype":"Boolean","safe":true},{"name":"version","offset":3474,"parameters":[],"returntype":"Integer","safe":true},{"name":"vote","offset":3286,"parameters":[{"name":"epoch","type":"Integer"},{"name":"candidates","type":"Array"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","transfer","vote"]}],"supportedstandards":[],"trusts":[],"extra":null}
{"name":"NeoFS Alphabet","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":35,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"emit","offset":2828,"parameters":[],"returntype":"Void","safe":false},{"name":"gas","offset":2649,"parameters":[],"returntype":"Integer","safe":true},{"name":"name","offset":3450,"parameters":[],"returntype":"String","safe":true},{"name":"neo","offset":2663,"parameters":[],"returntype":"Integer","safe":true},{"name":"onNEP17Payment","offset":1161,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":2517,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":3470,"parameters":[],"returntype":"Boolean","safe":true},{"name":"version","offset":3466,"parameters":[],"returntype":"Integer","safe":true},{"name":"vote","offset":3287,"parameters":[{"name":"epoch","type":"Integer"},{"name":"candidates","type":"Array"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","transfer","vote"]}],"supportedstandards":[],"trusts":[],"extra":null}
15 changes: 5 additions & 10 deletions contracts/balance/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ func Transfer(from, to interop.Hash160, amount int, data any) 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 {
Expand All @@ -215,8 +214,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)

Expand Down Expand Up @@ -246,8 +244,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{accPrefix}, storage.KeysOnly|storage.RemovePrefix)
for iterator.Next(it) {
Expand Down Expand Up @@ -281,8 +278,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)

Expand Down Expand Up @@ -311,8 +307,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)

Expand Down
Binary file modified contracts/balance/contract.nef
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/balance/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NeoFS Balance","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":1546,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"burn","offset":2098,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"decimals","offset":1524,"parameters":[],"returntype":"Integer","safe":true},{"name":"lock","offset":1692,"parameters":[{"name":"txDetails","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}],"returntype":"Void","safe":false},{"name":"mint","offset":1977,"parameters":[{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"newEpoch","offset":1847,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"symbol","offset":1520,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":1528,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":1565,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"transferX","offset":1589,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":1389,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"version","offset":2249,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Lock","parameters":[{"name":"txID","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}]},{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]},{"name":"TransferX","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","subscribeForNewEpoch"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
{"name":"NeoFS Balance","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":1547,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"burn","offset":2071,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"decimals","offset":1525,"parameters":[],"returntype":"Integer","safe":true},{"name":"lock","offset":1686,"parameters":[{"name":"txDetails","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}],"returntype":"Void","safe":false},{"name":"mint","offset":1957,"parameters":[{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"newEpoch","offset":1834,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"symbol","offset":1521,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":1529,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":1566,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"transferX","offset":1590,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":1390,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"version","offset":2215,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Lock","parameters":[{"name":"txID","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}]},{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]},{"name":"TransferX","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","subscribeForNewEpoch"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
25 changes: 9 additions & 16 deletions contracts/container/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func PutNamed(container []byte, signature interop.Signature,
panic("insufficient balance to create container")
}

multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()

details := common.ContainerFeeTransferDetails(containerID)

Expand Down Expand Up @@ -383,8 +382,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)
Expand Down Expand Up @@ -515,8 +513,7 @@ func AddNextEpochNodes(cID interop.Hash256, placementVector uint8, publicKeys []
ctx := storage.GetContext()
validatePlacementIndex(ctx, cID, placementVector)

multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()

commonPrefix := append([]byte{nextEpochNodesPrefix}, cID...)
commonPrefix = append(commonPrefix, placementVector)
Expand Down Expand Up @@ -636,8 +633,8 @@ func CommitContainerListUpdate(cID interop.Hash256, replicas []uint8) {
}

ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)

common.CheckAlphabetWitness()

oldNodesPrefix := append([]byte{nodesPrefix}, cID...)
newNodesPrefix := append([]byte{nextEpochNodesPrefix}, cID...)
Expand Down Expand Up @@ -743,8 +740,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK
panic(cst.NotFoundError)
}

multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()

rule := ExtendedACL{
Value: eACL,
Expand Down Expand Up @@ -911,17 +907,15 @@ func IterateAllContainerSizes(epoch int) iterator.Iterator {
func NewEpoch(epochNum int) {
ctx := storage.GetContext()

multiaddr := common.AlphabetAddress()
common.CheckAlphabetWitness(multiaddr)
common.CheckAlphabetWitness()

cleanupContainers(ctx, epochNum)
}

// 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")
Expand All @@ -930,8 +924,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")
Expand Down
Binary file modified contracts/container/contract.nef
Binary file not shown.
Loading

0 comments on commit c4a3bf0

Please sign in to comment.