payment

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("no records could be found")
	ErrExists   = errors.New("the transaction index for this signature already exists")
)

Functions

This section is empty.

Types

type ByBlock

type ByBlock []*Record

func (ByBlock) Len

func (a ByBlock) Len() int

func (ByBlock) Less

func (a ByBlock) Less(i, j int) bool

func (ByBlock) Swap

func (a ByBlock) Swap(i, j int)

type PaymentType

type PaymentType uint32
const (
	PaymentType_Send PaymentType = iota
	PaymentType_Receive
)

type Record

type Record struct {
	Id uint64 // The internal database id for this transaction

	BlockId          uint64
	BlockTime        time.Time
	TransactionId    string // The signature of the Solana transaction, which could contain multiple payments
	TransactionIndex uint32 // The index that the transfer (payment) instruction appears at inside the Solana transaction
	Rendezvous       string // The public key of the party that is the rendezvous point for this payment (might be empty)
	IsExternal       bool   // External payments are deprecated, in favour of the new deposit store

	Source      string // The source account id for this payment
	Destination string // The destination account id for this payment
	Quantity    uint64 // The amount of Kin (in Quarks)

	ExchangeCurrency string  // The (external) agreed upon currency for the exchange
	ExchangeRate     float64 // The (external) agreed upon exchange rate for determining the amount of Kin to transfer
	UsdMarketValue   float64 // The (internal) market value of this transfer based on the internal exchange rate record
	Region           *string // The (external) agreed upon country flag for the currency

	IsWithdraw bool

	ConfirmationState transaction.Confirmation
	CreatedAt         time.Time
}

The structure for metadata behind a payment or token transfer between two parties. This data is considered untrusted as it comes from the client apps directly and not from the blockchain. It gives us the intended native currencies for the agreed upon exchange between two app users. This data cannot be derived from the blockchain alone. We could guess at it, but then we would definitely be off by a couple decimal points every now and then when reporting the booking cost back to the user.

Note: This is generally unused right now and should be deprecated with the new intent system and external data models. There's a few use cases still hitting this which, in particular, need to know the order of transfers.

func NewFromTransfer

func NewFromTransfer(transfer *token.DecompiledTransfer, sig string, index int, rate float64, now time.Time) *Record

func NewFromTransferChecked

func NewFromTransferChecked(transfer *token.DecompiledTransfer2, sig string, index int, rate float64, now time.Time) (*Record, error)

type Store

type Store interface {
	// Get finds the record for a given id
	//
	// ErrNotFound is returned if the record cannot be found
	Get(ctx context.Context, txId string, index uint32) (*Record, error)

	// GetAllForTransaction returns payment records in the store for a
	// given transaction signature.
	//
	// ErrNotFound is returned if no rows are found.
	GetAllForTransaction(ctx context.Context, txId string) ([]*Record, error)

	// GetAllForAccount returns payment records in the store for a
	// given "account" after a provided "cursor" value and limited to at most
	// "limit" results.
	//
	// ErrNotFound is returned if no rows are found.
	GetAllForAccount(ctx context.Context, account string, cursor uint64, limit uint, ordering query.Ordering) ([]*Record, error)

	// GetAllForAccountByType returns payment records in the store for a
	// given "account" after a provided "cursor" value and limited to at most
	// "limit" results.
	//
	// ErrNotFound is returned if no rows are found.
	GetAllForAccountByType(ctx context.Context, account string, cursor uint64, limit uint, ordering query.Ordering, paymentType PaymentType) ([]*Record, error)

	// GetAllForAccountByTypeAfterBlock returns payment records in the store for a
	// given "account" after a "block" after a provided "cursor" value and limited
	// to at most "limit" results.
	//
	// ErrNotFound is returned if no rows are found.
	GetAllForAccountByTypeAfterBlock(ctx context.Context, account string, block uint64, cursor uint64, limit uint, ordering query.Ordering, paymentType PaymentType) ([]*Record, error)

	// GetAllForAccountByTypeWithinBlockRange returns payment records in the store
	// for a given "account" within a "block" range (lowerBound, upperBOund) after a
	// provided "cursor" value and limited to at most "limit" results.
	//
	// ErrNotFound is returned if no rows are found.
	GetAllForAccountByTypeWithinBlockRange(ctx context.Context, account string, lowerBound, upperBound uint64, cursor uint64, limit uint, ordering query.Ordering, paymentType PaymentType) ([]*Record, error)

	// GetExternalDepositAmount gets the total amount of Kin in quarks deposited to
	// an account via a deposit from an external account.
	GetExternalDepositAmount(ctx context.Context, account string) (uint64, error)

	// Put saves payment metadata to the store.
	//
	// ErrTransactionIndexExists is returned if a transaction with the same signature already exists.
	Put(ctx context.Context, record *Record) error

	// Update an existing record on the backend store/database
	//
	// ErrNotFound is returned if the record cannot be found
	Update(ctx context.Context, record *Record) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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