[#21] Add SetConfig and UpdateInnerRing method invoke helpers

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-08 11:48:26 +03:00
parent 2a142155d9
commit a19e9c1f00

View file

@ -11,6 +11,11 @@ type (
Key *keys.PublicKey Key *keys.PublicKey
Status uint32 Status uint32
} }
SetConfigArgs struct {
Key []byte
Value []byte
}
) )
const ( const (
@ -18,6 +23,8 @@ const (
setNewEpochMethod = "newEpoch" setNewEpochMethod = "newEpoch"
approvePeerMethod = "addPeer" approvePeerMethod = "addPeer"
updatePeerStateMethod = "updateState" updatePeerStateMethod = "updateState"
setConfigMethod = "setConfigMethod"
updateInnerRingMethod = "updateInnerRingMethod"
) )
// Epoch return epoch value from contract. // Epoch return epoch value from contract.
@ -39,7 +46,7 @@ func Epoch(cli *client.Client, con util.Uint160) (int64, error) {
return epoch, nil return epoch, nil
} }
// SetNewEpoch invokes NewEpoch method. // SetNewEpoch invokes newEpoch method.
func SetNewEpoch(cli *client.Client, con util.Uint160, epoch uint64) error { func SetNewEpoch(cli *client.Client, con util.Uint160, epoch uint64) error {
if cli == nil { if cli == nil {
return client.ErrNilClient return client.ErrNilClient
@ -48,7 +55,7 @@ func SetNewEpoch(cli *client.Client, con util.Uint160, epoch uint64) error {
return cli.Invoke(con, extraFee, setNewEpochMethod, int64(epoch)) return cli.Invoke(con, extraFee, setNewEpochMethod, int64(epoch))
} }
// ApprovePeer invokes AddPeer method. // ApprovePeer invokes addPeer method.
func ApprovePeer(cli *client.Client, con util.Uint160, peer []byte) error { func ApprovePeer(cli *client.Client, con util.Uint160, peer []byte) error {
if cli == nil { if cli == nil {
return client.ErrNilClient return client.ErrNilClient
@ -57,7 +64,7 @@ func ApprovePeer(cli *client.Client, con util.Uint160, peer []byte) error {
return cli.Invoke(con, extraFee, approvePeerMethod, peer) return cli.Invoke(con, extraFee, approvePeerMethod, peer)
} }
// UpdatePeerState invokes AddPeer method. // UpdatePeerState invokes addPeer method.
func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs) error { func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs) error {
if cli == nil { if cli == nil {
return client.ErrNilClient return client.ErrNilClient
@ -68,3 +75,29 @@ func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs)
int64(args.Status), int64(args.Status),
) )
} }
// 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)
}