circle

package
v0.0.0-...-c846bbc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const StellarChainCode = "XLM"

Variables

View Source
var (
	ErrUnsupportedCurrency           = errors.New("unsupported Circle currency code")
	ErrUnsupportedCurrencyForNetwork = errors.New("unsupported Circle currency code for this network type")
)

AllowedAssetsMap is a map of Circle currency codes to Stellar assets, for each network type.

Functions

func ParseStellarAsset

func ParseStellarAsset(circleCurrency string, networkType utils.NetworkType) (data.Asset, error)

ParseStellarAsset returns the Stellar asset for the given Circle currency code, or an error if the currency is not supported in the SDP.

Types

type APIError

type APIError struct {
	// Code is the Circle API error code.
	Code    int              `json:"code"`
	Message string           `json:"message"`
	Errors  []APIErrorDetail `json:"errors,omitempty"`
	// StatusCode is the HTTP status code.
	StatusCode int `json:"status_code,omitempty"`
}

APIError represents the error response from Circle APIs.

func (APIError) Error

func (e APIError) Error() string

Error implements the error interface for APIError.

type APIErrorDetail

type APIErrorDetail struct {
	Error        string                 `json:"error"`
	Message      string                 `json:"message"`
	Location     string                 `json:"location"`
	InvalidValue interface{}            `json:"invalidValue,omitempty"`
	Constraints  map[string]interface{} `json:"constraints,omitempty"`
}

APIErrorDetail represents the detailed error information.

type AccountConfiguration

type AccountConfiguration struct {
	Payments WalletConfig `json:"payments,omitempty"`
}

AccountConfiguration represents the configuration settings of an account.

type Balance

type Balance struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
}

Balance represents the amount and currency of a balance or transfer.

type Balances

type Balances struct {
	Available []Balance `json:"available"`
	Unsettled []Balance `json:"unsettled"`
}

Balances represents the available and unsettled balances for different currencies.

type Client

type Client struct {
	BasePath string
	APIKey   string
	// contains filtered or unexported fields
}

Client provides methods to interact with the Circle API.

func (*Client) GetAccountConfiguration

func (client *Client) GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)

GetAccountConfiguration retrieves the configuration of the Circle Account.

func (*Client) GetBusinessBalances

func (client *Client) GetBusinessBalances(ctx context.Context) (*Balances, error)

GetBusinessBalances retrieves the available and unsettled balances for different currencies.

func (*Client) GetTransferByID

func (client *Client) GetTransferByID(ctx context.Context, id string) (*Transfer, error)

GetTransferByID retrieves a transfer by its ID.

Circle API documentation: https://developers.circle.com/circle-mint/reference/gettransfer.

func (*Client) Ping

func (client *Client) Ping(ctx context.Context) (bool, error)

Ping checks that the service is running.

Circle API documentation: https://developers.circle.com/circle-mint/reference/ping.

func (*Client) PostTransfer

func (client *Client) PostTransfer(ctx context.Context, transferReq TransferRequest) (*Transfer, error)

PostTransfer creates a new transfer.

Circle API documentation: https://developers.circle.com/circle-mint/reference/createtransfer.

type ClientConfig

type ClientConfig struct {
	EncryptedAPIKey    *string   `db:"encrypted_api_key"`
	WalletID           *string   `db:"wallet_id"`
	EncrypterPublicKey *string   `db:"encrypter_public_key"`
	UpdatedAt          time.Time `db:"updated_at"`
	CreatedAt          time.Time `db:"created_at"`
}

type ClientConfigModel

type ClientConfigModel struct {
	DBConnectionPool db.DBConnectionPool
	Encrypter        utils.PrivateKeyEncrypter
}

func NewClientConfigModel

func NewClientConfigModel(dbConnectionPool db.DBConnectionPool) *ClientConfigModel

func (*ClientConfigModel) Get

Get retrieves the circle client config from the database if it exists.

func (*ClientConfigModel) GetDecryptedAPIKey

func (m *ClientConfigModel) GetDecryptedAPIKey(ctx context.Context, passphrase string) (string, error)

GetDecryptedAPIKey retrieves the decrypted API key from the database.

func (*ClientConfigModel) Upsert

func (m *ClientConfigModel) Upsert(ctx context.Context, configUpdate ClientConfigUpdate) error

Upsert insert or update the client configuration for Circle into the database.

type ClientConfigModelInterface

type ClientConfigModelInterface interface {
	Upsert(ctx context.Context, configUpdate ClientConfigUpdate) error
	GetDecryptedAPIKey(ctx context.Context, passphrase string) (string, error)
	Get(ctx context.Context) (*ClientConfig, error)
}

type ClientConfigUpdate

type ClientConfigUpdate struct {
	EncryptedAPIKey    *string `db:"encrypted_api_key"`
	WalletID           *string `db:"wallet_id"`
	EncrypterPublicKey *string `db:"encrypter_public_key"`
}

type ClientFactory

type ClientFactory func(opts ClientOptions) ClientInterface

ClientFactory is a function that creates a ClientInterface.

type ClientInterface

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)
	GetBusinessBalances(ctx context.Context) (*Balances, error)
	GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)
}

ClientInterface defines the interface for interacting with the Circle API.

func NewClient

func NewClient(opts ClientOptions) ClientInterface

NewClient creates a new instance of Circle Client.

type ClientOptions

type ClientOptions struct {
	NetworkType    utils.NetworkType
	APIKey         string
	TenantManager  tenant.ManagerInterface
	MonitorService monitor.MonitorServiceInterface
}

type ConfigurationResponse

type ConfigurationResponse struct {
	Data AccountConfiguration `json:"data,omitempty"`
}

ConfigurationResponse represents the response containing account configuration.

type Environment

type Environment string

Environment holds the possible environments for the Circle API.

const (
	Production Environment = "https://api.circle.com"
	Sandbox    Environment = "https://api-sandbox.circle.com"
)

type ListBusinessBalancesResponse

type ListBusinessBalancesResponse struct {
	Data Balances `json:"data,omitempty"`
}

ListBusinessBalancesResponse represents the response containing business balances.

type MockClient

type MockClient struct {
	mock.Mock
}

MockClient is an autogenerated mock type for the ClientInterface type

func NewMockClient

func NewMockClient(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockClient

NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockClient) GetAccountConfiguration

func (_m *MockClient) GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)

GetAccountConfiguration provides a mock function with given fields: ctx

func (*MockClient) GetBusinessBalances

func (_m *MockClient) GetBusinessBalances(ctx context.Context) (*Balances, error)

GetBusinessBalances provides a mock function with given fields: ctx

func (*MockClient) GetTransferByID

func (_m *MockClient) GetTransferByID(ctx context.Context, id string) (*Transfer, error)

GetTransferByID provides a mock function with given fields: ctx, id

func (*MockClient) Ping

func (_m *MockClient) Ping(ctx context.Context) (bool, error)

Ping provides a mock function with given fields: ctx

func (*MockClient) PostTransfer

func (_m *MockClient) PostTransfer(ctx context.Context, transferRequest TransferRequest) (*Transfer, error)

PostTransfer provides a mock function with given fields: ctx, transferRequest

type MockClientConfigModel

type MockClientConfigModel struct {
	mock.Mock
}

MockClientConfigModel is an autogenerated mock type for the ClientConfigModelInterface type

func NewMockClientConfigModel

func NewMockClientConfigModel(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockClientConfigModel

NewMockClientConfigModel creates a new instance of MockClientConfigModel. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockClientConfigModel) Get

Get provides a mock function with given fields: ctx

func (*MockClientConfigModel) GetDecryptedAPIKey

func (_m *MockClientConfigModel) GetDecryptedAPIKey(ctx context.Context, passphrase string) (string, error)

GetDecryptedAPIKey provides a mock function with given fields: ctx, passphrase

func (*MockClientConfigModel) Upsert

func (_m *MockClientConfigModel) Upsert(ctx context.Context, configUpdate ClientConfigUpdate) error

Upsert provides a mock function with given fields: ctx, configUpdate

type MockService

type MockService struct {
	mock.Mock
}

MockService is an autogenerated mock type for the ServiceInterface type

func NewMockService

func NewMockService(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockService

NewMockService creates a new instance of MockService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockService) GetAccountConfiguration

func (_m *MockService) GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)

GetAccountConfiguration provides a mock function with given fields: ctx

func (*MockService) GetBusinessBalances

func (_m *MockService) GetBusinessBalances(ctx context.Context) (*Balances, error)

GetBusinessBalances provides a mock function with given fields: ctx

func (*MockService) GetTransferByID

func (_m *MockService) GetTransferByID(ctx context.Context, id string) (*Transfer, error)

GetTransferByID provides a mock function with given fields: ctx, id

func (*MockService) Ping

func (_m *MockService) Ping(ctx context.Context) (bool, error)

Ping provides a mock function with given fields: ctx

func (*MockService) PostTransfer

func (_m *MockService) PostTransfer(ctx context.Context, transferRequest TransferRequest) (*Transfer, error)

PostTransfer provides a mock function with given fields: ctx, transferRequest

func (*MockService) SendPayment

func (_m *MockService) SendPayment(ctx context.Context, paymentRequest PaymentRequest) (*Transfer, error)

SendPayment provides a mock function with given fields: ctx, paymentRequest

type PaymentRequest

type PaymentRequest struct {
	SourceWalletID            string
	DestinationStellarAddress string
	Amount                    string
	StellarAssetCode          string
	IdempotencyKey            string
}

func (PaymentRequest) GetCircleAssetCode

func (p PaymentRequest) GetCircleAssetCode() (string, error)

GetCircleAssetCode converts the request's Stellar asset code to a Circle's asset code.

func (PaymentRequest) Validate

func (p PaymentRequest) Validate() error

type RetryableError

type RetryableError struct {
	// contains filtered or unexported fields
}

func (RetryableError) Error

func (re RetryableError) Error() string

type Service

type Service struct {
	ClientFactory        ClientFactory
	ClientConfigModel    ClientConfigModelInterface
	NetworkType          utils.NetworkType
	EncryptionPassphrase string
	TenantManager        tenant.ManagerInterface
	MonitorService       monitor.MonitorServiceInterface
}

func NewService

func NewService(opts ServiceOptions) (*Service, error)

func (*Service) GetAccountConfiguration

func (s *Service) GetAccountConfiguration(ctx context.Context) (*AccountConfiguration, error)

func (*Service) GetBusinessBalances

func (s *Service) GetBusinessBalances(ctx context.Context) (*Balances, error)

func (*Service) GetTransferByID

func (s *Service) GetTransferByID(ctx context.Context, transferID string) (*Transfer, error)

func (*Service) Ping

func (s *Service) Ping(ctx context.Context) (bool, error)

func (*Service) PostTransfer

func (s *Service) PostTransfer(ctx context.Context, transferRequest TransferRequest) (*Transfer, error)

func (*Service) SendPayment

func (s *Service) SendPayment(ctx context.Context, paymentRequest PaymentRequest) (*Transfer, error)

type ServiceInterface

type ServiceInterface interface {
	ClientInterface
	SendPayment(ctx context.Context, paymentRequest PaymentRequest) (*Transfer, error)
}

ServiceInterface defines the interface for Circle related SDP operations.

type ServiceOptions

type ServiceOptions struct {
	ClientFactory        ClientFactory
	ClientConfigModel    ClientConfigModelInterface
	TenantManager        tenant.ManagerInterface
	NetworkType          utils.NetworkType
	EncryptionPassphrase string
	MonitorService       monitor.MonitorServiceInterface
}

func (ServiceOptions) Validate

func (o ServiceOptions) Validate() error

type Transfer

type Transfer struct {
	ID              string            `json:"id"`
	Source          TransferAccount   `json:"source"`
	Destination     TransferAccount   `json:"destination"`
	Amount          Balance           `json:"amount"`
	TransactionHash string            `json:"transactionHash,omitempty"`
	Status          TransferStatus    `json:"status"`
	ErrorCode       TransferErrorCode `json:"errorCode,omitempty"`
	CreateDate      time.Time         `json:"createDate"`
}

Transfer represents a transfer of funds from a Circle Endpoint to another. A circle endpoint can be a wallet, card, wire, or blockchain address.

type TransferAccount

type TransferAccount struct {
	Type       TransferAccountType `json:"type"`
	ID         string              `json:"id,omitempty"`
	Chain      string              `json:"chain,omitempty"`
	Address    string              `json:"address,omitempty"`
	AddressTag string              `json:"addressTag,omitempty"`
}

TransferAccount represents the source or destination of the transfer.

type TransferAccountType

type TransferAccountType string

TransferAccountType represents the type of the source or destination of the transfer.

const (
	TransferAccountTypeCard       TransferAccountType = "card"
	TransferAccountTypeWire       TransferAccountType = "wire"
	TransferAccountTypeBlockchain TransferAccountType = "blockchain"
	TransferAccountTypeWallet     TransferAccountType = "wallet"
)

type TransferErrorCode

type TransferErrorCode string
const (
	TransferErrorCodeInsufficientFunds TransferErrorCode = "insufficient_funds"
	TransferErrorCodeBlockchainError   TransferErrorCode = "blockchain_error"
	TransferErrorCodeTransferDenied    TransferErrorCode = "transfer_denied"
	TransferErrorCodeTransferFailed    TransferErrorCode = "transfer_failed"
)

type TransferRequest

type TransferRequest struct {
	Source         TransferAccount `json:"source"`
	Destination    TransferAccount `json:"destination"`
	Amount         Balance         `json:"amount"`
	IdempotencyKey string          `json:"idempotencyKey"`
}

TransferRequest represents the request to create a new transfer.

type TransferResponse

type TransferResponse struct {
	Data Transfer `json:"data"`
}

TransferResponse represents the response from the Circle APIs.

type TransferStatus

type TransferStatus string
const (
	TransferStatusPending  TransferStatus = "pending"
	TransferStatusComplete TransferStatus = "complete" // means success
	TransferStatusFailed   TransferStatus = "failed"
)

func (TransferStatus) ToPaymentStatus

func (s TransferStatus) ToPaymentStatus() (data.PaymentStatus, error)

type WalletConfig

type WalletConfig struct {
	MasterWalletID string `json:"masterWalletId,omitempty"`
}

WalletConfig represents the wallet configuration with details such as the master wallet ID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL