@@ -53,22 +53,22 @@ func NewAccessAdapter(logger *zerolog.Logger, emulator emulator.Emulator) *Acces
53
53
}
54
54
}
55
55
56
- func convertError (err error ) error {
56
+ func convertError (err error , defaultStatusCode codes. Code ) error {
57
57
if err != nil {
58
58
switch err .(type ) {
59
59
case types.InvalidArgumentError :
60
60
return status .Error (codes .InvalidArgument , err .Error ())
61
61
case types.NotFoundError :
62
62
return status .Error (codes .NotFound , err .Error ())
63
63
default :
64
- return status .Error (codes . Internal , err .Error ())
64
+ return status .Error (defaultStatusCode , err .Error ())
65
65
}
66
66
}
67
67
return nil
68
68
}
69
69
70
70
func (a * AccessAdapter ) Ping (_ context.Context ) error {
71
- return convertError (a .emulator .Ping ())
71
+ return convertError (a .emulator .Ping (), codes . Internal )
72
72
}
73
73
74
74
func (a * AccessAdapter ) GetNetworkParameters (_ context.Context ) access.NetworkParameters {
@@ -78,7 +78,7 @@ func (a *AccessAdapter) GetNetworkParameters(_ context.Context) access.NetworkPa
78
78
func (a * AccessAdapter ) GetLatestBlockHeader (_ context.Context , _ bool ) (* flowgo.Header , flowgo.BlockStatus , error ) {
79
79
block , err := a .emulator .GetLatestBlock ()
80
80
if err != nil {
81
- return nil , flowgo .BlockStatusUnknown , convertError (err )
81
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
82
82
}
83
83
84
84
a .logger .Debug ().Fields (map [string ]any {
@@ -92,7 +92,7 @@ func (a *AccessAdapter) GetLatestBlockHeader(_ context.Context, _ bool) (*flowgo
92
92
func (a * AccessAdapter ) GetBlockHeaderByHeight (_ context.Context , height uint64 ) (* flowgo.Header , flowgo.BlockStatus , error ) {
93
93
block , err := a .emulator .GetBlockByHeight (height )
94
94
if err != nil {
95
- return nil , flowgo .BlockStatusUnknown , convertError (err )
95
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
96
96
}
97
97
98
98
a .logger .Debug ().Fields (map [string ]any {
@@ -106,7 +106,7 @@ func (a *AccessAdapter) GetBlockHeaderByHeight(_ context.Context, height uint64)
106
106
func (a * AccessAdapter ) GetBlockHeaderByID (_ context.Context , id flowgo.Identifier ) (* flowgo.Header , flowgo.BlockStatus , error ) {
107
107
block , err := a .emulator .GetBlockByID (id )
108
108
if err != nil {
109
- return nil , flowgo .BlockStatusUnknown , convertError (err )
109
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
110
110
}
111
111
112
112
a .logger .Debug ().Fields (map [string ]any {
@@ -120,7 +120,7 @@ func (a *AccessAdapter) GetBlockHeaderByID(_ context.Context, id flowgo.Identifi
120
120
func (a * AccessAdapter ) GetLatestBlock (_ context.Context , _ bool ) (* flowgo.Block , flowgo.BlockStatus , error ) {
121
121
block , err := a .emulator .GetLatestBlock ()
122
122
if err != nil {
123
- return nil , flowgo .BlockStatusUnknown , convertError (err )
123
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
124
124
}
125
125
126
126
a .logger .Debug ().Fields (map [string ]any {
@@ -134,7 +134,7 @@ func (a *AccessAdapter) GetLatestBlock(_ context.Context, _ bool) (*flowgo.Block
134
134
func (a * AccessAdapter ) GetBlockByHeight (_ context.Context , height uint64 ) (* flowgo.Block , flowgo.BlockStatus , error ) {
135
135
block , err := a .emulator .GetBlockByHeight (height )
136
136
if err != nil {
137
- return nil , flowgo .BlockStatusUnknown , convertError (err )
137
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
138
138
}
139
139
140
140
a .logger .Debug ().Fields (map [string ]any {
@@ -148,7 +148,7 @@ func (a *AccessAdapter) GetBlockByHeight(_ context.Context, height uint64) (*flo
148
148
func (a * AccessAdapter ) GetBlockByID (_ context.Context , id flowgo.Identifier ) (* flowgo.Block , flowgo.BlockStatus , error ) {
149
149
block , err := a .emulator .GetBlockByID (id )
150
150
if err != nil {
151
- return nil , flowgo .BlockStatusUnknown , convertError (err )
151
+ return nil , flowgo .BlockStatusUnknown , convertError (err , codes . Internal )
152
152
}
153
153
154
154
a .logger .Debug ().Fields (map [string ]any {
@@ -162,7 +162,7 @@ func (a *AccessAdapter) GetBlockByID(_ context.Context, id flowgo.Identifier) (*
162
162
func (a * AccessAdapter ) GetCollectionByID (_ context.Context , id flowgo.Identifier ) (* flowgo.LightCollection , error ) {
163
163
collection , err := a .emulator .GetCollectionByID (id )
164
164
if err != nil {
165
- return nil , convertError (err )
165
+ return nil , convertError (err , codes . Internal )
166
166
}
167
167
168
168
a .logger .Debug ().
@@ -175,7 +175,7 @@ func (a *AccessAdapter) GetCollectionByID(_ context.Context, id flowgo.Identifie
175
175
func (a * AccessAdapter ) GetTransaction (_ context.Context , id flowgo.Identifier ) (* flowgo.TransactionBody , error ) {
176
176
tx , err := a .emulator .GetTransaction (id )
177
177
if err != nil {
178
- return nil , convertError (err )
178
+ return nil , convertError (err , codes . Internal )
179
179
}
180
180
181
181
a .logger .Debug ().
@@ -197,14 +197,14 @@ func (a *AccessAdapter) GetTransactionResult(
197
197
) {
198
198
result , err := a .emulator .GetTransactionResult (id )
199
199
if err != nil {
200
- return nil , convertError (err )
200
+ return nil , convertError (err , codes . Internal )
201
201
}
202
202
203
203
// Convert CCF events to JSON events, else return CCF encoded version
204
204
if requiredEventEncodingVersion == entities .EventEncodingVersion_JSON_CDC_V0 {
205
205
result .Events , err = ConvertCCFEventsToJsonEvents (result .Events )
206
206
if err != nil {
207
- return nil , convertError (err )
207
+ return nil , convertError (err , codes . Internal )
208
208
}
209
209
}
210
210
a .logger .Debug ().
@@ -217,7 +217,7 @@ func (a *AccessAdapter) GetTransactionResult(
217
217
func (a * AccessAdapter ) GetAccount (_ context.Context , address flowgo.Address ) (* flowgo.Account , error ) {
218
218
account , err := a .emulator .GetAccount (address )
219
219
if err != nil {
220
- return nil , convertError (err )
220
+ return nil , convertError (err , codes . Internal )
221
221
}
222
222
223
223
a .logger .Debug ().
@@ -230,7 +230,7 @@ func (a *AccessAdapter) GetAccount(_ context.Context, address flowgo.Address) (*
230
230
func (a * AccessAdapter ) GetAccountAtLatestBlock (ctx context.Context , address flowgo.Address ) (* flowgo.Account , error ) {
231
231
account , err := a .GetAccount (ctx , address )
232
232
if err != nil {
233
- return nil , convertError (err )
233
+ return nil , convertError (err , codes . Internal )
234
234
}
235
235
236
236
a .logger .Debug ().
@@ -253,7 +253,7 @@ func (a *AccessAdapter) GetAccountAtBlockHeight(
253
253
254
254
account , err := a .emulator .GetAccountAtBlockHeight (address , height )
255
255
if err != nil {
256
- return nil , convertError (err )
256
+ return nil , convertError (err , codes . Internal )
257
257
}
258
258
return account , nil
259
259
}
@@ -264,12 +264,12 @@ func convertScriptResult(result *types.ScriptResult, err error) ([]byte, error)
264
264
}
265
265
266
266
if ! result .Succeeded () {
267
- return nil , result .Error
267
+ return nil , status . Error ( codes . InvalidArgument , result .Error . Error ())
268
268
}
269
269
270
270
valueBytes , err := jsoncdc .Encode (result .Value )
271
271
if err != nil {
272
- return nil , status . Error ( codes . Internal , err . Error () )
272
+ return nil , convertError ( err , codes . InvalidArgument )
273
273
}
274
274
275
275
return valueBytes , nil
@@ -280,7 +280,14 @@ func (a *AccessAdapter) ExecuteScriptAtLatestBlock(
280
280
script []byte ,
281
281
arguments [][]byte ,
282
282
) ([]byte , error ) {
283
- a .logger .Debug ().Msg ("👤 ExecuteScriptAtLatestBlock called" )
283
+ latestBlock , err := a .emulator .GetLatestBlock ()
284
+ if err != nil {
285
+ return nil , err
286
+ }
287
+ a .logger .Debug ().
288
+ Uint64 ("blockHeight" , latestBlock .Header .Height ).
289
+ Msg ("👤 ExecuteScriptAtLatestBlock called" )
290
+
284
291
result , err := a .emulator .ExecuteScript (script , arguments )
285
292
if err == nil {
286
293
utils .PrintScriptResult (a .logger , result )
@@ -332,7 +339,7 @@ func (a *AccessAdapter) GetEventsForHeightRange(
332
339
) ([]flowgo.BlockEvents , error ) {
333
340
events , err := a .emulator .GetEventsForHeightRange (eventType , startHeight , endHeight )
334
341
if err != nil {
335
- return nil , convertError (err )
342
+ return nil , convertError (err , codes . Internal )
336
343
}
337
344
338
345
eventCount := 0
@@ -343,7 +350,7 @@ func (a *AccessAdapter) GetEventsForHeightRange(
343
350
events [i ].Events , err = ConvertCCFEventsToJsonEvents (events [i ].Events )
344
351
eventCount = eventCount + len (events [i ].Events )
345
352
if err != nil {
346
- return nil , convertError (err )
353
+ return nil , convertError (err , codes . Internal )
347
354
}
348
355
}
349
356
}
@@ -366,7 +373,7 @@ func (a *AccessAdapter) GetEventsForBlockIDs(
366
373
) ([]flowgo.BlockEvents , error ) {
367
374
events , err := a .emulator .GetEventsForBlockIDs (eventType , blockIDs )
368
375
if err != nil {
369
- return nil , convertError (err )
376
+ return nil , convertError (err , codes . Internal )
370
377
}
371
378
372
379
eventCount := 0
@@ -377,7 +384,7 @@ func (a *AccessAdapter) GetEventsForBlockIDs(
377
384
events [i ].Events , err = ConvertCCFEventsToJsonEvents (events [i ].Events )
378
385
eventCount = eventCount + len (events [i ].Events )
379
386
if err != nil {
380
- return nil , convertError (err )
387
+ return nil , convertError (err , codes . Internal )
381
388
}
382
389
}
383
390
}
@@ -426,18 +433,18 @@ func (a *AccessAdapter) GetTransactionResultByIndex(
426
433
) (* access.TransactionResult , error ) {
427
434
results , err := a .emulator .GetTransactionResultsByBlockID (blockID )
428
435
if err != nil {
429
- return nil , convertError (err )
436
+ return nil , convertError (err , codes . Internal )
430
437
}
431
438
if len (results ) <= int (index ) {
432
- return nil , convertError (& types.TransactionNotFoundError {ID : flowgo.Identifier {}})
439
+ return nil , convertError (& types.TransactionNotFoundError {ID : flowgo.Identifier {}}, codes . Internal )
433
440
}
434
441
435
442
// Convert CCF events to JSON events, else return CCF encoded version
436
443
if requiredEventEncodingVersion == entities .EventEncodingVersion_JSON_CDC_V0 {
437
444
for i := range results {
438
445
results [i ].Events , err = ConvertCCFEventsToJsonEvents (results [i ].Events )
439
446
if err != nil {
440
- return nil , convertError (err )
447
+ return nil , convertError (err , codes . Internal )
441
448
}
442
449
}
443
450
}
@@ -448,7 +455,7 @@ func (a *AccessAdapter) GetTransactionResultByIndex(
448
455
func (a * AccessAdapter ) GetTransactionsByBlockID (_ context.Context , blockID flowgo.Identifier ) ([]* flowgo.TransactionBody , error ) {
449
456
result , err := a .emulator .GetTransactionsByBlockID (blockID )
450
457
if err != nil {
451
- return nil , convertError (err )
458
+ return nil , convertError (err , codes . Internal )
452
459
}
453
460
return result , nil
454
461
}
@@ -460,15 +467,15 @@ func (a *AccessAdapter) GetTransactionResultsByBlockID(
460
467
) ([]* access.TransactionResult , error ) {
461
468
result , err := a .emulator .GetTransactionResultsByBlockID (blockID )
462
469
if err != nil {
463
- return nil , convertError (err )
470
+ return nil , convertError (err , codes . Internal )
464
471
}
465
472
466
473
// Convert CCF events to JSON events, else return CCF encoded version
467
474
if requiredEventEncodingVersion == entities .EventEncodingVersion_JSON_CDC_V0 {
468
475
for i := range result {
469
476
result [i ].Events , err = ConvertCCFEventsToJsonEvents (result [i ].Events )
470
477
if err != nil {
471
- return nil , convertError (err )
478
+ return nil , convertError (err , codes . Internal )
472
479
}
473
480
}
474
481
}
@@ -481,7 +488,7 @@ func (a *AccessAdapter) SendTransaction(_ context.Context, tx *flowgo.Transactio
481
488
Str ("txID" , tx .ID ().String ()).
482
489
Msg (`✉️ Transaction submitted` )
483
490
484
- return convertError (a .emulator .SendTransaction (tx ))
491
+ return convertError (a .emulator .SendTransaction (tx ), codes . Internal )
485
492
}
486
493
487
494
func (a * AccessAdapter ) GetNodeVersionInfo (
0 commit comments