From c3f7ccaee6a720c19448b1fa4ae4b68ddf18e559 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 20 Jul 2021 15:08:47 +0300 Subject: [PATCH] [#687] neofs-adm: set alphabet and notary nodes Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/initialize.go | 22 +++++++++- .../modules/morph/initialize_roles.go | 40 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 cmd/neofs-adm/internal/modules/morph/initialize_roles.go diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index 3431ecee0..a2266ac28 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -7,6 +7,7 @@ import ( "path" "time" + "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" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" @@ -48,7 +49,11 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error { return err } - // TODO 2. Setup notary and alphabet nodes in designate contract. + cmd.Println("Stage 2: set notary and alphabet nodes in designate contract.") + if err := initCtx.setNotaryAndAlphabetNodes(); err != nil { + return err + } + // TODO 3. Deploy NNS contract with ID=0. // TODO 4. Deploy NeoFS contracts. // TODO 5. Setup NeoFS contracts addresses in NNS. @@ -160,6 +165,21 @@ loop: return nil } +func (c *initializeContext) sendCommitteeTx(script []byte, sysFee int64) error { + tx, err := c.Client.CreateTxFromScript(script, c.CommitteeAcc, sysFee, 0, []client.SignerAccount{{ + Signer: transaction.Signer{ + Account: c.CommitteeAcc.Contract.ScriptHash(), + Scopes: transaction.CalledByEntry, + }, + Account: c.CommitteeAcc, + }}) + if err != nil { + return fmt.Errorf("can't create tx: %w", err) + } + + return c.multiSignAndSend(tx, committeeAccountName) +} + func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) { for i := range w.Accounts { if w.Accounts[i].Label == typ { diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_roles.go b/cmd/neofs-adm/internal/modules/morph/initialize_roles.go new file mode 100644 index 000000000..dbb587cf3 --- /dev/null +++ b/cmd/neofs-adm/internal/modules/morph/initialize_roles.go @@ -0,0 +1,40 @@ +package morph + +import ( + "fmt" + + "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" + "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" +) + +func (c *initializeContext) setNotaryAndAlphabetNodes() error { + designateHash, err := c.Client.GetNativeContractHash(nativenames.Designation) + if err != nil { + return fmt.Errorf("can't fetch %s hash: %w", nativenames.Designation, err) + } + + var pubs []interface{} + for _, w := range c.Wallets { + acc, err := getWalletAccount(w, singleAccountName) + if err != nil { + return err + } + + pubs = append(pubs, acc.PrivateKey().PublicKey().Bytes()) + } + + w := io.NewBufBinWriter() + emit.AppCall(w.BinWriter, designateHash, "designateAsRole", + callflag.States|callflag.AllowNotify, int64(noderoles.P2PNotary), pubs) + emit.AppCall(w.BinWriter, designateHash, "designateAsRole", + callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs) + + if err := c.sendCommitteeTx(w.Bytes(), -1); err != nil { + return err + } + + return c.awaitTx() +}