Skip to content

Commit

Permalink
update response from create node
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Feb 20, 2025
1 parent 705bf25 commit 00a7984
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 19 additions & 3 deletions pkg/registrar_gateway/registrar_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (r *registrarGateway) getTwin(url string, twinID uint64) (result types.Acco
defer resp.Body.Close()

err = json.NewDecoder(resp.Body).Decode(&result)

if r.twinID == 0 {
r.twinID = result.TwinID
}
return result, err
}

Expand Down Expand Up @@ -422,6 +426,9 @@ func (r *registrarGateway) getTwinByPubKey(url string, pk []byte) (result uint64
var account types.Account
err = json.NewDecoder(resp.Body).Decode(&account)

if r.twinID == 0 {
r.twinID = account.TwinID
}
return account.TwinID, err
}

Expand Down Expand Up @@ -486,10 +493,13 @@ func (r *registrarGateway) createNode(url string, node types.UpdateNodeRequest)

defer resp.Body.Close()

err = json.NewDecoder(resp.Body).Decode(&nodeID)
result := struct {
NodeID uint64 `json:"node_id"`
}{}
err = json.NewDecoder(resp.Body).Decode(&result)

r.nodeID = nodeID
return nodeID, err
r.nodeID = result.NodeID
return result.NodeID, err
}

func (r *registrarGateway) getFarm(url string) (farm types.Farm, err error) {
Expand Down Expand Up @@ -538,6 +548,9 @@ func (r *registrarGateway) getNode(url string) (node types.Node, err error) {
return
}

if r.nodeID == 0 {
r.nodeID = node.NodeID
}
return node, err
}

Expand Down Expand Up @@ -580,6 +593,9 @@ func (r *registrarGateway) getNodeByTwinID(url string, twin uint64) (result uint
return result, ErrorRecordNotFound
}

if r.nodeID == 0 {
r.nodeID = nodes[0].NodeID
}
return nodes[0].NodeID, nil
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type Farm struct {
FarmName string `json:"farm_name"`
TwinID uint64 `json:"twin_id"` // Farmer account reference
Dedicated bool `json:"dedicated"`
CreatedAt time.Time
UpdatedAt time.Time
}

type Node struct {
Expand Down

0 comments on commit 00a7984

Please sign in to comment.