forked from sei-protocol/sei-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.go
76 lines (71 loc) · 1.83 KB
/
tx.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
package main
import (
"context"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
typestx "github.com/cosmos/cosmos-sdk/types/tx"
)
func SendTx(
key cryptotypes.PrivKey,
txBuilder *client.TxBuilder,
mode typestx.BroadcastMode,
seqDelta uint64,
failureExpected bool,
loadtestClient LoadTestClient,
gas uint64,
fee int64,
) func() {
(*txBuilder).SetGasLimit(gas)
(*txBuilder).SetFeeAmount([]sdk.Coin{
sdk.NewCoin("usei", sdk.NewInt(fee)),
})
loadtestClient.SignerClient.SignTx(loadtestClient.ChainID, txBuilder, key, seqDelta)
txBytes, _ := TestConfig.TxConfig.TxEncoder()((*txBuilder).GetTx())
return func() {
grpcRes, err := loadtestClient.TxClient.BroadcastTx(
context.Background(),
&typestx.BroadcastTxRequest{
Mode: mode,
TxBytes: txBytes,
},
)
if err != nil {
if failureExpected {
fmt.Printf("Error: %s\n", err)
} else {
panic(err)
}
if grpcRes == nil || grpcRes.TxResponse == nil {
return
}
}
for grpcRes.TxResponse.Code == sdkerrors.ErrMempoolIsFull.ABCICode() {
// retry after a second until either succeed or fail for some other reason
fmt.Printf("Mempool full\n")
time.Sleep(1 * time.Second)
grpcRes, err = loadtestClient.TxClient.BroadcastTx(
context.Background(),
&typestx.BroadcastTxRequest{
Mode: mode,
TxBytes: txBytes,
},
)
if err != nil {
if failureExpected {
fmt.Printf("key=%s error=%s\n", key.PubKey().Address().String(), err)
} else {
panic(err)
}
}
}
if grpcRes.TxResponse.Code != 0 {
fmt.Printf("Error: %d, %s\n", grpcRes.TxResponse.Code, grpcRes.TxResponse.RawLog)
} else {
loadtestClient.AppendTxHash(grpcRes.TxResponse.TxHash)
}
}
}