Skip to content

Commit 7dedad3

Browse files
author
a-ok123
committed
feat: update error handling in client initialization and hash computation, and comment out coverage upload steps
1 parent 4669399 commit 7dedad3

10 files changed

Lines changed: 31 additions & 23 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ jobs:
6363
- name: Run tests
6464
run: go test -v -race -coverprofile=coverage.out ./...
6565

66-
- name: Upload coverage
67-
uses: codecov/codecov-action@v3
68-
with:
69-
file: ./coverage.out
66+
# - name: Upload coverage
67+
# uses: codecov/codecov-action@v3
68+
# with:
69+
# file: ./coverage.out
7070

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
- name: Run tests
3636
run: go test -v -race -coverprofile=coverage.out ./...
3737

38-
- name: Upload coverage
39-
uses: codecov/codecov-action@v3
40-
with:
41-
file: ./coverage.out
38+
# - name: Upload coverage
39+
# uses: codecov/codecov-action@v3
40+
# with:
41+
# file: ./coverage.out
4242

blockchain/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"sync"
88
"time"
99

10-
sdk "github.com/cosmos/cosmos-sdk/types"
1110
"github.com/cosmos/cosmos-sdk/crypto/keyring"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
1212
"google.golang.org/grpc"
1313
"google.golang.org/grpc/credentials"
1414
"google.golang.org/grpc/credentials/insecure"
@@ -67,7 +67,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
6767
// Determine if we should use TLS based on the endpoint
6868
// Use TLS if: port is 443, or hostname doesn't start with "localhost"/"127.0.0.1"
6969
useTLS := shouldUseTLS(cfg.GRPCAddr)
70-
70+
7171
var creds credentials.TransportCredentials
7272
if useTLS {
7373
// Use system TLS credentials for secure connections
@@ -76,7 +76,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
7676
// Use insecure credentials for local development
7777
creds = insecure.NewCredentials()
7878
}
79-
79+
8080
// Create gRPC connection
8181
dialOpts := []grpc.DialOption{
8282
grpc.WithTransportCredentials(creds),
@@ -86,7 +86,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
8686
),
8787
}
8888

89-
conn, err := grpc.DialContext(ctx, cfg.GRPCAddr, dialOpts...)
89+
conn, err := grpc.NewClient(cfg.GRPCAddr, dialOpts...)
9090
if err != nil {
9191
return nil, fmt.Errorf("failed to connect to gRPC: %w", err)
9292
}
@@ -126,23 +126,23 @@ func shouldUseTLS(addr string) bool {
126126
if strings.HasSuffix(addr, ":443") {
127127
return true
128128
}
129-
129+
130130
// Check if it's a local address (localhost, 127.0.0.1, or no hostname)
131131
if strings.HasPrefix(addr, "localhost:") ||
132132
strings.HasPrefix(addr, "127.0.0.1:") ||
133133
strings.HasPrefix(addr, "0.0.0.0:") ||
134134
strings.HasPrefix(addr, ":") { // Just port, implies localhost
135135
return false
136136
}
137-
137+
138138
// For any other remote address, prefer TLS by default for security
139139
// This covers domain names without explicit port 443
140140
if !strings.Contains(addr, "localhost") &&
141141
!strings.Contains(addr, "127.0.0.1") &&
142142
!strings.Contains(addr, "0.0.0.0") {
143143
return true
144144
}
145-
145+
146146
return false
147147
}
148148

blockchain/tx.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ func (c *Client) BuildAndSignTx(ctx context.Context, msg sdk.Msg, memo string) (
124124
}
125125
builder.SetGasLimit(gas)
126126

127-
builder.SetSignatures() // clear placeholder signature
127+
err = builder.SetSignatures() // clear placeholder signature
128+
if err != nil {
129+
return nil, fmt.Errorf("clear placeholder signature: %w", err)
130+
}
128131

129132
// Ensure a minimum fee to satisfy chain requirements
130133
fee := int64(math.Ceil(float64(gas) / 40.0)) //the gas price is 0.025

client/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, opts ...Option) (*
5454
Timeout: cfg.StorageTimeout,
5555
}, kr)
5656
if err != nil {
57-
blockchainClient.Close()
57+
err = blockchainClient.Close()
58+
if err != nil {
59+
return nil, fmt.Errorf("cascade init failed: %v; also failed to close blockchain client: %w", err, err)
60+
}
5861
return nil, fmt.Errorf("failed to initialize cascade client: %w", err)
5962
}
6063

examples/cascade-download/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func main() {
5757
if err != nil {
5858
log.Fatalf("Failed to create client: %v", err)
5959
}
60-
defer client.Close()
60+
defer client.Close() //nolint:errcheck
6161

6262
fmt.Println("Downloading file...")
6363
result, err := client.Cascade.Download(ctx, *actionID, *outputDir)

examples/cascade-upload/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func main() {
5151
if err != nil {
5252
log.Fatalf("Failed to create client: %v", err)
5353
}
54-
defer client.Close()
54+
defer client.Close() //nolint:errcheck
5555

5656
fmt.Println("Uploading file...")
5757
opts := []cascade.UploadOption{cascade.WithPublic(*public)}

examples/claim-tokens/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141
if err != nil {
4242
log.Fatalf("Failed to create client: %v", err)
4343
}
44-
defer client.Close()
44+
defer client.Close() //nolint:errcheck
4545

4646
fmt.Println("Claim tokens example - to be implemented")
4747
fmt.Println("This example will demonstrate claiming tokens from the old chain")

examples/query-actions/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
if err != nil {
5050
log.Fatalf("Failed to create client: %v", err)
5151
}
52-
defer client.Close()
52+
defer client.Close() //nolint:errcheck
5353

5454
if id := strings.TrimSpace(*actionID); id != "" {
5555
// Query a specific action

internal/utils/hash.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
// HashFile computes the Blake3 hash of a file
88
func HashFile(data []byte) []byte {
99
hasher := blake3.New(32, nil)
10-
hasher.Write(data)
10+
_, err := hasher.Write(data)
11+
if err != nil {
12+
return nil
13+
}
1114
return hasher.Sum(nil)
1215
}
13-

0 commit comments

Comments
 (0)