core

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAssetNotExist = errors.New("asset not exist")
)
View Source
var (
	ErrInvalidTrace = errors.New("invalid trace")
)

Functions

func EncodeToken

func EncodeToken(token TokenItem) ([]byte, error)

func EncodeTokens

func EncodeTokens(tokens TokenItems) ([]byte, error)

Types

type Asset added in v0.1.8

type Asset struct {
	ID             uint64          `sql:"PRIMARY_KEY;" json:"id"`
	AssetID        string          `sql:"size:36;" json:"asset_id,omitempty"`
	CreatedAt      time.Time       `json:"created_at,omitempty"`
	UpdatedAt      time.Time       `json:"updated_at,omitempty"`
	Version        int64           `sql:"not null" json:"version,omitempty"`
	Verified       bool            `json:"verified"`
	Name           string          `sql:"size:64" json:"name,omitempty"`
	Symbol         string          `sql:"size:32" json:"symbol,omitempty"`
	DisplaySymbol  string          `sql:"size:32;default:null;" json:"display_symbol,omitempty"`
	ChainID        string          `sql:"size:36" json:"chain_id,omitempty"`
	Price          decimal.Decimal `sql:"type:decimal(32,8);default:0" json:"price,omitempty"`
	PriceUpdatedAt *time.Time      `sql:"default:null" json:"price_updated_at,omitempty"`
}

type AssetService added in v0.1.8

type AssetService interface {
	Find(ctx context.Context, assetID string) (*Asset, error)
}

AssetService provides access to assets information in the remote system like mixin network.

type AssetStore added in v0.1.8

type AssetStore interface {
	Save(ctx context.Context, asset *Asset) error
	Find(ctx context.Context, assetIDs ...string) ([]*Asset, error)
	ListAll(ctx context.Context) ([]*Asset, error)
}

AssetStore defines operations for working with assets on db.

type Factory

type Factory interface {
	Platform() string
	GasAsset() string
	CreateTransaction(ctx context.Context, tokens TokenItems, trace string) (*Transaction, error)
	SendTransaction(ctx context.Context, tx *Transaction) error
	ReadTransaction(ctx context.Context, hash string) (*Transaction, error)
}

type Fee added in v0.1.8

type Fee struct {
	FeeAssetID string
	FeeAmount  decimal.Decimal
}

type Order

type Order struct {
	ID            uint64          `sql:"PRIMARY_KEY;" json:"id"`
	CreatedAt     time.Time       `json:"created_at"`
	UpdatedAt     time.Time       `json:"updated_at"`
	Version       int             `json:"version,omitempty"`
	TraceID       string          `sql:"size:36;" json:"trace_id,omitempty"`
	State         OrderState      `json:"state"`
	UserID        string          `sql:"size:36;" json:"user_id,omitempty"`
	FeeAsset      string          `sql:"size:36;" json:"fee_asset,omitempty"`
	FeeAmount     decimal.Decimal `sql:"type:decimal(64,8)" json:"fee_amount,omitempty"`
	GasUsage      decimal.Decimal `sql:"type:decimal(64,8)" json:"gas_usage,omitempty"`
	Platform      string          `sql:"size:255;" json:"platform,omitempty"`
	TokenRequests TokenItems      `sql:"type:longtext;" json:"token_requests,omitempty"`
	Tokens        TokenItems      `sql:"type:longtext;" json:"tokens,omitempty"`
	Transaction   string          `sql:"size:128;" json:"transaction,omitempty"`
}

type OrderState

type OrderState int
const (
	OrderStateNew OrderState = iota
	OrderStatePaid
	OrderStateProcessing
	OrderStateFailed
	OrderStateDone
)

type OrderStore

type OrderStore interface {
	Create(ctx context.Context, order *Order) error
	Update(ctx context.Context, order *Order) error
	Find(ctx context.Context, traceID string) (*Order, error)
	List(ctx context.Context, state OrderState, limit int) ([]*Order, error)
}

type Session

type Session interface {
	// Login return user mixin id
	Login(ctx context.Context, accessToken string) (*User, error)
}

type Snapshot

type Snapshot struct {
	CreatedAt       time.Time       `json:"created_at,omitempty"`
	SnapshotID      string          `json:"snapshot_id,omitempty"`
	UserID          string          `json:"user_id,omitempty"`
	OpponentID      string          `json:"opponent_id,omitempty"`
	TraceID         string          `json:"trace_id,omitempty"`
	AssetID         string          `json:"asset_id,omitempty"`
	Source          string          `json:"source,omitempty"`
	Amount          decimal.Decimal `json:"amount,omitempty"`
	Memo            string          `json:"memo,omitempty"`
	TransactionHash string          `json:"transaction_hash,omitempty"`
}

type System

type System struct {
	Version      string
	ClientID     string
	ClientSecret string
	Fees         map[string]*Fee
	WhiteList    map[string]bool
}

System stores system information.

type TokenItem added in v0.1.8

type TokenItem struct {
	AssetID     string `json:"asset_id,omitempty"`
	AssetKey    string `json:"asset_key,omitempty"`
	Name        string `json:"name,omitempty"`
	Symbol      string `json:"symbol,omitempty"`
	TotalSupply uint64 `json:"total_supply,omitempty"`
}

func DecodeToken

func DecodeToken(data []byte) (*TokenItem, []byte)

func (TokenItem) MarshalBinary added in v0.1.8

func (t TokenItem) MarshalBinary() ([]byte, error)

func (*TokenItem) UnmarshalBinary added in v0.1.8

func (t *TokenItem) UnmarshalBinary(data []byte) error

type TokenItems added in v0.1.8

type TokenItems []*TokenItem

func DecodeTokens

func DecodeTokens(data []byte) TokenItems

func (TokenItems) MarshalBinary added in v0.1.8

func (t TokenItems) MarshalBinary() ([]byte, error)

func (*TokenItems) Scan added in v0.1.8

func (s *TokenItems) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (*TokenItems) UnmarshalBinary added in v0.1.8

func (t *TokenItems) UnmarshalBinary(data []byte) error

func (TokenItems) Value added in v0.1.8

func (s TokenItems) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

type TokenRequest added in v0.1.8

type TokenRequest struct {
	Type   TokenType `json:"type"`
	Asset1 string    `json:"asset1,omitempty"`
	Asset2 string    `json:"asset2,omitempty"`
}

type TokenRequests added in v0.1.8

type TokenRequests []*TokenRequest

func (*TokenRequests) Scan added in v0.1.8

func (s *TokenRequests) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (TokenRequests) Value added in v0.1.8

func (s TokenRequests) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

type TokenType added in v0.1.8

type TokenType int
const (
	TokenTypeFswapLP TokenType = iota
)

type Transaction

type Transaction struct {
	ID        uint64           `sql:"PRIMARY_KEY;" json:"id"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
	Version   int              `json:"version"`
	TraceID   string           `sql:"size:36;" json:"trace_id,omitempty"`
	Hash      string           `sql:"size:127;" json:"hash,omitempty"`
	Raw       string           `sql:"type:longtext;" json:"raw,omitempty"`
	State     TransactionState `json:"state,omitempty"`
	Tokens    TokenItems       `sql:"type:longtext;" json:"tokens,omitempty"`
	Gas       decimal.Decimal  `sql:"type:decimal(64,8)" json:"gas,omitempty"`
}

type TransactionState

type TransactionState int
const (
	TransactionStateNew TransactionState = iota
	TransactionStatePending
	TransactionStateFailed
	TransactionStateSuccess
)

type TransactionStore

type TransactionStore interface {
	Create(ctx context.Context, tx *Transaction) error
	Update(ctx context.Context, tx *Transaction) error
	Find(ctx context.Context, hash string) (*Transaction, error)
	FindTrace(ctx context.Context, traceID string) ([]*Transaction, error)
}

type Transfer

type Transfer struct {
	ID        int64            `sql:"PRIMARY_KEY" json:"id,omitempty"`
	Priority  TransferPriority `json:"priority"`
	CreatedAt time.Time        `json:"created_at,omitempty"`
	UpdatedAt time.Time        `json:"updated_at,omitempty"`
	TraceID   string           `sql:"type:char(36)" json:"trace_id,omitempty"`
	AssetID   string           `sql:"type:char(36)" json:"asset_id,omitempty"`
	Amount    decimal.Decimal  `sql:"type:decimal(64,8)" json:"amount,omitempty"`
	Memo      string           `sql:"size:200" json:"memo,omitempty"`
	Threshold uint8            `json:"threshold,omitempty"`
	Opponents pq.StringArray   `sql:"type:varchar(1024)" json:"opponents,omitempty"`
}

type TransferPriority

type TransferPriority int
const (
	TransferPriorityHigh TransferPriority = iota
	TransferPriorityNormal
	TransferPriorityLow
)

type User

type User struct {
	MixinID string `json:"mixin_id,omitempty"`
	Role    string `json:"role,omitempty"`
	Lang    string `json:"lang,omitempty"`
	Name    string `json:"name,omitempty"`
	Avatar  string `json:"avatar,omitempty"`
}

type UserService

type UserService interface {
	Find(ctx context.Context, mixinID string) (*User, error)
	Login(ctx context.Context, token string) (*User, error)
}

type WalletService

type WalletService interface {
	ListSnapshots(ctx context.Context, offset time.Time, limit int) ([]*Snapshot, error)
	Transfer(ctx context.Context, transfer *Transfer) error
}

type WalletStore

type WalletStore interface {
	ListTransfers(ctx context.Context, limit int) ([]*Transfer, error)
	CreateTransfers(ctx context.Context, transfers []*Transfer) error
	ExpireTransfers(ctx context.Context, transfers []*Transfer) error
	CountTransfers(ctx context.Context) (int, error)
}

Jump to

Keyboard shortcuts

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