database

package
v0.0.0-...-9318148 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressType

type AddressType string
const (
	AddressTypeUser AddressType = "user"
	AddressTypeHot  AddressType = "hot"
	AddressTypeCold AddressType = "cold"
)

func ParseAddressType

func ParseAddressType(s string) (AddressType, error)

func (AddressType) String

func (at AddressType) String() string

type Addresses

type Addresses struct {
	GUID        uuid.UUID   `gorm:"primary_key" json:"guid"`
	Address     string      `gorm:"type:varchar;unique;not null;" json:"address"`
	AddressType AddressType `gorm:"type:varchar(10);not null;default:'user'" json:"address_type"`
	PublicKey   string      `gorm:"type:varchar;not null" json:"public_key"`
	Timestamp   uint64      `gorm:"type:bigint;not null;check:timestamp > 0" json:"timestamp"`
}

func (*Addresses) Validate

func (a *Addresses) Validate() error

type AddressesDB

type AddressesDB interface {
	AddressesView

	StoreAddresses(string, []*Addresses) error
}

func NewAddressesDB

func NewAddressesDB(db *gorm.DB) AddressesDB

type AddressesView

type AddressesView interface {
	AddressExist(requestId string, address string) (bool, AddressType)
	QueryAddressesByToAddress(string, string) (*Addresses, error)
	QueryHotWalletInfo(string) (*Addresses, error)
	QueryColdWalletInfo(string) (*Addresses, error)
	GetAllAddresses(string) ([]*Addresses, error)
}

type Balances

type Balances struct {
	GUID         uuid.UUID   `gorm:"primary_key" json:"guid"`
	Address      string      `gorm:"type:varchar;not null" json:"address"`
	TokenAddress string      `gorm:"type:varchar;not null" json:"token_address"`
	AddressType  AddressType `gorm:"type:varchar(10);not null;default:'eoa'" json:"address_type"`
	Balance      *big.Int    `gorm:"type:numeric;not null;default:0;check:balance >= 0;serializer:u256" json:"balance"`
	LockBalance  *big.Int    `gorm:"type:numeric;not null;default:0;serializer:u256" json:"lock_balance"`
	Timestamp    uint64      `gorm:"type:bigint;not null;check:timestamp > 0" json:"timestamp"`
}

type BalancesDB

type BalancesDB interface {
	BalancesView

	UpdateOrCreate(string, []*TokenBalance) error
	StoreBalances(string, []*Balances) error
	UpdateBalanceListByTwoAddress(string, []*Balances) error
	UpdateBalance(string, *Balances) error
}

func NewBalancesDB

func NewBalancesDB(db *gorm.DB) BalancesDB

type BalancesView

type BalancesView interface {
	QueryWalletBalanceByTokenAndAddress(
		requestId string,
		addressType AddressType,
		address,
		tokenAddress string,
	) (*Balances, error)
}

type Blocks

type Blocks struct {
	Hash       string   `gorm:"primaryKey;serializer:bytes"`
	ParentHash string   `gorm:"serializer:bytes"`
	Number     *big.Int `gorm:"serializer:u256"`
	Timestamp  uint64
}

type BlocksDB

type BlocksDB interface {
	BlocksView

	StoreBlockss([]Blocks) error
	DeleteBlocksByNumber(blockHeader []Blocks) error
}

func NewBlocksDB

func NewBlocksDB(db *gorm.DB) BlocksDB

type BlocksView

type BlocksView interface {
	LatestBlocks() (*Blocks, error)
	QueryBlocksByNumber(*big.Int) (*Blocks, error)
}

type Business

type Business struct {
	GUID        uuid.UUID `gorm:"primaryKey" json:"guid"`
	BusinessUid string    `json:"business_uid"`
	NotifyUrl   string    `json:"notify_url"`
	Timestamp   uint64
}

type BusinessDB

type BusinessDB interface {
	BusinessView

	StoreBusiness(*Business) error
}

func NewBusinessDB

func NewBusinessDB(db *gorm.DB) BusinessDB

type BusinessView

type BusinessView interface {
	QueryBusinessList() ([]*Business, error)
	QueryBusinessByUuid(string) (*Business, error)
}

type CreateTableDB

type CreateTableDB interface {
	CreateTable(tableName, realTableName string)
}

func NewCreateTableDB

func NewCreateTableDB(db *gorm.DB) CreateTableDB

type DB

type DB struct {
	CreateTable  CreateTableDB
	Blocks       BlocksDB
	ReorgBlocks  ReorgBlocksDB
	Addresses    AddressesDB
	Balances     BalancesDB
	Deposits     DepositsDB
	Withdraws    WithdrawsDB
	Transactions TransactionsDB
	Tokens       TokensDB
	Business     BusinessDB
	Internals    InternalsDB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(ctx context.Context, dbConfig config.DBConfig) (*DB, error)

func SetupDb

func SetupDb() *DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) ExecuteSQLMigration

func (db *DB) ExecuteSQLMigration(migrationsFolder string) error

func (*DB) Transaction

func (db *DB) Transaction(fn func(db *DB) error) error

type Deposits

type Deposits struct {
	GUID                 uuid.UUID       `gorm:"primaryKey;type:varchar(36)" json:"guid"`
	Timestamp            uint64          `gorm:"not null;check:timestamp > 0" json:"timestamp"`
	Status               TxStatus        `gorm:"type:varchar(10);not null" json:"status"`
	Confirms             uint8           `gorm:"not null;default:0" json:"confirms"`
	BlockHash            string          `gorm:"type:varchar;not null" json:"block_hash"`
	BlockNumber          *big.Int        `gorm:"not null;check:block_number > 0;serializer:u256" json:"block_number"`
	TxHash               string          `gorm:"column:hash;type:varchar;not null" json:"hash"`
	TxType               TransactionType `gorm:"type:varchar;not null" json:"tx_type"`
	FromAddress          string          `gorm:"type:varchar;not null" json:"from_address"`
	ToAddress            string          `gorm:"type:varchar;not null" json:"to_address"`
	Amount               *big.Int        `gorm:"not null;serializer:u256" json:"amount"`
	GasLimit             uint64          `gorm:"not null" json:"gas_limit"`
	MaxFeePerGas         string          `gorm:"type:varchar;not null" json:"max_fee_per_gas"`
	MaxPriorityFeePerGas string          `gorm:"type:varchar;not null" json:"max_priority_fee_per_gas"`
	TokenType            TokenType       `gorm:"type:varchar;not null" json:"token_type"`
	TokenAddress         string          `gorm:"type:varchar;not null" json:"token_address"`
	TokenId              string          `gorm:"type:varchar;not null" json:"token_id"`
	TokenMeta            string          `gorm:"type:varchar;not null" json:"token_meta"`
	TxSignHex            string          `gorm:"type:varchar;not null" json:"tx_sign_hex"`
}

type DepositsDB

type DepositsDB interface {
	DepositsView

	StoreDeposits(string, []*Deposits) error
	UpdateDepositsComfirms(requestId string, blockNumber uint64, confirms uint64) error
	UpdateDepositById(requestId string, guid string, signedTx string, status TxStatus) error
	UpdateDepositsStatusById(requestId string, status TxStatus, depositList []*Deposits) error
	UpdateDepositsStatusByTxHash(requestId string, status TxStatus, depositList []*Deposits) error
	UpdateDepositListByTxHash(requestId string, depositList []*Deposits) error
	UpdateDepositListById(requestId string, depositList []*Deposits) error
	HandleFallBackDeposits(requestId string, startBlock, EndBlock *big.Int) error
}

func NewDepositsDB

func NewDepositsDB(db *gorm.DB) DepositsDB

type DepositsView

type DepositsView interface {
	QueryNotifyDeposits(requestId string) ([]*Deposits, error)
	QueryDepositsByTxHash(requestId string, txHash string) (*Deposits, error)
	QueryDepositsById(requestId string, guid string) (*Deposits, error)
}

type GasInfo

type GasInfo struct {
	GasLimit             uint64
	MaxFeePerGas         string
	MaxPriorityFeePerGas string
}

type Internals

type Internals struct {
	GUID                 uuid.UUID       `gorm:"primaryKey" json:"guid"`
	Timestamp            uint64          `json:"timestamp"`
	Status               TxStatus        `json:"status" gorm:"column:status"`
	BlockHash            string          `gorm:"column:block_hash" json:"block_hash"`
	BlockNumber          *big.Int        `gorm:"serializer:u256;column:block_number" json:"block_number"`
	TxHash               string          `gorm:"column:hash" json:"hash"`
	TxType               TransactionType `json:"tx_type" gorm:"column:tx_type"`
	FromAddress          string          `json:"from_address"`
	ToAddress            string          `json:"to_address"`
	Amount               *big.Int        `gorm:"serializer:u256;column:amount" json:"amount"`
	GasLimit             uint64          `json:"gas_limit"`
	MaxFeePerGas         string          `json:"max_fee_per_gas"`
	MaxPriorityFeePerGas string          `json:"max_priority_fee_per_gas"`
	TokenType            TokenType       `json:"token_type" gorm:"column:token_type"` // ETH, ERC20, ERC721, ERC1155
	TokenAddress         string          `json:"token_address"`
	TokenId              string          `json:"token_id" gorm:"column:token_id"`     // ERC721/ERC1155 的 token ID
	TokenMeta            string          `json:"token_meta" gorm:"column:token_meta"` // Token 元数据
	TxSignHex            string          `json:"tx_sign_hex" gorm:"column:tx_sign_hex"`
}

type InternalsDB

type InternalsDB interface {
	InternalsView

	StoreInternal(string, *Internals) error
	UpdateInternalByTxHash(requestId string, txHash string, signedTx string, status TxStatus) error
	UpdateInternalById(requestId string, id string, signedTx string, status TxStatus) error
	UpdateInternalStatusByTxHash(requestId string, status TxStatus, internalsList []*Internals) error
	UpdateInternalListByHash(requestId string, internalsList []*Internals) error
	UpdateInternalListById(requestId string, internalsList []*Internals) error
	HandleFallBackInternals(requestId string, startBlock, EndBlock *big.Int) error
}

func NewInternalsDB

func NewInternalsDB(db *gorm.DB) InternalsDB

type InternalsView

type InternalsView interface {
	QueryNotifyInternal(requestId string) ([]*Internals, error)
	QueryInternalsByTxHash(requestId string, txHash string) (*Internals, error)
	QueryInternalsById(requestId string, guid string) (*Internals, error)
	UnSendInternalsList(requestId string) ([]*Internals, error)
}

type ReorgBlocks

type ReorgBlocks struct {
	Hash       string   `gorm:"primaryKey;"`
	ParentHash string   `json:"parent_hash"`
	Number     *big.Int `gorm:"serializer:u256"`
	Timestamp  uint64
}

type ReorgBlocksDB

type ReorgBlocksDB interface {
	ReorgBlocksView

	StoreReorgBlocks([]ReorgBlocks) error
}

func NewReorgBlocksDB

func NewReorgBlocksDB(db *gorm.DB) ReorgBlocksDB

type ReorgBlocksView

type ReorgBlocksView interface {
	LatestReorgBlocks() (*rpcclient.BlockHeader, error)
}

type TokenBalance

type TokenBalance struct {
	FromAddress  string          `json:"from_address"`
	ToAddress    string          `json:"to_address"`
	TokenAddress string          `json:"to_ken_address"`
	Balance      *big.Int        `json:"balance"`
	TxType       TransactionType `json:"tx_type"`
}

type TokenType

type TokenType string
const (
	TokenTypeETH     TokenType = "ETH"
	TokenTypeERC20   TokenType = "ERC20"
	TokenTypeERC721  TokenType = "ERC721"
	TokenTypeERC1155 TokenType = "ERC1155"
)

type Tokens

type Tokens struct {
	GUID          uuid.UUID `gorm:"primaryKey" json:"guid"`
	TokenAddress  string    `json:"token_address"`
	Decimals      uint8     `json:"uint"`
	TokenName     string    `json:"tokens_name"`
	CollectAmount *big.Int  `gorm:"serializer:u256" json:"collect_amount"`
	ColdAmount    *big.Int  `gorm:"serializer:u256" json:"cold_amount"`
	Timestamp     uint64    `json:"timestamp"`
}

type TokensDB

type TokensDB interface {
	TokensView

	StoreTokens(string, []Tokens) error
}

func NewTokensDB

func NewTokensDB(db *gorm.DB) TokensDB

type TokensView

type TokensView interface {
	TokensInfoByAddress(string, string) (*Tokens, error)
}

type TransactionType

type TransactionType string
const (
	TxTypeUnKnow     TransactionType = "unknow"
	TxTypeDeposit    TransactionType = "deposit"
	TxTypeWithdraw   TransactionType = "withdraw"
	TxTypeCollection TransactionType = "collection"
	TxTypeHot2Cold   TransactionType = "hot2cold"
	TxTypeCold2Hot   TransactionType = "cold2hot"
)

func ParseTransactionType

func ParseTransactionType(s string) (TransactionType, error)

type Transactions

type Transactions struct {
	GUID         uuid.UUID        `gorm:"primaryKey" json:"guid"`
	BlockHash    string           `gorm:"column:block_hash"  db:"block_hash" json:"block_hash"`
	BlockNumber  *big.Int         `gorm:"serializer:u256;column:block_number" db:"block_number" json:"BlockNumber" form:"block_number"`
	Hash         string           `gorm:"column:hash"  db:"hash" json:"hash"`
	FromAddress  string           `json:"from_address"`
	ToAddress    string           `json:"to_address"`
	TokenAddress string           `json:"token_address"`
	TokenId      string           `json:"token_id" gorm:"column:token_id"`
	TokenMeta    string           `json:"token_meta" gorm:"column:token_meta"`
	Fee          *big.Int         `gorm:"serializer:u256;column:fee" db:"fee" json:"Fee" form:"fee"`
	Amount       *big.Int         `gorm:"serializer:u256;column:amount" db:"amount" json:"Amount" form:"amount"`
	Status       account.TxStatus `json:"status"`
	TxType       TransactionType  `json:"tx_type" gorm:"column:tx_type"`
	Timestamp    uint64
}

type TransactionsDB

type TransactionsDB interface {
	TransactionsView

	StoreTransactions(string, []*Transactions, uint64) error
	UpdateTransactionsStatus(requestId string, blockNumber *big.Int) error
	UpdateTransactionStatus(requestId string, txList []*Transactions) error
	HandleFallBackTransactions(requestId string, startBlock, EndBlock *big.Int) error
}

func NewTransactionsDB

func NewTransactionsDB(db *gorm.DB) TransactionsDB

type TransactionsView

type TransactionsView interface {
	QueryTransactionByHash(requestId string, hash string) (*Transactions, error)
	QueryFallBackTransactions(requestId string, startBlock, EndBlock *big.Int) ([]*Transactions, error)
}

type TxStatus

type TxStatus string
const (
	TxStatusCreateUnsigned TxStatus = "create_unsign"
	TxStatusSigned         TxStatus = "signed"
	TxStatusBroadcasted    TxStatus = "broadcasted"
	TxStatusWalletDone     TxStatus = "wallet_done"
	TxStatusNotified       TxStatus = "notified"
	TxStatusSuccess        TxStatus = "success"
	TxStatusFallback       TxStatus = "fallback"
)

type Withdraws

type Withdraws struct {
	GUID                 uuid.UUID       `gorm:"primaryKey" json:"guid"`
	Timestamp            uint64          `json:"timestamp"`
	Status               TxStatus        `json:"status" gorm:"column:status"`
	BlockHash            string          `gorm:"column:block_hash" json:"block_hash"`
	BlockNumber          *big.Int        `gorm:"serializer:u256;column:block_number" json:"block_number"`
	TxHash               string          `gorm:"column:hash" json:"hash"`
	TxType               TransactionType `gorm:"column:tx_type" json:"tx_type"`
	FromAddress          string          `gorm:"column:from_address" json:"from_address"`
	ToAddress            string          `gorm:"column:to_address" json:"to_address"`
	Amount               *big.Int        `gorm:"serializer:u256;column:amount" json:"amount"`
	GasLimit             uint64          `json:"gas_limit"`
	MaxFeePerGas         string          `json:"max_fee_per_gas"`
	MaxPriorityFeePerGas string          `json:"max_priority_fee_per_gas"`
	TokenType            TokenType       `json:"token_type" gorm:"column:token_type"` // ETH, ERC20, ERC721, ERC1155
	TokenAddress         string          `json:"token_address" gorm:"column:token_address"`
	TokenId              string          `json:"token_id" gorm:"column:token_id"`     // ERC721/ERC1155 的 token ID
	TokenMeta            string          `json:"token_meta" gorm:"column:token_meta"` // Token 元数据

	// 交易签名
	TxSignHex string `json:"tx_sign_hex" gorm:"column:tx_sign_hex"`
}

type WithdrawsDB

type WithdrawsDB interface {
	WithdrawsView

	StoreWithdraw(requestId string, withdraw *Withdraws) error
	UpdateWithdrawByTxHash(requestId string, txHash string, signedTx string, status TxStatus) error
	UpdateWithdrawById(requestId string, guid string, signedTx string, status TxStatus) error
	UpdateWithdrawStatusById(requestId string, status TxStatus, withdrawsList []*Withdraws) error
	UpdateWithdrawStatusByTxHash(requestId string, status TxStatus, withdrawsList []*Withdraws) error
	UpdateWithdrawListByTxHash(requestId string, withdrawsList []*Withdraws) error
	UpdateWithdrawListById(requestId string, withdrawsList []*Withdraws) error
	HandleFallBackWithdraw(requestId string, startBlock, EndBlock *big.Int) error
}

func NewWithdrawsDB

func NewWithdrawsDB(db *gorm.DB) WithdrawsDB

type WithdrawsView

type WithdrawsView interface {
	QueryNotifyWithdraws(requestId string) ([]*Withdraws, error)
	QueryWithdrawsByHash(requestId string, txHash string) (*Withdraws, error)
	QueryWithdrawsById(requestId string, guid string) (*Withdraws, error)
	UnSendWithdrawsList(requestId string) ([]*Withdraws, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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