model

package
v0.0.0-...-dc3c4d4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BillStatusCreated = iota
	BillStatusSubmitting
	BillStatusSubmitted
	BillStatusFailed
)

Variables

View Source
var (
	// general error
	ErrNil            = &BusinessError{Code: 0, Message: "OK"}
	ErrValidation     = &BusinessError{Code: 1, Message: "Invalid parameter"}
	ErrInternalServer = &BusinessError{Code: 2, Message: "Internal server error"}
	ErrAuth           = &BusinessError{Code: 3, Message: "Authentication failed"}

	// specific error
	ErrAppNotFound        = &BusinessError{Code: 10000, Message: "APP not found"}
	ErrResourceNotFound   = &BusinessError{Code: 10001, Message: "Resource not found"}
	ErrInsufficentBalance = &BusinessError{Code: 10002, Message: "Insufficient balance"}
	ErrAccountFrozen      = &BusinessError{Code: 10003, Message: "Account fronzen"}
	ErrInvalidAppOperator = &BusinessError{Code: 10004, Message: "Invalid APP operator"}
	ErrNotBillingApp      = &BusinessError{Code: 10005, Message: "Not a billing APP"}
)
View Source
var All = []interface{}{
	&Bill{},
}

Functions

This section is empty.

Types

type AppAccount

type AppAccount struct {
	// APP contract address
	App string
	// account address
	Address string
	// frozen status, 0 means not frozen
	Frozen int64
	// deduction fee
	Fee decimal.Decimal
	// pending balance
	Balance decimal.Decimal
	// the confirmed block number, math.MaxInt64 means not confirmed
	ConfirmedBlock int64
}

func NewAppAccount

func NewAppAccount(app, address string, frozen int64, balance *big.Int) *AppAccount

func (*AppAccount) DecreaseBalance

func (account *AppAccount) DecreaseBalance(delta *big.Int) bool

func (*AppAccount) DecreaseFee

func (account *AppAccount) DecreaseFee(delta *big.Int) bool

func (*AppAccount) IncreaseBalance

func (account *AppAccount) IncreaseBalance(delta *big.Int)

func (*AppAccount) IncreaseFee

func (account *AppAccount) IncreaseFee(delta *big.Int)

func (*AppAccount) IsConfirmed

func (account *AppAccount) IsConfirmed() bool

func (*AppAccount) IsFrozen

func (account *AppAccount) IsFrozen() bool

func (*AppAccount) TotalBalance

func (account *AppAccount) TotalBalance() *big.Int

type Bill

type Bill struct {
	ID uint64
	// APP contract address
	App string `gorm:"size:64;not null;index:idx_app_addr,priority:1"`
	// account address
	Address string `gorm:"size:64;not null;index:idx_app_addr,priority:2"`
	// total deduction fee
	Fee decimal.Decimal `gorm:"size:128;type:string"`
	// 0 - created, 1 - submitting, 2 - submitted
	// record shall be deleted if settlement confirmed
	Status uint8 `gorm:"default:0"`
	// transaction hash if submitted
	TxnHash string `gorm:"size:64;type:string"`
	// memo
	Memo string `gorm:"size:256;type:string"`
	// create date
	CreatedAt time.Time
	// update date
	UpdatedAt time.Time
}

Bill bills to settle on blockchain

type BusinessError

type BusinessError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func IsBusinessError

func IsBusinessError(err error) (*BusinessError, bool)

func (*BusinessError) Error

func (err *BusinessError) Error() string

func (*BusinessError) GetObject

func (be *BusinessError) GetObject(toType interface{}) error

GetObject converts the business error data to an arbitrary type.

The function works as you would expect it from json.Unmarshal()

func (*BusinessError) IsNil

func (err *BusinessError) IsNil() bool

func (*BusinessError) WithData

func (be *BusinessError) WithData(data interface{}) *BusinessError

Jump to

Keyboard shortcuts

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