Files
Maxence MaireauxandGitHub 22ebbe0a85 feat: CE/EE split architecture (#644)
* feat: Create EE architecture

* feat: Move Fireblocks to EE

* feat: Add dual CE/EE licensing model

Update root LICENSE to dual-license format distinguishing Community
Edition (MIT) from Enterprise Edition (ee/LICENSE), aligned with
the formancehq/stack licensing model.

* refactor: Rename main_ee.go to ee.go for cleaner build tag convention

* feat: Move Coinbase Prime to EE

* feat: just

* fix: tidy & package name
2026-02-24 15:26:29 +00:00

69 lines
1.7 KiB
Go

package coinbaseprime
import (
"context"
"encoding/json"
"strings"
"github.com/formancehq/go-libs/v3/currency"
"github.com/formancehq/payments/internal/models"
)
type accountsState struct {
Cursor string `json:"cursor"`
}
func (p *Plugin) fetchNextAccounts(ctx context.Context, req models.FetchNextAccountsRequest) (models.FetchNextAccountsResponse, error) {
var oldState accountsState
if req.State != nil {
if err := json.Unmarshal(req.State, &oldState); err != nil {
return models.FetchNextAccountsResponse{}, err
}
}
response, err := p.client.GetWallets(ctx, oldState.Cursor, req.PageSize)
if err != nil {
return models.FetchNextAccountsResponse{}, err
}
accounts := make([]models.PSPAccount, 0, len(response.Wallets))
for _, wallet := range response.Wallets {
symbol := strings.ToUpper(strings.TrimSpace(wallet.Symbol))
_, ok := p.currencies[symbol]
if !ok {
p.logger.Infof("skipping wallet %s: unsupported currency %q", wallet.ID, wallet.Symbol)
continue
}
raw, err := json.Marshal(wallet)
if err != nil {
return models.FetchNextAccountsResponse{}, err
}
defaultAsset := currency.FormatAsset(p.currencies, symbol)
accounts = append(accounts, models.PSPAccount{
Reference: wallet.ID,
CreatedAt: wallet.CreatedAt,
Name: &wallet.Name,
DefaultAsset: &defaultAsset,
Metadata: map[string]string{
"wallet_type": wallet.Type,
},
Raw: raw,
})
}
newState := accountsState{Cursor: response.Pagination.NextCursor}
payload, err := json.Marshal(newState)
if err != nil {
return models.FetchNextAccountsResponse{}, err
}
return models.FetchNextAccountsResponse{
Accounts: accounts,
NewState: payload,
HasMore: response.Pagination.HasNext,
}, nil
}