2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2022-01-31 11:58:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// UpdatePeerPrm groups parameters of UpdatePeerState operation.
|
|
|
|
type UpdatePeerPrm struct {
|
|
|
|
key []byte
|
|
|
|
state netmap.NodeState
|
2021-11-10 10:44:19 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// SetKey sets public key.
|
|
|
|
func (u *UpdatePeerPrm) SetKey(key []byte) {
|
|
|
|
u.key = key
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// SetState sets node state.
|
|
|
|
func (u *UpdatePeerPrm) SetState(state netmap.NodeState) {
|
|
|
|
u.state = state
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// UpdatePeerState changes peer status through Netmap contract call.
|
|
|
|
func (c *Client) UpdatePeerState(p UpdatePeerPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(updateStateMethod)
|
2022-01-31 11:58:55 +00:00
|
|
|
prm.SetArgs(int64(p.state.ToV2()), p.key)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
if err := c.client.Invoke(prm); err != nil {
|
|
|
|
return fmt.Errorf("could not invoke smart contract: %w", err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|