[#1518] Upgrade NeoFS SDK Go with changed subnet package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-15 11:08:10 +03:00 committed by LeL
parent f602d05b0a
commit 2e4a1cb6df
12 changed files with 32 additions and 90 deletions

View file

@ -140,18 +140,13 @@ var cmdSubnetCreate = &cobra.Command{
for {
num = rand.Uint32()
id.SetNumber(num)
id.SetNumeric(num)
if !subnetid.IsZero(id) {
break
}
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
// declare creator ID and encode it
var creator user.ID
user.IDFromKey(&creator, key.PrivateKey.PublicKey)
@ -162,12 +157,7 @@ var cmdSubnetCreate = &cobra.Command{
info.SetID(id)
info.SetOwner(creator)
binInfo, err := info.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet info: %w", err)
}
err = invokeMethod(key, true, "put", binID, key.PublicKey().Bytes(), binInfo)
err = invokeMethod(key, true, "put", id.Marshal(), key.PublicKey().Bytes(), info.Marshal())
if err != nil {
return fmt.Errorf("morph invocation: %w", err)
}
@ -210,7 +200,7 @@ var cmdSubnetRemove = &cobra.Command{
// read ID and encode it
var id subnetid.ID
err = id.UnmarshalText([]byte(viper.GetString(flagSubnetRemoveID)))
err = id.DecodeString(viper.GetString(flagSubnetRemoveID))
if err != nil {
return fmt.Errorf("decode ID text: %w", err)
}
@ -219,12 +209,7 @@ var cmdSubnetRemove = &cobra.Command{
return errZeroSubnet
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
err = invokeMethod(key, false, "delete", binID)
err = invokeMethod(key, false, "delete", id.Marshal())
if err != nil {
return fmt.Errorf("morph invocation: %w", err)
}
@ -254,7 +239,7 @@ var cmdSubnetGet = &cobra.Command{
// read ID and encode it
var id subnetid.ID
err := id.UnmarshalText([]byte(viper.GetString(flagSubnetGetID)))
err := id.DecodeString(viper.GetString(flagSubnetGetID))
if err != nil {
return fmt.Errorf("decode ID text: %w", err)
}
@ -263,11 +248,6 @@ var cmdSubnetGet = &cobra.Command{
return errZeroSubnet
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
// use random key to fetch the data
// we could use raw neo-go client to perform testInvoke
// without keys, as it is done in other commands
@ -276,7 +256,7 @@ var cmdSubnetGet = &cobra.Command{
return fmt.Errorf("init subnet client: %w", err)
}
res, err := testInvokeMethod(*key, "get", binID)
res, err := testInvokeMethod(*key, "get", id.Marshal())
if err != nil {
return fmt.Errorf("morph invocation: %w", err)
}
@ -297,11 +277,7 @@ var cmdSubnetGet = &cobra.Command{
}
// print information
var ownerID user.ID
info.ReadOwner(&ownerID)
cmd.Printf("Owner: %s\n", &ownerID)
cmd.Printf("Owner: %s\n", info.Owner())
return nil
},
@ -350,7 +326,7 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error {
// read ID and encode it
var id subnetid.ID
err = id.UnmarshalText([]byte(viper.GetString(flagSubnetAdminSubnet)))
err = id.DecodeString(viper.GetString(flagSubnetAdminSubnet))
if err != nil {
return fmt.Errorf("decode ID text: %w", err)
}
@ -359,11 +335,6 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error {
return errZeroSubnet
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
// read admin key and decode it
binAdminKey, err := hex.DecodeString(viper.GetString(flagSubnetAdminID))
if err != nil {
@ -377,7 +348,7 @@ func manageSubnetAdmins(cmd *cobra.Command, rm bool) error {
// prepare call parameters
prm := make([]interface{}, 0, 3)
prm = append(prm, binID)
prm = append(prm, id.Marshal())
var method string
@ -497,7 +468,7 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error {
// read ID and encode it
var id subnetid.ID
err = id.UnmarshalText([]byte(viper.GetString(flagSubnetClientSubnet)))
err = id.DecodeString(viper.GetString(flagSubnetClientSubnet))
if err != nil {
return fmt.Errorf("decode ID text: %w", err)
}
@ -506,11 +477,6 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error {
return errZeroSubnet
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
// read client ID and encode it
var clientID user.ID
@ -539,7 +505,7 @@ func manageSubnetClients(cmd *cobra.Command, rm bool) error {
method = "addUser"
}
err = invokeMethod(key, false, method, binID, binGroupID, clientID.WalletBytes())
err = invokeMethod(key, false, method, id.Marshal(), binGroupID, clientID.WalletBytes())
if err != nil {
return fmt.Errorf("morph invocation: %w", err)
}
@ -596,7 +562,7 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error {
// read ID and encode it
var id subnetid.ID
err = id.UnmarshalText([]byte(viper.GetString(flagSubnetNodeSubnet)))
err = id.DecodeString(viper.GetString(flagSubnetNodeSubnet))
if err != nil {
return fmt.Errorf("decode ID text: %w", err)
}
@ -605,11 +571,6 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error {
return errZeroSubnet
}
binID, err := id.Marshal()
if err != nil {
return fmt.Errorf("marshal subnet ID: %w", err)
}
// read node ID and encode it
binNodeID, err := hex.DecodeString(viper.GetString(flagSubnetNode))
if err != nil {
@ -628,7 +589,7 @@ func manageSubnetNodes(cmd *cobra.Command, rm bool) error {
method = "addNode"
}
err = invokeMethod(key, false, method, binID, binNodeID)
err = invokeMethod(key, false, method, id.Marshal(), binNodeID)
if err != nil {
return fmt.Errorf("morph invocation: %w", err)
}