From 4270b0d0de9dfaed5dab831fd23747394955970b Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Tue, 22 Oct 2024 16:22:36 +0700 Subject: [PATCH] add grpc client --- client/grpc_client.go | 5 ++--- go.mod | 2 +- main.go | 12 ++++++------ nodes.toml | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/client/grpc_client.go b/client/grpc_client.go index 029e629..de0cec2 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -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 { diff --git a/go.mod b/go.mod index a76acd4..913cc8f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/main.go b/main.go index 26ca152..41b2c0e 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,7 @@ func main() { sequence++ start := time.Now() - resp, _, err := sendTransactionWithRetry( + resp, err := sendTransactionWithRetry( config, nodeURL, chainID, @@ -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, @@ -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++ { @@ -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(): @@ -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) } diff --git a/nodes.toml b/nodes.toml index 964dc15..435cadb 100644 --- a/nodes.toml +++ b/nodes.toml @@ -15,7 +15,7 @@ revision_number = 4 timeout_height = 21720608 slip44 = 118 -msg_type = "bank_send" +msg_type = "store_code" [msg_params] @@ -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"