forked from TrueCloudLab/frostfs-node
[#687] neofs-adm: set alphabet and notary nodes
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
425c1db5c0
commit
c3f7ccaee6
2 changed files with 61 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"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/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
|
@ -48,7 +49,11 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
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 3. Deploy NNS contract with ID=0.
|
||||||
// TODO 4. Deploy NeoFS contracts.
|
// TODO 4. Deploy NeoFS contracts.
|
||||||
// TODO 5. Setup NeoFS contracts addresses in NNS.
|
// TODO 5. Setup NeoFS contracts addresses in NNS.
|
||||||
|
@ -160,6 +165,21 @@ loop:
|
||||||
return nil
|
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) {
|
func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
||||||
for i := range w.Accounts {
|
for i := range w.Accounts {
|
||||||
if w.Accounts[i].Label == typ {
|
if w.Accounts[i].Label == typ {
|
||||||
|
|
40
cmd/neofs-adm/internal/modules/morph/initialize_roles.go
Normal file
40
cmd/neofs-adm/internal/modules/morph/initialize_roles.go
Normal file
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in a new issue