transaction

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaComment     wallet.MetaDataKey = "comment"
	MetaErrorReason wallet.MetaDataKey = "errorReason"

	MetaTransactionID     = "transactionId"
	MetaRecipientWalletID = "recipientWalletId"
	MetaMerchantID        = "merchantId"
)
View Source
const (
	// MerchantIDWildcard discards filtration by merchant id
	MerchantIDWildcard = int64(-1)

	// SystemMerchantID indicates txs related to system
	SystemMerchantID = int64(0)
)

Variables

View Source
var (
	ErrNotFound            = errors.New("transaction not found")
	ErrSameStatus          = errors.New("status not changed")
	ErrInvalidUpdateParams = errors.New("invalid update params")
)

Functions

This section is empty.

Types

type ConfirmTransaction

type ConfirmTransaction struct {
	Status          Status
	SenderAddress   string
	TransactionHash string
	FactAmount      money.Money
	NetworkFee      money.Money
	MetaData        MetaData
	// contains filtered or unexported fields
}

func (*ConfirmTransaction) AllowZeroNetworkFee

func (c *ConfirmTransaction) AllowZeroNetworkFee()

type CreateOpt

type CreateOpt func(p *CreateTransaction)

func IncomingUnexpected

func IncomingUnexpected() CreateOpt

IncomingUnexpected marks that tx should be stored as StatusCompleted w/o any further processing.

type CreateTransaction

type CreateTransaction struct {
	Type Type

	// EntityID that is related to that tx.
	// In case of incoming tx that's payment id
	// In case of internal tx that's 0
	// In case of withdrawal tx that's payment (withdrawal) id
	EntityID int64

	SenderAddress string
	SenderWallet  *wallet.Wallet

	RecipientAddress string
	RecipientWallet  *wallet.Wallet

	TransactionHash string

	Currency   money.CryptoCurrency
	Amount     money.Money
	USDAmount  money.Money
	ServiceFee money.Money

	IsTest bool
	// contains filtered or unexported fields
}

type Filter

type Filter struct {
	RecipientWalletID int64
	NetworkID         string
	Currency          string
	Types             []Type
	Statuses          []Status
	HashIsEmpty       bool
}

Filter filter for resolving tx by wallet, network & currency and possible types/statuses. If types/statuses field is empty, then filter this type is omitted.

type MetaData

type MetaData wallet.MetaData

type ReceiveTransaction

type ReceiveTransaction struct {
	Status          Status
	SenderAddress   string
	TransactionHash string
	FactAmount      money.Money
	MetaData        MetaData
}

type Service

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

func New

func New(
	store *repository.Store,
	blockchainService blockchain.Resolver,
	wallets *wallet.Service,
	logger *zerolog.Logger,
) *Service

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, tx *Transaction, status Status, reason string, setNetworkFee *money.Money) error

func (*Service) Confirm

func (s *Service) Confirm(
	ctx context.Context,
	merchantID, txID int64,
	params ConfirmTransaction,
) (*Transaction, error)

func (*Service) Create

func (s *Service) Create(
	ctx context.Context,
	merchantID int64,
	params CreateTransaction,
	opts ...CreateOpt,
) (*Transaction, error)

Create creates transaction record in the database. If Type is TypeInternal, merchantID should be zero.

func (*Service) CreateSystemTopup added in v0.6.0

func (s *Service) CreateSystemTopup(ctx context.Context, merchantID int64, params CreateTransaction) (*Transaction, error)

func (*Service) EagerLoadByPaymentIDs

func (s *Service) EagerLoadByPaymentIDs(ctx context.Context, merchantID int64, paymentIDs []int64) ([]*Transaction, error)

func (*Service) GetByFilter

func (s *Service) GetByFilter(ctx context.Context, filter Filter) (*Transaction, error)

GetByFilter returns tx filtered by recipient wallet id and other stuff.

func (*Service) GetByHash

func (s *Service) GetByHash(ctx context.Context, networkID, txHash string) (*Transaction, error)

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, merchantID, id int64) (*Transaction, error)

func (*Service) GetLatestByPaymentID

func (s *Service) GetLatestByPaymentID(ctx context.Context, paymentID int64) (*Transaction, error)

func (*Service) ListByFilter

func (s *Service) ListByFilter(ctx context.Context, filter Filter, limit int64) ([]*Transaction, error)

ListByFilter returns several txs filtered by recipient wallet id and other stuff.

func (*Service) Receive

func (s *Service) Receive(
	ctx context.Context,
	merchantID, txID int64,
	params ReceiveTransaction,
) (*Transaction, error)

Receive updates tx when system notices tx on the blockchain, but it's not confirmed yet.

func (*Service) UpdateTransactionHash

func (s *Service) UpdateTransactionHash(ctx context.Context, merchantID, txID int64, txHash string) error

type Status

type Status string
const (
	// StatusPending tx was created
	StatusPending Status = "pending"

	// StatusInProgress tx is in progress: blockchain transaction is not confirmed yet
	StatusInProgress Status = "inProgress"

	// StatusInProgressInvalid tx is in progress: blockchain transaction is not confirmed yet
	// but system already sees that amount is not expected
	StatusInProgressInvalid Status = "inProgressInv"

	// StatusCompleted transaction completed
	StatusCompleted Status = "completed"

	// StatusCompletedInvalid transaction completed but not as expected
	// e.g. user deposits more than required
	StatusCompletedInvalid Status = "completedInv"

	// StatusCancelled transaction was canceled w/o actual appearance on blockchain
	StatusCancelled Status = "canceled"

	// StatusFailed transaction was confirmed in blockchain as failed (reverted)
	// but gas was consumed
	StatusFailed Status = "failed"
)

type Transaction

type Transaction struct {
	ID int64

	CreatedAt time.Time
	UpdatedAt time.Time

	MerchantID int64

	RecipientAddress  string
	RecipientWalletID *int64
	SenderAddress     *string
	SenderWalletID    *int64
	HashID            *string

	Type     Type
	EntityID int64
	Status   Status

	Currency  money.CryptoCurrency
	Amount    money.Money
	USDAmount money.Money

	FactAmount *money.Money

	ServiceFee money.Money
	NetworkFee *money.Money

	IsTest bool

	MetaData MetaData
}
func (tx *Transaction) ExplorerLink() (string, error)

ExplorerLink returns link with blockchain explorer e.g. EtherScan

func (*Transaction) IsFinalized

func (tx *Transaction) IsFinalized() bool

func (*Transaction) IsInProgress

func (tx *Transaction) IsInProgress() bool

func (*Transaction) NetworkID

func (tx *Transaction) NetworkID() string
func (tx *Transaction) PaymentLink() (string, error)

PaymentLink returns link for payment QR code generation.

type Type

type Type string
const (
	// TypeIncoming is for incoming payments
	TypeIncoming Type = "incoming"

	// TypeInternal is for moving assets from inbound to outbound wallets on blockchain
	TypeInternal Type = "internal"

	// TypeWithdrawal is for moving assets from outbound wallets to merchant's address
	TypeWithdrawal Type = "withdrawal"

	// TypeVirtual is for moving assets within OxygenPay w/o reflecting it on blockchain
	// (e.g. merchant to merchant, system to merchant, ...)
	TypeVirtual Type = "virtual"
)

Jump to

Keyboard shortcuts

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