@@ -23,37 +23,29 @@ import (
23
23
"github.com/threefoldtech/zos4/pkg/types"
24
24
"github.com/threefoldtech/zosbase/pkg"
25
25
"github.com/threefoldtech/zosbase/pkg/environment"
26
- "github.com/threefoldtech/zosbase/pkg/gridtypes"
27
26
)
28
27
29
28
const AuthHeader = "X-Auth"
30
29
31
30
type registrarGateway struct {
32
- sub * substrate.Substrate
33
31
mu sync.Mutex
34
32
baseURL string
35
33
httpClient * http.Client
36
- identity gridtypes.Identity
37
34
privKey ed25519.PrivateKey
38
35
nodeID uint64
39
36
twinID uint64
40
37
}
41
38
42
39
var ErrorRecordNotFound = errors .New ("could not fine the reqested record" )
43
40
44
- func NewRegistrarGateway (cl zbus.Client , manager substrate. Manager ) (zos4Pkg.RegistrarGateway , error ) {
41
+ func NewRegistrarGateway (cl zbus.Client ) (zos4Pkg.RegistrarGateway , error ) {
45
42
client := http .DefaultClient
46
43
env := environment .MustGet ()
47
- sub , err := manager .Substrate ()
48
- if err != nil {
49
- return & registrarGateway {}, err
50
- }
51
44
52
45
identity := stubs .NewIdentityManagerStub (cl )
53
46
sk := ed25519 .PrivateKey (identity .PrivateKey (context .TODO ()))
54
47
55
48
gw := & registrarGateway {
56
- sub : sub ,
57
49
httpClient : client ,
58
50
baseURL : env .RegistrarURL ,
59
51
mu : sync.Mutex {},
@@ -108,22 +100,22 @@ func (g *registrarGateway) EnsureAccount(twinID uint64, pk []byte) (twin types.A
108
100
}
109
101
110
102
func (g * registrarGateway ) GetContract (id uint64 ) (result substrate.Contract , serr pkg.SubstrateError ) {
111
- log .Trace ().Str ("method" , "GetContract" ).Uint64 ("id" , id ).Msg ("method called" )
112
- contract , err := g .sub .GetContract (id )
113
-
114
- serr = buildSubstrateError (err )
115
- if err != nil {
116
- return
117
- }
118
- return * contract , serr
103
+ // log.Trace().Str("method", "GetContract").Uint64("id", id).Msg("method called")
104
+ // contract, err := g.sub.GetContract(id)
105
+ //
106
+ // serr = buildSubstrateError(err)
107
+ // if err != nil {
108
+ // return
109
+ // }
110
+ return
119
111
}
120
112
121
113
func (g * registrarGateway ) GetContractIDByNameRegistration (name string ) (result uint64 , serr pkg.SubstrateError ) {
122
- log .Trace ().Str ("method" , "GetContractIDByNameRegistration" ).Str ("name" , name ).Msg ("method called" )
123
- contractID , err := g .sub .GetContractIDByNameRegistration (name )
124
-
125
- serr = buildSubstrateError (err )
126
- return contractID , serr
114
+ // log.Trace().Str("method", "GetContractIDByNameRegistration").Str("name", name).Msg("method called")
115
+ // contractID, err := g.sub.GetContractIDByNameRegistration(name)
116
+ //
117
+ // serr = buildSubstrateError(err)
118
+ return
127
119
}
128
120
129
121
func (r * registrarGateway ) GetFarm (id uint64 ) (farm types.Farm , err error ) {
@@ -148,16 +140,17 @@ func (r *registrarGateway) GetNodeByTwinID(twin uint64) (result uint64, err erro
148
140
}
149
141
150
142
func (g * registrarGateway ) GetNodeContracts (node uint32 ) ([]subTypes.U64 , error ) {
151
- log .Trace ().Str ("method" , "GetNodeContracts" ).Uint32 ("node" , node ).Msg ("method called" )
152
- return g .sub .GetNodeContracts (node )
143
+ // log.Trace().Str("method", "GetNodeContracts").Uint32("node", node).Msg("method called")
144
+ // return g.sub.GetNodeContracts(node)
145
+ return []subTypes.U64 {}, nil
153
146
}
154
147
155
148
func (g * registrarGateway ) GetNodeRentContract (node uint32 ) (result uint64 , serr pkg.SubstrateError ) {
156
- log .Trace ().Str ("method" , "GetNodeRentContract" ).Uint32 ("node" , node ).Msg ("method called" )
157
- contractID , err := g .sub .GetNodeRentContract (node )
158
-
159
- serr = buildSubstrateError (err )
160
- return contractID , serr
149
+ // log.Trace().Str("method", "GetNodeRentContract").Uint32("node", node).Msg("method called")
150
+ // contractID, err := g.sub.GetNodeRentContract(node)
151
+ //
152
+ // serr = buildSubstrateError(err)
153
+ return
161
154
}
162
155
163
156
func (r * registrarGateway ) GetNodes (farmID uint32 ) (nodeIDs []uint32 , err error ) {
@@ -168,8 +161,9 @@ func (r *registrarGateway) GetNodes(farmID uint32) (nodeIDs []uint32, err error)
168
161
}
169
162
170
163
func (g * registrarGateway ) GetPowerTarget () (power substrate.NodePower , err error ) {
171
- log .Trace ().Str ("method" , "GetPowerTarget" ).Uint32 ("node id" , uint32 (g .nodeID )).Msg ("method called" )
172
- return g .sub .GetPowerTarget (uint32 (g .nodeID ))
164
+ // log.Trace().Str("method", "GetPowerTarget").Uint32("node id", uint32(g.nodeID)).Msg("method called")
165
+ // return g.sub.GetPowerTarget(uint32(g.nodeID))
166
+ return
173
167
}
174
168
175
169
func (r * registrarGateway ) GetTwin (id uint64 ) (result types.Account , err error ) {
@@ -187,43 +181,46 @@ func (r *registrarGateway) GetTwinByPubKey(pk []byte) (result uint64, err error)
187
181
}
188
182
189
183
func (r * registrarGateway ) Report (consumptions []substrate.NruConsumption ) (subTypes.Hash , error ) {
190
- contractIDs := make ([]uint64 , 0 , len (consumptions ))
191
- for _ , v := range consumptions {
192
- contractIDs = append (contractIDs , uint64 (v .ContractID ))
193
- }
194
-
195
- log .Debug ().Str ("method" , "Report" ).Uints64 ("contract ids" , contractIDs ).Msg ("method called" )
196
- r .mu .Lock ()
197
- defer r .mu .Unlock ()
198
-
199
- url := fmt .Sprintf ("%s/v1/nodes/%d/consumption" , r .baseURL , r .nodeID )
200
-
201
- var body bytes.Buffer
202
- _ , err := r .httpClient .Post (url , "application/json" , & body )
203
- if err != nil {
204
- return subTypes.Hash {}, err
205
- }
206
-
207
- // I need to know what is hash to be able to respond with it
208
- return r .sub .Report (r .identity , consumptions )
184
+ // contractIDs := make([]uint64, 0, len(consumptions))
185
+ // for _, v := range consumptions {
186
+ // contractIDs = append(contractIDs, uint64(v.ContractID))
187
+ // }
188
+ //
189
+ // log.Debug().Str("method", "Report").Uints64("contract ids", contractIDs).Msg("method called")
190
+ // r.mu.Lock()
191
+ // defer r.mu.Unlock()
192
+ //
193
+ // url := fmt.Sprintf("%s/v1/nodes/%d/consumption", r.baseURL, r.nodeID)
194
+ //
195
+ // var body bytes.Buffer
196
+ // _, err := r.httpClient.Post(url, "application/json", &body)
197
+ // if err != nil {
198
+ // return subTypes.Hash{}, err
199
+ // }
200
+ //
201
+ // // I need to know what is hash to be able to respond with it
202
+ // return r.sub.Report(r.identity, consumptions)
203
+ return subTypes.Hash {}, nil
209
204
}
210
205
211
206
func (g * registrarGateway ) SetContractConsumption (resources ... substrate.ContractResources ) error {
212
- contractIDs := make ([]uint64 , 0 , len (resources ))
213
- for _ , v := range resources {
214
- contractIDs = append (contractIDs , uint64 (v .ContractID ))
215
- }
216
- log .Debug ().Str ("method" , "SetContractConsumption" ).Uints64 ("contract ids" , contractIDs ).Msg ("method called" )
217
- g .mu .Lock ()
218
- defer g .mu .Unlock ()
219
- return g .sub .SetContractConsumption (g .identity , resources ... )
207
+ // contractIDs := make([]uint64, 0, len(resources))
208
+ // for _, v := range resources {
209
+ // contractIDs = append(contractIDs, uint64(v.ContractID))
210
+ // }
211
+ // log.Debug().Str("method", "SetContractConsumption").Uints64("contract ids", contractIDs).Msg("method called")
212
+ // g.mu.Lock()
213
+ // defer g.mu.Unlock()
214
+ // return g.sub.SetContractConsumption(g.identity, resources...)
215
+ return nil
220
216
}
221
217
222
218
func (g * registrarGateway ) SetNodePowerState (up bool ) (hash subTypes.Hash , err error ) {
223
- log .Debug ().Str ("method" , "SetNodePowerState" ).Bool ("up" , up ).Msg ("method called" )
224
- g .mu .Lock ()
225
- defer g .mu .Unlock ()
226
- return g .sub .SetNodePowerState (g .identity , up )
219
+ // log.Debug().Str("method", "SetNodePowerState").Bool("up", up).Msg("method called")
220
+ // g.mu.Lock()
221
+ // defer g.mu.Unlock()
222
+ // return g.sub.SetNodePowerState(g.identity, up)
223
+ return subTypes.Hash {}, nil
227
224
}
228
225
229
226
func (r * registrarGateway ) UpdateNode (node types.NodeRegistrationRequest ) (uint64 , error ) {
@@ -249,9 +246,10 @@ func (r *registrarGateway) UpdateNodeUptimeV2(uptime uint64, timestampHint uint6
249
246
}
250
247
251
248
func (g * registrarGateway ) GetTime () (time.Time , error ) {
252
- log .Trace ().Str ("method" , "Time" ).Msg ("method called" )
253
-
254
- return g .sub .Time ()
249
+ // log.Trace().Str("method", "Time").Msg("method called")
250
+ //
251
+ // return g.sub.Time()
252
+ return time .Now (), nil
255
253
}
256
254
257
255
func buildSubstrateError (err error ) (serr pkg.SubstrateError ) {
@@ -442,7 +440,8 @@ func (r *registrarGateway) getZosVersion(url string) (string, error) {
442
440
443
441
defer resp .Body .Close ()
444
442
445
- var version gridtypes.Versioned
443
+ var version types.ZosVersion
444
+
446
445
err = json .NewDecoder (resp .Body ).Decode (& version )
447
446
448
447
return version .Version , err
0 commit comments