Documentation ¶
Overview ¶
Package mongodb is a wrapper of mongo-go-driver that defines the collections and CRUD apis on them.
Index ¶
- Variables
- func AddRouterSwap(ms *MgoSwap) error
- func AddRouterSwapResult(mr *MgoSwapResult) error
- func AddUsedRValue(pubkey, r string) error
- func AllocateRouterSwapNonce(args *tokens.BuildTxArgs, nonceptr *uint64, isRecycleNonce bool) (swapnonce uint64, err error)
- func ConvertFromSwapInfo(swapinfo *SwapInfo) (tokens.SwapInfo, error)
- func FindNextSwapNonce(chainID, mpc string) (uint64, error)
- func GetRouterSwapKey(fromChainID, txid string, logindex int) string
- func GetStatusInfo(statuses string) (statusInfo map[string]interface{}, err error)
- func HasClient() bool
- func MongoServerInit(appName string, hosts []string, dbName, user, pass string)
- func PassRouterSwapVerify(fromChainID, txid string, logindex int, timestamp int64) error
- func RouterAdminPassBigValue(fromChainID, txid string, logIndex int) error
- func RouterAdminPassForbiddenSwapout(fromChainID, txid string, logIndex int) error
- func RouterAdminReswap(fromChainID, txid string, logIndex int) error
- func UpdateRouterOldSwapTxs(fromChainID, txid string, logindex int, swapTx string) error
- func UpdateRouterSwapHeight(fromChainID, txid string, logindex int, height uint64) error
- func UpdateRouterSwapInfoAndStatus(fromChainID, txid string, logindex int, swapInfo *SwapInfo, status SwapStatus, ...) error
- func UpdateRouterSwapResult(fromChainID, txid string, logindex int, items *SwapResultUpdateItems) error
- func UpdateRouterSwapResultStatus(fromChainID, txid string, logindex int, status SwapStatus, timestamp int64, ...) error
- func UpdateRouterSwapStatus(fromChainID, txid string, logindex int, status SwapStatus, timestamp int64, ...) error
- type AnyCallSwapInfo
- type ERC20SwapInfo
- type MgoSwap
- func FindRouterSwap(fromChainID, txid string, logindex int) (*MgoSwap, error)
- func FindRouterSwapAuto(fromChainID, txid string, logindex int) (*MgoSwap, error)
- func FindRouterSwapsWithChainIDAndStatus(fromChainID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
- func FindRouterSwapsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
- func FindRouterSwapsWithToChainIDAndStatus(toChainID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
- func GetRegisteredRouterSwap(fromChainID, txid string, logIndex int) (oldSwap *MgoSwap, registeredOk bool)
- type MgoSwapResult
- func FindRouterSwapResult(fromChainID, txid string, logindex int) (*MgoSwapResult, error)
- func FindRouterSwapResultAuto(fromChainID, txid string, logindex int) (*MgoSwapResult, error)
- func FindRouterSwapResults(fromChainID, address string, offset, limit int, status string) ([]*MgoSwapResult, error)
- func FindRouterSwapResultsOfTx(fromChainID, txid string) ([]*MgoSwapResult, error)
- func FindRouterSwapResultsToReplace(chainID string, septime int64) ([]*MgoSwapResult, error)
- func FindRouterSwapResultsToStable(chainID string, septime int64) ([]*MgoSwapResult, error)
- func FindRouterSwapResultsWithChainIDAndStatus(fromChainID string, status SwapStatus, septime int64) ([]*MgoSwapResult, error)
- func FindRouterSwapResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
- type MgoUsedRValue
- type NFTSwapInfo
- type SwapInfo
- type SwapResultUpdateItems
- type SwapStatus
Constants ¶
This section is empty.
Variables ¶
var ( ErrItemNotFound = newError(-32002, "mgoError: Item not found") ErrItemIsDup = newError(-32003, "mgoError: Item is duplicate") ErrSwapNotFound = newError(-32011, "mgoError: Swap is not found") ErrWrongKey = newError(-32012, "mgoError: Wrong key") ErrForbidUpdateNonce = newError(-32013, "mgoError: Forbid update swap nonce") ErrForbidUpdateSwapTx = newError(-32014, "mgoError: Forbid update swap tx") )
mongodb special errors
var ( // MgoWaitGroup wait all mongodb related task done MgoWaitGroup = new(sync.WaitGroup) )
Functions ¶
func AddRouterSwapResult ¶
func AddRouterSwapResult(mr *MgoSwapResult) error
AddRouterSwapResult add router swap result
func AddUsedRValue ¶
AddUsedRValue add used r, if error mean already exist
func AllocateRouterSwapNonce ¶
func AllocateRouterSwapNonce(args *tokens.BuildTxArgs, nonceptr *uint64, isRecycleNonce bool) (swapnonce uint64, err error)
AllocateRouterSwapNonce allocate swap nonce (for parallel signing)
func ConvertFromSwapInfo ¶
ConvertFromSwapInfo convert
func FindNextSwapNonce ¶
FindNextSwapNonce find next swap nonce
func GetRouterSwapKey ¶
GetRouterSwapKey get router swap key
func GetStatusInfo ¶
GetStatusInfo get status info
func MongoServerInit ¶
MongoServerInit int mongodb server session
func PassRouterSwapVerify ¶
PassRouterSwapVerify pass router swap verify
func RouterAdminPassBigValue ¶
RouterAdminPassBigValue pass big value
func RouterAdminPassForbiddenSwapout ¶
RouterAdminPassForbiddenSwapout pass forbidden swapout
func RouterAdminReswap ¶
RouterAdminReswap reswap
func UpdateRouterOldSwapTxs ¶
UpdateRouterOldSwapTxs update old swaptxs by appending `swapTx`
func UpdateRouterSwapHeight ¶
UpdateRouterSwapHeight update router swap height on source chain
func UpdateRouterSwapInfoAndStatus ¶
func UpdateRouterSwapInfoAndStatus(fromChainID, txid string, logindex int, swapInfo *SwapInfo, status SwapStatus, timestamp int64, memo string) error
UpdateRouterSwapInfoAndStatus update router swap info and status
func UpdateRouterSwapResult ¶
func UpdateRouterSwapResult(fromChainID, txid string, logindex int, items *SwapResultUpdateItems) error
UpdateRouterSwapResult update router swap result
func UpdateRouterSwapResultStatus ¶
func UpdateRouterSwapResultStatus(fromChainID, txid string, logindex int, status SwapStatus, timestamp int64, memo string) error
UpdateRouterSwapResultStatus update router swap result status
func UpdateRouterSwapStatus ¶
func UpdateRouterSwapStatus(fromChainID, txid string, logindex int, status SwapStatus, timestamp int64, memo string) error
UpdateRouterSwapStatus update router swap status
Types ¶
type AnyCallSwapInfo ¶
type AnyCallSwapInfo struct { CallFrom string `bson:",omitempty" json:"callFrom,omitempty"` CallTo string `bson:",omitempty" json:"callTo,omitempty"` CallData string `bson:",omitempty" json:"callData,omitempty"` Fallback string `bson:",omitempty" json:"fallback,omitempty"` Flags string `bson:",omitempty" json:"flags,omitempty"` AppID string `bson:",omitempty" json:"appid,omitempty"` Nonce string `bson:",omitempty" json:"nonce,omitempty"` ExtData string `bson:",omitempty" json:"extdata,omitempty"` Message string `bson:",omitempty" json:"message,omitempty"` Attestation string `bson:",omitempty" json:"attestation,omitempty"` }
AnyCallSwapInfo struct
type ERC20SwapInfo ¶
type ERC20SwapInfo struct { Token string `bson:"token" json:"token"` TokenID string `bson:"tokenID" json:"tokenID"` SwapoutID string `bson:"swapoutID,omitempty" json:"swapoutID,omitempty"` CallProxy string `bson:"callProxy,omitempty" json:"callProxy,omitempty"` CallData string `bson:"callData,omitempty" json:"callData,omitempty"` }
ERC20SwapInfo struct
type MgoSwap ¶
type MgoSwap struct { Key string `bson:"_id" json:",omitempty"` // fromChainID + txid + logindex SwapType uint32 `bson:"swaptype"` TxID string `bson:"txid"` TxTo string `bson:"txto"` TxHeight uint64 `bson:"txheight"` From string `bson:"from"` Bind string `bson:"bind"` Value string `bson:"value"` LogIndex int `bson:"logIndex"` FromChainID string `bson:"fromChainID"` ToChainID string `bson:"toChainID"` SwapInfo `bson:"swapinfo"` Status SwapStatus `bson:"status"` InitTime int64 `bson:"inittime"` Timestamp int64 `bson:"timestamp"` Memo string `bson:"memo" json:",omitempty"` }
MgoSwap registered swap
func FindRouterSwap ¶
FindRouterSwap find router swap
func FindRouterSwapAuto ¶
FindRouterSwapAuto find router swap
func FindRouterSwapsWithChainIDAndStatus ¶
func FindRouterSwapsWithChainIDAndStatus(fromChainID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
FindRouterSwapsWithChainIDAndStatus find router swap with chainid and status in the past septime
func FindRouterSwapsWithStatus ¶
func FindRouterSwapsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
FindRouterSwapsWithStatus find router swap with status
func FindRouterSwapsWithToChainIDAndStatus ¶
func FindRouterSwapsWithToChainIDAndStatus(toChainID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
FindRouterSwapsWithToChainIDAndStatus find router swap with toChainID and status in the past septime
func GetRegisteredRouterSwap ¶
func GetRegisteredRouterSwap(fromChainID, txid string, logIndex int) (oldSwap *MgoSwap, registeredOk bool)
GetRegisteredRouterSwap get registered router swap
func (*MgoSwap) ToSwapResult ¶
func (swap *MgoSwap) ToSwapResult() *MgoSwapResult
ToSwapResult converts
type MgoSwapResult ¶
type MgoSwapResult struct { Key string `bson:"_id"` // fromChainID + txid + logindex SwapType uint32 `bson:"swaptype"` TxID string `bson:"txid"` TxTo string `bson:"txto"` TxHeight uint64 `bson:"txheight"` TxTime uint64 `bson:"txtime" json:",omitempty"` From string `bson:"from"` To string `bson:"to"` Bind string `bson:"bind"` Value string `bson:"value"` LogIndex int `bson:"logIndex"` FromChainID string `bson:"fromChainID"` ToChainID string `bson:"toChainID"` SwapInfo `bson:"swapinfo"` SwapTx string `bson:"swaptx"` OldSwapTxs []string `bson:"oldswaptxs,omitempty" json:"oldswaptxs,omitempty"` SwapHeight uint64 `bson:"swapheight"` SwapTime uint64 `bson:"swaptime"` SwapValue string `bson:"swapvalue"` SwapNonce uint64 `bson:"swapnonce"` Status SwapStatus `bson:"status"` InitTime int64 `bson:"inittime"` Timestamp int64 `bson:"timestamp"` Memo string `bson:"memo" json:",omitempty"` MPC string `bson:"mpc"` TTL uint64 `bson:"ttl"` }
MgoSwapResult swap result (verified swap)
func FindRouterSwapResult ¶
func FindRouterSwapResult(fromChainID, txid string, logindex int) (*MgoSwapResult, error)
FindRouterSwapResult find router swap result
func FindRouterSwapResultAuto ¶
func FindRouterSwapResultAuto(fromChainID, txid string, logindex int) (*MgoSwapResult, error)
FindRouterSwapResultAuto find router swap result
func FindRouterSwapResults ¶
func FindRouterSwapResults(fromChainID, address string, offset, limit int, status string) ([]*MgoSwapResult, error)
FindRouterSwapResults find router swap results with chainid and address
func FindRouterSwapResultsOfTx ¶
func FindRouterSwapResultsOfTx(fromChainID, txid string) ([]*MgoSwapResult, error)
FindRouterSwapResultsOfTx find router swap results of tx
func FindRouterSwapResultsToReplace ¶
func FindRouterSwapResultsToReplace(chainID string, septime int64) ([]*MgoSwapResult, error)
FindRouterSwapResultsToReplace find router swap result with status
func FindRouterSwapResultsToStable ¶
func FindRouterSwapResultsToStable(chainID string, septime int64) ([]*MgoSwapResult, error)
FindRouterSwapResultsToStable find swap results to stable
func FindRouterSwapResultsWithChainIDAndStatus ¶
func FindRouterSwapResultsWithChainIDAndStatus(fromChainID string, status SwapStatus, septime int64) ([]*MgoSwapResult, error)
FindRouterSwapResultsWithChainIDAndStatus find router swap result with chainid and status in the past septime
func FindRouterSwapResultsWithStatus ¶
func FindRouterSwapResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
FindRouterSwapResultsWithStatus find router swap result with status
type MgoUsedRValue ¶
type MgoUsedRValue struct { Key string `bson:"_id"` // r + pubkey Timestamp int64 `bson:"timestamp"` }
MgoUsedRValue security enhancement
type NFTSwapInfo ¶
type NFTSwapInfo struct { Token string `bson:"token" json:"token"` TokenID string `bson:"tokenID" json:"tokenID"` IDs []string `bson:"ids" json:"ids"` Amounts []string `bson:"amounts" json:"amounts"` Batch bool `bson:"batch" json:"batch"` Data string `bson:"data,omitempty" json:"data,omitempty"` }
NFTSwapInfo struct
type SwapInfo ¶
type SwapInfo struct { ERC20SwapInfo *ERC20SwapInfo `bson:"routerSwapInfo,omitempty" json:"routerSwapInfo,omitempty"` NFTSwapInfo *NFTSwapInfo `bson:"nftSwapInfo,omitempty" json:"nftSwapInfo,omitempty"` AnyCallSwapInfo *AnyCallSwapInfo `bson:"anycallSwapInfo2,omitempty" json:"anycallSwapInfo2,omitempty"` }
SwapInfo struct
func ConvertToSwapInfo ¶
ConvertToSwapInfo convert
type SwapResultUpdateItems ¶
type SwapResultUpdateItems struct { MPC string SwapTx string SwapHeight uint64 SwapTime uint64 SwapValue string SwapNonce uint64 Status SwapStatus Timestamp int64 Memo string TTL uint64 }
SwapResultUpdateItems swap update items
type SwapStatus ¶
type SwapStatus uint16
SwapStatus swap status
const ( TxNotStable SwapStatus = 0 TxVerifyFailed SwapStatus = 1 TxWithWrongValue SwapStatus = 3 TxNotSwapped SwapStatus = 5 TxProcessed SwapStatus = 7 MatchTxEmpty SwapStatus = 8 MatchTxNotStable SwapStatus = 9 MatchTxStable SwapStatus = 10 TxWithBigValue SwapStatus = 12 MatchTxFailed SwapStatus = 14 SwapInBlacklist SwapStatus = 15 ManualMakeFail SwapStatus = 16 TxWithWrongPath SwapStatus = 19 MissTokenConfig SwapStatus = 20 NoUnderlyingToken SwapStatus = 21 TxMaybeUnsafe SwapStatus = 22 SwapoutForbidden SwapStatus = 23 TxNeedReswap SwapStatus = 24 KeepStatus SwapStatus = 255 Reswapping SwapStatus = 256 )
swap status values
func GetRouterSwapStatusByVerifyError ¶
func GetRouterSwapStatusByVerifyError(err error) SwapStatus
GetRouterSwapStatusByVerifyError get router swap status by verify error
func (SwapStatus) IsRegisteredOk ¶
func (status SwapStatus) IsRegisteredOk() bool
IsRegisteredOk is successfully registered
func (SwapStatus) IsResultStatus ¶
func (status SwapStatus) IsResultStatus() bool
IsResultStatus is swap result status
func (SwapStatus) String ¶
func (status SwapStatus) String() string
nolint:gocyclo // allow big simple switch