2019-10-17 15:04:50 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package stripecoinpayments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/big"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
|
|
|
"storj.io/storj/satellite/payments/coinpayments"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TransactionsDB is an interface which defines functionality
|
|
|
|
// of DB which stores coinpayments transactions.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type TransactionsDB interface {
|
|
|
|
// Insert inserts new coinpayments transaction into DB.
|
|
|
|
Insert(ctx context.Context, tx Transaction) (*Transaction, error)
|
2019-10-23 13:04:54 +01:00
|
|
|
// Update updates status and received for set of transactions.
|
2019-10-29 16:04:34 +00:00
|
|
|
Update(ctx context.Context, updates []TransactionUpdate, applies coinpayments.TransactionIDList) error
|
|
|
|
// Consume marks transaction as consumed, so it won't participate in apply account balance loop.
|
|
|
|
Consume(ctx context.Context, id coinpayments.TransactionID) error
|
2019-11-15 14:59:39 +00:00
|
|
|
// LockRate locks conversion rate for transaction.
|
|
|
|
LockRate(ctx context.Context, id coinpayments.TransactionID, rate *big.Float) error
|
|
|
|
// GetLockedRate returns locked conversion rate for transaction or error if non exists.
|
|
|
|
GetLockedRate(ctx context.Context, id coinpayments.TransactionID) (*big.Float, 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)
|
2019-10-23 13:04:54 +01:00
|
|
|
// ListPending returns TransactionsPage with pending transactions.
|
|
|
|
ListPending(ctx context.Context, offset int64, limit int, before time.Time) (TransactionsPage, error)
|
2019-11-12 11:14:34 +00:00
|
|
|
// List Unapplied returns TransactionsPage with completed transaction that should be applied to account balance.
|
2019-10-29 16:04:34 +00:00
|
|
|
ListUnapplied(ctx context.Context, offset int64, limit int, before time.Time) (TransactionsPage, 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
|
|
|
|
Amount big.Float
|
|
|
|
Received big.Float
|
|
|
|
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
|
|
|
|
}
|
2019-10-23 13:04:54 +01:00
|
|
|
|
|
|
|
// TransactionUpdate holds transaction update info.
|
|
|
|
type TransactionUpdate struct {
|
|
|
|
TransactionID coinpayments.TransactionID
|
|
|
|
Status coinpayments.Status
|
|
|
|
Received big.Float
|
|
|
|
}
|
|
|
|
|
|
|
|
// TransactionsPage holds set of transaction and indicates if
|
|
|
|
// there are more transactions to fetch.
|
|
|
|
type TransactionsPage struct {
|
|
|
|
Transactions []Transaction
|
|
|
|
Next bool
|
|
|
|
NextOffset int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDList returns transaction id list of page's transactions.
|
|
|
|
func (page *TransactionsPage) IDList() coinpayments.TransactionIDList {
|
|
|
|
var list coinpayments.TransactionIDList
|
|
|
|
for _, tx := range page.Transactions {
|
|
|
|
list = append(list, tx.ID)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|