Skip to content

Commit 88fae6c

Browse files
committed
refactor multiple activation service url
1 parent 29660a7 commit 88fae6c

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

pkg/api_gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type SubstrateGateway interface {
1111
CreateNode(node substrate.Node) (uint32, error)
1212
CreateTwin(relay string, pk []byte) (uint32, error)
13-
EnsureAccount(activationURL string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error)
13+
EnsureAccount(activationURL []string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error)
1414
GetContract(id uint64) (substrate.Contract, SubstrateError)
1515
GetContractIDByNameRegistration(name string) (uint64, SubstrateError)
1616
GetFarm(id uint32) (substrate.Farm, error)

pkg/perf/iperf/iperf_task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (t *IperfTest) Run(ctx context.Context) (interface{}, error) {
8181
return nil, err
8282
}
8383

84+
// get public up nodes
8485
freeFarmNodes, err := g.GetUpNodes(ctx, 0, 1, 0, true, true)
8586
if err != nil {
8687
return nil, errors.Wrap(err, "failed to list freefarm nodes from graphql")

pkg/perf/publicip/publicip_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stub
186186
if err != nil {
187187
return false, err
188188
}
189+
189190
nodes, err := gql.GetUpNodes(ctx, 0, farmID, 0, false, false)
190191
if err != nil {
191192
return false, fmt.Errorf("failed to get farm %d nodes: %w", farmID, err)
192193
}
193-
194194
cl := perf.GetZbusClient(ctx)
195195
registrar := stubs.NewRegistrarStub(cl)
196196
var nodeID uint32

pkg/registrar/register.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,7 @@ func registerNode(
149149

150150
sk := ed25519.PrivateKey(mgr.PrivateKey(ctx))
151151

152-
for _, url := range env.ActivationURL {
153-
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
154-
break
155-
}
156-
}
157-
if err != nil {
152+
if _, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash); err != nil {
158153
return 0, 0, errors.Wrap(err, "failed to ensure account")
159154
}
160155

pkg/registrar/registrar.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,8 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
155155

156156
func (r *Registrar) reActivate(ctx context.Context, cl zbus.Client, env environment.Environment) error {
157157
substrateGateway := stubs.NewSubstrateGatewayStub(cl)
158-
var err error
159158

160-
for _, url := range env.ActivationURL {
161-
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
162-
break
163-
}
164-
}
159+
_, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash)
165160

166161
return err
167162
}

pkg/stubs/api_gateway_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (s *SubstrateGatewayStub) CreateTwin(ctx context.Context, arg0 string, arg1
6363
return
6464
}
6565

66-
func (s *SubstrateGatewayStub) EnsureAccount(ctx context.Context, arg0 string, arg1 string, arg2 string) (ret0 tfchainclientgo.AccountInfo, ret1 error) {
66+
func (s *SubstrateGatewayStub) EnsureAccount(ctx context.Context, arg0 []string, arg1 string, arg2 string) (ret0 tfchainclientgo.AccountInfo, ret1 error) {
6767
args := []interface{}{arg0, arg1, arg2}
6868
result, err := s.client.RequestContext(ctx, s.module, s.object, "EnsureAccount", args...)
6969
if err != nil {

pkg/substrate_gateway/substrate_gateway.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,21 @@ func (g *substrateGateway) CreateTwin(relay string, pk []byte) (uint32, error) {
4848
return g.sub.CreateTwin(g.identity, relay, pk)
4949
}
5050

51-
func (g *substrateGateway) EnsureAccount(activationURL string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) {
51+
func (g *substrateGateway) EnsureAccount(activationURL []string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) {
5252
log.Debug().
5353
Str("method", "EnsureAccount").
54-
Str("activation url", activationURL).
54+
Strs("activation url", activationURL).
5555
Str("terms and conditions link", termsAndConditionsLink).
5656
Str("terms and conditions hash", termsAndConditionsHash).
5757
Msg("method called")
5858
g.mu.Lock()
5959
defer g.mu.Unlock()
60-
return g.sub.EnsureAccount(g.identity, activationURL, termsAndConditionsLink, termsAndConditionsHash)
60+
for _, url := range activationURL {
61+
if info, err = g.sub.EnsureAccount(g.identity, url, termsAndConditionsLink, termsAndConditionsHash); err == nil {
62+
return
63+
}
64+
}
65+
return
6166
}
6267

6368
func (g *substrateGateway) GetContract(id uint64) (result substrate.Contract, serr pkg.SubstrateError) {

0 commit comments

Comments
 (0)