2021-07-20 12:08:47 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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 {
|
2021-07-20 14:51:45 +00:00
|
|
|
if ok, err := c.setRolesFinished(); ok || err != nil {
|
|
|
|
if err == nil {
|
|
|
|
c.Command.Println("Stage 2: already performed.")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-29 13:35:57 +00:00
|
|
|
designateHash := c.nativeHash(nativenames.Designation)
|
2021-07-20 12:08:47 +00:00
|
|
|
|
|
|
|
var pubs []interface{}
|
2021-07-30 11:26:44 +00:00
|
|
|
for _, acc := range c.Accounts {
|
2021-07-20 12:08:47 +00:00
|
|
|
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)
|
|
|
|
|
2022-08-29 19:31:32 +00:00
|
|
|
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
2021-07-20 12:08:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.awaitTx()
|
|
|
|
}
|
2021-07-20 14:51:45 +00:00
|
|
|
|
|
|
|
func (c *initializeContext) setRolesFinished() (bool, error) {
|
|
|
|
height, err := c.Client.GetBlockCount()
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:47:13 +00:00
|
|
|
h := c.nativeHash(nativenames.Designation)
|
|
|
|
pubs, err := getDesignatedByRole(c.Client, h, noderoles.NeoFSAlphabet, height)
|
2021-07-20 14:51:45 +00:00
|
|
|
return len(pubs) == len(c.Wallets), err
|
|
|
|
}
|