vendopunkto

package
v0.0.0-...-a71e659 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Currency

type Currency struct {
	Symbol       string `sql:",pk"`
	Name         string `sql:",notnull"`
	LogoImageURL string
}

Currency holds metada for a currency.

type CurrencyRepository

type CurrencyRepository interface {
	Search(ctx context.Context) ([]Currency, error)
	FindBySymbol(ctx context.Context, symbol string) (*Currency, error)
	FindBySymbols(ctx context.Context, symbols []string) ([]*Currency, error)
	SelectOrInsert(ctx context.Context, currency *Currency) (*Currency, error)
	AddOrUpdate(ctx context.Context, currency *Currency) (*Currency, error)
}

CurrencyRepository is the abstraction for handling currencies database

type Invoice

type Invoice struct {
	ID             string          `sql:",pk"`
	Total          decimal.Decimal `sql:",notnull"`
	Currency       string          `sql:",notnull"`
	CreatedAt      time.Time       `sql:",notnull"`
	PaymentMethods []*PaymentMethod
}

func (*Invoice) AddPaymentMethod

func (invoice *Invoice) AddPaymentMethod(
	currency string,
	address string,
	amount decimal.Decimal,
) *PaymentMethod

func (Invoice) CalculatePaymentMethodRemaining

func (invoice Invoice) CalculatePaymentMethodRemaining(method PaymentMethod) decimal.Decimal

CalculatePaymentMethodRemaining returns how much is remaining in the method's currency to fully pay this invoice

func (*Invoice) CalculatePaymentPercentage

func (invoice *Invoice) CalculatePaymentPercentage() float64

CalculatePaymentPercentage returns how much of this invoice has been payed in percentage. Given that an invoice could be payed using multiple currencies, this tells us what percentage of the invoice has been payed

func (*Invoice) CalculateRemainingAmount

func (invoice *Invoice) CalculateRemainingAmount() decimal.Decimal

CalculateRemainingAmount returns how much is needed to fully pay this invoice in the invoice's currency

func (*Invoice) CalculateTotalPayedAmount

func (invoice *Invoice) CalculateTotalPayedAmount() decimal.Decimal

CalculateTotalPayedAmount returns the total amount, of all payments converted to the invoice's currency

func (*Invoice) FindDefaultPaymentMethod

func (invoice *Invoice) FindDefaultPaymentMethod() *PaymentMethod

func (*Invoice) FindPaymentMethodForAddress

func (invoice *Invoice) FindPaymentMethodForAddress(address string) *PaymentMethod

func (*Invoice) FindPaymentMethodForCurrency

func (invoice *Invoice) FindPaymentMethodForCurrency(currency string) *PaymentMethod

func (*Invoice) Status

func (invoice *Invoice) Status() InvoiceStatus

type InvoiceFilter

type InvoiceFilter struct {
}

type InvoiceManager

type InvoiceManager interface {
	GetInvoice(ctx context.Context, id string) (*Invoice, error)
	Search(ctx context.Context, filter InvoiceFilter) ([]Invoice, error)
	GetInvoiceByAddress(ctx context.Context, address string) (*Invoice, error)
	CreateInvoice(ctx context.Context, params dtos.InvoiceCreationParams) (*Invoice, error)
	CreateAddressForPaymentMethod(ctx context.Context, invoiceID string,
		currency string) (*Invoice, error)
	ConfirmPayment(ctx context.Context, address string, confirmations uint64,
		amount decimal.Decimal, txHash string, blockHeight uint64) (*Invoice, error)
}

InvoiceManager is the logic abstraction

type InvoiceRepository

type InvoiceRepository interface {
	Search(ctx context.Context, filter InvoiceFilter) ([]Invoice, error)
	FindByID(ctx context.Context, id string) (*Invoice, error)
	FindByAddress(ctx context.Context, address string) (*Invoice, error)
	Create(ctx context.Context, invoice *Invoice) error
	UpdatePaymentMethod(ctx context.Context, method *PaymentMethod) error
	CreatePayment(ctx context.Context, payment *Payment) error
	UpdatePayment(ctx context.Context, payment *Payment) error

	// GetMaxBlockHeightForCurrencies returns a map of currencies and the last
	// known block height. It must return all currencies that are awaiting
	// payment, even if they don't have a known last block height.
	GetMaxBlockHeightForCurrencies(ctx context.Context) (map[string]uint64, error)
}

InvoiceRepository is the abstraction for handling Invoices database

type InvoiceStatus

type InvoiceStatus int

InvoiceStatus determines the current status for the invoice

const (
	// Pending when the invoice has been created but the wallet has not
	// received payment yet or the payment amount is not enough
	Pending InvoiceStatus = 1
	// Completed when the invoice has been payed completely.
	Completed InvoiceStatus = 2
	// Failed when the payments fails for whatever reason
	Failed InvoiceStatus = 3
)

type InvoiceTopic

type InvoiceTopic interface {
	Register(invoiceID string) <-chan Invoice
	Unregister(invoiceID string)
	Send(msg Invoice)
	Close()
}

InvoiceTopic is a pub-sub mechanism where consumers can Register to receive messages sent to using Send. credits to https://github.com/tv42/topic/blob/master/topic.go

type Payment

type Payment struct {
	ID              uint            `sql:",pk"`
	TxHash          string          `sql:",notnull"`
	PaymentMethodID uint            `sql:",notnull"`
	Amount          decimal.Decimal `sql:",notnull"`
	Confirmations   uint64
	BlockHeight     uint64
	ConfirmedAt     time.Time
	CreatedAt       time.Time `sql:",notnull"`
}

func (*Payment) Status

func (payment *Payment) Status() PaymentStatus

func (*Payment) Update

func (payment *Payment) Update(confirmations uint64, blockHeight uint64) bool

type PaymentMethod

type PaymentMethod struct {
	ID        uint            `sql:",pk"`
	InvoiceID string          `sql:",notnull"`
	Total     decimal.Decimal `sql:",notnull"`
	Currency  string          `sql:",notnull"`
	Address   string          `sql:",notnull"`
	Payments  []*Payment
}

func (*PaymentMethod) AddPayment

func (method *PaymentMethod) AddPayment(
	txHash string,
	amount decimal.Decimal,
	confirmations uint64,
	blockHeight uint64,
) *Payment

func (*PaymentMethod) FindPayment

func (method *PaymentMethod) FindPayment(txHash string) *Payment

type PaymentStatus

type PaymentStatus int

PaymentStatus of the payment

const (
	// Mempool when the wallet has received the payment, and it's waiting
	// to be included in a block.
	Mempool PaymentStatus = 1
	// Confirmed when the wallet has received enough confirmations.
	Confirmed PaymentStatus = 2
)

type PluginManager

type PluginManager interface {
	LoadPlugins(ctx context.Context)
	GetAllPlugins() ([]plugin.PluginInfo, error)
	GetWallet(ID string) (plugin.WalletPlugin, error)
	GetWalletForCurrency(currency string) (plugin.WalletPlugin, error)
	GetWalletInfoForCurrency(currency string) (plugin.WalletPluginInfo, error)
	GetAllCurrencies() ([]plugin.WalletPluginCurrency, error)
	GetExchangeRatesPlugin(ID string) (plugin.ExchangeRatesPlugin, error)
	GetConfiguredExchangeRatesPlugin() (plugin.ExchangeRatesPlugin, error)
}

PluginManager is the first line of control for plugins

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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