2019-10-17 15:04:50 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2023-04-06 12:41:14 +01:00
|
|
|
package stripe
|
2019-10-17 15:04:50 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
satellite/payments: specialized type for monetary amounts
Why: big.Float is not an ideal type for dealing with monetary amounts,
because no matter how high the precision, some non-integer decimal
values can not be represented exactly in base-2 floating point. Also,
storing gob-encoded big.Float values in the database makes it very hard
to use those values in meaningful queries, making it difficult to do
any sort of analysis on billing.
For better accuracy, then, we can just represent monetary values as
integers (in whatever base units are appropriate for the currency). For
example, STORJ tokens or Bitcoins can not be split into pieces smaller
than 10^-8, so we can store amounts of STORJ or BTC with precision
simply by moving the decimal point 8 digits to the right. For USD values
(assuming we don't want to deal with fractional cents), we can move the
decimal point 2 digits to the right.
To make it easier and less error-prone to deal with the math involved, I
introduce here a new type, monetary.Amount, instances of which have an
associated value _and_ a currency.
Change-Id: I03395d52f0e2473cf301361f6033722b54640265
2021-08-10 23:29:50 +01:00
|
|
|
"github.com/shopspring/decimal"
|
2019-10-17 15:04:50 +01:00
|
|
|
|
2022-09-06 13:43:09 +01:00
|
|
|
"storj.io/common/currency"
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-10-17 15:04:50 +01:00
|
|
|
"storj.io/storj/satellite/payments/coinpayments"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TransactionsDB is an interface which defines functionality
|
|
|
|
// of DB which stores coinpayments transactions.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type TransactionsDB interface {
|
2019-11-15 14:59:39 +00:00
|
|
|
// GetLockedRate returns locked conversion rate for transaction or error if non exists.
|
satellite/payments: specialized type for monetary amounts
Why: big.Float is not an ideal type for dealing with monetary amounts,
because no matter how high the precision, some non-integer decimal
values can not be represented exactly in base-2 floating point. Also,
storing gob-encoded big.Float values in the database makes it very hard
to use those values in meaningful queries, making it difficult to do
any sort of analysis on billing.
For better accuracy, then, we can just represent monetary values as
integers (in whatever base units are appropriate for the currency). For
example, STORJ tokens or Bitcoins can not be split into pieces smaller
than 10^-8, so we can store amounts of STORJ or BTC with precision
simply by moving the decimal point 8 digits to the right. For USD values
(assuming we don't want to deal with fractional cents), we can move the
decimal point 2 digits to the right.
To make it easier and less error-prone to deal with the math involved, I
introduce here a new type, monetary.Amount, instances of which have an
associated value _and_ a currency.
Change-Id: I03395d52f0e2473cf301361f6033722b54640265
2021-08-10 23:29:50 +01:00
|
|
|
GetLockedRate(ctx context.Context, id coinpayments.TransactionID) (decimal.Decimal, error)
|
2019-11-12 11:14:34 +00:00
|
|
|
// ListAccount returns all transaction for specific user.
|
|
|
|
ListAccount(ctx context.Context, userID uuid.UUID) ([]Transaction, error)
|
2022-11-29 12:36:41 +00:00
|
|
|
// TestInsert inserts new coinpayments transaction into DB.
|
|
|
|
TestInsert(ctx context.Context, tx Transaction) (time.Time, error)
|
|
|
|
// TestLockRate locks conversion rate for transaction.
|
|
|
|
TestLockRate(ctx context.Context, id coinpayments.TransactionID, rate decimal.Decimal) error
|
2019-10-17 15:04:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transaction defines coinpayments transaction info that is stored in the DB.
|
|
|
|
type Transaction struct {
|
|
|
|
ID coinpayments.TransactionID
|
|
|
|
AccountID uuid.UUID
|
|
|
|
Address string
|
2022-09-06 13:43:09 +01:00
|
|
|
Amount currency.Amount
|
|
|
|
Received currency.Amount
|
2019-10-17 15:04:50 +01:00
|
|
|
Status coinpayments.Status
|
|
|
|
Key string
|
2019-11-15 14:59:39 +00:00
|
|
|
Timeout time.Duration
|
2019-10-17 15:04:50 +01:00
|
|
|
CreatedAt time.Time
|
|
|
|
}
|