forked from TrueCloudLab/frostfs-node
[#726] neofs-adm: set alphabet contract addresses in NNS
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
4d65e138f5
commit
9e56012760
2 changed files with 74 additions and 0 deletions
|
@ -14,6 +14,8 @@ import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const lastGlagoliticLetter = 41
|
||||||
|
|
||||||
func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := getN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,8 +42,43 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
return errors.New("invalid response from NNS contract: length mismatch")
|
return errors.New("invalid response from NNS contract: length mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
irSize := 0
|
||||||
|
for ; irSize < lastGlagoliticLetter; irSize++ {
|
||||||
|
ok, err := c.NNSIsAvailable(cs.Hash, getAlphabetNNSDomain(irSize))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
||||||
|
|
||||||
|
if irSize != 0 {
|
||||||
|
bw.Reset()
|
||||||
|
for i := 0; i < irSize; i++ {
|
||||||
|
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
||||||
|
getAlphabetNNSDomain(i),
|
||||||
|
int64(nns.TXT))
|
||||||
|
}
|
||||||
|
|
||||||
|
alphaRes, err := c.InvokeScript(bw.Bytes(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch info from NNS: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < irSize; i++ {
|
||||||
|
ctrHash := "hash is invalid"
|
||||||
|
bs, err := alphaRes.Stack[i].TryBytes()
|
||||||
|
if err == nil {
|
||||||
|
ctrHash = string(bs) // hashes are stored as hex-encoded LE string
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = tw.Write([]byte(fmt.Sprintf("alphabet %d:\t%s\n", i, ctrHash)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i := range contractList {
|
for i := range contractList {
|
||||||
ctrHash := "hash is invalid"
|
ctrHash := "hash is invalid"
|
||||||
bs, err := res.Stack[i].TryBytes()
|
bs, err := res.Stack[i].TryBytes()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package morph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
|
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
|
@ -45,6 +46,38 @@ func (c *initializeContext) setNNS() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alphaCs, err := c.readContract(ctrPath, alphabetContract)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't read alphabet contract: %w", err)
|
||||||
|
}
|
||||||
|
for i, w := range c.Wallets {
|
||||||
|
acc, err := getWalletAccount(w, singleAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
||||||
|
|
||||||
|
domain := getAlphabetNNSDomain(i)
|
||||||
|
if ok, err := c.nnsDomainAvailable(h, domain); err != nil {
|
||||||
|
return err
|
||||||
|
} else if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
emit.AppCall(bw.BinWriter, h, "register", callflag.All,
|
||||||
|
domain, c.CommitteeAcc.Contract.ScriptHash())
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
emit.AppCall(bw.BinWriter, h, "setRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), alphaCs.Hash.StringLE())
|
||||||
|
|
||||||
|
sysFee := int64(defaultRegisterSysfee + native.GASFactor)
|
||||||
|
if err := c.sendCommitteeTx(bw.Bytes(), sysFee); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
for _, ctrName := range contractList {
|
||||||
cs, err := c.readContract(ctrPath, ctrName)
|
cs, err := c.readContract(ctrPath, ctrName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -98,3 +131,7 @@ func (c *initializeContext) nnsDomainAvailable(nnsHash util.Uint160, domain stri
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAlphabetNNSDomain(i int) string {
|
||||||
|
return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".neofs"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue