domain

package
v0.0.0-...-93b2285 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MainNet = `main`
	TestNet = `test`
)
View Source
const (
	Rub FiatCurrency   = `RUB`
	Btc CryptoCurrency = `btc`
)
View Source
const (
	MinorDiv = 100000000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address interface {
	Pub() string
	Wif() string
	Uid() uint32
}

type AddressGeneratorContext

type AddressGeneratorContext struct {
	Currency CryptoCurrency
	UserId   uint32
}

type Cache

type Cache interface {
	Get(ctx context.Context, key string) CacheResponse
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) CacheResponse
	Context() context.Context
}

type CacheResponse

type CacheResponse interface {
	Val() string
	Err() error
}

type Crypto

type Crypto struct {
	Currency  CryptoCurrency `pg:",pk"`
	Address   string         `pg:",pk"`
	UserId    uint32         `sql:",fk"`
	Balance   float64
	UpdatedAt time.Time
	Fiat      float64
	User      *domain.User
}

Crypto represents the last state of user`s balance

type CryptoAddressGenerator

type CryptoAddressGenerator interface {
	Generate(context *AddressGeneratorContext) (Address, error)
}

type CryptoCurrency

type CryptoCurrency string

CryptoCurrency is a cryptocurrency type

type CryptoRepository

type CryptoRepository interface {
	// AssignAddress inserts crypto address to user
	AssignAddress(*Crypto, Address) error
	// Get fetches convenient entity
	Get(user *domain.User, currency CryptoCurrency) *Crypto
	// UpdateBalance updates balance and fiat fields only
	UpdateBalance(user *Crypto) error
	// FindOutdated looking for outdated rows
	FindOutdated(date time.Time, limit int) ([]*Crypto, error)
}

CryptoRepository keeps crypto user`s addresses

type ExchangeRateConverter

type ExchangeRateConverter interface {
	Convert(*Wallet, FiatCurrency) (float64, error)
}

ExchangeRateConverter converts wallet's balance to fiat currency

type FiatCurrency

type FiatCurrency string

FiatCurrency is a fiat currency type

type Gate

type Gate interface {
	Send(request *http.Request) (resp *http.Response, err error)
}

type Rate

type Rate struct {
	M      float64 `json:"15m"`
	Last   float64 `json:"last"`
	Buy    float64 `json:"buy"`
	Sell   float64 `json:"sell"`
	Symbol string  `json:"symbol"`
}

Rate contains exchange rate for some fiat currency

type Rates

type Rates map[FiatCurrency]*Rate

Rates is a map of Rate where key is a fiat currency name

type Session

type Session struct {
	UserId   int
	Token    string
	Datetime time.Time    `pg:"default:now(),notnull"`
	OAuth    domain.Oauth `pg:"notnull"`
}

type TextHandler

type TextHandler interface {
	Handle(request TextRequest) error
}

type TextRequest

type TextRequest struct {
	CryptoCurrency CryptoCurrency
	FiatCurrency   FiatCurrency
	// contains filtered or unexported fields
}

func NewTextRequest

func NewTextRequest(peerId int, msg string) TextRequest

NewTextRequest handles variety texts

func (*TextRequest) GetMessage

func (r *TextRequest) GetMessage() string

func (*TextRequest) GetPeerId

func (r *TextRequest) GetPeerId() int

type Wallet

type Wallet struct {
	Hash160       string  `json:"hash160"`
	Address       string  `json:"address"`
	NTx           int     `json:"n_tx"`
	NUnredeemed   int     `json:"n_unredeemed"`
	TotalReceived int     `json:"total_received"`
	TotalSent     int     `json:"total_sent"`
	FinalBalance  float64 `json:"final_balance"`
}

func NewWallet

func NewWallet() *Wallet

func (*Wallet) BalanceToBTC

func (r *Wallet) BalanceToBTC() float64

func (*Wallet) MarshalBinary

func (r *Wallet) MarshalBinary() (data []byte, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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