11package handlers
22
33import (
4+ "context"
45 "fmt"
56 "net/http"
67
@@ -38,7 +39,7 @@ func GetBigMap() gin.HandlerFunc {
3839 return
3940 }
4041
41- stats , err := ctx .BigMapDiffs .GetStats (req .Ptr )
42+ stats , err := ctx .BigMapDiffs .GetStats (c . Request . Context (), req .Ptr )
4243 if handleError (c , ctx .Storage , err , 0 ) {
4344 return
4445 }
@@ -52,29 +53,29 @@ func GetBigMap() gin.HandlerFunc {
5253 }
5354
5455 if stats .Total == 0 {
55- actions , err := ctx .BigMapActions .Get (req .Ptr , 1 , 0 )
56+ actions , err := ctx .BigMapActions .Get (c . Request . Context (), req .Ptr , 1 , 0 )
5657 if handleError (c , ctx .Storage , err , 0 ) {
5758 return
5859 }
5960 if len (actions ) > 0 {
6061 res .Address = actions [0 ].Address
6162 }
6263 } else {
63- destination , err := ctx .Accounts .Get (res .Address )
64+ destination , err := ctx .Accounts .Get (c . Request . Context (), res .Address )
6465 if handleError (c , ctx .Storage , err , 0 ) {
6566 return
6667 }
67- res .ContractAlias = destination .Alias
6868
6969 operation , err := ctx .Operations .Last (
70+ c .Request .Context (),
7071 map [string ]interface {}{
7172 "status" : types .OperationStatusApplied ,
7273 "destination_id" : destination .ID ,
7374 }, 0 )
7475 if handleError (c , ctx .Storage , err , 0 ) {
7576 return
7677 }
77- proto , err := ctx .Cache .ProtocolByID (operation .ProtocolID )
78+ proto , err := ctx .Cache .ProtocolByID (c . Request . Context (), operation .ProtocolID )
7879 if handleError (c , ctx .Storage , err , 0 ) {
7980 return
8081 }
@@ -94,7 +95,7 @@ func GetBigMap() gin.HandlerFunc {
9495 return
9596 }
9697
97- script , err := ctx .Contracts .ScriptPart (res .Address , proto .SymLink , consts .STORAGE )
98+ script , err := ctx .Contracts .ScriptPart (c . Request . Context (), res .Address , proto .SymLink , consts .STORAGE )
9899 if handleError (c , ctx .Storage , err , 0 ) {
99100 return
100101 }
@@ -146,7 +147,7 @@ func GetBigMapHistory() gin.HandlerFunc {
146147 return
147148 }
148149
149- bm , err := ctx .BigMapActions .Get (req .Ptr , 0 , 0 )
150+ bm , err := ctx .BigMapActions .Get (c . Request . Context (), req .Ptr , 0 , 0 )
150151 if handleError (c , ctx .Storage , err , 0 ) {
151152 return
152153 }
@@ -189,7 +190,7 @@ func GetBigMapKeys() gin.HandlerFunc {
189190 return
190191 }
191192
192- keys , err := ctx .BigMapDiffs .Keys (bigmapdiff.GetContext {
193+ keys , err := ctx .BigMapDiffs .Keys (c . Request . Context (), bigmapdiff.GetContext {
193194 Ptr : & req .Ptr ,
194195 Size : pageReq .Size ,
195196 Offset : pageReq .Offset ,
@@ -201,12 +202,12 @@ func GetBigMapKeys() gin.HandlerFunc {
201202 return
202203 }
203204
204- symLink , err := getCurrentSymLink (ctx .Blocks )
205+ symLink , err := getCurrentSymLink (c . Request . Context (), ctx .Blocks )
205206 if handleError (c , ctx .Storage , err , 0 ) {
206207 return
207208 }
208209
209- response , err := prepareBigMapKeys (ctx , keys , symLink )
210+ response , err := prepareBigMapKeys (c . Request . Context (), ctx , keys , symLink )
210211 if handleError (c , ctx .Storage , err , 0 ) {
211212 return
212213 }
@@ -246,7 +247,7 @@ func GetBigMapByKeyHash() gin.HandlerFunc {
246247 return
247248 }
248249
249- bm , total , err := ctx .BigMapDiffs .GetByPtrAndKeyHash (req .Ptr , req .KeyHash , pageReq .Size , pageReq .Offset )
250+ bm , total , err := ctx .BigMapDiffs .GetByPtrAndKeyHash (c . Request . Context (), req .Ptr , req .KeyHash , pageReq .Size , pageReq .Offset )
250251 if handleError (c , ctx .Storage , err , 0 ) {
251252 return
252253 }
@@ -255,12 +256,12 @@ func GetBigMapByKeyHash() gin.HandlerFunc {
255256 c .SecureJSON (http .StatusNoContent , gin.H {})
256257 return
257258 }
258- symLink , err := getCurrentSymLink (ctx .Blocks )
259+ symLink , err := getCurrentSymLink (c . Request . Context (), ctx .Blocks )
259260 if handleError (c , ctx .Storage , err , 0 ) {
260261 return
261262 }
262263
263- response , err := prepareBigMapItem (ctx , bm , req .KeyHash , symLink )
264+ response , err := prepareBigMapItem (c . Request . Context (), ctx , bm , req .KeyHash , symLink )
264265 if handleError (c , ctx .Storage , err , 0 ) {
265266 return
266267 }
@@ -294,17 +295,17 @@ func GetCurrentBigMapKeyHash() gin.HandlerFunc {
294295 return
295296 }
296297
297- state , err := ctx .BigMapDiffs .Current (req .KeyHash , req .Ptr )
298+ state , err := ctx .BigMapDiffs .Current (c . Request . Context (), req .KeyHash , req .Ptr )
298299 if handleError (c , ctx .Storage , err , 0 ) {
299300 return
300301 }
301302
302- symLink , err := getCurrentSymLink (ctx .Blocks )
303+ symLink , err := getCurrentSymLink (c . Request . Context (), ctx .Blocks )
303304 if handleError (c , ctx .Storage , err , 0 ) {
304305 return
305306 }
306307
307- bigMapType , err := getBigMapType (ctx , state .Contract , state .Ptr , symLink )
308+ bigMapType , err := getBigMapType (c . Request . Context (), ctx , state .Contract , state .Ptr , symLink )
308309 if handleError (c , ctx .Storage , err , 0 ) {
309310 return
310311 }
@@ -348,7 +349,7 @@ func GetBigMapDiffCount() gin.HandlerFunc {
348349 return
349350 }
350351
351- count , err := ctx .BigMapDiffs .Count (req .Ptr )
352+ count , err := ctx .BigMapDiffs .Count (c . Request . Context (), req .Ptr )
352353 if err != nil {
353354 if ctx .Storage .IsRecordNotFound (err ) {
354355 c .SecureJSON (http .StatusOK , CountResponse {})
@@ -357,16 +358,16 @@ func GetBigMapDiffCount() gin.HandlerFunc {
357358 handleError (c , ctx .Storage , err , 0 )
358359 return
359360 }
360- c .SecureJSON (http .StatusOK , CountResponse {count })
361+ c .SecureJSON (http .StatusOK , CountResponse {int64 ( count ) })
361362 }
362363}
363364
364- func prepareBigMapKeys (ctx * config.Context , data []bigmapdiff.BigMapState , symLink string ) ([]BigMapResponseItem , error ) {
365+ func prepareBigMapKeys (c context. Context , ctx * config.Context , data []bigmapdiff.BigMapState , symLink string ) ([]BigMapResponseItem , error ) {
365366 if len (data ) == 0 {
366367 return []BigMapResponseItem {}, nil
367368 }
368369
369- bigMapType , err := getBigMapType (ctx , data [0 ].Contract , data [0 ].Ptr , symLink )
370+ bigMapType , err := getBigMapType (c , ctx , data [0 ].Contract , data [0 ].Ptr , symLink )
370371 if err != nil {
371372 return nil , err
372373 }
@@ -393,12 +394,12 @@ func prepareBigMapKeys(ctx *config.Context, data []bigmapdiff.BigMapState, symLi
393394 return res , nil
394395}
395396
396- func prepareBigMapItem (ctx * config.Context , data []bigmapdiff.BigMapDiff , keyHash , symLink string ) (res BigMapDiffByKeyResponse , err error ) {
397+ func prepareBigMapItem (c context. Context , ctx * config.Context , data []bigmapdiff.BigMapDiff , keyHash , symLink string ) (res BigMapDiffByKeyResponse , err error ) {
397398 if len (data ) == 0 {
398399 return
399400 }
400401
401- bigMapType , err := getBigMapType (ctx , data [0 ].Contract , data [0 ].Ptr , symLink )
402+ bigMapType , err := getBigMapType (c , ctx , data [0 ].Contract , data [0 ].Ptr , symLink )
402403 if err != nil {
403404 return
404405 }
@@ -424,13 +425,13 @@ func prepareBigMapItem(ctx *config.Context, data []bigmapdiff.BigMapDiff, keyHas
424425 return
425426}
426427
427- func getBigMapType (ctx * config.Context , contract string , ptr int64 , symLink string ) (* ast.BigMap , error ) {
428- storageType , err := getStorageType (ctx .Contracts , contract , symLink )
428+ func getBigMapType (c context. Context , ctx * config.Context , contract string , ptr int64 , symLink string ) (* ast.BigMap , error ) {
429+ storageType , err := getStorageType (c , ctx .Contracts , contract , symLink )
429430 if err != nil {
430431 return nil , err
431432 }
432433
433- actions , err := ctx .BigMapActions .Get (ptr , 2 , 0 )
434+ actions , err := ctx .BigMapActions .Get (c , ptr , 2 , 0 )
434435 if err != nil {
435436 return nil , err
436437 }
@@ -443,18 +444,18 @@ func getBigMapType(ctx *config.Context, contract string, ptr int64, symLink stri
443444 operationID = actions [1 ].OperationID
444445 }
445446 }
446- operation , err := ctx .Operations .GetByID (operationID )
447+ operation , err := ctx .Operations .GetByID (c , operationID )
447448 if err != nil {
448449 return nil , err
449450 }
450451 deffatedStorage = operation .DeffatedStorage
451452 } else {
452- contract , err := ctx .Accounts .Get (contract )
453+ contract , err := ctx .Accounts .Get (c , contract )
453454 if err != nil {
454455 return nil , err
455456 }
456457
457- operation , err := ctx .Operations .Last (map [string ]interface {}{
458+ operation , err := ctx .Operations .Last (c , map [string ]interface {}{
458459 "destination_id" : contract .ID ,
459460 "status" : types .OperationStatusApplied ,
460461 }, 0 )
0 commit comments