2020-07-24 13:54:03 +00:00
|
|
|
package invoke
|
|
|
|
|
|
|
|
import (
|
2020-09-03 14:32:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
2020-09-03 14:32:37 +00:00
|
|
|
type (
|
|
|
|
UpdatePeerArgs struct {
|
|
|
|
Key *keys.PublicKey
|
|
|
|
Status uint32
|
|
|
|
}
|
2020-09-08 08:48:26 +00:00
|
|
|
|
|
|
|
SetConfigArgs struct {
|
|
|
|
Key []byte
|
|
|
|
Value []byte
|
|
|
|
}
|
2020-09-03 14:32:37 +00:00
|
|
|
)
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
const (
|
2020-09-03 14:32:37 +00:00
|
|
|
getEpochMethod = "epoch"
|
|
|
|
setNewEpochMethod = "newEpoch"
|
|
|
|
approvePeerMethod = "addPeer"
|
|
|
|
updatePeerStateMethod = "updateState"
|
2020-09-08 08:48:26 +00:00
|
|
|
setConfigMethod = "setConfigMethod"
|
|
|
|
updateInnerRingMethod = "updateInnerRingMethod"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Epoch return epoch value from contract.
|
|
|
|
func Epoch(cli *client.Client, con util.Uint160) (int64, error) {
|
|
|
|
if cli == nil {
|
|
|
|
return 0, client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
val, err := cli.TestInvoke(con, getEpochMethod)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:57:52 +00:00
|
|
|
epoch, err := client.IntFromStackItem(val[0])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return epoch, nil
|
|
|
|
}
|
|
|
|
|
2020-09-08 08:48:26 +00:00
|
|
|
// SetNewEpoch invokes newEpoch method.
|
2020-07-24 13:54:03 +00:00
|
|
|
func SetNewEpoch(cli *client.Client, con util.Uint160, epoch uint64) error {
|
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.Invoke(con, extraFee, setNewEpochMethod, int64(epoch))
|
|
|
|
}
|
2020-09-03 14:32:37 +00:00
|
|
|
|
2020-09-08 08:48:26 +00:00
|
|
|
// ApprovePeer invokes addPeer method.
|
2020-09-03 14:32:37 +00:00
|
|
|
func ApprovePeer(cli *client.Client, con util.Uint160, peer []byte) error {
|
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.Invoke(con, extraFee, approvePeerMethod, peer)
|
|
|
|
}
|
|
|
|
|
2020-09-08 08:48:26 +00:00
|
|
|
// UpdatePeerState invokes addPeer method.
|
2020-09-03 14:32:37 +00:00
|
|
|
func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs) error {
|
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.Invoke(con, extraFee, updatePeerStateMethod,
|
|
|
|
args.Key.Bytes(),
|
|
|
|
int64(args.Status),
|
|
|
|
)
|
|
|
|
}
|
2020-09-08 08:48:26 +00:00
|
|
|
|
|
|
|
// SetConfig invokes setConfig method.
|
|
|
|
func SetConfig(cli *client.Client, con util.Uint160, args *SetConfigArgs) error {
|
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.Invoke(con, extraFee, setConfigMethod,
|
|
|
|
args.Key,
|
|
|
|
args.Value,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateInnerRing invokes updateInnerRing method.
|
|
|
|
func UpdateInnerRing(cli *client.Client, con util.Uint160, list []*keys.PublicKey) error {
|
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
rawKeys := make([][]byte, 0, len(list))
|
|
|
|
for i := range list {
|
|
|
|
rawKeys = append(rawKeys, list[i].Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.Invoke(con, extraFee, updateInnerRingMethod, rawKeys)
|
|
|
|
}
|