-
Notifications
You must be signed in to change notification settings - Fork 349
/
Copy pathtx_client.go
675 lines (589 loc) · 20.2 KB
/
tx_client.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
package user
import (
"bytes"
"context"
"errors"
"fmt"
"math"
"strconv"
"strings"
"sync"
"time"
"github.com/celestiaorg/go-square/v2/share"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdktypes "github.com/cosmos/cosmos-sdk/types"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/rpc/core"
"google.golang.org/grpc"
"github.com/celestiaorg/celestia-app/v3/app"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
"github.com/celestiaorg/celestia-app/v3/app/grpc/tx"
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/celestia-app/v3/x/minfee"
)
const (
DefaultPollTime = 3 * time.Second
DefaultGasMultiplier float64 = 1.1
txTrackerPruningInterval = 10 * time.Minute
)
type Option func(client *TxClient)
// txInfo is a struct that holds the sequence and the signer of a transaction
// in the local tx pool.
type txInfo struct {
sequence uint64
signer string
timestamp time.Time
}
// TxResponse is a response from the chain after
// a transaction has been submitted.
type TxResponse struct {
// Height is the block height at which the transaction was included on-chain.
Height int64
TxHash string
Code uint32
}
// BroadcastTxError is an error that occurs when broadcasting a transaction.
type BroadcastTxError struct {
TxHash string
Code uint32
// ErrorLog is the error output of the app's logger
ErrorLog string
}
func (e *BroadcastTxError) Error() string {
return fmt.Sprintf("broadcast tx error: %s", e.ErrorLog)
}
// ExecutionError is an error that occurs when a transaction gets executed.
type ExecutionError struct {
TxHash string
Code uint32
// ErrorLog is the error output of the app's logger
ErrorLog string
}
func (e *ExecutionError) Error() string {
return fmt.Sprintf("tx execution failed with code %d: %s", e.Code, e.ErrorLog)
}
// WithGasMultiplier is a functional option allows to configure the gas multiplier.
func WithGasMultiplier(multiplier float64) Option {
return func(c *TxClient) {
c.gasMultiplier = multiplier
}
}
// WithDefaultGasPrice sets the gas price.
func WithDefaultGasPrice(price float64) Option {
return func(c *TxClient) {
c.defaultGasPrice = price
}
}
func WithPollTime(time time.Duration) Option {
return func(c *TxClient) {
c.pollTime = time
}
}
func WithDefaultAddress(address sdktypes.AccAddress) Option {
return func(c *TxClient) {
record, err := c.signer.keys.KeyByAddress(address)
if err != nil {
panic(err)
}
c.defaultAccount = record.Name
c.defaultAddress = address
}
}
func WithDefaultAccount(name string) Option {
return func(c *TxClient) {
rec, err := c.signer.keys.Key(name)
if err != nil {
panic(err)
}
addr, err := rec.GetAddress()
if err != nil {
panic(err)
}
c.defaultAccount = name
c.defaultAddress = addr
}
}
// TxClient is an abstraction for building, signing, and broadcasting Celestia transactions
// It supports multiple accounts. If none is specified, it will
// try use the default account.
// TxClient is thread-safe.
type TxClient struct {
mtx sync.Mutex
signer *Signer
registry codectypes.InterfaceRegistry
grpc *grpc.ClientConn
// how often to poll the network for confirmation of a transaction
pollTime time.Duration
// gasMultiplier is used to increase gas limit as it is sometimes underestimated
gasMultiplier float64
// defaultGasPrice is the price used if no price is provided
defaultGasPrice float64
defaultAccount string
defaultAddress sdktypes.AccAddress
// txTracker maps the tx hash to the Sequence and signer of the transaction
// that was submitted to the chain
txTracker map[string]txInfo
}
// NewTxClient returns a new signer using the provided keyring
func NewTxClient(
signer *Signer,
conn *grpc.ClientConn,
registry codectypes.InterfaceRegistry,
options ...Option,
) (*TxClient, error) {
records, err := signer.keys.List()
if err != nil {
return nil, fmt.Errorf("retrieving keys: %w", err)
}
if len(records) == 0 {
return nil, errors.New("signer must have at least one key")
}
addr, err := records[0].GetAddress()
if err != nil {
return nil, err
}
txClient := &TxClient{
signer: signer,
registry: registry,
grpc: conn,
pollTime: DefaultPollTime,
gasMultiplier: DefaultGasMultiplier,
defaultGasPrice: appconsts.DefaultMinGasPrice,
defaultAccount: records[0].Name,
defaultAddress: addr,
txTracker: make(map[string]txInfo),
}
for _, opt := range options {
opt(txClient)
}
return txClient, nil
}
// SetupTxClient uses the underlying grpc connection to populate the chainID, accountNumber and sequence number of all
// the accounts in the keyring.
func SetupTxClient(
ctx context.Context,
keys keyring.Keyring,
conn *grpc.ClientConn,
encCfg encoding.Config,
options ...Option,
) (*TxClient, error) {
resp, err := tmservice.NewServiceClient(conn).GetLatestBlock(
ctx,
&tmservice.GetLatestBlockRequest{},
)
if err != nil {
return nil, err
}
chainID := resp.SdkBlock.Header.ChainID
appVersion := resp.SdkBlock.Header.Version.App
records, err := keys.List()
if err != nil {
return nil, err
}
accounts := make([]*Account, 0, len(records))
for _, record := range records {
addr, err := record.GetAddress()
if err != nil {
return nil, err
}
accNum, seqNum, err := QueryAccount(ctx, conn, encCfg.InterfaceRegistry, addr)
if err != nil {
// skip over the accounts that don't exist in state
continue
}
accounts = append(accounts, NewAccount(record.Name, accNum, seqNum))
}
// query the min gas price from the chain
minPrice, err := QueryMinimumGasPrice(ctx, conn)
if err != nil {
return nil, fmt.Errorf("querying minimum gas price: %w", err)
}
options = append([]Option{WithDefaultGasPrice(minPrice)}, options...)
signer, err := NewSigner(keys, encCfg.TxConfig, chainID, appVersion, accounts...)
if err != nil {
return nil, fmt.Errorf("failed to create signer: %w", err)
}
return NewTxClient(signer, conn, encCfg.InterfaceRegistry, options...)
}
// SubmitPayForBlob forms a transaction from the provided blobs, signs it, and submits it to the chain.
// TxOptions may be provided to set the fee and gas limit.
func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastPayForBlob(ctx, blobs, opts...)
if err != nil {
return nil, err
}
return client.ConfirmTx(ctx, resp.TxHash)
}
// SubmitPayForBlobWithAccount forms a transaction from the provided blobs, signs it with the provided account, and submits it to the chain.
// TxOptions may be provided to set the fee and gas limit.
func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastPayForBlobWithAccount(ctx, account, blobs, opts...)
if err != nil {
return nil, err
}
return client.ConfirmTx(ctx, resp.TxHash)
}
// BroadcastPayForBlob signs and broadcasts a transaction to pay for blobs.
// It does not confirm that the transaction has been committed on chain.
// If no gas or gas price is set, it will estimate the gas and use
// the max effective gas price: max(localMinGasPrice, networkMinGasPrice).
func (client *TxClient) BroadcastPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) {
return client.BroadcastPayForBlobWithAccount(ctx, client.defaultAccount, blobs, opts...)
}
func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) {
client.mtx.Lock()
defer client.mtx.Unlock()
if err := client.checkAccountLoaded(ctx, account); err != nil {
return nil, err
}
blobSizes := make([]uint32, len(blobs))
for i, blob := range blobs {
blobSizes[i] = uint32(len(blob.Data()))
}
gasLimit := uint64(float64(types.DefaultEstimateGas(blobSizes)) * client.gasMultiplier)
fee := uint64(math.Ceil(appconsts.DefaultMinGasPrice * float64(gasLimit)))
// prepend calculated params, so it can be overwritten in case the user has specified it.
opts = append([]TxOption{SetGasLimit(gasLimit), SetFee(fee)}, opts...)
txBytes, _, err := client.signer.CreatePayForBlobs(account, blobs, opts...)
if err != nil {
return nil, err
}
return client.broadcastTx(ctx, txBytes, account)
}
// SubmitTx forms a transaction from the provided messages, signs it, and submits it to the chain. TxOptions
// may be provided to set the fee and gas limit.
func (client *TxClient) SubmitTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastTx(ctx, msgs, opts...)
if err != nil {
return nil, err
}
return client.ConfirmTx(ctx, resp.TxHash)
}
func (client *TxClient) BroadcastTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (*sdktypes.TxResponse, error) {
client.mtx.Lock()
defer client.mtx.Unlock()
// prune transactions that are older than 10 minutes
// pruning has to be done in broadcast, since users
// might not always call ConfirmTx().
client.pruneTxTracker()
account, err := client.getAccountNameFromMsgs(msgs)
if err != nil {
return nil, err
}
if err := client.checkAccountLoaded(ctx, account); err != nil {
return nil, err
}
txBuilder, err := client.signer.txBuilder(msgs, opts...)
if err != nil {
return nil, err
}
hasUserSetFee := false
for _, coin := range txBuilder.GetTx().GetFee() {
if coin.Denom == appconsts.BondDenom {
hasUserSetFee = true
break
}
}
gasLimit := txBuilder.GetTx().GetGas()
if gasLimit == 0 {
if !hasUserSetFee {
// add at least 1utia as fee to builder as it affects gas calculation.
txBuilder.SetFeeAmount(sdktypes.NewCoins(sdktypes.NewCoin(appconsts.BondDenom, sdktypes.NewInt(1))))
}
gasLimit, err = client.estimateGas(ctx, txBuilder)
if err != nil {
return nil, err
}
txBuilder.SetGasLimit(gasLimit)
}
if !hasUserSetFee {
fee := int64(math.Ceil(appconsts.DefaultMinGasPrice * float64(gasLimit)))
txBuilder.SetFeeAmount(sdktypes.NewCoins(sdktypes.NewCoin(appconsts.BondDenom, sdktypes.NewInt(fee))))
}
account, _, err = client.signer.signTransaction(txBuilder)
if err != nil {
return nil, err
}
txBytes, err := client.signer.EncodeTx(txBuilder.GetTx())
if err != nil {
return nil, err
}
return client.broadcastTx(ctx, txBytes, account)
}
func (client *TxClient) broadcastTx(ctx context.Context, txBytes []byte, signer string) (*sdktypes.TxResponse, error) {
txClient := sdktx.NewServiceClient(client.grpc)
resp, err := txClient.BroadcastTx(
ctx,
&sdktx.BroadcastTxRequest{
Mode: sdktx.BroadcastMode_BROADCAST_MODE_SYNC,
TxBytes: txBytes,
},
)
if err != nil {
return nil, err
}
if resp.TxResponse.Code != abci.CodeTypeOK {
broadcastTxErr := &BroadcastTxError{
TxHash: resp.TxResponse.TxHash,
Code: resp.TxResponse.Code,
ErrorLog: resp.TxResponse.RawLog,
}
return nil, broadcastTxErr
}
// save the sequence and signer of the transaction in the local txTracker
// before the sequence is incremented
client.txTracker[resp.TxResponse.TxHash] = txInfo{
sequence: client.signer.accounts[signer].Sequence(),
signer: signer,
timestamp: time.Now(),
}
// after the transaction has been submitted, we can increment the
// sequence of the signer
if err := client.signer.IncrementSequence(signer); err != nil {
return nil, fmt.Errorf("increment sequencing: %w", err)
}
return resp.TxResponse, nil
}
// pruneTxTracker removes transactions from the local tx tracker that are older than 10 minutes
func (client *TxClient) pruneTxTracker() {
for hash, txInfo := range client.txTracker {
if time.Since(txInfo.timestamp) >= txTrackerPruningInterval {
delete(client.txTracker, hash)
}
}
}
// ConfirmTx periodically pings the provided node for the commitment of a transaction by its
// hash. It will continually loop until the context is cancelled, the tx is found or an error
// is encountered.
func (client *TxClient) ConfirmTx(ctx context.Context, txHash string) (*TxResponse, error) {
txClient := tx.NewTxClient(client.grpc)
pollTicker := time.NewTicker(client.pollTime)
defer pollTicker.Stop()
for {
resp, err := txClient.TxStatus(ctx, &tx.TxStatusRequest{TxId: txHash})
if err != nil {
return nil, err
}
switch resp.Status {
case core.TxStatusPending:
// Continue polling if the transaction is still pending
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-pollTicker.C:
continue
}
case core.TxStatusCommitted:
txResponse := &TxResponse{
Height: resp.Height,
TxHash: txHash,
Code: resp.ExecutionCode,
}
if resp.ExecutionCode != abci.CodeTypeOK {
executionErr := &ExecutionError{
TxHash: txHash,
Code: resp.ExecutionCode,
ErrorLog: resp.Error,
}
client.deleteFromTxTracker(txHash)
return nil, executionErr
}
client.deleteFromTxTracker(txHash)
return txResponse, nil
case core.TxStatusEvicted:
return nil, client.handleEvictions(txHash)
default:
client.deleteFromTxTracker(txHash)
return nil, fmt.Errorf("transaction with hash %s not found; it was likely rejected", txHash)
}
}
}
// handleEvictions handles the scenario where a transaction is evicted from the mempool.
// It removes the evicted transaction from the local tx tracker without incrementing
// the signer's sequence.
func (client *TxClient) handleEvictions(txHash string) error {
client.mtx.Lock()
defer client.mtx.Unlock()
// Get transaction from the local tx tracker
txInfo, exists := client.txTracker[txHash]
if !exists {
return fmt.Errorf("tx: %s not found in tx client txTracker; likely failed during broadcast", txHash)
}
// The sequence should be rolled back to the sequence of the transaction that was evicted to be
// ready for resubmission. All transactions with a later nonce will be kicked by the nodes tx pool.
if err := client.signer.SetSequence(txInfo.signer, txInfo.sequence); err != nil {
return fmt.Errorf("setting sequence: %w", err)
}
delete(client.txTracker, txHash)
return fmt.Errorf("tx was evicted from the mempool")
}
// deleteFromTxTracker safely deletes a transaction from the local tx tracker.
func (client *TxClient) deleteFromTxTracker(txHash string) {
client.mtx.Lock()
defer client.mtx.Unlock()
delete(client.txTracker, txHash)
}
// EstimateGas simulates the transaction, calculating the amount of gas that was consumed during execution. The final
// result will be multiplied by gasMultiplier(that is set in TxClient)
func (client *TxClient) EstimateGas(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (uint64, error) {
client.mtx.Lock()
defer client.mtx.Unlock()
txBuilder, err := client.signer.txBuilder(msgs, opts...)
if err != nil {
return 0, err
}
return client.estimateGas(ctx, txBuilder)
}
func (client *TxClient) estimateGas(ctx context.Context, txBuilder client.TxBuilder) (uint64, error) {
// add at least 1utia as fee to builder as it affects gas calculation.
txBuilder.SetFeeAmount(sdktypes.NewCoins(sdktypes.NewCoin(appconsts.BondDenom, sdktypes.NewInt(1))))
_, _, err := client.signer.signTransaction(txBuilder)
if err != nil {
return 0, err
}
txBytes, err := client.signer.EncodeTx(txBuilder.GetTx())
if err != nil {
return 0, err
}
resp, err := sdktx.NewServiceClient(client.grpc).Simulate(ctx, &sdktx.SimulateRequest{
TxBytes: txBytes,
})
if err != nil {
return 0, err
}
gasLimit := uint64(float64(resp.GasInfo.GasUsed) * client.gasMultiplier)
return gasLimit, nil
}
// Account returns an account of the signer from the key name. Also returns a bool if the
// account exists.
// Thread-safe
func (client *TxClient) Account(name string) *Account {
client.mtx.Lock()
defer client.mtx.Unlock()
acc, exists := client.signer.accounts[name]
if !exists {
return nil
}
return acc.Copy()
}
func (client *TxClient) AccountByAddress(address sdktypes.AccAddress) *Account {
client.mtx.Lock()
defer client.mtx.Unlock()
return client.signer.AccountByAddress(address)
}
func (client *TxClient) DefaultAddress() sdktypes.AccAddress {
return client.defaultAddress
}
func (client *TxClient) DefaultAccountName() string { return client.defaultAccount }
func (client *TxClient) checkAccountLoaded(ctx context.Context, account string) error {
if _, exists := client.signer.accounts[account]; exists {
return nil
}
record, err := client.signer.keys.Key(account)
if err != nil {
return fmt.Errorf("trying to find account %s on keyring: %w", account, err)
}
addr, err := record.GetAddress()
if err != nil {
return fmt.Errorf("retrieving address from keyring: %w", err)
}
// FIXME: have a less trusting way of getting the account number and sequence
accNum, sequence, err := QueryAccount(ctx, client.grpc, client.registry, addr)
if err != nil {
return fmt.Errorf("querying account %s: %w", account, err)
}
return client.signer.AddAccount(NewAccount(account, accNum, sequence))
}
func (client *TxClient) getAccountNameFromMsgs(msgs []sdktypes.Msg) (string, error) {
var addr sdktypes.AccAddress
for _, msg := range msgs {
signers := msg.GetSigners()
if len(signers) != 1 {
return "", fmt.Errorf("only one signer per transaction supported, got %d", len(signers))
}
if addr == nil {
addr = signers[0]
}
if !bytes.Equal(addr, signers[0]) {
return "", errors.New("not supported: got two different signers across multiple messages")
}
}
record, err := client.signer.keys.KeyByAddress(addr)
if err != nil {
return "", err
}
return record.Name, nil
}
// GetTxFromTxTracker gets transaction info from the tx client's local tx tracker by its hash
func (client *TxClient) GetTxFromTxTracker(hash string) (sequence uint64, signer string, exists bool) {
client.mtx.Lock()
defer client.mtx.Unlock()
txInfo, exists := client.txTracker[hash]
return txInfo.sequence, txInfo.signer, exists
}
// Signer exposes the tx clients underlying signer
func (client *TxClient) Signer() *Signer {
return client.signer
}
func (client *TxClient) SetDefaultGasPrice(price float64) {
client.mtx.Lock()
defer client.mtx.Unlock()
client.defaultGasPrice = price
}
func (client *TxClient) SetGasMultiplier(multiplier float64) {
client.mtx.Lock()
defer client.mtx.Unlock()
client.gasMultiplier = multiplier
}
// QueryMinimumGasPrice queries both the nodes local and network wide
// minimum gas prices, returning the maximum of the two.
func QueryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {
cfgRsp, err := nodeservice.NewServiceClient(grpcConn).Config(ctx, &nodeservice.ConfigRequest{})
if err != nil {
return 0, err
}
localMinCoins, err := sdktypes.ParseDecCoins(cfgRsp.MinimumGasPrice)
if err != nil {
return 0, err
}
localMinPrice := localMinCoins.AmountOf(app.BondDenom).MustFloat64()
networkMinPrice, err := QueryNetworkMinGasPrice(ctx, grpcConn)
if err != nil {
// check if the network version supports a global min gas
// price using a regex check. If not (i.e. v1) use the
// local price only
if strings.Contains(err.Error(), "unknown subspace: minfee") {
return localMinPrice, nil
}
return 0, err
}
// return the highest value of the two
if networkMinPrice > localMinPrice {
return networkMinPrice, nil
}
return localMinPrice, nil
}
func QueryNetworkMinGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {
paramsClient := paramtypes.NewQueryClient(grpcConn)
// NOTE: that we don't prove that this is the correct value
paramResponse, err := paramsClient.Params(ctx, ¶mtypes.QueryParamsRequest{Subspace: minfee.ModuleName, Key: string(minfee.KeyNetworkMinGasPrice)})
if err != nil {
return 0, fmt.Errorf("querying params module: %w", err)
}
var networkMinPrice float64
// Value is empty if network min gas price is not supported i.e. v1 state machine.
if paramResponse.Param.Value != "" {
networkMinPrice, err = strconv.ParseFloat(strings.Trim(paramResponse.Param.Value, `"`), 64)
if err != nil {
return 0, fmt.Errorf("parsing network min gas price: %w", err)
}
}
return networkMinPrice, nil
}