2020-07-24 13:54:03 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2020-07-24 13:54:03 +00:00
|
|
|
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
// UpdatePeerPrm groups parameters of UpdatePeerState operation.
|
|
|
|
type UpdatePeerPrm struct {
|
|
|
|
key []byte
|
|
|
|
state netmap.NodeState
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKey sets public key.
|
|
|
|
func (u *UpdatePeerPrm) SetKey(key []byte) {
|
|
|
|
u.key = key
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetState sets node state.
|
|
|
|
func (u *UpdatePeerPrm) SetState(state netmap.NodeState) {
|
|
|
|
u.state = state
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// UpdatePeerState changes peer status through Netmap contract
|
|
|
|
// call.
|
2021-11-10 10:44:19 +00:00
|
|
|
func (w *Wrapper) UpdatePeerState(prm UpdatePeerPrm) error {
|
2020-07-24 13:54:03 +00:00
|
|
|
args := contract.UpdateStateArgs{}
|
2021-11-10 10:44:19 +00:00
|
|
|
|
|
|
|
args.SetPublicKey(prm.key)
|
|
|
|
args.SetState(int64(prm.state.ToV2()))
|
|
|
|
args.InvokePrmOptional = prm.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
// invoke smart contract call
|
2021-05-18 08:12:51 +00:00
|
|
|
if err := w.client.UpdateState(args); err != nil {
|
|
|
|
return fmt.Errorf("could not invoke smart contract: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|