walleter

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 11 Imported by: 0

README

neco-wallet-center

Documentation

Index

Constants

View Source
const (
	ERC20AssetType   = 0
	ERC1155AssetType = 1
	Other            = 2
)

Variables

View Source
var (
	ErrIncorrectAssetType    = errors.New("incorrect asset type in command")
	ErrIncorrectERC1155Param = errors.New("incorrect erc1155 parameters")
	ErrIncorrectCheckSign    = errors.New("check sign is invalid")
	ErrNoEnoughNFT           = errors.New("insufficient nft balance")
	ErrNoEnoughERC20Balance  = errors.New("insufficient balance")
	ErrNoEnoughBalanceForFee = errors.New("insufficient balance for fee")
	ErrAssetTypeNotSupport   = errors.New("not support current asset type")
	ErrActionTypeNotSupport  = errors.New("not support action type")
	ErrCannotFindERC20Wallet = errors.New("cannot find erc20 wallet")
)

Functions

This section is empty.

Types

type AssetType

type AssetType int

type CommandSourceType

type CommandSourceType int
const (
	InGame        CommandSourceType = 0
	Ethereum      CommandSourceType = 1
	GoerliTestnet CommandSourceType = 2
	BSC           CommandSourceType = 3
	BSCTestnet    CommandSourceType = 4
)

func (CommandSourceType) String

func (s CommandSourceType) String() string

type ERC1155Command

type ERC1155Command struct {
	Ids    []uint64
	Values []uint64
}

type ERC1155TokenWallet

type ERC1155TokenWallet struct {
	gorm.Model `swagger-ignore:"true"`
	AccountId  uint64 `json:"account_id"`
	Ids        string `json:"ids"`
	Values     string `json:"values"`
}

type ERC1155WalletLog

type ERC1155WalletLog struct {
	gorm.Model     `swagger-ignore:"true"`
	AccountId      uint64               `json:"account_id"`
	BusinessModule string               `json:"business_module" gorm:"type:varchar(64);not null;"`
	ActionType     string               `json:"action_type" gorm:"type:varchar(64);not null;"`
	Source         string               `json:"source" gorm:"type:varchar(20)"`
	Ids            string               `json:"ids"`
	Values         string               `json:"values"`
	Fees           erc20TokenCollection `json:"fees" gorm:"type:json;"`
	Status         string               `json:"status" gorm:"type:varchar(10);not null;"`
	OriginalWallet Wallet               `json:"original_wallet" gorm:"type:json;not null;"`
	SettledWallet  Wallet               `json:"settled_wallet" gorm:"type:json;"`
}

ERC1155WalletLog Wallet flow log

type ERC20Command

type ERC20Command struct {
	Token   ERC20TokenEnum
	Value   float64
	Decimal uint64
}

type ERC20Token

type ERC20Token struct {
	Index   uint64
	Symbol  string
	Decimal uint64
}

type ERC20TokenEnum

type ERC20TokenEnum int

ERC20TokenEnum ERC20 token name currently supported.

const (
	ETH ERC20TokenEnum = iota
	BNB
	USDT
	USDC
	BUSD
	NAMIX
	FISHX
)

func (ERC20TokenEnum) String

func (t ERC20TokenEnum) String() string

type ERC20TokenWallet

type ERC20TokenWallet struct {
	gorm.Model    `swagger-ignore:"true"`
	AccountId     uint64  `json:"account_id"`
	Token         string  `json:"token" gorm:"type:varchar(20)"`
	Balance       float64 `json:"balance"`
	Decimal       uint64  `json:"decimal"`
	TotalIncome   float64 `json:"total_income"`
	TotalSpend    float64 `json:"total_spend"`
	TotalDeposit  float64 `json:"total_deposit"`
	TotalWithdraw float64 `json:"total_withdraw"`
	TotalFee      float64 `json:"total_fee"`
}

type ERC20WalletLog

type ERC20WalletLog struct {
	gorm.Model     `swagger-ignore:"true"`
	AccountId      uint64               `json:"account_id"`
	BusinessModule string               `json:"business_module" gorm:"type:varchar(64);not null;"`
	ActionType     string               `json:"action_type" gorm:"type:varchar(64);not null;"`
	Source         string               `json:"source" gorm:"type:varchar(20)"`
	Tokens         erc20TokenCollection `json:"tokens" gorm:"type:json;not null"`
	Fees           erc20TokenCollection `json:"fees" gorm:"type:json;"`
	Status         string               `json:"status" gorm:"type:varchar(64);not null;"`
	OriginalWallet Wallet               `json:"original_wallet" gorm:"type:json;not null;"`
	SettledWallet  Wallet               `json:"settled_wallet" gorm:"type:json;not null;"`
}

ERC20WalletLog Wallet flow log

type Number

type Number interface {
	int64 | uint64 | float64
}

type Wallet

type Wallet struct {
	gorm.Model       `swagger-ignore:"true"`
	AccountId        uint64             `json:"account_id" gorm:"unique;not null"`
	ERC20TokenData   []ERC20TokenWallet `json:"erc_20_token_data" gorm:"foreignKey:AccountId;references:AccountId"`
	ERC1155TokenData ERC1155TokenWallet `json:"erc_1155_token_data" gorm:"foreignKey:AccountId;references:AccountId"`
	CheckSign        string             `json:"check_sign" gorm:"type:varchar(128);not null;"`
}

func (*Wallet) Scan

func (w *Wallet) Scan(input interface{}) error

func (Wallet) Value

func (w Wallet) Value() (driver.Value, error)

type WalletActionType

type WalletActionType int

WalletActionType Actions for wallet command, we will change user's assets in wallet according to wallet action type.

const (
	// Initialize initializing a wallet for a user when there is no wallet account of this user.
	Initialize WalletActionType = 0

	// Income will perform the addition operation to user's wallet in game database.
	Income WalletActionType = 1

	// Spend will perform subtraction to user's wallet in game database.
	Spend WalletActionType = 2

	// Deposit when uses deposit assets from Blockchain, will perform addition operation in game database.
	Deposit WalletActionType = 3

	// Withdraw when users withdraw assets from game, will perform subtraction operation in game database.
	Withdraw WalletActionType = 4

	// ChargeFee will perform subtraction operation in game database.
	ChargeFee WalletActionType = 5
)

func (WalletActionType) String

func (t WalletActionType) String() string

type WalletCommand

type WalletCommand struct {
	// User account id. unique
	AccountId uint64

	// 0: ERC20 token, 1: erc1155 token. 2. other type.
	AssetType AssetType

	// Action of this command. initialize, withdraw, deposit, etc.
	ActionType WalletActionType

	// ERC20 command, if we want to operate ERC20 asset, this should not be nil. otherwise this must be nil.
	ERC20Commands []ERC20Command

	// ERC20 command, if we want to operate ERC1155 asset, this should not be nil. otherwise this must be nil.
	ERC1155Command ERC1155Command

	// Fee charging command, if len(FeeCommands) > 0, assets should be deducted from user's account.
	FeeCommands []ERC20Command

	// A name about which part sent this command
	BusinessModule string

	// Command happened source.
	CommandSource CommandSourceType
}

WalletCommand is an object of the operation for withdrawals or depositions. Anytime when users deposit, withdraw or spend an asset, we should construct a WalletCommand object to operate the wallet in database.

func NewERC1155WalletCommand

func NewERC1155WalletCommand(
	accountId uint64,
	actionType WalletActionType,
	businessModule string,
	commandSource CommandSourceType,
	ids []uint64,
	values []uint64,
	fees map[ERC20TokenEnum]float64,
) WalletCommand

func NewERC20WalletCommand

func NewERC20WalletCommand(
	accountId uint64,
	actionType WalletActionType,
	businessModule string,
	commandSource CommandSourceType,
	erc20Tokens map[ERC20TokenEnum]float64,
	fees map[ERC20TokenEnum]float64,
) WalletCommand

func NewInitWalletCommand

func NewInitWalletCommand(accountId uint64) WalletCommand

type WalletLogStatus

type WalletLogStatus int

WalletLogStatus the results of performing wallet commands.

const (
	Pending WalletLogStatus = 0
	Done    WalletLogStatus = 1
	Failed  WalletLogStatus = 2
)

func (WalletLogStatus) String

func (s WalletLogStatus) String() string

type Walleter

type Walleter struct {
	// contains filtered or unexported fields
}

Walleter the library entry object.

func New

func New(db *gorm.DB, chargerAccountId uint64) *Walleter

func (*Walleter) GetWalletByAccountId

func (s *Walleter) GetWalletByAccountId(accountId uint64) (Wallet, error)

func (*Walleter) HandleWalletCommand

func (s *Walleter) HandleWalletCommand(db *gorm.DB, command WalletCommand) (Wallet, error)

Jump to

Keyboard shortcuts

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