core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTrace = errors.New("invalid trace")
)

Functions

func EncodeToken

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

func EncodeTokens

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

Types

type Address

type Address struct {
	Destination string `json:"destination,omitempty"`
	Tag         string `json:"tag,omitempty"`
}

func (Address) MarshalBinary

func (a Address) MarshalBinary() ([]byte, error)

func (*Address) Scan

func (a *Address) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(data []byte) error

func (*Address) Value

func (a *Address) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

type Factory

type Factory interface {
	Platform() string
	GasAsset() string
	CreateTransaction(ctx context.Context, tokens []*Token, receiver *Address) (*Transaction, error)
	SendTransaction(ctx context.Context, tx *Transaction) error
	ReadTransaction(ctx context.Context, hash string) (*Transaction, error)
}

type Gas

type Gas struct {
	Mins             number.Values
	Multiplier       decimal.Decimal
	StrictMultiplier 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"`
	Tokens      Tokens          `sql:"type:longtext;" json:"tokens,omitempty"`
	Result      Tokens          `sql:"type:longtext;" json:"result,omitempty"`
	Receiver    *Address        `sql:"size:255;" json:"receiver,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
	Gas          Gas
	Addresses    map[string]*Address
}

System stores system information.

type Token

type Token struct {
	Name        string `gorm:"size:255;" json:"name,omitempty"`
	Symbol      string `gorm:"size:255;" json:"symbol,omitempty"`
	TotalSupply uint64 `json:"total_supply,omitempty"`
	AssetKey    string `gorm:"size:255;" json:"asset_key,omitempty"`
	AssetID     string `gorm:"size:36;" json:"asset_id,omitempty"`
}

func DecodeToken

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

func (Token) MarshalBinary

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

func (*Token) UnmarshalBinary

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

type Tokens

type Tokens []*Token

func DecodeTokens

func DecodeTokens(data []byte) Tokens

func (Tokens) MarshalBinary

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

func (*Tokens) Scan

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

Scan implements the sql.Scanner interface for database deserialization.

func (*Tokens) UnmarshalBinary

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

func (Tokens) Value

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

Value implements the driver.Valuer interface for database serialization.

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           `json:"hash,omitempty"`
	Raw       string           `sql:"type:longtext;" json:"raw,omitempty"`
	State     TransactionState `json:"state,omitempty"`
	Tokens    Tokens           `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
	ReqTransfer(ctx context.Context, transfer *Transfer) (string, 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