database

package
v0.0.0-...-48d27f4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockHeaderFromHeader

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

func ReorgBlockHeaderFromHeader

func ReorgBlockHeaderFromHeader(header *types.Header) syncclient.BlockHeader

Types

type Addresses

type Addresses struct {
	GUID        uuid.UUID `gorm:"primaryKey" json:"guid"`
	Address     string    `json:"address"`
	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 {
	AddressExist(requestId string, address string) (bool, uint8)
	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:"primaryKey" json:"guid"`
	Address     string    `json:"address"`
	AddressType uint8     `json:"address_type"` //0:用户地址;1:热钱包地址(归集地址);2:冷钱包地址
	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) error
}

func NewBalancesDB

func NewBalancesDB(db *gorm.DB) BalancesDB

type BalancesView

type BalancesView interface {
	QueryWalletBalanceByAddress(requestId string, addressType uint8, address string) (*Balances, error)
}

type Blocks

type Blocks struct {
	Hash      string `gorm:"primaryKey"`
	PrevHash  string
	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() (*syncclient.BlockHeader, error)
}

type Business

type Business struct {
	GUID        uuid.UUID `gorm:"primaryKey" json:"guid"`
	BusinessUid string    `json:"business_uid"`
	NotifyUrl   string    `json:"notify_url"`
	CallBackUrl string    `json:"call_back_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 ChildTxs

type ChildTxs struct {
	GUID        uuid.UUID `gorm:"primaryKey" json:"guid"`
	Hash        string    `json:"hash"`
	TxId        string    `json:"tx_id"`
	TxIndex     *big.Int  `gorm:"serializer:u256" json:"tx_index"`
	TxType      string    `json:"tx_type"`
	FromAddress string    `json:"from_address"`
	ToAddress   string    `json:"to_address"`
	Amount      string    `json:"amount"`
	Timestamp   uint64    `json:"timestamp"`
}

type ChildTxsDB

type ChildTxsDB interface {
	ChildTxsView

	StoreChildTxs(string, []ChildTxs) error
}

func NewChildTxsDB

func NewChildTxsDB(db *gorm.DB) ChildTxsDB

type ChildTxsView

type ChildTxsView interface {
	QueryChildTxnByTxId(string, string) ([]ChildTxs, 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
	Business     BusinessDB
	Deposits     DepositsDB
	Withdraws    WithdrawsDB
	Internals    InternalsDB
	Transactions TransactionsDB
	Vins         VinsDB
	Vouts        VoutsDB
	ChildTxs     ChildTxsDB
	// 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   string
	BlockNumber *big.Int `gorm:"serializer:u256"`
	Hash        string   `json:"hash"`
	Fee         *big.Int `gorm:"serializer:u256"`
	LockTime    *big.Int `gorm:"serializer:u256"`
	Version     string   `json:"version"`
	Confirms    uint8    `json:"confirms"`
	Status      TxStatus `json:"status"`
	Timestamp   uint64   `json:"timestamp"`
}

type DepositsDB

type DepositsDB interface {
	DepositsView

	StoreDeposits(string, []Deposits) error
	UpdateDepositsComfirms(requestId string, blockNumber uint64, confirms uint64) error
	UpdateDepositsNotifyStatus(requestId string, status uint8, depositList []Deposits) 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   string    `json:"block_hash"`
	BlockNumber *big.Int  `gorm:"serializer:u256;check:block_number > 0" json:"block_number"`
	Hash        string    `json:"hash"`
	Fee         *big.Int  `gorm:"serializer:u256" json:"fee"`
	LockTime    *big.Int  `gorm:"serializer:u256" json:"lock_time"`
	Version     string    `json:"version"`
	TxType      string    `json:"tx_type"`
	TxSignHex   string    `json:"tx_sign_hex"`
	Status      TxStatus  `json:"status"`
	Timestamp   uint64    `json:"timestamp"`
}

type InternalsDB

type InternalsDB interface {
	InternalsView

	StoreInternal(string, *Internals) error
	UpdateInternalTx(requestId string, transactionId string, signedTx string, status TxStatus) error
	UpdateInternalStatus(requestId string, status TxStatus, internalsList []Internals) error
}

func NewInternalsDB

func NewInternalsDB(db *gorm.DB) InternalsDB

type InternalsView

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

type ReorgBlocks

type ReorgBlocks struct {
	Hash      string `gorm:"primaryKey"`
	PrevHash  string
	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() (*syncclient.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       string   `json:"tx_type"` // deposit:充值;withdraw:提现;collection:归集;hot2cold:热转冷;cold2hot:冷转热
}

type Transactions

type Transactions struct {
	GUID        uuid.UUID `gorm:"primaryKey" json:"guid"`
	BlockHash   string
	BlockNumber *big.Int `gorm:"serializer:u256"`
	Hash        string   `json:"hash"`
	Fee         *big.Int `gorm:"serializer:u256"`
	LockTime    *big.Int `gorm:"serializer:u256"`
	TxType      string   `json:"tx_type"`
	Version     string   `json:"version"`
	Status      TxStatus `json:"status"`
	Timestamp   uint64   `json:"timestamp"`
}

type TransactionsDB

type TransactionsDB interface {
	TransactionsView

	StoreTransactions(string, []Transactions) error
}

func NewTransactionsDB

func NewTransactionsDB(db *gorm.DB) TransactionsDB

type TransactionsView

type TransactionsView interface {
}

type TxStatus

type TxStatus string
const (
	//====================父交易的状态==========================
	TxStatusWaitSign             TxStatus = "wait_sign"           // 交易等待签名
	TxStatusUnSent               TxStatus = "unsend"              // 交易未发送
	TxStatusSent                 TxStatus = "sent"                // 交易已发送
	TxStatusSentNotify           TxStatus = "sent_notify_success" // 交易以广播通知
	TxStatusSentNotifyFail       TxStatus = "sent_notify_fail"    // 交易以广播失败通知
	TxStatusWithdrawed           TxStatus = "withdrawed"          // 交易已发送
	TxStatusWithdrawedNotify     TxStatus = "withdrawed_notify_success"
	TxStatusWithdrawedNotifyFail TxStatus = "withdrawed_notify_fail"

	TxStatusUnSafe              TxStatus = "unsafe"                   // 链上扫到交易
	TxStatusSafe                TxStatus = "safe"                     // 交易过了安全确认位
	TxStatusFinalized           TxStatus = "finalized"                // 交易已完成,可以提现
	TxStatusUnSafeNotify        TxStatus = "unsafe_notify_success"    // 链上扫到交易已通知
	TxStatusSafeNotify          TxStatus = "safe_notify_success"      // 交易过了安全确认位已通知
	TxStatusFinalizedNotify     TxStatus = "finalized_notify_success" // 交易完成已通知
	TxStatusUnSafeNotifyFail    TxStatus = "unsafe_notify_fail"       // 链上扫到交易通知失败
	TxStatusSafeNotifyFail      TxStatus = "safe_notify_fail"         // 交易过了安全确认位通知失败
	TxStatusFinalizedNotifyFail TxStatus = "finalized_notify_fail"    // 交易完成通知失败

	TxStatusSuccess        TxStatus = "done_success"
	TxStatusFail           TxStatus = "done_fail"
	TxStatusFailNotify     TxStatus = "done_fail_notify_success"
	TxStatusFailNotifyFail TxStatus = "done_fail_notify_fail"

	TxStatusFallback           TxStatus = "fallback"                // 交易回滚状态
	TxStatusFallbackNotify     TxStatus = "fallback_notify_success" // 交易回滚通知成功
	TxStatusFallbackNotifyFail TxStatus = "fallback_notify_fail"    // 交易回滚通知失败
	TxStatusFallbackDone       TxStatus = "done_fallback"           // 交易回滚状态

	TxStatusInternalCallBack TxStatus = "send_to_business_for_sign"
)

提现是没有确认位的

type Vins

type Vins struct {
	GUID             uuid.UUID `gorm:"primaryKey" json:"guid"`
	Address          string    `json:"address"`
	TxId             string    `json:"tx_id"`
	Vout             uint8     `json:"vout"`
	Script           string    `json:"script"`
	Witness          string    `json:"witness"`
	Amount           *big.Int  `gorm:"serializer:u256" json:"amount"`
	SpendTxHash      string    `json:"spend_tx_hash"`
	SpendBlockHeight *big.Int  `gorm:"serializer:u256" json:"spend_block_height"`
	IsSpend          bool      `json:"is_spend"`
	Timestamp        uint64    `json:"timestamp"`
}

type VinsDB

type VinsDB interface {
	VinsView

	StoreVins(string, []Vins) error
	UpdateVinsTx(requestId string, txId string, address string, IsSpend bool, spendTxHash string, spendBlockHeight *big.Int) error
}

func NewVinsDB

func NewVinsDB(db *gorm.DB) VinsDB

type VinsView

type VinsView interface {
	QueryVinByTxId(string, string, string) (*Vins, error)
	QueryVinsByAddress(string, string) ([]Vins, error)
}

type Vouts

type Vouts struct {
	GUID      uuid.UUID `gorm:"primaryKey" json:"guid"`
	Address   string    `json:"address"`
	N         uint8     `json:"n"`
	Script    string    `json:"script"`
	Amount    *big.Int  `gorm:"serializer:u256" json:"amount"`
	Timestamp uint64    `json:"timestamp"`
}

type VoutsDB

type VoutsDB interface {
	VoutsView

	StoreVouts(string, []Vouts) error
}

func NewVoutsDB

func NewVoutsDB(db *gorm.DB) VoutsDB

type VoutsView

type VoutsView interface {
}

type Withdraws

type Withdraws struct {
	Guid        uuid.UUID `gorm:"primaryKey" json:"guid"`
	BlockHash   string    `json:"block_hash"`
	BlockNumber *big.Int  `gorm:"serializer:u256;check:block_number > 0" json:"block_number"`
	Hash        string    `json:"hash"`
	Fee         *big.Int  `gorm:"serializer:u256" json:"fee"`
	LockTime    *big.Int  `gorm:"serializer:u256" json:"lock_time"`
	Version     string    `json:"version"`
	TxSignHex   string    `json:"tx_sign_hex"`
	Status      TxStatus  `json:"status"`
	Timestamp   uint64    `json:"timestamp"`
}

type WithdrawsDB

type WithdrawsDB interface {
	WithdrawsView

	StoreWithdraws(string, *Withdraws) error
	UpdateWithdrawStatus(requestId string, status TxStatus, withdrawsList []Withdraws) error
	UpdateWithdrawByGuuid(requestId string, transactionId string, txSignedHex string) error
}

func NewWithdrawsDB

func NewWithdrawsDB(db *gorm.DB) WithdrawsDB

type WithdrawsView

type WithdrawsView interface {
	QueryNotifyWithdraws(requestId 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