core

package
v0.0.0-...-d1cf776 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeInternal         = 1
	ErrCodeInvalidParam     = 2
	ErrCodeUnauthorized     = 3
	ErrCodePermissionDenied = 4
)
View Source
const (
	// transaction
	ErrCodeTransactionNotExists = 10000
	ErrCodeInvalidSignature     = 10001
	ErrCodeInvalidAsset         = 10002
)
View Source
const (
	// output
	ErrCodeOutputNotExists    = 10100
	ErrCodeOutputKeyExists    = 10101
	ErrCodeOutputAlreadySpent = 10102
)
View Source
const (
	ErrCodeInsufficientBalance = 10202
	ErrCodeTracePaidByOthers   = 10203
)

Variables

This section is empty.

Functions

func CreateError

func CreateError(status, code int, msg, hint string) error

func NewOutput

func NewOutput(addrs []*hxnet.Address, asset crypto.Hash, amount decimal.Decimal, outputIndex int) (*hxnet.Output, error)

Types

type Error

type Error struct {
	Status  int    `json:"-"`
	Code    int    `json:"code"`
	Message string `json:"msg"`
	Hint    string `json:"hint,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type KernelService

type KernelService interface {
	SubmitTransaction(ctx context.Context, tx *hxnet.Transaction) (crypto.Hash, error)
	ReadTransaction(ctx context.Context, txHash crypto.Hash) (*hxnet.Transaction, error)
	ReadUTXO(ctx context.Context, txHash crypto.Hash, index int) (*hxnet.UTXO, error)
	ReadSnapshots(ctx context.Context, from, count int) ([]*hxnet.Snapshot, error)
}

type PendingTransaction

type PendingTransaction struct {
	ID             uint        `gorm:"PRIMARY_KEY;" json:"id"`
	TraceID        string      `gorm:"SIZE:36;UNIQUE;" json:"trace_id"`
	UserID         uuid.UUID   `gorm:"SIZE:36;" json:"user_id"`
	CreatedAt      time.Time   `json:"created_at"`
	DeletedAt      *time.Time  `gorm:"INDEX;" json:"deleted_at,omitempty"`
	Hash           crypto.Hash `gorm:"SIZE:128;" json:"hash"`
	RawTransaction string      `gorm:"type:LONGTEXT;" json:"raw_transaction"`
}

func (PendingTransaction) TableName

func (t PendingTransaction) TableName() string

type Snapshot

type Snapshot struct {
	ID         uint            `gorm:"PRIMARY_KEY;" json:"id"`
	CreatedAt  time.Time       `json:"created_at"`
	Hash       crypto.Hash     `gorm:"SIZE:128;" json:"hash"`
	TraceID    string          `gorm:"SIZE:36;" json:"trace_id"`
	Asset      crypto.Hash     `gorm:"SIZE:128;" json:"asset"`
	UserID     uuid.UUID       `gorm:"SIZE:36;" json:"user_id"`
	OpponentID uuid.UUID       `gorm:"SIZE:36;" json:"opponent_id"`
	Amount     decimal.Decimal `gorm:"type:DECIMAL(30,8);" json:"amount"`
	Memo       string          `gorm:"type:LONGTEXT;" json:"memo"`
}

func (Snapshot) TableName

func (s Snapshot) TableName() string

type Store

type Store interface {
	AddUser(ctx context.Context, user *User) error
	ReadUser(ctx context.Context, userID uuid.UUID) (*User, error)
	QueryUser(ctx context.Context, pubSpend string) (*User, error)

	ReadUTXO(ctx context.Context, userID uuid.UUID, asset crypto.Hash) (*UTXO, error)
	QuerySnapshots(ctx context.Context, userID uuid.UUID, asset crypto.Hash, order string, from uint, limit int) ([]*Snapshot, error)
	AddKernelTransaction(ctx context.Context, transaction *hxnet.Transaction, timestamp time.Time) error

	QueryPendingTransactions(ctx context.Context, limit int) ([]*PendingTransaction, error)
	AddPendingTransaction(ctx context.Context, traceID string, tx *hxnet.Transaction, sender uuid.UUID, addresses []string) (crypto.Hash, error)
	ExpirePendingTransaction(ctx context.Context, tx *PendingTransaction) error
}

type UTXO

type UTXO struct {
	ID        uint            `gorm:"PRIMARY_KEY;" json:"id"`
	CreatedAt time.Time       `json:"created_at"`
	UserID    uuid.UUID       `gorm:"SIZE:36;" json:"user_id"`
	Asset     crypto.Hash     `gorm:"SIZE:64;" json:"asset"`
	TxHash    crypto.Hash     `gorm:"SIZE:64;" json:"tx_hash"`
	Index     int             `json:"index"`
	KeyIndex  int             `json:"key_index"`
	KeyCount  int             `json:"key_count"`
	Amount    decimal.Decimal `gorm:"type:DECIMAL(30,8);" json:"amount"`
	Mask      crypto.Key      `gorm:"SIZE:64;" json:"mask"`
	Key       crypto.Key      `gorm:"SIZE:64;" json:"key"`
}

func (UTXO) Export

func (u UTXO) Export() *hxnet.Input

func (UTXO) TableName

func (u UTXO) TableName() string

type User

type User struct {
	UserID      uuid.UUID  `gorm:"SIZE:36;PRIMARY_KEY;" json:"user_id"`
	CreatedAt   time.Time  `json:"created_at"`
	Address     string     `gorm:"SIZE:255;" json:"address"`
	PublicSpend crypto.Key `gorm:"SIZE:64;" json:"public_spend"`
	Keystore    string     `gorm:"SIZE:512;" json:"keystore"`
	// contains filtered or unexported fields
}

func (*User) HxAddress

func (user *User) HxAddress(publicOnly bool) (*hxnet.Address, error)

func (User) NewOutput

func (user User) NewOutput(asset crypto.Hash, amount decimal.Decimal, outputIndex int) (*hxnet.Output, error)

func (User) NewTransaction

func (user User) NewTransaction(dests []*hxnet.Address, utxo *UTXO, memo string) (*hxnet.Transaction, error)

func (User) TableName

func (user User) TableName() string

Jump to

Keyboard shortcuts

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