Skip to content

Commit

Permalink
Merge pull request #18 from coinbase/marcin/linting-fixes
Browse files Browse the repository at this point in the history
Fixing some linting issues
  • Loading branch information
marcin-cb authored Aug 23, 2024
2 parents 3dd3244 + df2cf57 commit 0126f76
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Coinbase Go SDK Changelog

## [TBD] - TBD
## [0.0.1] - 2024-08-23

### Added

-
Initial release of the Coinbase Go SDK

- Support for Staking on External Wallets
- Full support for Shared ETH Staking
- Partial support for Dedicated ETH Staking
- Only stake is supported, unstake will be coming soon
- On networks `holesky` and `mainnet`
- Support for getting stakeable balances on External Wallets
- Support for Listing Rewards on External Wallets
8 changes: 7 additions & 1 deletion pkg/coinbase/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coinbase

import (
"net/http"
"time"

"github.com/coinbase/coinbase-sdk-go/gen/client"
"github.com/coinbase/coinbase-sdk-go/pkg/auth"
Expand Down Expand Up @@ -61,7 +62,12 @@ func NewClient(o ...ClientOption) (*Client, error) {
}
}
if c.baseHTTPClient == nil {
c.baseHTTPClient = http.DefaultClient
c.baseHTTPClient = &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
TLSHandshakeTimeout: 5 * time.Second,
},
}
}
c.cfg.HTTPClient = c.baseHTTPClient
if c.cfg.HTTPClient.Transport == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/coinbase/staking_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *StakingOperation) GetSignedVoluntaryExitMessages() ([]string, error) {
stakingOperationMetadata := s.model.GetMetadata().ArrayOfSignedVoluntaryExitMessageMetadata

if s.model.Metadata == nil {
return []string{}, nil
return nil, nil
}

for _, metadata := range *stakingOperationMetadata {
Expand Down
6 changes: 3 additions & 3 deletions pkg/coinbase/staking_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Client) ListStakingRewards(

// No addresses to fetch rewards for.
if len(addresses) == 0 {
return []StakingReward{}, nil
return nil, nil
}

// We're assuming the addresses will be all for the same networkId and assetId.
Expand All @@ -53,7 +53,7 @@ func (c *Client) ListStakingRewards(
// Get the asset.
asset, err := c.fetchAsset(ctx, networkId, assetId)
if err != nil {
return []StakingReward{}, err
return nil, err
}

// Create a list of address ids.
Expand All @@ -74,7 +74,7 @@ func (c *Client) ListStakingRewards(
// Get the rewards for the address ids.
resp, err := c.getRewards(ctx, page, rewardsReq)
if err != nil {
return []StakingReward{}, err
return nil, err
}

for _, stakingReward := range resp.GetData() {
Expand Down
11 changes: 7 additions & 4 deletions pkg/coinbase/staking_reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type mockController struct {

func TestListStakingRewards_Success(t *testing.T) {
tests := map[string]struct {
req ListRewardsRequest
setup func(*mockController)
req ListRewardsRequest
expectedRespLen int
setup func(*mockController)
}{
"happy path with no pages": {
req: ListRewardsRequest{
Expand All @@ -48,6 +49,7 @@ func TestListStakingRewards_Success(t *testing.T) {
mockFetchAsset(t, c.assetsAPI, http.StatusOK)
mockFetchStakingRewards(t, c.stakeAPI, http.StatusOK)
},
expectedRespLen: 1,
},
"happy path with a page": {
req: ListRewardsRequest{
Expand All @@ -65,17 +67,18 @@ func TestListStakingRewards_Success(t *testing.T) {
mockFetchAsset(t, c.assetsAPI, http.StatusOK)
mockFetchStakingRewardsWithPage(t, c.stakeAPI)
},
expectedRespLen: 2,
},
"happy path with no addresses": {
req: ListRewardsRequest{
assetId: "test-asset-id",
address: []Address{},
startTime: time.Now(),
endTime: time.Now(),
format: api.STAKINGREWARDFORMAT_USD,
},
setup: func(c *mockController) {
},
expectedRespLen: 0,
},
}

Expand Down Expand Up @@ -103,8 +106,8 @@ func TestListStakingRewards_Success(t *testing.T) {
tc.req.endTime,
tc.req.format,
)
assert.NotNilf(t, resp, "response should not be nil")
assert.NoError(t, err, "error should be nil")
assert.Equal(t, tc.expectedRespLen, len(resp), "response length should be 0")
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/coinbase/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"log"
"math/big"

"github.com/coinbase/coinbase-sdk-go/gen/client"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (t *Transaction) Sign(k *ecdsa.PrivateKey) error {

bytes, err := signedTx.MarshalBinary()
if err != nil {
log.Fatalf("error marshaling transaction: %v", err)
return err
}

signedPayload := hex.EncodeToString(bytes)
Expand Down

0 comments on commit 0126f76

Please sign in to comment.