2022-05-10 13:18:23 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package storjscan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2022-09-06 13:43:09 +01:00
|
|
|
"storj.io/common/currency"
|
2022-05-10 13:18:23 +01:00
|
|
|
"storj.io/storj/private/blockchain"
|
2022-06-01 22:59:47 +01:00
|
|
|
"storj.io/storj/satellite/payments"
|
2022-05-10 13:18:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ErrNoPayments represents err when there is no payments in the DB.
|
|
|
|
var ErrNoPayments = errs.New("no payments in the database")
|
|
|
|
|
|
|
|
// PaymentsDB is storjscan payments DB interface.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type PaymentsDB interface {
|
|
|
|
// InsertBatch inserts list of payments into DB.
|
|
|
|
InsertBatch(ctx context.Context, payments []CachedPayment) error
|
|
|
|
// List returns list of all storjscan payments order by block number and log index desc mainly for testing.
|
|
|
|
List(ctx context.Context) ([]CachedPayment, error)
|
|
|
|
// ListWallet returns list of storjscan payments order by block number and log index desc.
|
|
|
|
ListWallet(ctx context.Context, wallet blockchain.Address, limit int, offset int64) ([]CachedPayment, error)
|
|
|
|
// LastBlock returns the highest block known to DB for specified payment status.
|
2022-06-01 22:59:47 +01:00
|
|
|
LastBlock(ctx context.Context, status payments.PaymentStatus) (int64, error)
|
2022-05-10 13:18:23 +01:00
|
|
|
// DeletePending removes all pending transactions from the DB.
|
|
|
|
DeletePending(ctx context.Context) error
|
2022-06-17 00:29:31 +01:00
|
|
|
// ListConfirmed returns list of confirmed storjscan payments greater than the given timestamp.
|
|
|
|
ListConfirmed(ctx context.Context, blockNumber int64, logIndex int) ([]CachedPayment, error)
|
2022-05-10 13:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// CachedPayment holds cached data of storjscan payment.
|
|
|
|
type CachedPayment struct {
|
2022-06-01 22:59:47 +01:00
|
|
|
From blockchain.Address `json:"from"`
|
|
|
|
To blockchain.Address `json:"to"`
|
2022-09-06 13:43:09 +01:00
|
|
|
TokenValue currency.Amount `json:"tokenValue"`
|
|
|
|
USDValue currency.Amount `json:"usdValue"`
|
2022-06-01 22:59:47 +01:00
|
|
|
Status payments.PaymentStatus `json:"status"`
|
|
|
|
BlockHash blockchain.Hash `json:"blockHash"`
|
|
|
|
BlockNumber int64 `json:"blockNumber"`
|
|
|
|
Transaction blockchain.Hash `json:"transaction"`
|
|
|
|
LogIndex int `json:"logIndex"`
|
|
|
|
Timestamp time.Time `json:"timestamp"`
|
2022-05-10 13:18:23 +01:00
|
|
|
}
|