Remove method alphabetAddress
from frostfs
contract #77
5 changed files with 26 additions and 66 deletions
|
@ -1,6 +1,5 @@
|
|||
name: "FrostFS"
|
||||
safemethods:
|
||||
- "alphabetAddress"
|
||||
- "config"
|
||||
- "innerRingCandidates"
|
||||
- "listConfig"
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
|
||||
"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/storage"
|
||||
)
|
||||
|
@ -26,7 +25,6 @@ const (
|
|||
CandidateFeeConfigKey = "InnerRingCandidateFee"
|
||||
withdrawFeeConfigKey = "WithdrawFee"
|
||||
|
||||
alphabetKey = "alphabet"
|
||||
candidatesKey = "candidates"
|
||||
|
||||
processingContractKey = "processingScriptHash"
|
||||
|
@ -71,9 +69,6 @@ func _deploy(data any, isUpdate bool) {
|
|||
}
|
||||
}
|
||||
|
||||
// initialize all storage slices
|
||||
common.SetSerialized(ctx, alphabetKey, args.keys)
|
||||
|
||||
storage.Put(ctx, processingContractKey, args.addrProc)
|
||||
|
||||
ln := len(args.config)
|
||||
|
@ -106,13 +101,6 @@ func Update(script []byte, manifest []byte, data any) {
|
|||
runtime.Log("frostfs contract updated")
|
||||
}
|
||||
|
||||
// AlphabetAddress returns 2\3n+1 multisignature address of alphabet nodes.
|
||||
// It is used in sidechain notary disabled environment.
|
||||
func AlphabetAddress() interop.Hash160 {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
return multiaddress(getAlphabetNodes(ctx))
|
||||
}
|
||||
|
||||
// InnerRingCandidates returns an array of structures that contain an Inner Ring
|
||||
// candidate node key.
|
||||
func InnerRingCandidates() []common.IRNode {
|
||||
|
@ -137,8 +125,7 @@ func InnerRingCandidateRemove(key interop.PublicKey) {
|
|||
keyOwner := runtime.CheckWitness(key)
|
||||
|
||||
if !keyOwner {
|
||||
multiaddr := AlphabetAddress()
|
||||
if !runtime.CheckWitness(multiaddr) {
|
||||
if !runtime.CheckWitness(common.AlphabetAddress()) {
|
||||
panic("this method must be invoked by candidate or alphabet")
|
||||
}
|
||||
}
|
||||
|
@ -358,16 +345,6 @@ func Version() int {
|
|||
return common.Version
|
||||
}
|
||||
|
||||
// getAlphabetNodes returns a deserialized slice of nodes from storage.
|
||||
func getAlphabetNodes(ctx storage.Context) []interop.PublicKey {
|
||||
data := storage.Get(ctx, alphabetKey)
|
||||
if data != nil {
|
||||
return std.Deserialize(data.([]byte)).([]interop.PublicKey)
|
||||
}
|
||||
|
||||
return []interop.PublicKey{}
|
||||
}
|
||||
|
||||
// getConfig returns the installed frostfs configuration value or nil if it is not set.
|
||||
func getConfig(ctx storage.Context, key any) interface{} {
|
||||
postfix := key.([]byte)
|
||||
|
|
|
@ -3,19 +3,11 @@ package processing
|
|||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
frostfsContractKey = "frostfsScriptHash"
|
||||
|
||||
multiaddrMethod = "alphabetAddress"
|
||||
)
|
||||
|
||||
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
||||
|
@ -33,18 +25,6 @@ func _deploy(data any, isUpdate bool) {
|
|||
return
|
||||
}
|
||||
|
||||
args := data.(struct {
|
||||
addrFrostFS interop.Hash160
|
||||
})
|
||||
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if len(args.addrFrostFS) != interop.Hash160Len {
|
||||
panic("incorrect length of contract script hash")
|
||||
}
|
||||
|
||||
storage.Put(ctx, frostfsContractKey, args.addrFrostFS)
|
||||
|
||||
runtime.Log("processing contract initialized")
|
||||
}
|
||||
|
||||
|
@ -66,11 +46,7 @@ func Update(script []byte, manifest []byte, data any) {
|
|||
// Verify method returns true if transaction contains valid multisignature of
|
||||
// Alphabet nodes of the Inner Ring.
|
||||
func Verify() bool {
|
||||
ctx := storage.GetContext()
|
||||
frostfsContractAddr := storage.Get(ctx, frostfsContractKey).(interop.Hash160)
|
||||
multiaddr := contract.Call(frostfsContractAddr, multiaddrMethod, contract.ReadOnly).(interop.Hash160)
|
||||
|
||||
return runtime.CheckWitness(multiaddr)
|
||||
return runtime.CheckWitness(common.AlphabetAddress())
|
||||
}
|
||||
|
||||
// Version returns the version of the contract.
|
||||
|
|
|
@ -103,11 +103,6 @@ func New(actor Actor, hash util.Uint160) *Contract {
|
|||
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||
}
|
||||
|
||||
// AlphabetAddress invokes `alphabetAddress` method of contract.
|
||||
func (c *ContractReader) AlphabetAddress() (util.Uint160, error) {
|
||||
return unwrap.Uint160(c.invoker.Call(c.hash, "alphabetAddress"))
|
||||
}
|
||||
|
||||
// Config invokes `config` method of contract.
|
||||
func (c *ContractReader) Config(key []byte) (any, error) {
|
||||
return func(item stackitem.Item, err error) (any, error) {
|
||||
|
|
|
@ -4,28 +4,41 @@ import (
|
|||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const processingPath = "../processing"
|
||||
|
||||
func deployProcessingContract(t *testing.T, e *neotest.Executor, addrFrostFS util.Uint160) util.Uint160 {
|
||||
func deployProcessingContract(t *testing.T, e *neotest.Executor) util.Uint160 {
|
||||
c := neotest.CompileFile(t, e.CommitteeHash, processingPath, path.Join(processingPath, "config.yml"))
|
||||
|
||||
args := make([]any, 1)
|
||||
args[0] = addrFrostFS
|
||||
|
||||
e.DeployContract(t, c, args)
|
||||
e.DeployContract(t, c, nil)
|
||||
return c.Hash
|
||||
}
|
||||
|
||||
func newProcessingInvoker(t *testing.T) (*neotest.ContractInvoker, neotest.Signer) {
|
||||
frostfsInvoker, irMultiAcc, _ := newFrostFSInvoker(t, 2)
|
||||
hash := deployProcessingContract(t, frostfsInvoker.Executor, frostfsInvoker.Hash)
|
||||
func newProcessingInvoker(t *testing.T) (*neotest.ContractInvoker, neotest.SingleSigner) {
|
||||
e := newExecutor(t)
|
||||
|
||||
return frostfsInvoker.CommitteeInvoker(hash), irMultiAcc
|
||||
acc, err := wallet.NewAccount()
|
||||
require.NoError(t, err)
|
||||
|
||||
sig := neotest.NewSingleSigner(acc)
|
||||
|
||||
gasHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Gas)
|
||||
require.NoError(t, err)
|
||||
vc := e.CommitteeInvoker(gasHash).WithSigners(e.Validator)
|
||||
vc.Invoke(t, true, "transfer",
|
||||
e.Validator.ScriptHash(), sig.ScriptHash(),
|
||||
int64(10_0000_0000), nil)
|
||||
|
||||
hash := deployProcessingContract(t, e)
|
||||
|
||||
return e.CommitteeInvoker(hash), sig
|
||||
}
|
||||
|
||||
func TestVerify_Processing(t *testing.T) {
|
||||
|
@ -35,6 +48,6 @@ func TestVerify_Processing(t *testing.T) {
|
|||
|
||||
cIR := c.WithSigners(irMultiAcc)
|
||||
|
||||
cIR.Invoke(t, stackitem.NewBool(true), method)
|
||||
c.Invoke(t, stackitem.NewBool(false), method)
|
||||
cIR.Invoke(t, stackitem.NewBool(false), method)
|
||||
c.Invoke(t, stackitem.NewBool(true), method)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue