diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index 3431ecee..a2266ac2 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 00000000..dbb587cf --- /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() +}