Skip to content

Commit

Permalink
add grpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Oct 22, 2024
1 parent 0f8b8b4 commit 4270b0d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package client
import (
"context"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

sdk "github.com/cosmos/cosmos-sdk/types"
tx "github.com/cosmos/cosmos-sdk/types/tx"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type GRPCClient struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ require (
google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {
sequence++

start := time.Now()
resp, _, err := sendTransactionWithRetry(
resp, err := sendTransactionWithRetry(
config,
nodeURL,
chainID,
Expand Down Expand Up @@ -93,7 +93,7 @@ func main() {
// Re-send the transaction with the correct sequence
currentSequence = sequence
sequence++
resp, _, err := sendTransactionWithRetry(
resp, err := sendTransactionWithRetry(
config,
nodeURL,
chainID,
Expand Down Expand Up @@ -143,7 +143,7 @@ func main() {
}
}

func sendTransactionWithRetry(config types.Config, nodeURL, chainID string, sequence, accNum uint64, privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, acctAddress, msgType string, msgParams types.MsgParams) (*coretypes.ResultBroadcastTx, string, error) {
func sendTransactionWithRetry(config types.Config, nodeURL, chainID string, sequence, accNum uint64, privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, acctAddress, msgType string, msgParams types.MsgParams) (*coretypes.ResultBroadcastTx, error) {
var lastErr error
startTime := time.Now()
for retry := 0; retry < MaxRetries; retry++ {
Expand Down Expand Up @@ -178,7 +178,7 @@ func sendTransactionWithRetry(config types.Config, nodeURL, chainID string, sequ

select {
case resp := <-respChan:
return resp, "", nil
return resp, nil
case err := <-errChan:
lastErr = err
case <-ctx.Done():
Expand All @@ -189,12 +189,12 @@ func sendTransactionWithRetry(config types.Config, nodeURL, chainID string, sequ
fmt.Printf("%s Retry %d failed after %v: %v\n", time.Now().Format("15:04:05"), retry, attemptDuration, lastErr)

if time.Since(startTime) > 2*time.Second {
return nil, "", fmt.Errorf("total retry time exceeded 1 second")
return nil, fmt.Errorf("total retry time exceeded 1 second")
}

time.Sleep(TimeoutDuration)
}

totalDuration := time.Since(startTime)
return nil, "", fmt.Errorf("failed after %d retries in %v: %v", MaxRetries, totalDuration, lastErr)
return nil, fmt.Errorf("failed after %d retries in %v: %v", MaxRetries, totalDuration, lastErr)
}
6 changes: 3 additions & 3 deletions nodes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ revision_number = 4
timeout_height = 21720608
slip44 = 118

msg_type = "bank_send"
msg_type = "store_code"

[msg_params]

Expand All @@ -24,8 +24,8 @@ to_address = ""


#[msg_params]
#wasm_file = "/Users/faddat/hardhat/target/wasm32-unknown-unknown/release/statefilestore.wasm"
#label = "statefilestore"
wasm_file = "/Users/faddat/hardhat/target/wasm32-unknown-unknown/release/statefilestore.wasm"
label = "statefilestore"

#msg_type = "instantiate_contract"

Expand Down

0 comments on commit 4270b0d

Please sign in to comment.