-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.go
564 lines (460 loc) · 18.5 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
// This file implements the gRPC API methods defined in service/rpc/api_gen.proto . For documentation,
// see that file and related request/response fields in the generated gnonativetypes.proto .
package service
import (
"context"
"errors"
"time"
"connectrpc.com/connect"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/crypto/bip39"
crypto_keys "github.com/gnolang/gno/tm2/pkg/crypto/keys"
"github.com/gnolang/gno/tm2/pkg/crypto/keys/keyerror"
"github.com/gnolang/gno/tm2/pkg/std"
"go.uber.org/zap"
"github.com/gnolang/gno/gno.land/pkg/gnoclient"
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
api_gen "github.com/gnolang/gnonative/api/gen/go"
)
func (s *gnoNativeService) SetRemote(ctx context.Context, req *connect.Request[api_gen.SetRemoteRequest]) (*connect.Response[api_gen.SetRemoteResponse], error) {
var err error
s.client.RPCClient, err = rpcclient.NewHTTPClient(req.Msg.Remote)
if err != nil {
return nil, api_gen.ErrCode_ErrSetRemote.Wrap(err)
}
s.remote = req.Msg.Remote
return connect.NewResponse(&api_gen.SetRemoteResponse{}), nil
}
func (s *gnoNativeService) GetRemote(ctx context.Context, req *connect.Request[api_gen.GetRemoteRequest]) (*connect.Response[api_gen.GetRemoteResponse], error) {
return connect.NewResponse(&api_gen.GetRemoteResponse{Remote: s.remote}), nil
}
func (s *gnoNativeService) SetChainID(ctx context.Context, req *connect.Request[api_gen.SetChainIDRequest]) (*connect.Response[api_gen.SetChainIDResponse], error) {
s.getSigner().ChainID = req.Msg.ChainId
return connect.NewResponse(&api_gen.SetChainIDResponse{}), nil
}
func (s *gnoNativeService) GetChainID(ctx context.Context, req *connect.Request[api_gen.GetChainIDRequest]) (*connect.Response[api_gen.GetChainIDResponse], error) {
return connect.NewResponse(&api_gen.GetChainIDResponse{ChainId: s.getSigner().ChainID}), nil
}
func (s *gnoNativeService) GenerateRecoveryPhrase(ctx context.Context, req *connect.Request[api_gen.GenerateRecoveryPhraseRequest]) (*connect.Response[api_gen.GenerateRecoveryPhraseResponse], error) {
const mnemonicEntropySize = 256
entropySeed, err := bip39.NewEntropy(mnemonicEntropySize)
if err != nil {
return nil, err
}
phrase, err := bip39.NewMnemonic(entropySeed[:])
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.GenerateRecoveryPhraseResponse{Phrase: phrase}), nil
}
func convertKeyInfo(key crypto_keys.Info) (*api_gen.KeyInfo, error) {
return &api_gen.KeyInfo{
Type: uint32(key.GetType()),
Name: key.GetName(),
Address: key.GetAddress().Bytes(),
PubKey: key.GetPubKey().Bytes(),
}, nil
}
func (s *gnoNativeService) ListKeyInfo(ctx context.Context, req *connect.Request[api_gen.ListKeyInfoRequest]) (*connect.Response[api_gen.ListKeyInfoResponse], error) {
s.logger.Debug("ListKeyInfo called")
keys, err := s.getSigner().Keybase.List()
if err != nil {
return nil, err
}
formatedKeys := make([]*api_gen.KeyInfo, 0)
for _, key := range keys {
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
formatedKeys = append(formatedKeys, info)
}
return connect.NewResponse(&api_gen.ListKeyInfoResponse{Keys: formatedKeys}), nil
}
func (s *gnoNativeService) HasKeyByName(ctx context.Context, req *connect.Request[api_gen.HasKeyByNameRequest]) (*connect.Response[api_gen.HasKeyByNameResponse], error) {
s.logger.Debug("HasKeyByName called")
has, err := s.getSigner().Keybase.HasByName(req.Msg.Name)
if err != nil {
return nil, getGrpcError(err)
}
return connect.NewResponse(&api_gen.HasKeyByNameResponse{Has: has}), nil
}
func (s *gnoNativeService) HasKeyByAddress(ctx context.Context, req *connect.Request[api_gen.HasKeyByAddressRequest]) (*connect.Response[api_gen.HasKeyByAddressResponse], error) {
s.logger.Debug("HasKeyByAddress called")
has, err := s.getSigner().Keybase.HasByAddress(crypto.AddressFromBytes(req.Msg.Address))
if err != nil {
return nil, getGrpcError(err)
}
return connect.NewResponse(&api_gen.HasKeyByAddressResponse{Has: has}), nil
}
func (s *gnoNativeService) HasKeyByNameOrAddress(ctx context.Context, req *connect.Request[api_gen.HasKeyByNameOrAddressRequest]) (*connect.Response[api_gen.HasKeyByNameOrAddressResponse], error) {
s.logger.Debug("HasKeyByNameOrAddress called")
has, err := s.getSigner().Keybase.HasByNameOrAddress(req.Msg.NameOrBech32)
if err != nil {
return nil, getGrpcError(err)
}
return connect.NewResponse(&api_gen.HasKeyByNameOrAddressResponse{Has: has}), nil
}
func (s *gnoNativeService) GetKeyInfoByName(ctx context.Context, req *connect.Request[api_gen.GetKeyInfoByNameRequest]) (*connect.Response[api_gen.GetKeyInfoByNameResponse], error) {
s.logger.Debug("GetKeyInfoByName called")
key, err := s.getSigner().Keybase.GetByName(req.Msg.Name)
if err != nil {
return nil, getGrpcError(err)
}
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.GetKeyInfoByNameResponse{Key: info}), nil
}
func (s *gnoNativeService) GetKeyInfoByAddress(ctx context.Context, req *connect.Request[api_gen.GetKeyInfoByAddressRequest]) (*connect.Response[api_gen.GetKeyInfoByAddressResponse], error) {
s.logger.Debug("GetKeyInfoByAddress called")
key, err := s.getSigner().Keybase.GetByAddress(crypto.AddressFromBytes(req.Msg.Address))
if err != nil {
return nil, getGrpcError(err)
}
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.GetKeyInfoByAddressResponse{Key: info}), nil
}
func (s *gnoNativeService) GetKeyInfoByNameOrAddress(ctx context.Context, req *connect.Request[api_gen.GetKeyInfoByNameOrAddressRequest]) (*connect.Response[api_gen.GetKeyInfoByNameOrAddressResponse], error) {
s.logger.Debug("GetKeyInfoByNameOrAddress called")
key, err := s.getSigner().Keybase.GetByNameOrAddress(req.Msg.NameOrBech32)
if err != nil {
return nil, getGrpcError(err)
}
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.GetKeyInfoByNameOrAddressResponse{Key: info}), nil
}
func (s *gnoNativeService) CreateAccount(ctx context.Context, req *connect.Request[api_gen.CreateAccountRequest]) (*connect.Response[api_gen.CreateAccountResponse], error) {
s.logger.Debug("CreateAccount called", zap.String("NameOrBech32", req.Msg.NameOrBech32))
key, err := s.getSigner().Keybase.CreateAccount(req.Msg.NameOrBech32, req.Msg.Mnemonic, req.Msg.Bip39Passwd, req.Msg.Password, req.Msg.Account, req.Msg.Index)
if err != nil {
return nil, err
}
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.CreateAccountResponse{Key: info}), nil
}
func (s *gnoNativeService) SelectAccount(ctx context.Context, req *connect.Request[api_gen.SelectAccountRequest]) (*connect.Response[api_gen.SelectAccountResponse], error) {
s.logger.Debug("SelectAccount called", zap.String("NameOrBech32", req.Msg.NameOrBech32))
// The key may already be in s.userAccounts, but the info may have changed on disk. So always get from disk.
key, err := s.getSigner().Keybase.GetByNameOrAddress(req.Msg.NameOrBech32)
if err != nil {
return nil, getGrpcError(err)
}
info, err := convertKeyInfo(key)
if err != nil {
return nil, err
}
s.lock.Lock()
account, ok := s.userAccounts[req.Msg.NameOrBech32]
if !ok {
account = &userAccount{}
s.userAccounts[req.Msg.NameOrBech32] = account
}
account.keyInfo = key
s.activeAccount = account
s.lock.Unlock()
s.getSigner().Account = req.Msg.NameOrBech32
s.getSigner().Password = account.password
return connect.NewResponse(&api_gen.SelectAccountResponse{
Key: info,
HasPassword: account.password != "",
}), nil
}
func (s *gnoNativeService) SetPassword(ctx context.Context, req *connect.Request[api_gen.SetPasswordRequest]) (*connect.Response[api_gen.SetPasswordResponse], error) {
s.lock.Lock()
defer s.lock.Unlock()
if s.activeAccount == nil {
return nil, api_gen.ErrCode_ErrNoActiveAccount
}
s.activeAccount.password = req.Msg.Password
s.getSigner().Password = req.Msg.Password
// Check the password.
if err := s.getSigner().Validate(); err != nil {
return nil, getGrpcError(err)
}
return connect.NewResponse(&api_gen.SetPasswordResponse{}), nil
}
func (s *gnoNativeService) GetActiveAccount(ctx context.Context, req *connect.Request[api_gen.GetActiveAccountRequest]) (*connect.Response[api_gen.GetActiveAccountResponse], error) {
s.logger.Debug("GetActiveAccount called")
s.lock.RLock()
account := s.activeAccount
s.lock.RUnlock()
if account == nil {
return nil, api_gen.ErrCode_ErrNoActiveAccount
}
info, err := convertKeyInfo(account.keyInfo)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.GetActiveAccountResponse{
Key: info,
HasPassword: account.password != "",
}), nil
}
func (s *gnoNativeService) QueryAccount(ctx context.Context, req *connect.Request[api_gen.QueryAccountRequest]) (*connect.Response[api_gen.QueryAccountResponse], error) {
s.logger.Debug("QueryAccount", zap.ByteString("address", req.Msg.Address))
// gnoclient wants the bech32 address.
account, _, err := s.client.QueryAccount(crypto.AddressFromBytes(req.Msg.Address))
if err != nil {
return nil, getGrpcError(err)
}
formattedCoins := make([]*api_gen.Coin, 0)
for _, coin := range account.Coins {
formattedCoins = append(formattedCoins, &api_gen.Coin{
Denom: coin.Denom,
Amount: coin.Amount,
})
}
var pubKeyBytes []byte
if account.PubKey != nil {
pubKeyBytes = account.PubKey.Bytes()
}
res := connect.NewResponse(&api_gen.QueryAccountResponse{AccountInfo: &api_gen.BaseAccount{
Address: account.Address.Bytes(),
Coins: formattedCoins,
PubKey: pubKeyBytes,
AccountNumber: account.AccountNumber,
Sequence: account.Sequence,
}})
return res, nil
}
func (s *gnoNativeService) DeleteAccount(ctx context.Context, req *connect.Request[api_gen.DeleteAccountRequest]) (*connect.Response[api_gen.DeleteAccountResponse], error) {
if err := s.getSigner().Keybase.Delete(req.Msg.NameOrBech32, req.Msg.Password, req.Msg.SkipPassword); err != nil {
return nil, getGrpcError(err)
}
s.lock.Lock()
delete(s.userAccounts, req.Msg.NameOrBech32)
if s.activeAccount != nil &&
(s.activeAccount.keyInfo.GetName() == req.Msg.NameOrBech32 || crypto.AddressToBech32(s.activeAccount.keyInfo.GetAddress()) == req.Msg.NameOrBech32) {
// The deleted account was the active account.
s.activeAccount = nil
}
s.lock.Unlock()
return connect.NewResponse(&api_gen.DeleteAccountResponse{}), nil
}
func (s *gnoNativeService) Query(ctx context.Context, req *connect.Request[api_gen.QueryRequest]) (*connect.Response[api_gen.QueryResponse], error) {
s.logger.Debug("Query", zap.String("path", req.Msg.Path), zap.ByteString("data", req.Msg.Data))
cfg := gnoclient.QueryCfg{
Path: req.Msg.Path,
Data: req.Msg.Data,
}
bres, err := s.client.Query(cfg)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.QueryResponse{Result: bres.Response.Data}), nil
}
func (s *gnoNativeService) Render(ctx context.Context, req *connect.Request[api_gen.RenderRequest]) (*connect.Response[api_gen.RenderResponse], error) {
s.logger.Debug("Render", zap.String("packagePath", req.Msg.PackagePath), zap.String("args", req.Msg.Args))
result, _, err := s.client.Render(req.Msg.PackagePath, req.Msg.Args)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.RenderResponse{Result: result}), nil
}
func (s *gnoNativeService) QEval(ctx context.Context, req *connect.Request[api_gen.QEvalRequest]) (*connect.Response[api_gen.QEvalResponse], error) {
s.logger.Debug("QEval", zap.String("packagePath", req.Msg.PackagePath), zap.String("expression", req.Msg.Expression))
result, _, err := s.client.QEval(req.Msg.PackagePath, req.Msg.Expression)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.QEvalResponse{Result: result}), nil
}
func (s *gnoNativeService) Call(ctx context.Context, req *connect.Request[api_gen.CallRequest], stream *connect.ServerStream[api_gen.CallResponse]) error {
for _, msg := range req.Msg.Msgs {
s.logger.Debug("Call", zap.String("package", msg.PackagePath), zap.String("function", msg.Fnc), zap.Any("args", msg.Args))
}
s.lock.RLock()
if s.activeAccount == nil {
s.lock.RUnlock()
return api_gen.ErrCode_ErrNoActiveAccount
}
s.lock.RUnlock()
cfg := gnoclient.BaseTxCfg{
GasFee: req.Msg.GasFee,
GasWanted: req.Msg.GasWanted,
Memo: req.Msg.Memo,
}
msgs := make([]gnoclient.MsgCall, 0)
for _, msg := range req.Msg.Msgs {
msgs = append(msgs, gnoclient.MsgCall{
PkgPath: msg.PackagePath,
FuncName: msg.Fnc,
Args: msg.Args,
Send: msg.Send,
})
}
bres, err := s.client.Call(cfg, msgs...)
if err != nil {
return getGrpcError(err)
}
if err := stream.Send(&api_gen.CallResponse{
Result: bres.DeliverTx.Data,
}); err != nil {
s.logger.Error("Call stream.Send returned error", zap.Error(err))
return err
}
return nil
}
func (s *gnoNativeService) Send(ctx context.Context, req *connect.Request[api_gen.SendRequest], stream *connect.ServerStream[api_gen.SendResponse]) error {
for _, msg := range req.Msg.Msgs {
s.logger.Debug("Send", zap.String("toAddress", crypto.AddressToBech32(crypto.AddressFromBytes(msg.ToAddress))), zap.String("send", msg.Send))
}
s.lock.RLock()
if s.activeAccount == nil {
s.lock.RUnlock()
return api_gen.ErrCode_ErrNoActiveAccount
}
s.lock.RUnlock()
cfg := gnoclient.BaseTxCfg{
GasFee: req.Msg.GasFee,
GasWanted: req.Msg.GasWanted,
Memo: req.Msg.Memo,
}
msgs := make([]gnoclient.MsgSend, 0)
for _, msg := range req.Msg.Msgs {
msgs = append(msgs, gnoclient.MsgSend{
ToAddress: crypto.AddressFromBytes(msg.ToAddress),
Send: msg.Send,
})
}
_, err := s.client.Send(cfg, msgs...)
if err != nil {
return getGrpcError(err)
}
if err := stream.Send(&api_gen.SendResponse{}); err != nil {
s.logger.Error("Send stream.Send returned error", zap.Error(err))
return err
}
return nil
}
func (s *gnoNativeService) Run(ctx context.Context, req *connect.Request[api_gen.RunRequest], stream *connect.ServerStream[api_gen.RunResponse]) error {
s.lock.RLock()
if s.activeAccount == nil {
s.lock.RUnlock()
return api_gen.ErrCode_ErrNoActiveAccount
}
s.lock.RUnlock()
cfg := gnoclient.BaseTxCfg{
GasFee: req.Msg.GasFee,
GasWanted: req.Msg.GasWanted,
Memo: req.Msg.Memo,
}
msgs := make([]gnoclient.MsgRun, 0)
for _, msg := range req.Msg.Msgs {
memPkg := &std.MemPackage{
Files: []*std.MemFile{
{
Name: "main.gno",
Body: msg.Package,
},
},
}
msgs = append(msgs, gnoclient.MsgRun{
Package: memPkg,
Send: msg.Send,
})
}
bres, err := s.client.Run(cfg, msgs...)
if err != nil {
return getGrpcError(err)
}
if err := stream.Send(&api_gen.RunResponse{
Result: string(bres.DeliverTx.Data),
}); err != nil {
s.logger.Error("Run stream.Send returned error", zap.Error(err))
return err
}
return nil
}
func (s *gnoNativeService) AddressToBech32(ctx context.Context, req *connect.Request[api_gen.AddressToBech32Request]) (*connect.Response[api_gen.AddressToBech32Response], error) {
s.logger.Debug("AddressToBech32", zap.ByteString("address", req.Msg.Address))
bech32Address := crypto.AddressToBech32(crypto.AddressFromBytes(req.Msg.Address))
return connect.NewResponse(&api_gen.AddressToBech32Response{Bech32Address: bech32Address}), nil
}
func (s *gnoNativeService) AddressFromBech32(ctx context.Context, req *connect.Request[api_gen.AddressFromBech32Request]) (*connect.Response[api_gen.AddressFromBech32Response], error) {
address, err := crypto.AddressFromBech32(req.Msg.Bech32Address)
if err != nil {
return nil, err
}
return connect.NewResponse(&api_gen.AddressFromBech32Response{Address: address.Bytes()}), nil
}
func (s *gnoNativeService) Hello(ctx context.Context, req *connect.Request[api_gen.HelloRequest]) (*connect.Response[api_gen.HelloResponse], error) {
s.logger.Debug("Hello called")
defer s.logger.Debug("Hello returned ok")
return connect.NewResponse(&api_gen.HelloResponse{
Greeting: "Hello " + req.Msg.Name,
}), nil
}
// HelloStream is for debug purposes
func (s *gnoNativeService) HelloStream(ctx context.Context, req *connect.Request[api_gen.HelloStreamRequest], stream *connect.ServerStream[api_gen.HelloStreamResponse]) error {
s.logger.Debug("HelloStream called")
for i := 0; i < 4; i++ {
if err := stream.Send(&api_gen.HelloStreamResponse{
Greeting: "Hello " + req.Msg.Name,
}); err != nil {
s.logger.Error("HelloStream returned error", zap.Error(err))
return err
}
time.Sleep(2 * time.Second)
}
s.logger.Debug("HelloStream returned ok")
return nil
}
// If err is a recognized Go error, return the equivalent Grpc error.
// Otherwise, just return err.
func getGrpcError(err error) error {
if keyerror.IsErrKeyNotFound(err) {
return api_gen.ErrCode_ErrCryptoKeyNotFound
} else if keyerror.IsErrWrongPassword(err) {
return api_gen.ErrCode_ErrDecryptionFailed
}
// The following match errors in https://github.com/gnolang/gno/blob/master/tm2/pkg/std/errors.go .
if errors.As(err, &std.TxDecodeError{}) {
return api_gen.ErrCode_ErrTxDecode
} else if errors.As(err, &std.InvalidSequenceError{}) {
return api_gen.ErrCode_ErrInvalidSequence
} else if errors.As(err, &std.UnauthorizedError{}) {
return api_gen.ErrCode_ErrUnauthorized
} else if errors.As(err, &std.InsufficientFundsError{}) {
return api_gen.ErrCode_ErrInsufficientFunds
} else if errors.As(err, &std.UnknownRequestError{}) {
return api_gen.ErrCode_ErrUnknownRequest
} else if errors.As(err, &std.InvalidAddressError{}) {
return api_gen.ErrCode_ErrInvalidAddress
} else if errors.As(err, &std.UnknownAddressError{}) {
return api_gen.ErrCode_ErrUnknownAddress
} else if errors.As(err, &std.InvalidPubKeyError{}) {
return api_gen.ErrCode_ErrInvalidPubKey
} else if errors.As(err, &std.InsufficientCoinsError{}) {
return api_gen.ErrCode_ErrInsufficientCoins
} else if errors.As(err, &std.InvalidCoinsError{}) {
return api_gen.ErrCode_ErrInvalidCoins
} else if errors.As(err, &std.InvalidGasWantedError{}) {
return api_gen.ErrCode_ErrInvalidGasWanted
} else if errors.As(err, &std.OutOfGasError{}) {
return api_gen.ErrCode_ErrOutOfGas
} else if errors.As(err, &std.MemoTooLargeError{}) {
return api_gen.ErrCode_ErrMemoTooLarge
} else if errors.As(err, &std.InsufficientFeeError{}) {
return api_gen.ErrCode_ErrInsufficientFee
} else if errors.As(err, &std.TooManySignaturesError{}) {
return api_gen.ErrCode_ErrTooManySignatures
} else if errors.As(err, &std.NoSignaturesError{}) {
return api_gen.ErrCode_ErrNoSignatures
} else if errors.As(err, &std.GasOverflowError{}) {
return api_gen.ErrCode_ErrGasOverflow
} else {
return err
}
}