Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose pending claimable balance #51

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Coinbase Go SDK Changelog

## [0.0.18] - 2025-02-10

### Added

- Add `GetPendingClaimableBalance` function to help users get the pending claimable balance for a given address.

## [0.0.17] - 2025-02-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
"Correlation-Context",
fmt.Sprintf(
"%s,%s",
fmt.Sprintf("%s=%s", "sdk_version", "0.0.17"),
fmt.Sprintf("%s=%s", "sdk_version", "0.0.18"),
fmt.Sprintf("%s=%s", "sdk_language", "go"),
),
)
Expand Down
28 changes: 22 additions & 6 deletions pkg/coinbase/staking_context_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

// StakingContextBalance represents the active stakeable balances for a given address and asset.
type StakingContextBalance struct {
StakeableBalance *Balance
UnstakeableBalance *Balance
ClaimableBalance *Balance
StakeableBalance *Balance
UnstakeableBalance *Balance
PendingClaimableBalance *Balance
ClaimableBalance *Balance
}

// StakingBalanceOption allows for the passing of custom options to the staking balance
Expand All @@ -37,6 +38,15 @@ func (c *Client) GetUnstakeableBalance(ctx context.Context, assetId string, addr
return sb.UnstakeableBalance, nil
}

func (c *Client) GetPendingClaimableBalance(ctx context.Context, assetId string, address *Address, o ...StakingBalanceOption) (*Balance, error) {
sb, err := c.fetchStakingBalances(ctx, assetId, address, o...)
if err != nil {
return nil, err
}

return sb.PendingClaimableBalance, nil
}

// GetClaimableBalance returns the claimable balance.
func (c *Client) GetClaimableBalance(ctx context.Context, assetId string, address *Address, o ...StakingBalanceOption) (*Balance, error) {
sb, err := c.fetchStakingBalances(ctx, assetId, address, o...)
Expand Down Expand Up @@ -92,14 +102,20 @@ func newStakingBalancesFromModel(context *client.StakingContext) (*StakingContex
return nil, err
}

pendingClaimableBalance, err := newBalanceFromModel(&context.Context.PendingClaimableBalance)
if err != nil {
return nil, err
}

claimableBalance, err := newBalanceFromModel(&context.Context.ClaimableBalance)
if err != nil {
return nil, err
}

return &StakingContextBalance{
StakeableBalance: stakeableBalance,
UnstakeableBalance: unstakeableBalance,
ClaimableBalance: claimableBalance,
StakeableBalance: stakeableBalance,
UnstakeableBalance: unstakeableBalance,
PendingClaimableBalance: pendingClaimableBalance,
ClaimableBalance: claimableBalance,
}, nil
}
Loading