Documentation ¶
Index ¶
- Constants
- Variables
- func ReleaseLock(ctx context.Context, q repository.Querier, walletID int64, ...) error
- type Balance
- type BalanceOperation
- type BlockchainService
- type EntityType
- type MetaData
- type MetaDataKey
- type Pagination
- type Service
- func (s *Service) AcquireLock(ctx context.Context, merchantID int64, currency money.CryptoCurrency, ...) (*Wallet, error)
- func (s *Service) BulkCreateWallets(ctx context.Context, bc kmswallet.Blockchain, amount int64) ([]*Wallet, error)
- func (s *Service) Create(ctx context.Context, bc kmswallet.Blockchain, walletType Type) (*Wallet, error)
- func (s *Service) CreateSignedTransaction(ctx context.Context, sender *Wallet, recipient string, ...) (string, error)
- func (s *Service) DecrementPendingTransaction(ctx context.Context, walletID int64, isTest bool) error
- func (s *Service) EnsureBalance(ctx context.Context, entityType EntityType, entityID int64, ...) (*Balance, error)
- func (s *Service) EnsureOutboundWallet(ctx context.Context, bc kmswallet.Blockchain) (*Wallet, bool, error)
- func (s *Service) GetBalanceByID(ctx context.Context, entityType EntityType, entityID, balanceID int64) (*Balance, error)
- func (s *Service) GetBalanceByUUID(ctx context.Context, entityType EntityType, entityID int64, ...) (*Balance, error)
- func (s *Service) GetByID(ctx context.Context, id int64) (*Wallet, error)
- func (s *Service) GetByUUID(ctx context.Context, id uuid.UUID) (*Wallet, error)
- func (s *Service) GetMerchantBalance(ctx context.Context, merchantID int64, currency, networkID string) (*Balance, error)
- func (s *Service) GetMerchantBalanceByUUID(ctx context.Context, merchantID int64, balanceID uuid.UUID) (*Balance, error)
- func (s *Service) GetWalletsBalance(ctx context.Context, walletID int64, currency, networkID string) (*Balance, error)
- func (s *Service) IncrementConfirmedTransaction(ctx context.Context, walletID int64, isTest bool) error
- func (s *Service) IncrementPendingTransaction(ctx context.Context, walletID int64, isTest bool) (int, error)
- func (s *Service) List(ctx context.Context, pagination Pagination) ([]*Wallet, *int64, error)
- func (s *Service) ListBalances(ctx context.Context, entityType EntityType, entityID int64, withUSD bool) ([]*Balance, error)
- func (s *Service) ReleaseLock(ctx context.Context, walletID int64, currency, networkID string) error
- func (s *Service) UpdateBalanceByID(ctx context.Context, id int64, params UpdateBalanceByIDQuery) (*Balance, error)
- func (s *Service) UpdateBalancesForWithdrawal(ctx context.Context, params UpdateBalancesForWithdrawal) error
- func (s *Service) UpdateTatumSubscription(ctx context.Context, wallet *Wallet, subscription TatumSubscription) error
- type TatumSubscription
- type Type
- type UpdateBalanceByIDQuery
- type UpdateBalanceQuery
- type UpdateBalancesForWithdrawal
- type Wallet
Constants ¶
const ( EntityTypeMerchant EntityType = "merchant" EntityTypeWallet EntityType = "wallet" OperationIncrement BalanceOperation = "increment" OperationDecrement BalanceOperation = "decrement" MetaOperation MetaDataKey = "operation" MetaAmountRaw MetaDataKey = "amountRaw" MetaAmountFormatted MetaDataKey = "amountFormatted" MetaTransactionID MetaDataKey = "transactionID" MetaSenderWalletID MetaDataKey = "senderWallerID" MetaRecipientWalletID MetaDataKey = "recipientWalletID" )
Variables ¶
var ( ErrNotFound = errors.New("wallet not found") ErrBalanceNotFound = errors.New("balance not found") ErrInvalidBlockchain = errors.New("invalid blockchain provided") ErrInvalidType = errors.New("invalid type provided") ErrInsufficientBalance = errors.New("insufficient balance") ErrInsufficienceMerchantBalance = errors.Wrap(ErrInsufficientBalance, "merchant") )
var ( ErrTxConfirm = errors.New("nothing to confirm") ErrTxRollback = errors.New("nothing to rollback") )
Functions ¶
func ReleaseLock ¶
Types ¶
type Balance ¶
type Balance struct { ID int64 UUID uuid.UUID EntityType EntityType EntityID int64 CreatedAt time.Time UpdatedAt time.Time Network string NetworkID string CurrencyType money.CryptoCurrencyType Currency string Amount money.Money // UsdAmount eager-loaded. See Service.loadUSDBalances UsdAmount *money.Money }
func UpdateBalance ¶
func UpdateBalance(ctx context.Context, q repository.Querier, params UpdateBalanceQuery) (*Balance, error)
UpdateBalance increments/decrements balance of entity (wallet / merchant) and optionally adds audit log. increment works based on postgres "upsert" feature: "INSERT ... ON CONFLICT (...) DO UPDATE ...". Balance is created if not exists.
Warning: this function is meant to be used only in db transactions
func (*Balance) Blockchain ¶ added in v0.3.0
func (b *Balance) Blockchain() money.Blockchain
type BalanceOperation ¶
type BalanceOperation string
type BlockchainService ¶
type BlockchainService interface { blockchain.Convertor }
type EntityType ¶
type EntityType string
type MetaData ¶
type MetaData map[MetaDataKey]string
type MetaDataKey ¶
type MetaDataKey string
type Pagination ¶
type Pagination struct { Start int64 Limit int32 FilterByBlockchain kmswallet.Blockchain FilterByType Type }
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func New ¶
func New( kmsClient kmsclient.ClientService, blockchainService BlockchainService, store *repository.Store, logger *zerolog.Logger, ) *Service
func (*Service) AcquireLock ¶
func (s *Service) AcquireLock(ctx context.Context, merchantID int64, currency money.CryptoCurrency, isTest bool) (*Wallet, error)
AcquireLock finds and locks wallet of specified type currency for selected merchantID. If required wallet isn't found, then the new one is being created. This method uses transactions.
func (*Service) BulkCreateWallets ¶
func (*Service) CreateSignedTransaction ¶
func (*Service) DecrementPendingTransaction ¶
func (*Service) EnsureBalance ¶
func (s *Service) EnsureBalance( ctx context.Context, entityType EntityType, entityID int64, currency money.CryptoCurrency, isTest bool, ) (*Balance, error)
func (*Service) EnsureOutboundWallet ¶
func (s *Service) EnsureOutboundWallet(ctx context.Context, bc kmswallet.Blockchain) (*Wallet, bool, error)
EnsureOutboundWallet finds or creates outbound wallet for specified blockchain. Outbound wallets are used for funds withdrawal.
func (*Service) GetBalanceByID ¶
func (*Service) GetBalanceByUUID ¶
func (*Service) GetMerchantBalance ¶
func (*Service) GetMerchantBalanceByUUID ¶
func (*Service) GetWalletsBalance ¶
func (*Service) IncrementConfirmedTransaction ¶
func (*Service) IncrementPendingTransaction ¶
func (s *Service) IncrementPendingTransaction(ctx context.Context, walletID int64, isTest bool) (int, error)
IncrementPendingTransaction updates Wallet's nonce parameter and returns nonce for next tx.
func (*Service) ListBalances ¶
func (*Service) ReleaseLock ¶
func (s *Service) ReleaseLock(ctx context.Context, walletID int64, currency, networkID string) error
ReleaseLock does the opposite of AcquireLock.
func (*Service) UpdateBalanceByID ¶
func (*Service) UpdateBalancesForWithdrawal ¶
func (s *Service) UpdateBalancesForWithdrawal(ctx context.Context, params UpdateBalancesForWithdrawal) error
func (*Service) UpdateTatumSubscription ¶
func (s *Service) UpdateTatumSubscription(ctx context.Context, wallet *Wallet, subscription TatumSubscription) error
UpdateTatumSubscription updates tatum_* fields and reflects changes in *Wallet argument.
type TatumSubscription ¶
type UpdateBalanceByIDQuery ¶
type UpdateBalanceByIDQuery struct { Operation BalanceOperation Amount money.Money Comment string MetaData MetaData }
type UpdateBalanceQuery ¶
type UpdateBalanceQuery struct { EntityID int64 EntityType EntityType Operation BalanceOperation Currency money.CryptoCurrency Amount money.Money Comment string MetaData MetaData IsTest bool }