Skip to content

Commit

Permalink
update fireblocks get asset addresses endpoint (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Jul 23, 2024
1 parent 9bbcdab commit 500607f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
46 changes: 38 additions & 8 deletions chainio/clients/fireblocks/get_asset_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"strings"
)

Expand All @@ -20,15 +21,44 @@ type AssetAddress struct {

func (f *client) GetAssetAddresses(ctx context.Context, vaultID string, assetID AssetID) ([]AssetAddress, error) {
f.logger.Debug("Fireblocks get asset addressees", "vaultID", vaultID, "assetID", assetID)
path := fmt.Sprintf("/v1/vault/accounts/%s/%s/addresses", vaultID, assetID)
res, err := f.makeRequest(ctx, "GET", path, nil)
if err != nil {
return nil, fmt.Errorf("error making request: %w", err)
}
var addresses []AssetAddress
err = json.NewDecoder(strings.NewReader(string(res))).Decode(&addresses)
if err != nil {
return nil, fmt.Errorf("error parsing response body: %w", err)
type paging struct {
Before string `json:"before"`
After string `json:"after"`
}
var response struct {
Addresses []AssetAddress `json:"addresses"`
Paging paging `json:"paging"`
}

p := paging{}
next := true
for next {
path := fmt.Sprintf("/v1/vault/accounts/%s/%s/addresses_paginated", vaultID, assetID)
u, err := url.Parse(path)
if err != nil {
return addresses, fmt.Errorf("error parsing URL: %w", err)
}
q := u.Query()
q.Set("before", p.Before)
q.Set("after", p.After)
u.RawQuery = q.Encode()

res, err := f.makeRequest(ctx, "GET", u.String(), nil)
if err != nil {
return nil, fmt.Errorf("error making request: %w", err)
}
body := string(res)
err = json.NewDecoder(strings.NewReader(body)).Decode(&response)
if err != nil {
return addresses, fmt.Errorf("error parsing response body: %s: %w", body, err)
}

addresses = append(addresses, response.Addresses...)
p = response.Paging
if p.After == "" {
next = false
}
}

return addresses, nil
Expand Down
1 change: 0 additions & 1 deletion chainio/clients/fireblocks/list_vault_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (f *client) ListVaultAccounts(ctx context.Context) ([]VaultAccount, error)
q.Set("before", p.Before)
q.Set("after", p.After)
u.RawQuery = q.Encode()
fmt.Println("URL: ", u.String())
res, err := f.makeRequest(ctx, "GET", u.String(), nil)
if err != nil {
return accounts, fmt.Errorf("error making request: %w", err)
Expand Down

0 comments on commit 500607f

Please sign in to comment.