neofs-adm: set hardcode nns hashes

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-17 15:24:10 +03:00
parent bd3f43cdeb
commit 44bf2e8d06
2 changed files with 73 additions and 0 deletions

View file

@ -188,6 +188,16 @@ var (
RunE: updateContracts,
}
hardcodeNNSCmd = &cobra.Command{
Use: "hardcode-nns",
Short: "FIX for mainnet update",
PreRun: func(cmd *cobra.Command, _ []string) {
_ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag))
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
},
RunE: hardcodeNNS,
}
dumpContainersCmd = &cobra.Command{
Use: "dump-containers",
Short: "Dump NeoFS containers to file",
@ -274,6 +284,10 @@ func init() {
dumpBalancesCmd.Flags().BoolP(dumpBalancesProxyFlag, "p", false, "dump balances of the proxy contract")
dumpBalancesCmd.Flags().Bool(dumpBalancesUseScriptHashFlag, false, "use script-hash format for addresses")
RootCmd.AddCommand(hardcodeNNSCmd)
hardcodeNNSCmd.Flags().String(alphabetWalletsFlag, "", "path to alphabet wallets dir")
hardcodeNNSCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
RootCmd.AddCommand(updateContractsCmd)
updateContractsCmd.Flags().String(alphabetWalletsFlag, "", "path to alphabet wallets dir")
updateContractsCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")

View file

@ -3,6 +3,11 @@ package morph
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neofs-contract/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -19,3 +24,57 @@ func updateContracts(cmd *cobra.Command, _ []string) error {
return wCtx.updateContracts()
}
func hardcodeNNS(cmd *cobra.Command, _ []string) error {
c, err := newInitializeContext(cmd, viper.GetViper())
if err != nil {
return fmt.Errorf("initialization error: %w", err)
}
/* FIX for mainnet, set hardcoded hashes. */
hashes := map[string]string{
"neofs.neofs": "2cafa46838e8b564468ebd868dcafdd99dce6221",
"audit.neofs": "85fe181f4aa3cbdc94023d97c69001ece0730398",
"balance.neofs": "dc1ec98d9d0c5f9dfade16144defe08cffc5ca55",
"container.neofs": "1b6e68d299b570e1cb7e86eadfdc06aa2e8e0cc5",
"neofsid.neofs": "0a64ce753653cc97c0467e1334d9d3678ca8c682",
"netmap.neofs": "7c5bdb23e36cc7cce95bf42f3ab9e452c2501df1",
"reputation.neofs": "7ad824fd1eeb1565be2cee3889214b9aa605d2fc",
"subnet.neofs": "70d5b161d7fc7f6ba32d324d88bf74327f15ca8d",
/* "az": */ getAlphabetNNSDomain(0): "2392438eb31100857c0f161c66791872b249aa13",
/* "buky": */ getAlphabetNNSDomain(1): "83ef4226d5d6519ca9c99a5de13b1b5ca223a6ad",
/* "vedi": */ getAlphabetNNSDomain(2): "6250927beaa9aa5a00171379dcb7187b0c91d17d",
/* "glagoli": */ getAlphabetNNSDomain(3): "1d6a2519ba41a139b2ced1bfd5013938271a7578",
/* "dobro": */ getAlphabetNNSDomain(4): "b65fc7a3c31cf57a90d7eb1c0e9909e4ca69133c",
/* "yest": */ getAlphabetNNSDomain(5): "f95b6ff8cd3b027c9911c18115518ad8c5d2f591",
/* "zhivete": */ getAlphabetNNSDomain(6): "5b17c579bf56884fd68af152432b3b5aee7aee76",
}
nnsCs, err := c.Client.GetContractStateByID(1)
if err != nil {
panic(err)
}
w := io.NewBufBinWriter()
for name, sh := range hashes {
h, err := util.Uint160DecodeStringLE(sh)
if err != nil {
return fmt.Errorf("invalid hash: %s", sh)
}
cs, err := c.Client.GetContractStateByHash(h)
if err != nil || cs.Hash != h {
return fmt.Errorf("contract %s should have hash %s, but: %w", name, sh, err)
}
emit.AppCall(w.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
name, int64(nns.TXT), h.StringLE())
c.Command.Printf("NNS: Set %s -> %s\n", name, h.StringLE())
}
if w.Err != nil {
panic(w.Err)
}
if err := c.sendCommitteeTx(w.Bytes(), -1, false); err != nil {
return err
}
return c.awaitTx()
}