[#1555] neofs-adm: Allow to remove nodes from the netmap

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-27 17:47:13 +03:00 committed by fyrchik
parent 32fd3692bf
commit b41658db04
3 changed files with 91 additions and 7 deletions

View file

@ -6,6 +6,7 @@ import (
"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"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/spf13/cobra"
@ -28,6 +29,19 @@ func forceNewEpochCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
bw := io.NewBufBinWriter()
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
return err
}
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
return err
}
return wCtx.awaitTx()
}
func emitNewEpochCall(bw *io.BufBinWriter, wCtx *initializeContext, nmHash util.Uint160) error {
res, err := invokeFunction(wCtx.Client, nmHash, "epoch", nil, nil)
if err != nil || res.State != vm.HaltState.String() || len(res.Stack) == 0 {
return errors.New("can't fetch current epoch from the netmap contract")
@ -39,15 +53,10 @@ func forceNewEpochCmd(cmd *cobra.Command, args []string) error {
}
newEpoch := bi.Int64() + 1
cmd.Printf("Current epoch: %s, increase to %d.\n", bi, newEpoch)
wCtx.Command.Printf("Current epoch: %s, increase to %d.\n", bi, newEpoch)
// In NeoFS this is done via Notary contract. Here, however, we can form the
// transaction locally.
bw := io.NewBufBinWriter()
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
return err
}
return wCtx.awaitTx()
return bw.Err
}