Skip to content

Commit

Permalink
Merge pull request #433 from stellar/release/2.1.1
Browse files Browse the repository at this point in the history
Release `2.1.1`
  • Loading branch information
marwen-abid authored Oct 8, 2024
2 parents 4508b3b + 7e14a61 commit 6e952c4
Show file tree
Hide file tree
Showing 38 changed files with 468 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/anchor_platform_integration_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Run Docker Compose for SDP and Anchor Platform
working-directory: dev
run: docker-compose -f docker-compose-sdp-anchor.yml down && docker-compose -f docker-compose-sdp-anchor.yml up --build -d
run: docker compose -f docker-compose-sdp-anchor.yml down && docker compose -f docker-compose-sdp-anchor.yml up --build -d

- name: Install curl
run: sudo apt-get update && sudo apt-get install -y curl
Expand All @@ -55,4 +55,4 @@ jobs:
- name: Docker logs
if: always()
working-directory: dev
run: docker-compose -f docker-compose-sdp-anchor.yml logs && docker-compose -f docker-compose-sdp-anchor.yml down
run: docker compose -f docker-compose-sdp-anchor.yml logs && docker compose -f docker-compose-sdp-anchor.yml down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
with:
version: v1.56.2 # this is the golangci-lint version
args: --timeout 5m0s
skip-build-cache: true
skip-pkg-cache: true

- name: Run ./gomod.sh
run: ./gomod.sh
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/e2e_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
e2e:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
platform:
- "Stellar"
Expand All @@ -46,12 +47,12 @@ jobs:

- name: Cleanup data
working-directory: internal/integrationtests/docker
run: docker-compose -f docker-compose-e2e-tests.yml down -v
run: docker compose -f docker-compose-e2e-tests.yml down -v
shell: bash

- name: Run Docker Compose for SDP, Anchor Platform and TSS
working-directory: internal/integrationtests/docker
run: docker-compose -f docker-compose-e2e-tests.yml up --build -V -d
run: docker compose -f docker-compose-e2e-tests.yml up --build -V -d
shell: bash

- name: Install curl
Expand Down Expand Up @@ -98,5 +99,5 @@ jobs:
- name: Docker logs
if: always()
working-directory: internal/integrationtests/docker
run: docker-compose -f docker-compose-e2e-tests.yml logs && docker-compose -f docker-compose-e2e-tests.yml down
run: docker compose -f docker-compose-e2e-tests.yml logs && docker compose -f docker-compose-e2e-tests.yml down
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:

- name: Cleanup data
working-directory: internal/integrationtests/docker
run: docker-compose -f docker-compose-e2e-tests.yml down -v
run: docker compose -f docker-compose-e2e-tests.yml down -v
shell: bash

- name: Run Docker Compose for SDP, Anchor Platform and TSS
working-directory: internal/integrationtests/docker
run: docker-compose -f docker-compose-e2e-tests.yml up --build -V -d
run: docker compose -f docker-compose-e2e-tests.yml up --build -V -d
shell: bash

- name: Install curl
Expand Down Expand Up @@ -140,6 +140,6 @@ jobs:
if: always()
working-directory: internal/integrationtests/docker
run: |
docker-compose -f docker-compose-e2e-tests.yml logs
docker-compose -f docker-compose-e2e-tests.yml down -v
docker compose -f docker-compose-e2e-tests.yml logs
docker compose -f docker-compose-e2e-tests.yml down -v
shell: bash
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

None

## [2.1.1](https://github.com/stellar/stellar-disbursement-platform-backend/releases/tag/2.1.1) ([diff](https://github.com/stellar/stellar-disbursement-platform-backend/compare/2.1.0...2.1.1))

### Changed
- Removed calls related to the deprecated Circle Accounts API and replaced them with calls to `GET /v1/businessAccount/balances` and `GET /configuration`. [#433](https://github.com/stellar/stellar-disbursement-platform-backend/pull/433).

## [2.1.0](https://github.com/stellar/stellar-disbursement-platform-backend/releases/tag/2.1.0) ([diff](https://github.com/stellar/stellar-disbursement-platform-backend/compare/2.0.0...2.1.0))

Release of the Stellar Disbursement Platform v2.1.0. This release introduces
Expand Down
2 changes: 1 addition & 1 deletion dev/docker-compose-tss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
NETWORK_PASSPHRASE: "Test SDF Network ; September 2015"
HORIZON_URL: "https://horizon-testnet.stellar.org"
NUM_CHANNEL_ACCOUNTS: "3"
MAX_BASE_FEE: "100"
MAX_BASE_FEE: "1000000"
TSS_METRICS_PORT: "9002"
TSS_METRICS_TYPE: "TSS_PROMETHEUS"
DISTRIBUTION_PUBLIC_KEY: ${DISTRIBUTION_PUBLIC_KEY}
Expand Down
14 changes: 7 additions & 7 deletions dev/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ fi

# prepare
echo $DIVIDER
echo "====> 👀 start calling docker-compose -p sdp-multi-tenant down"
echo "====> 👀 start calling docker compose -p sdp-multi-tenant down"
docker ps -aq | xargs docker stop | xargs docker rm
#docker-compose -p sdp-multi-tenant down
docker-compose down
echo "====> ✅ finish calling docker-compose down"
#docker compose -p sdp-multi-tenant down
docker compose down
echo "====> ✅ finish calling docker compose down"

# Run docker compose
echo $DIVIDER
Expand Down Expand Up @@ -67,11 +67,11 @@ fi
echo $DIVIDER
echo "====> 👀calling docker compose up"
export GIT_COMMIT="debug"
docker-compose -p sdp-multi-tenant up -d --build
docker compose -p sdp-multi-tenant up -d --build

# Run docker compose
echo $DIVIDER
echo "====> ✅finish calling docker-compose up"
echo "====> ✅finish calling docker compose up"


# Initialize tenants
Expand Down Expand Up @@ -144,7 +144,7 @@ echo "====> ✅Step 3: finished initialization of tenants"
echo $DIVIDER
# Initialize test_users
echo "====> Step 4: initialize test users..."
docker-compose -p sdp-multi-tenant exec sdp-api ./dev/scripts/add_test_users.sh
docker compose -p sdp-multi-tenant exec sdp-api ./dev/scripts/add_test_users.sh
echo $DIVIDER

echo "🎉🎉🎉🎉 SUCCESS! 🎉🎉🎉🎉"
Expand Down
4 changes: 2 additions & 2 deletions helmchart/sdp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: stellar-disbursement-platform
description: A Helm chart for the Stellar Disbursement Platform Backend (A.K.A. `sdp`)
version: "2.1.0"
appVersion: "2.1.0"
version: "2.1.1"
appVersion: "2.1.1"
type: application
maintainers:
- name: Stellar Development Foundation
Expand Down
5 changes: 3 additions & 2 deletions internal/anchorplatform/sep24_auth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package anchorplatform

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -40,14 +41,14 @@ func checkSEP24ClientAndHomeDomains(ctx context.Context, sep24Claims *SEP24JWTCl
missingDomain := "missing client domain in the token claims"
if networkPassphrase == network.PublicNetworkPassphrase {
log.Ctx(ctx).Error(missingDomain)
return fmt.Errorf(missingDomain)
return errors.New(missingDomain)
}
log.Ctx(ctx).Warn(missingDomain)
}
if sep24Claims.HomeDomain() == "" {
missingDomain := "missing home domain in the token claims"
log.Ctx(ctx).Error(missingDomain)
return fmt.Errorf(missingDomain)
return errors.New(missingDomain)
}
return nil
}
Expand Down
32 changes: 32 additions & 0 deletions internal/circle/account_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package circle

import (
"encoding/json"
"fmt"
"net/http"
)

// ConfigurationResponse represents the response containing account configuration.
type ConfigurationResponse struct {
Data AccountConfiguration `json:"data,omitempty"`
}

// AccountConfiguration represents the configuration settings of an account.
type AccountConfiguration struct {
Payments WalletConfig `json:"payments,omitempty"`
}

// WalletConfig represents the wallet configuration with details such as the master wallet ID.
type WalletConfig struct {
MasterWalletID string `json:"masterWalletId,omitempty"`
}

// parseAccountConfigurationResponse parses the response containing account configuration.
func parseAccountConfigurationResponse(resp *http.Response) (*AccountConfiguration, error) {
var configurationResponse ConfigurationResponse
if err := json.NewDecoder(resp.Body).Decode(&configurationResponse); err != nil {
return nil, fmt.Errorf("decoding response: %w", err)
}

return &configurationResponse.Data, nil
}
30 changes: 27 additions & 3 deletions internal/circle/balance.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package circle

import (
"encoding/json"
"errors"
"fmt"
"net/http"

"github.com/stellar/stellar-disbursement-platform-backend/internal/data"
"github.com/stellar/stellar-disbursement-platform-backend/internal/services/assets"
Expand All @@ -13,6 +16,17 @@ var (
ErrUnsupportedCurrencyForNetwork = errors.New("unsupported Circle currency code for this network type")
)

// ListBusinessBalancesResponse represents the response containing business balances.
type ListBusinessBalancesResponse struct {
Data Balances `json:"data,omitempty"`
}

// Balances represents the available and unsettled balances for different currencies.
type Balances struct {
Available []Balance `json:"available"`
Unsettled []Balance `json:"unsettled"`
}

// Balance represents the amount and currency of a balance or transfer.
type Balance struct {
Amount string `json:"amount"`
Expand All @@ -34,12 +48,12 @@ var AllowedAssetsMap = map[string]map[utils.NetworkType]data.Asset{
// ParseStellarAsset returns the Stellar asset for the given Circle currency code, or an error if the currency is not
// supported in the SDP.
func ParseStellarAsset(circleCurrency string, networkType utils.NetworkType) (data.Asset, error) {
return ParseStellarAssetFromAllowlist(circleCurrency, networkType, AllowedAssetsMap)
return parseStellarAssetFromAllowlist(circleCurrency, networkType, AllowedAssetsMap)
}

// ParseStellarAssetFromAllowlist returns the Stellar asset for the given Circle currency code, or an error if the
// parseStellarAssetFromAllowlist returns the Stellar asset for the given Circle currency code, or an error if the
// currency is not supported in the SDP. This function allows for the use of a custom asset allowlist.
func ParseStellarAssetFromAllowlist(circleCurrency string, networkType utils.NetworkType, allowedAssetsMap map[string]map[utils.NetworkType]data.Asset) (data.Asset, error) {
func parseStellarAssetFromAllowlist(circleCurrency string, networkType utils.NetworkType, allowedAssetsMap map[string]map[utils.NetworkType]data.Asset) (data.Asset, error) {
assetByNetworkType, ok := allowedAssetsMap[circleCurrency]
if !ok {
return data.Asset{}, ErrUnsupportedCurrency
Expand All @@ -52,3 +66,13 @@ func ParseStellarAssetFromAllowlist(circleCurrency string, networkType utils.Net

return asset, nil
}

// parseBusinessBalancesResponse parses the response from the Circle API into a Balances struct.
func parseBusinessBalancesResponse(resp *http.Response) (*Balances, error) {
var balancesResponse ListBusinessBalancesResponse
if err := json.NewDecoder(resp.Body).Decode(&balancesResponse); err != nil {
return nil, fmt.Errorf("unmarshalling Circle HTTP response: %w", err)
}

return &balancesResponse.Data, nil
}
2 changes: 1 addition & 1 deletion internal/circle/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Test_ParseStellarAsset(t *testing.T) {
})

t.Run("FromAllowlist/"+tc.name, func(t *testing.T) {
asset, err := ParseStellarAssetFromAllowlist(tc.circleCurrency, tc.networkType, tc.allowedAssetsMap)
asset, err := parseStellarAssetFromAllowlist(tc.circleCurrency, tc.networkType, tc.allowedAssetsMap)

if tc.expectedError == nil {
assert.NoError(t, err)
Expand Down
43 changes: 33 additions & 10 deletions internal/circle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

const (
pingPath = "/ping"
transferPath = "/v1/transfers"
walletPath = "/v1/wallets"
pingPath = "/ping"
transferPath = "/v1/transfers"
businessBalancesPath = "/v1/businessAccount/balances"
configurationPath = "/v1/configuration"
)

var authErrorStatusCodes = []int{http.StatusUnauthorized, http.StatusForbidden}
Expand All @@ -35,7 +36,8 @@ type ClientInterface interface {
Ping(ctx context.Context) (bool, error)
PostTransfer(ctx context.Context, transferRequest TransferRequest) (*Transfer, error)
GetTransferByID(ctx context.Context, id string) (*Transfer, error)
GetWalletByID(ctx context.Context, id string) (*Wallet, error)
GetBusinessBalances(ctx context.Context) (*Balances, error)
GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)
}

// Client provides methods to interact with the Circle API.
Expand Down Expand Up @@ -157,11 +159,32 @@ func (client *Client) GetTransferByID(ctx context.Context, id string) (*Transfer
return parseTransferResponse(resp)
}

// GetWalletByID retrieves a wallet by its ID.
//
// Circle API documentation: https://developers.circle.com/circle-mint/reference/getwallet.
func (client *Client) GetWalletByID(ctx context.Context, id string) (*Wallet, error) {
url, err := url.JoinPath(client.BasePath, walletPath, id)
// GetBusinessBalances retrieves the available and unsettled balances for different currencies.
func (client *Client) GetBusinessBalances(ctx context.Context) (*Balances, error) {
url, err := url.JoinPath(client.BasePath, businessBalancesPath)
if err != nil {
return nil, fmt.Errorf("building path: %w", err)
}

resp, err := client.request(ctx, url, http.MethodGet, true, nil)
if err != nil {
return nil, fmt.Errorf("making request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
handleErr := client.handleError(ctx, resp)
if handleErr != nil {
return nil, fmt.Errorf("handling API response error: %w", handleErr)
}
}

return parseBusinessBalancesResponse(resp)
}

// GetAccountConfiguration retrieves the configuration of the Circle Account.
func (client *Client) GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error) {
url, err := url.JoinPath(client.BasePath, configurationPath)
if err != nil {
return nil, fmt.Errorf("building path: %w", err)
}
Expand All @@ -179,7 +202,7 @@ func (client *Client) GetWalletByID(ctx context.Context, id string) (*Wallet, er
}
}

return parseWalletResponse(resp)
return parseAccountConfigurationResponse(resp)
}

type RetryableError struct {
Expand Down
Loading

0 comments on commit 6e952c4

Please sign in to comment.