From 5d6a2dd916302b729b75ae2a90a945e845a77b49 Mon Sep 17 00:00:00 2001 From: Rawda Fawzy <47260239+rawdaGastan@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:10:46 +0200 Subject: [PATCH] add change power target to go client (#901) * add change power target to go client * rename function --- clients/tfchain-client-go/node.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clients/tfchain-client-go/node.go b/clients/tfchain-client-go/node.go index 0d18362a1..b9b436e16 100644 --- a/clients/tfchain-client-go/node.go +++ b/clients/tfchain-client-go/node.go @@ -688,6 +688,32 @@ func (s *Substrate) SetNodePowerState(identity Identity, up bool) (hash types.Ha return callResponse.Hash, nil } +// SetNodePowerTarget updates the power target of a node +func (s *Substrate) SetNodePowerTarget(identity Identity, nodeID uint32, up bool) (hash types.Hash, err error) { + cl, meta, err := s.GetClient() + if err != nil { + return hash, err + } + + power := Power{ + IsUp: up, + IsDown: !up, + } + + c, err := types.NewCall(meta, "TfgridModule.change_power_target", nodeID, power) + + if err != nil { + return hash, errors.Wrap(err, "failed to create call") + } + + callResponse, err := s.Call(cl, meta, identity, c) + if err != nil { + return hash, errors.Wrap(err, "failed to change node power target") + } + + return callResponse.Hash, nil +} + // GetPowerTarget returns the power target for a node func (s *Substrate) GetPowerTarget(nodeID uint32) (power NodePower, err error) { cl, meta, err := s.GetClient()