diff --git a/CHANGELOG.md b/CHANGELOG.md index 9747c60..dd8ec4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/coinbase/client.go b/pkg/coinbase/client.go index cf91d40..2ca77b6 100644 --- a/pkg/coinbase/client.go +++ b/pkg/coinbase/client.go @@ -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" @@ -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 { diff --git a/pkg/coinbase/staking_operation.go b/pkg/coinbase/staking_operation.go index c6f1aa9..64c894a 100644 --- a/pkg/coinbase/staking_operation.go +++ b/pkg/coinbase/staking_operation.go @@ -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 { diff --git a/pkg/coinbase/staking_reward.go b/pkg/coinbase/staking_reward.go index 2368963..d3f4e1b 100644 --- a/pkg/coinbase/staking_reward.go +++ b/pkg/coinbase/staking_reward.go @@ -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. @@ -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. @@ -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() { diff --git a/pkg/coinbase/staking_reward_test.go b/pkg/coinbase/staking_reward_test.go index a51829f..73ba70d 100644 --- a/pkg/coinbase/staking_reward_test.go +++ b/pkg/coinbase/staking_reward_test.go @@ -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{ @@ -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{ @@ -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, }, } @@ -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") }) } } diff --git a/pkg/coinbase/transaction.go b/pkg/coinbase/transaction.go index 19f3641..b594362 100644 --- a/pkg/coinbase/transaction.go +++ b/pkg/coinbase/transaction.go @@ -4,7 +4,6 @@ import ( "crypto/ecdsa" "encoding/hex" "fmt" - "log" "math/big" "github.com/coinbase/coinbase-sdk-go/gen/client" @@ -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)