blockchain

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: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidation         = errors.New("invalid data provided")
	ErrCurrencyNotFound   = errors.New("currency not found")
	ErrNoTokenAddress     = errors.New("token should have contract address filled")
	ErrParseMoney         = errors.New("unable to parse money value")
	ErrInsufficientFunds  = errors.New("wallet has insufficient funds")
	ErrInvalidTransaction = errors.New("transaction is invalid")
)

Functions

func CreateExplorerTXLink(blockchain money.Blockchain, networkID, txID string) (string, error)
func CreatePaymentLink(addr string, currency money.CryptoCurrency, amount money.Money, isTest bool) (string, error)

func DefaultSetup

func DefaultSetup(s *CurrencyResolver) error

nolint:gocritic DefaultSetup applied coins & tokens that are supported within Oxygen.

func NormalizeTicker added in v0.2.0

func NormalizeTicker(ticker string) string

NormalizeTicker normalizes fiat / crypto ticker for further usage in external services (e.g. Tatum).

Types

type BSCFee added in v0.3.0

type BSCFee struct {
	GasUnits     uint   `json:"gasUnits"`
	GasPrice     string `json:"gasPrice"`
	PriorityFee  string `json:"priorityFee"`
	TotalCostWEI string `json:"totalCostWei"`
	TotalCostBNB string `json:"totalCostBNB"`
	TotalCostUSD string `json:"totalCostUsd"`
	// contains filtered or unexported fields
}

type Broadcaster

type Broadcaster interface {
	BroadcastTransaction(ctx context.Context, blockchain money.Blockchain, hex string, isTest bool) (string, error)
	GetTransactionReceipt(ctx context.Context, blockchain money.Blockchain, transactionID string, isTest bool) (*TransactionReceipt, error)
}

type Conversion

type Conversion struct {
	Type ConversionType
	Rate float64
	From money.Money
	To   money.Money
}

type ConversionType

type ConversionType string
const (
	ConversionTypeFiatToFiat   ConversionType = "fiatToFiat"
	ConversionTypeFiatToCrypto ConversionType = "fiatToCrypto"
	ConversionTypeCryptoToFiat ConversionType = "cryptoToFiat"
)

type Convertor

type Convertor interface {
	GetExchangeRate(ctx context.Context, from, to string) (ExchangeRate, error)
	Convert(ctx context.Context, from, to, amount string) (Conversion, error)
	FiatToFiat(ctx context.Context, from money.Money, to money.FiatCurrency) (Conversion, error)
	FiatToCrypto(ctx context.Context, from money.Money, to money.CryptoCurrency) (Conversion, error)
	CryptoToFiat(ctx context.Context, from money.Money, to money.FiatCurrency) (Conversion, error)
}

type CurrencyResolver

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

func NewCurrencies

func NewCurrencies() *CurrencyResolver

func (*CurrencyResolver) GetCurrencyByBlockchainAndContract

func (r *CurrencyResolver) GetCurrencyByBlockchainAndContract(bc money.Blockchain, networkID, addr string) (money.CryptoCurrency, error)

GetCurrencyByBlockchainAndContract searches currency by blockchain and contract address across both mainnet & testnet.

func (*CurrencyResolver) GetCurrencyByTicker

func (r *CurrencyResolver) GetCurrencyByTicker(ticker string) (money.CryptoCurrency, error)

func (*CurrencyResolver) GetMinimalWithdrawalByTicker

func (r *CurrencyResolver) GetMinimalWithdrawalByTicker(ticker string) (money.Money, error)

GetMinimalWithdrawalByTicker returns minimal withdrawal amount in USD for selected ticker.

func (*CurrencyResolver) GetNativeCoin added in v0.3.0

func (r *CurrencyResolver) GetNativeCoin(chain money.Blockchain) (money.CryptoCurrency, error)

GetNativeCoin returns native coin by blockchain. Example: ETH -> ETH; BSC -> BNB.

func (*CurrencyResolver) GetUSDMinimalInternalTransferByTicker

func (r *CurrencyResolver) GetUSDMinimalInternalTransferByTicker(ticker string) (money.Money, error)

GetUSDMinimalInternalTransferByTicker returns minimal internal transfer amount in USD for selected ticker. internal transfer is a transfer from inbound to outbound O2pay wallet.

func (*CurrencyResolver) ListBlockchainCurrencies

func (r *CurrencyResolver) ListBlockchainCurrencies(blockchain money.Blockchain) []money.CryptoCurrency

func (*CurrencyResolver) ListSupportedBlockchains

func (r *CurrencyResolver) ListSupportedBlockchains() []money.Blockchain

func (*CurrencyResolver) ListSupportedCurrencies

func (r *CurrencyResolver) ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency

type EthFee

type EthFee struct {
	GasUnits     uint   `json:"gasUnits"`
	GasPrice     string `json:"gasPrice"`
	PriorityFee  string `json:"priorityFee"`
	TotalCostWEI string `json:"totalCostWei"`
	TotalCostETH string `json:"totalCostEth"`
	TotalCostUSD string `json:"totalCostUsd"`
	// contains filtered or unexported fields
}

type ExchangeRate

type ExchangeRate struct {
	From         string
	To           string
	Rate         float64
	CalculatedAt time.Time
}

type Fee

type Fee struct {
	CalculatedAt time.Time
	Currency     money.CryptoCurrency
	IsTest       bool
	// contains filtered or unexported fields
}

func NewFee

func NewFee(currency money.CryptoCurrency, at time.Time, isTest bool, fee any) Fee

func (*Fee) ToBSCFee added in v0.3.0

func (f *Fee) ToBSCFee() (BSCFee, error)

func (*Fee) ToEthFee

func (f *Fee) ToEthFee() (EthFee, error)

func (*Fee) ToMaticFee

func (f *Fee) ToMaticFee() (MaticFee, error)

func (*Fee) ToTronFee

func (f *Fee) ToTronFee() (TronFee, error)

type FeeCalculator

type FeeCalculator interface {
	CalculateFee(ctx context.Context, baseCurrency, currency money.CryptoCurrency, isTest bool) (Fee, error)
	CalculateWithdrawalFeeUSD(ctx context.Context, baseCurrency, currency money.CryptoCurrency, isTest bool) (money.Money, error)
}

type MaticFee

type MaticFee struct {
	GasUnits       uint   `json:"gasUnits"`
	GasPrice       string `json:"gasPrice"`
	PriorityFee    string `json:"priorityFee"`
	TotalCostWEI   string `json:"totalCostWei"`
	TotalCostMATIC string `json:"totalCostMatic"`
	TotalCostUSD   string `json:"totalCostUsd"`
	// contains filtered or unexported fields
}

type Providers

type Providers struct {
	Tatum    *tatum.Provider
	Trongrid *trongrid.Provider
}

type Resolver

type Resolver interface {
	ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency
	ListBlockchainCurrencies(blockchain money.Blockchain) []money.CryptoCurrency
	GetCurrencyByTicker(ticker string) (money.CryptoCurrency, error)
	GetNativeCoin(blockchain money.Blockchain) (money.CryptoCurrency, error)
	GetCurrencyByBlockchainAndContract(bc money.Blockchain, networkID, addr string) (money.CryptoCurrency, error)
	GetMinimalWithdrawalByTicker(ticker string) (money.Money, error)
	GetUSDMinimalInternalTransferByTicker(ticker string) (money.Money, error)
}

type Service

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

func New

func New(currencies *CurrencyResolver, providers Providers, enableCache bool, logger *zerolog.Logger) *Service

func (*Service) BroadcastTransaction

func (s *Service) BroadcastTransaction(ctx context.Context, blockchain money.Blockchain, rawTX string, isTest bool) (string, error)

func (*Service) CalculateFee

func (s *Service) CalculateFee(ctx context.Context, baseCurrency, currency money.CryptoCurrency, isTest bool) (Fee, error)

CalculateFee calculates blockchain transaction fee for selected currency.

func (*Service) CalculateWithdrawalFeeUSD

func (s *Service) CalculateWithdrawalFeeUSD(
	ctx context.Context,
	baseCurrency, currency money.CryptoCurrency,
	isTest bool,
) (money.Money, error)

CalculateWithdrawalFeeUSD withdrawal fees are tied to network fee but calculated in USD Example: usdFee, err := CalculateWithdrawalFeeUSD(ctx, eth, ethUSD, false)

func (*Service) Convert

func (s *Service) Convert(ctx context.Context, from, to, amount string) (Conversion, error)

Convert Converts currencies according to automatically resolved ConversionType. This method parses amount as float64, please don't use it internally as output would contain huge error rate when dealing with 18 eth decimals. Suitable for API responses.

func (*Service) CryptoToFiat

func (s *Service) CryptoToFiat(ctx context.Context, from money.Money, to money.FiatCurrency) (Conversion, error)

func (*Service) FiatToCrypto

func (s *Service) FiatToCrypto(ctx context.Context, from money.Money, to money.CryptoCurrency) (Conversion, error)

func (*Service) FiatToFiat

func (s *Service) FiatToFiat(ctx context.Context, from money.Money, to money.FiatCurrency) (Conversion, error)

func (*Service) GetExchangeRate

func (s *Service) GetExchangeRate(ctx context.Context, from, to string) (ExchangeRate, error)

func (*Service) GetTransactionReceipt

func (s *Service) GetTransactionReceipt(
	ctx context.Context,
	blockchain money.Blockchain,
	transactionID string,
	isTest bool,
) (*TransactionReceipt, error)

type TransactionReceipt

type TransactionReceipt struct {
	Blockchain    money.Blockchain
	IsTest        bool
	Sender        string
	Recipient     string
	Hash          string
	Nonce         uint64
	NetworkFee    money.Money
	Success       bool
	Confirmations int64
	IsConfirmed   bool
}

type TronFee

type TronFee struct {
	FeeLimitSun uint64 `json:"feeLimit"`
	FeeLimitTRX string `json:"feeLimitTrx"`
	FeeLimitUSD string `json:"feeLimitUsd"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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