@@ -288,6 +288,51 @@ func (bl *FxBlockchain) callBlockchain(ctx context.Context, method string, actio
288
288
return b , resp .StatusCode , nil
289
289
}
290
290
291
+ // TODO: The below method should be removed after fixing hte syncing issue with blockchain
292
+ func (bl * FxBlockchain ) callBlockchainWithSeedTemporary (ctx context.Context , method string , action string , p interface {}) ([]byte , int , error ) {
293
+ // Check blockchain health before proceeding
294
+ if err := bl .checkHealth (ctx ); err != nil {
295
+ return nil , http .StatusFailedDependency , err // Use 424 as the status code for a syncing blockchain
296
+ }
297
+
298
+ endpoint := prependProtocol ("api.node3.functionyard.fula.network" )
299
+ addr := endpoint + "/" + strings .Replace (action , "-" , "/" , - 1 )
300
+
301
+ // Use the bufPool and reqPool to reuse bytes.Buffer and http.Request objects
302
+ buf := bl .bufPool .Get ().(* bytes.Buffer )
303
+ req := bl .reqPool .Get ().(* http.Request )
304
+ defer func () {
305
+ bl .putBuf (buf )
306
+ bl .putReq (req )
307
+ }()
308
+
309
+ preparedRequest := bl .PlugSeedIfNeeded (ctx , action , p )
310
+ if err := json .NewEncoder (buf ).Encode (preparedRequest ); err != nil {
311
+ return nil , 0 , err
312
+ }
313
+ req , err := http .NewRequestWithContext (ctx , method , addr , buf )
314
+ if err != nil {
315
+ return nil , 0 , err
316
+ }
317
+
318
+ req .Header .Set ("Content-Type" , "application/json" )
319
+
320
+ resp , err := bl .ch .Do (req )
321
+ if err != nil {
322
+ return nil , 0 , err
323
+ }
324
+ defer resp .Body .Close ()
325
+
326
+ var bufRes bytes.Buffer
327
+ _ , err = io .Copy (& bufRes , resp .Body )
328
+ if err != nil {
329
+ return nil , resp .StatusCode , err
330
+ }
331
+ b := bufRes .Bytes ()
332
+
333
+ return b , resp .StatusCode , nil
334
+ }
335
+
291
336
func (bl * FxBlockchain ) PlugSeedIfNeeded (ctx context.Context , action string , req interface {}) interface {} {
292
337
switch action {
293
338
case actionSeeded , actionAccountExists , actionAccountFund , actionPoolCreate , actionPoolJoin , actionPoolCancelJoin , actionPoolVote , actionPoolLeave , actionManifestUpload , actionManifestStore , actionManifestRemove , actionManifestRemoveStorer , actionManifestRemoveStored , actionManifestBatchUpload , actionManifestBatchStore :
0 commit comments