storjscan

package
v1.59.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PaymentStatusConfirmed indicates that payment has required number of confirmations.
	PaymentStatusConfirmed = "confirmed"
	// PaymentStatusPending indicates that payment has not meet confirmation requirements.
	PaymentStatusPending = "pending"
)

Variables

View Source
var (
	// ClientErr is general purpose storjscan client error class.
	ClientErr = errs.Class("storjscan client")
	// ClientErrUnauthorized is unauthorized err storjscan client error class.
	ClientErrUnauthorized = errs.Class("storjscan client unauthorized")
)
View Source
var ChoreErr = errs.Class("storjscan chore")

ChoreErr is storjscan chore err class.

View Source
var ErrNoPayments = errs.New("no payments in the database")

ErrNoPayments represents err when there is no payments in the DB.

View Source
var (
	// Error defines storjscan service error.
	Error = errs.Class("storjscan service")
)

Functions

This section is empty.

Types

type CachedPayment added in v1.58.1

type CachedPayment struct {
	From        blockchain.Address
	To          blockchain.Address
	TokenValue  monetary.Amount
	Status      PaymentStatus
	BlockHash   blockchain.Hash
	BlockNumber int64
	Transaction blockchain.Hash
	LogIndex    int
	Timestamp   time.Time
}

CachedPayment holds cached data of storjscan payment.

type Chore added in v1.58.1

type Chore struct {
	TransactionCycle *sync2.Cycle
	// contains filtered or unexported fields
}

Chore periodically queries for new payments from storjscan.

architecture: Chore

func NewChore added in v1.58.1

func NewChore(log *zap.Logger, client *Client, paymentsDB PaymentsDB, confirmations int, interval time.Duration) *Chore

NewChore creates new chore.

func (*Chore) Close added in v1.58.1

func (chore *Chore) Close() (err error)

Close closes all underlying resources.

func (*Chore) Run added in v1.58.1

func (chore *Chore) Run(ctx context.Context) (err error)

Run runs storjscan payment loop.

type Client

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

Client is storjscan HTTP API client.

func NewClient

func NewClient(endpoint, identifier, secret string) *Client

NewClient creates new storjscan API client.

func (*Client) ClaimNewEthAddress added in v1.57.1

func (client *Client) ClaimNewEthAddress(ctx context.Context) (_ blockchain.Address, err error)

ClaimNewEthAddress claims a new ethereum wallet address for the given user.

func (*Client) Payments

func (client *Client) Payments(ctx context.Context, from int64) (_ LatestPayments, err error)

Payments retrieves all payments after specified block for wallets associated with particular API key.

type Config added in v1.57.1

type Config struct {
	Endpoint string `help:"storjscan API endpoint"`
	Auth     struct {
		Identifier string `help:"basic auth identifier"`
		Secret     string `help:"basic auth secret"`
	}
	Confirmations int `help:"required number of following blocks in the chain to accept payment as confirmed" default:"12"`
}

Config stores needed information for storjscan service initialization.

type DB

type DB interface {
	// Wallets is getter for wallets db.
	Wallets() WalletsDB
}

DB is storjscan DB interface.

architecture: Database

type Header struct {
	Hash      blockchain.Hash
	Number    int64
	Timestamp time.Time
}

Header holds ethereum blockchain block header data.

type LatestPayments

type LatestPayments struct {
	LatestBlock Header
	Payments    []Payment
}

LatestPayments contains latest payments and latest chain block header.

type Payment

type Payment struct {
	From        blockchain.Address
	To          blockchain.Address
	TokenValue  *big.Int
	USDValue    float64
	BlockHash   blockchain.Hash
	BlockNumber int64
	Transaction blockchain.Hash
	LogIndex    int
	Timestamp   time.Time
}

Payment holds storjscan payment data.

type PaymentStatus added in v1.58.1

type PaymentStatus string

PaymentStatus indicates payment status.

type PaymentsDB added in v1.58.1

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.
	LastBlock(ctx context.Context, status PaymentStatus) (int64, error)
	// DeletePending removes all pending transactions from the DB.
	DeletePending(ctx context.Context) error
}

PaymentsDB is storjscan payments DB interface.

architecture: Database

type Service added in v1.57.1

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

Service is an implementation for payment service via Stripe and Coinpayments.

architecture: Service

func NewService added in v1.57.1

func NewService(db DB, storjscanClient *Client) (*Service, error)

NewService creates a Service instance.

func (*Service) Claim added in v1.57.1

func (service *Service) Claim(ctx context.Context, userID uuid.UUID) (_ blockchain.Address, err error)

Claim gets a new crypto wallet and associates it with a user.

func (*Service) Get added in v1.57.1

func (service *Service) Get(ctx context.Context, userID uuid.UUID) (_ blockchain.Address, err error)

Get returns the crypto wallet address associated with the given user.

type WalletsDB

type WalletsDB interface {
	// Add adds a new storjscan wallet to the DB and associates it with a user.
	Add(ctx context.Context, userID uuid.UUID, walletAddress blockchain.Address) error
	// Get returns the wallet address associated with the given user.
	Get(ctx context.Context, userID uuid.UUID) (blockchain.Address, error)
	// GetAllUsers returns all user IDs that have associated storjscan wallets.
	GetAllUsers(ctx context.Context) (_ []uuid.UUID, err error)
}

WalletsDB is an interface which defines functionality of DB which stores user storjscan wallets.

architecture: Database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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