database

package
v0.0.0-...-68e5106 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockHeaderFromHeader

func BlockHeaderFromHeader(header *types.Header) rpcclient.BlockHeader

Types

type Addresses

type Addresses struct {
	GUID        uuid.UUID      `gorm:"primaryKey" json:"guid"`
	Address     common.Address `json:"address" gorm:"serializer:bytes"`
	AddressType uint8          `json:"address_type"` //0:用户地址;1:热钱包地址(归集地址);2:冷钱包地址
	PublicKey   string         `json:"public_key"`
	Timestamp   uint64
}

type AddressesDB

type AddressesDB interface {
	AddressesView

	StoreAddresses(string, []Addresses) error
}

func NewAddressesDB

func NewAddressesDB(db *gorm.DB) AddressesDB

type AddressesView

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

type Balances

type Balances struct {
	GUID         uuid.UUID      `gorm:"primaryKey" json:"guid"`
	Address      common.Address `json:"address" gorm:"serializer:bytes"`
	TokenAddress common.Address `json:"token_address" gorm:"serializer:bytes"`
	Balance      *big.Int       `gorm:"serializer:u256;column:balance" db:"balance" json:"Balance" form:"balance"`
	LockBalance  *big.Int       `gorm:"serializer:u256;column:lock_balance" db:"lock_balance" json:"LockBalance" form:"lock_balance"`
	Timestamp    uint64
}

type BalancesDB

type BalancesDB interface {
	BalancesView

	UpdateOrCreate(string, []TokenBalance) error
	StoreBalances(string, []Balances) error
	UpdateBalances(string, []Balances, bool) error
}

func NewBalancesDB

func NewBalancesDB(db *gorm.DB) BalancesDB

type BalancesView

type BalancesView interface {
	QueryWalletBalanceByTokenAndAddress(requestId string, address, tokenAddress common.Address) (*Balances, error)
	UnCollectionList(requestId string, amount *big.Int) ([]Balances, error)
	QueryHotWalletBalances(requestId string, amount *big.Int) ([]Balances, error)
	QueryBalancesByToAddress(requestId string, address *common.Address) (*Balances, error)
}

type Blocks

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

type BlocksDB

type BlocksDB interface {
	BlocksView

	StoreBlockss([]Blocks) error
}

func NewBlocksDB

func NewBlocksDB(db *gorm.DB) BlocksDB

type BlocksView

type BlocksView interface {
	LatestBlocks() (*rpcclient.BlockHeader, 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 {
	QueryBusinessByUuid(string) (*Business, error)
	QueryBusinessList() ([]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
	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 (*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" json:"guid"`
	BlockHash    common.Hash    `gorm:"column:block_hash;serializer:bytes"  db:"block_hash" json:"block_hash"`
	BlockNumber  *big.Int       `gorm:"serializer:u256;column:block_number" db:"block_number" json:"BlockNumber" form:"block_number"`
	Hash         common.Hash    `gorm:"column:hash;serializer:bytes"  db:"hash" json:"hash"`
	FromAddress  common.Address `json:"from_address" gorm:"serializer:bytes;column:from_address"`
	ToAddress    common.Address `json:"to_address" gorm:"serializer:bytes;column:to_address"`
	TokenAddress common.Address `json:"token_address" gorm:"serializer:bytes;column: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"`
	Confirms     uint8          `json:"confirms"` // 交易确认位
	Status       uint8          `json:"status"`   // 0:充值确认中,1:充值钱包层已到账;2:充值已通知业务层;3:充值完成;
	Timestamp    uint64
}

type DepositsDB

type DepositsDB interface {
	DepositsView

	StoreDeposits(string, []Deposits, uint64) error
	UpdateDepositsNotifyStatus(requestId string, status uint8, depositList []Deposits) error
	UpdateDepositsComfirms(requestId string, blockNumber uint64, confirms uint64) error
}

func NewDepositsDB

func NewDepositsDB(db *gorm.DB) DepositsDB

type DepositsView

type DepositsView interface {
	QueryNotifyDeposits(string) ([]Deposits, error)
}

type Internals

type Internals struct {
	GUID         uuid.UUID      `gorm:"primaryKey" json:"guid"`
	BlockHash    common.Hash    `gorm:"column:block_hash;serializer:bytes"  db:"block_hash" json:"block_hash"`
	BlockNumber  *big.Int       `gorm:"serializer:u256;column:block_number" db:"block_number" json:"BlockNumber" form:"block_number"`
	Hash         common.Hash    `gorm:"column:hash;serializer:bytes"  db:"hash" json:"hash"`
	FromAddress  common.Address `json:"from_address" gorm:"serializer:bytes;column:from_address"`
	ToAddress    common.Address `json:"to_address" gorm:"serializer:bytes;column:to_address"`
	TokenAddress common.Address `json:"token_address" gorm:"serializer:bytes;column: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       uint8          `json:"status"` // 0:交易未签名, 1:交易已签名, 2:交易已经发送到区块链网络;3:交易在钱包层已完成;4:已通知业务;5:成功
	TxType       string         `json:"tx_type"`
	TxSignHex    string         `json:"tx_sign_hex" gorm:"column:tx_sign_hex"`
	Timestamp    uint64
}

type InternalsDB

type InternalsDB interface {
	InternalsView

	StoreInternal(string, *Internals) error
	UpdateInternalTx(requestId string, transactionId string, signedTx string, fee *big.Int, status uint8) error
	UpdateInternalstatus(requestId string, status uint8, InternalsList []Internals) error
}

func NewInternalsDB

func NewInternalsDB(db *gorm.DB) InternalsDB

type InternalsView

type InternalsView interface {
	QueryNotifyInternal(requestId string) ([]Internals, error)

	QueryInternalsByHash(requestId string, txId string) (*Internals, error)
	UnSendInternalsList(requestId string) ([]Internals, error)
}

type TokenBalance

type TokenBalance struct {
	Address      common.Address `json:"address"`
	TokenAddress common.Address `json:"to_ken_address"`
	Balance      *big.Int       `json:"balance"`
	LockBalance  *big.Int       `json:"lock_balance"`
	TxType       uint8          `json:"tx_type"` // 0:充值;1:提现;2:归集;3:热转冷;4:冷转热
}

type Tokens

type Tokens struct {
	GUID          uuid.UUID      `gorm:"primaryKey" json:"guid"`
	TokenAddress  common.Address `gorm:"serializer:bytes" 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 Transactions

type Transactions struct {
	GUID             uuid.UUID      `gorm:"primaryKey" json:"guid"`
	BlockHash        common.Hash    `gorm:"column:block_hash;serializer:bytes"  db:"block_hash" json:"block_hash"`
	BlockNumber      *big.Int       `gorm:"serializer:u256;column:block_number" db:"block_number" json:"BlockNumber" form:"block_number"`
	Hash             common.Hash    `gorm:"column:hash;serializer:bytes"  db:"hash" json:"hash"`
	FromAddress      common.Address `json:"from_address" gorm:"serializer:bytes"`
	ToAddress        common.Address `json:"to_address" gorm:"serializer:bytes"`
	TokenAddress     common.Address `json:"token_address" gorm:"serializer:bytes"`
	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           uint8          `json:"status"`  // 0:交易确认中,1:钱包交易已到账;2:交易已通知业务层;3:交易完成
	TxType           uint8          `json:"tx_type"` // 0:充值;1:提现;2:归集;3:热转冷;4:冷转热
	TransactionIndex *big.Int       `gorm:"serializer:u256;column:transaction_index" db:"transaction_index" json:"TransactionIndex" form:"transaction_index"`
	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
}

func NewTransactionsDB

func NewTransactionsDB(db *gorm.DB) TransactionsDB

type TransactionsView

type TransactionsView interface {
	QueryTransactionByHash(requestId string, hash common.Hash) (*Transactions, error)
}

type Withdraws

type Withdraws struct {
	GUID         uuid.UUID      `gorm:"primaryKey" json:"guid"`
	BlockHash    common.Hash    `gorm:"column:block_hash;serializer:bytes"  db:"block_hash" json:"block_hash"`
	BlockNumber  *big.Int       `gorm:"serializer:u256;column:block_number" db:"block_number" json:"BlockNumber" form:"block_number"`
	Hash         common.Hash    `gorm:"column:hash;serializer:bytes"  db:"hash" json:"hash"`
	FromAddress  common.Address `json:"from_address" gorm:"serializer:bytes;column:from_address"`
	ToAddress    common.Address `json:"to_address" gorm:"serializer:bytes;column:to_address"`
	TokenAddress common.Address `json:"token_address" gorm:"serializer:bytes;column: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       uint8          `json:"status"` // 0:提现未签名, 1:提现交易已签名, 2:提现已经发送到区块链网络;3:提现在钱包层已完成;4:提现已通知业务;5:提现成功
	TxSignHex    string         `json:"tx_sign_hex" gorm:"column:tx_sign_hex"`
	Timestamp    uint64
}

type WithdrawsDB

type WithdrawsDB interface {
	WithdrawsView
	StoreWithdraw(string, *Withdraws) error
	UpdateWithdrawTx(requestId string, transactionId string, signedTx string, fee *big.Int, status uint8) error
	UpdateWithdrawStatus(requestId string, status uint8, withdrawsList []Withdraws) error
}

func NewWithdrawsDB

func NewWithdrawsDB(db *gorm.DB) WithdrawsDB

type WithdrawsView

type WithdrawsView interface {
	QueryWithdrawsByHash(requestId string, txId string) (*Withdraws, error)
	UnSendWithdrawsList(requestId string) ([]Withdraws, error)
	QueryNotifyWithdraws(string) ([]Withdraws, error)
	SubmitWithdrawFromBusiness(requestId string, fromAddress common.Address, toAddress common.Address, TokenAddress common.Address, amount *big.Int) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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