diff --git a/cmd/neofs-adm/internal/modules/morph/dump.go b/cmd/neofs-adm/internal/modules/morph/dump.go index 7a63aa26..d785b47e 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump.go +++ b/cmd/neofs-adm/internal/modules/morph/dump.go @@ -8,7 +8,6 @@ import ( "fmt" "text/tabwriter" - nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -17,6 +16,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index cb4ec8a6..7e109b23 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -7,7 +7,6 @@ import ( "strconv" "strings" - nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -20,6 +19,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/nns" morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client" ) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go index f8b00ae0..982c9da9 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go @@ -91,7 +91,12 @@ func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accTyp } func (c *initializeContext) multiSign(tx *transaction.Transaction, accType string) error { - network := c.Client.GetNetwork() + network, err := c.Client.GetNetwork() + if err != nil { + // error appears only if client + // has not been initialized + panic(err) + } // Use parameter context to avoid dealing with signature order. pc := scContext.NewParameterContext("", network, tx) diff --git a/cmd/neofs-adm/internal/modules/morph/notary.go b/cmd/neofs-adm/internal/modules/morph/notary.go index be6b0a49..7c60ddd9 100644 --- a/cmd/neofs-adm/internal/modules/morph/notary.go +++ b/cmd/neofs-adm/internal/modules/morph/notary.go @@ -124,7 +124,14 @@ func depositNotary(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't create tx: %w", err) } - err = acc.SignTx(c.GetNetwork(), tx) + mn, err := c.GetNetwork() + if err != nil { + // error appears only if client + // has not been initialized + panic(err) + } + + err = acc.SignTx(mn, tx) if err != nil { return fmt.Errorf("can't sign tx: %w", err) } diff --git a/go.mod b/go.mod index 6a0aff35..e123c85c 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,8 @@ require ( github.com/multiformats/go-multiaddr v0.4.0 github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d github.com/nspcc-dev/hrw v1.0.9 - github.com/nspcc-dev/neo-go v0.98.0 + github.com/nspcc-dev/neo-go v0.98.2 + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321144137-d5a9af5860af // indirect github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 github.com/nspcc-dev/neofs-contract v0.14.2 github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220316141620-a55ffa47966a diff --git a/go.sum b/go.sum index ed7526f8..cbe9c918 100644 Binary files a/go.sum and b/go.sum differ diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 54fa7f6f..ee98aa53 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -468,9 +468,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { // MagicNumber returns the magic number of the network // to which the underlying RPC node client is connected. -// -// Returns 0 in case of connection problems. -func (c *Client) MagicNumber() (res uint64, err error) { +func (c *Client) MagicNumber() (uint64, error) { c.switchLock.RLock() defer c.switchLock.RUnlock() @@ -478,7 +476,14 @@ func (c *Client) MagicNumber() (res uint64, err error) { return 0, ErrConnectionLost } - return uint64(c.client.GetNetwork()), nil + mNum, err := c.client.GetNetwork() + if err != nil { + // error appears only if client + // has not been initialized + panic(err) + } + + return uint64(mNum), nil } // BlockCount returns block count of the network diff --git a/pkg/morph/client/nns.go b/pkg/morph/client/nns.go index f85f99a1..083cfc5d 100644 --- a/pkg/morph/client/nns.go +++ b/pkg/morph/client/nns.go @@ -5,7 +5,6 @@ import ( "fmt" "strconv" - nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/rpc/client" @@ -13,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/nns" ) const ( diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index 14b881fb..91afa02a 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -380,11 +380,16 @@ func (c *Client) NotarySignAndInvokeTX(mainTx *transaction.Transaction) error { return err } + // error appears only if client + // is in inactive mode; that has + // been already checked above + magicNumber, _ := c.MagicNumber() + // mainTX is expected to be pre-validated: second witness must exist and be empty mainTx.Scripts[1].VerificationScript = multiaddrAccount.GetVerificationScript() mainTx.Scripts[1].InvocationScript = append( []byte{byte(opcode.PUSHDATA1), 64}, - multiaddrAccount.PrivateKey().SignHashable(uint32(c.client.GetNetwork()), mainTx)..., + multiaddrAccount.PrivateKey().SignHashable(uint32(magicNumber), mainTx)..., ) resp, err := c.client.SignAndPushP2PNotaryRequest(mainTx, @@ -618,10 +623,12 @@ func (c *Client) notaryWitnesses(invokedByAlpha bool, multiaddr *wallet.Account, // to pass Notary module verification var invokeScript []byte + magicNumber, _ := c.MagicNumber() + if invokedByAlpha { invokeScript = append( []byte{byte(opcode.PUSHDATA1), 64}, - multiaddr.PrivateKey().SignHashable(uint32(c.client.GetNetwork()), tx)..., + multiaddr.PrivateKey().SignHashable(uint32(magicNumber), tx)..., ) } else { // we can't provide alphabet node signature @@ -643,7 +650,7 @@ func (c *Client) notaryWitnesses(invokedByAlpha bool, multiaddr *wallet.Account, // then we have invoker witness invokeScript = append( []byte{byte(opcode.PUSHDATA1), 64}, - c.acc.PrivateKey().SignHashable(uint32(c.client.GetNetwork()), tx)..., + c.acc.PrivateKey().SignHashable(uint32(magicNumber), tx)..., ) w = append(w, transaction.Witness{