Documentation ¶
Overview ¶
Package mongodb is a wrapper of mgo.v2 that defines the collections and CRUD apis on them.
Index ¶
- Constants
- Variables
- func AddP2shAddress(ma *MgoP2shAddress) error
- func AddRegisteredAddress(address string) error
- func AddRegisteredSwap(chain, method, pairid, txid, chainid, logIndex, swapServer string) error
- func AddRegisteredSwapPending(chain, txid string) error
- func AddSwapHistory(isSwapin bool, txid, bind, swaptx string) error
- func AddSwapPost(post *MgoRegisteredSwap) error
- func AddSwapin(ms *MgoSwap) error
- func AddSwapinResult(mr *MgoSwapResult) error
- func AddSwapout(ms *MgoSwap) error
- func AddSwapoutResult(mr *MgoSwapResult) error
- func AddToBlacklist(address, pairID string) error
- func AddUsedRValue(pubkey, r string) error
- func FindP2shBindAddress(p2shAddress string) (string, error)
- func GetCountOfSwapinResults(pairID string) (int, error)
- func GetCountOfSwapinResultsWithStatus(pairID string, status SwapStatus) (int, error)
- func GetCountOfSwapinsWithStatus(pairID string, status SwapStatus) (int, error)
- func GetCountOfSwapoutResults(pairID string) (int, error)
- func GetCountOfSwapoutResultsWithStatus(pairID string, status SwapStatus) (int, error)
- func GetCountOfSwapoutsWithStatus(pairID string, status SwapStatus) (int, error)
- func GetRegisterStatus(status int) string
- func GetSwapKey(txid, pairID, bind string) string
- func HasSession() bool
- func LoadAllSwapNonces() (swapinNonces, swapoutNonces map[string]uint64)
- func ManualManageSwap(txid, pairID, bind, memo string, isSwapin, isPass bool) error
- func MongoServerInit(addrs []string, dbname, user, pass string)
- func PassSwapinBigValue(txid, pairID, bind string) error
- func PassSwapoutBigValue(txid, pairID, bind string) error
- func QueryBlacklist(address, pairID string) (isBlacked bool, err error)
- func RemoveFromBlacklist(address, pairID string) error
- func RemoveRegisteredSwap(txid string) error
- func Reswapin(txid, pairID, bind string) error
- func Reswapout(txid, pairID, bind string) error
- func ReverifySwapin(txid, pairID, bind string) error
- func ReverifySwapout(txid, pairID, bind string) error
- func UpdateLatestScanInfo(isSrc bool, blockHeight uint64) error
- func UpdateLatestSwapNonce(address string, isSwapin bool, nonce uint64) (err error)
- func UpdateLatestSwapinNonce(address string, nonce uint64) error
- func UpdateLatestSwapoutNonce(address string, nonce uint64) error
- func UpdateRegisteredSwapStatus(txid string, status string) error
- func UpdateRegisteredSwapStatusFailed(txid string) error
- func UpdateRegisteredSwapStatusSuccess(txid string) error
- func UpdateSwapPendingFailed(txid string) error
- func UpdateSwapPendingNotFound(txid string) error
- func UpdateSwapPendingStatus(txid string, status string) error
- func UpdateSwapPendingSuccess(txid string) error
- func UpdateSwapResultStatus(isSwapin bool, txid, pairID, bind string, status SwapStatus, timestamp int64, ...) error
- func UpdateSwapStatus(isSwapin bool, txid, pairID, bind string, status SwapStatus, timestamp int64, ...) error
- func UpdateSwapinResult(txid, pairID, bind string, items *SwapResultUpdateItems) error
- func UpdateSwapinResultStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
- func UpdateSwapinStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
- func UpdateSwapoutResult(txid, pairID, bind string, items *SwapResultUpdateItems) error
- func UpdateSwapoutResultStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
- func UpdateSwapoutStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
- type MgoBlackAccount
- type MgoLatestScanInfo
- type MgoLatestSwapNonce
- type MgoP2shAddress
- type MgoRegisteredAddress
- type MgoRegisteredSwap
- type MgoRegisteredSwapPending
- type MgoSwap
- func FindSwap(isSwapin bool, txid, pairID, bind string) (*MgoSwap, error)
- func FindSwapin(txid, pairID, bind string) (*MgoSwap, error)
- func FindSwapinsWithPairIDAndStatus(pairID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
- func FindSwapinsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
- func FindSwapout(txid, pairID, bind string) (*MgoSwap, error)
- func FindSwapoutsWithPairIDAndStatus(pairID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
- func FindSwapoutsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
- type MgoSwapHistory
- type MgoSwapResult
- func FindSwapResult(isSwapin bool, txid, pairID, bind string) (*MgoSwapResult, error)
- func FindSwapResultsToReplace(status SwapStatus, septime int64, isSwapin bool) ([]*MgoSwapResult, error)
- func FindSwapinResult(txid, pairID, bind string) (*MgoSwapResult, error)
- func FindSwapinResults(address, pairID string, offset, limit int, status string) ([]*MgoSwapResult, error)
- func FindSwapinResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
- func FindSwapoutResult(txid, pairID, bind string) (*MgoSwapResult, error)
- func FindSwapoutResults(address, pairID string, offset, limit int, status string) ([]*MgoSwapResult, error)
- func FindSwapoutResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
- type MgoSwapStatistics
- type MgoUsedRValue
- type SwapResultUpdateItems
- type SwapStatistics
- type SwapStatus
Constants ¶
const ( SwapSuccess string = "success" //find and success post NewRegister string = "new" // new SwapError string = "failed" SwapNotFound string = "swap not found" )
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 AddRegisteredAddress ¶
AddRegisteredAddress add register address
func AddRegisteredSwap ¶
AddRegisteredSwap add register swap
func AddRegisteredSwapPending ¶
AddRegisteredSwapPending add register swap tx
func AddSwapHistory ¶
AddSwapHistory add
func AddSwapPost ¶
func AddSwapPost(post *MgoRegisteredSwap) error
AddSwapPost add swap post success
func AddSwapinResult ¶
func AddSwapinResult(mr *MgoSwapResult) error
AddSwapinResult add swapin result
func AddSwapoutResult ¶
func AddSwapoutResult(mr *MgoSwapResult) error
AddSwapoutResult add swapout result
func AddToBlacklist ¶
AddToBlacklist add to blacklist
func AddUsedRValue ¶
AddUsedRValue add used r, if error mean already exist
func FindP2shBindAddress ¶
FindP2shBindAddress find bind address through p2sh address
func GetCountOfSwapinResults ¶
GetCountOfSwapinResults get count of swapin results
func GetCountOfSwapinResultsWithStatus ¶
func GetCountOfSwapinResultsWithStatus(pairID string, status SwapStatus) (int, error)
GetCountOfSwapinResultsWithStatus get count of swapin results with status
func GetCountOfSwapinsWithStatus ¶
func GetCountOfSwapinsWithStatus(pairID string, status SwapStatus) (int, error)
GetCountOfSwapinsWithStatus get count of swapins with status
func GetCountOfSwapoutResults ¶
GetCountOfSwapoutResults get count of swapout results
func GetCountOfSwapoutResultsWithStatus ¶
func GetCountOfSwapoutResultsWithStatus(pairID string, status SwapStatus) (int, error)
GetCountOfSwapoutResultsWithStatus get count of swapout results with status
func GetCountOfSwapoutsWithStatus ¶
func GetCountOfSwapoutsWithStatus(pairID string, status SwapStatus) (int, error)
GetCountOfSwapoutsWithStatus get count of swapout with status
func GetRegisterStatus ¶
func LoadAllSwapNonces ¶
LoadAllSwapNonces load
func ManualManageSwap ¶
ManualManageSwap manual manage swap
func MongoServerInit ¶
MongoServerInit int mongodb server session
func PassSwapinBigValue ¶
PassSwapinBigValue pass swapin big value
func PassSwapoutBigValue ¶
PassSwapoutBigValue pass swapout big value
func QueryBlacklist ¶
QueryBlacklist query if is blacked
func RemoveFromBlacklist ¶
RemoveFromBlacklist remove from blacklist
func RemoveRegisteredSwap ¶
RemoveRegisteredSwap remove register swap
func ReverifySwapin ¶
ReverifySwapin reverify swapin
func ReverifySwapout ¶
ReverifySwapout reverify swapout
func UpdateLatestScanInfo ¶
UpdateLatestScanInfo update latest scan info
func UpdateLatestSwapNonce ¶
UpdateLatestSwapNonce update
func UpdateLatestSwapinNonce ¶
UpdateLatestSwapinNonce update
func UpdateLatestSwapoutNonce ¶
UpdateLatestSwapoutNonce update
func UpdateRegisteredSwapStatusSuccess ¶
UpdateRegisteredSwapStatus update register swap status
func UpdateSwapPendingFailed ¶
UpdateSwapPending update register swap status
func UpdateSwapPendingNotFound ¶
UpdateSwapPending update register swap status
func UpdateSwapPendingStatus ¶
UpdateSwapPendingStatus update register swap status
func UpdateSwapPendingSuccess ¶
UpdateSwapPending update register swap status
func UpdateSwapResultStatus ¶
func UpdateSwapResultStatus(isSwapin bool, txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapResultStatus update swap result status
func UpdateSwapStatus ¶
func UpdateSwapStatus(isSwapin bool, txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapStatus update swap status
func UpdateSwapinResult ¶
func UpdateSwapinResult(txid, pairID, bind string, items *SwapResultUpdateItems) error
UpdateSwapinResult update swapin result
func UpdateSwapinResultStatus ¶
func UpdateSwapinResultStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapinResultStatus update swapin result status
func UpdateSwapinStatus ¶
func UpdateSwapinStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapinStatus update swapin status
func UpdateSwapoutResult ¶
func UpdateSwapoutResult(txid, pairID, bind string, items *SwapResultUpdateItems) error
UpdateSwapoutResult update swapout result
func UpdateSwapoutResultStatus ¶
func UpdateSwapoutResultStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapoutResultStatus update swapout result status
func UpdateSwapoutStatus ¶
func UpdateSwapoutStatus(txid, pairID, bind string, status SwapStatus, timestamp int64, memo string) error
UpdateSwapoutStatus update swapout status
Types ¶
type MgoBlackAccount ¶
type MgoBlackAccount struct { Key string `bson:"_id"` // address + pairid Address string `bson:"address"` PairID string `bson:"pairid"` Timestamp int64 `bson:"timestamp"` }
MgoBlackAccount key is address
type MgoLatestScanInfo ¶
type MgoLatestScanInfo struct { Key string `bson:"_id"` BlockHeight uint64 `bson:"blockheight"` Timestamp int64 `bson:"timestamp"` }
MgoLatestScanInfo latest scan info
func FindLatestScanInfo ¶
func FindLatestScanInfo(isSrc bool) (*MgoLatestScanInfo, error)
FindLatestScanInfo find latest scan info
type MgoLatestSwapNonce ¶
type MgoLatestSwapNonce struct { Key string `bson:"_id"` // address + isswapin Address string `bson:"address"` IsSwapin bool `bson:"isswapin"` SwapNonce uint64 `bson:"swapnonce"` Timestamp int64 `bson:"timestamp"` }
MgoLatestSwapNonce latest swap nonce
func FindLatestSwapNonce ¶
func FindLatestSwapNonce(key string) (*MgoLatestSwapNonce, error)
FindLatestSwapNonce find
type MgoP2shAddress ¶
MgoP2shAddress key is the bind address
func FindP2shAddress ¶
func FindP2shAddress(key string) (*MgoP2shAddress, error)
FindP2shAddress find p2sh addrss through bind address
func FindP2shAddresses ¶
func FindP2shAddresses(offset, limit int) ([]*MgoP2shAddress, error)
FindP2shAddresses find p2sh address
type MgoRegisteredAddress ¶
MgoRegisteredAddress key is address (in whitelist)
func FindRegisteredAddress ¶
func FindRegisteredAddress(key string) (*MgoRegisteredAddress, error)
FindRegisteredAddress find register address
type MgoRegisteredSwap ¶
type MgoRegisteredSwap struct { Key string `bson:"_id"` PairID string `bson:"pairid"` Method string `bson:"rpcmethod"` LogIndex uint64 `bson:"logindex"` SwapServer string `bson:"swapserver"` Chain string `bson:"chain"` ChainID uint64 `bson:"chainid"` Status string `bson:"status"` Timestamp int64 `bson:"timestamp"` Time string `bson:"time"` }
MgoRegisteredSwap key is address (in whitelist)
func FindRegisterdSwap ¶
func FindRegisterdSwap(chain string, offset, limit int) ([]*MgoRegisteredSwap, error)
func FindRegisterdSwapTxid ¶
func FindRegisterdSwapTxid(txid string) (*MgoRegisteredSwap, error)
func FindRegisteredSwapStatus ¶
func FindRegisteredSwapStatus(txid string) (*MgoRegisteredSwap, error)
FindRegisteredSwapStatus get register swap status
type MgoRegisteredSwapPending ¶
type MgoRegisteredSwapPending struct { Key string `bson:"_id"` Chain string `bson:"chain"` Status string `bson:"status"` Timestamp int64 `bson:"timestamp"` Time string `bson:"time"` }
MgoRegisteredSwapPending key is address (in whitelist)
func FindSwapPending ¶
func FindSwapPending(chain string, offset, limit int) ([]*MgoRegisteredSwapPending, error)
func FindSwapPendingStatus ¶
func FindSwapPendingStatus(txid string) (*MgoRegisteredSwapPending, error)
FindRegisteredSwapStatus get register swap status
func FindSwapPendingTxid ¶
func FindSwapPendingTxid(txid string) (*MgoRegisteredSwapPending, error)
type MgoSwap ¶
type MgoSwap struct { Key string `bson:"_id"` // txid + pairid + bind PairID string `bson:"pairid"` TxID string `bson:"txid"` TxTo string `bson:"txto"` TxType uint32 `bson:"txtype"` Bind string `bson:"bind"` Status SwapStatus `bson:"status"` InitTime int64 `bson:"inittime"` Timestamp int64 `bson:"timestamp"` Memo string `bson:"memo"` }
MgoSwap registered swap
func FindSwapin ¶
FindSwapin find swapin
func FindSwapinsWithPairIDAndStatus ¶
func FindSwapinsWithPairIDAndStatus(pairID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
FindSwapinsWithPairIDAndStatus find swapin with pairID and status in the past septime
func FindSwapinsWithStatus ¶
func FindSwapinsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
FindSwapinsWithStatus find swapin with status in the past septime
func FindSwapout ¶
FindSwapout find swapout
func FindSwapoutsWithPairIDAndStatus ¶
func FindSwapoutsWithPairIDAndStatus(pairID string, status SwapStatus, septime int64) ([]*MgoSwap, error)
FindSwapoutsWithPairIDAndStatus find swapout with pairID and status in the past septime
func FindSwapoutsWithStatus ¶
func FindSwapoutsWithStatus(status SwapStatus, septime int64) ([]*MgoSwap, error)
FindSwapoutsWithStatus find swapout with status
type MgoSwapHistory ¶
type MgoSwapHistory struct { Key bson.ObjectId `bson:"_id"` IsSwapin bool `bson:"isswapin"` TxID string `bson:"txid"` Bind string `bson:"bind"` SwapTx string `bson:"swaptx"` }
MgoSwapHistory swap history
func GetSwapHistory ¶
func GetSwapHistory(isSwapin bool, txid, bind string) ([]*MgoSwapHistory, error)
GetSwapHistory get
type MgoSwapResult ¶
type MgoSwapResult struct { Key string `bson:"_id"` // txid + pairid + bind PairID string `bson:"pairid"` TxID string `bson:"txid"` TxTo string `bson:"txto"` TxHeight uint64 `bson:"txheight"` TxTime uint64 `bson:"txtime"` From string `bson:"from"` To string `bson:"to"` Bind string `bson:"bind"` Value string `bson:"value"` SwapTx string `bson:"swaptx"` OldSwapTxs []string `bson:"oldswaptxs"` OldSwapVals []string `bson:"oldswapvals"` SwapHeight uint64 `bson:"swapheight"` SwapTime uint64 `bson:"swaptime"` SwapValue string `bson:"swapvalue"` SwapType uint32 `bson:"swaptype"` SwapNonce uint64 `bson:"swapnonce"` Status SwapStatus `bson:"status"` InitTime int64 `bson:"inittime"` Timestamp int64 `bson:"timestamp"` Memo string `bson:"memo"` }
MgoSwapResult swap result (verified swap)
func FindSwapResult ¶
func FindSwapResult(isSwapin bool, txid, pairID, bind string) (*MgoSwapResult, error)
FindSwapResult find swap result
func FindSwapResultsToReplace ¶
func FindSwapResultsToReplace(status SwapStatus, septime int64, isSwapin bool) ([]*MgoSwapResult, error)
FindSwapResultsToReplace find swap results to replace
func FindSwapinResult ¶
func FindSwapinResult(txid, pairID, bind string) (*MgoSwapResult, error)
FindSwapinResult find swapin result
func FindSwapinResults ¶
func FindSwapinResults(address, pairID string, offset, limit int, status string) ([]*MgoSwapResult, error)
FindSwapinResults find swapin history results
func FindSwapinResultsWithStatus ¶
func FindSwapinResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
FindSwapinResultsWithStatus find swapin result with status
func FindSwapoutResult ¶
func FindSwapoutResult(txid, pairID, bind string) (*MgoSwapResult, error)
FindSwapoutResult find swapout result
func FindSwapoutResults ¶
func FindSwapoutResults(address, pairID string, offset, limit int, status string) ([]*MgoSwapResult, error)
FindSwapoutResults find swapout history results
func FindSwapoutResultsWithStatus ¶
func FindSwapoutResultsWithStatus(status SwapStatus, septime int64) ([]*MgoSwapResult, error)
FindSwapoutResultsWithStatus find swapout result with status
type MgoSwapStatistics ¶
type MgoSwapStatistics struct { Key string `bson:"_id"` // pairid PairID string `bson:"pairid"` StableSwapinCount int `bson:"swapincount"` TotalSwapinValue string `bson:"totalswapinvalue"` TotalSwapinFee string `bson:"totalswapinfee"` StableSwapoutCount int `bson:"swapoutcount"` TotalSwapoutValue string `bson:"totalswapoutvalue"` TotalSwapoutFee string `bson:"totalswapoutfee"` }
MgoSwapStatistics swap statistics
func FindSwapStatistics ¶
func FindSwapStatistics(pairID string) (*MgoSwapStatistics, error)
FindSwapStatistics find swap statistics
type MgoUsedRValue ¶
type MgoUsedRValue struct { Key string `bson:"_id"` // r + pubkey Timestamp int64 `bson:"timestamp"` }
MgoUsedRValue security enhancement
type SwapResultUpdateItems ¶
type SwapResultUpdateItems struct { SwapTx string OldSwapTxs []string OldSwapVals []string SwapHeight uint64 SwapTime uint64 SwapValue string SwapType uint32 SwapNonce uint64 Status SwapStatus Timestamp int64 Memo string }
SwapResultUpdateItems swap update items
type SwapStatistics ¶
type SwapStatistics struct { PairID string TotalSwapinCount int TotalSwapoutCount int PendingSwapinCount int PendingSwapoutCount int StableSwapinCount int TotalSwapinValue string TotalSwapinFee string StableSwapoutCount int TotalSwapoutValue string TotalSwapoutFee string }
SwapStatistics rpc return struct
func GetSwapStatistics ¶
func GetSwapStatistics(pairID string) (*SwapStatistics, error)
GetSwapStatistics get swap statistics
type SwapStatus ¶
type SwapStatus uint16
SwapStatus swap status
const ( TxNotStable SwapStatus = iota // 0 TxVerifyFailed // 1 TxWithWrongSender // 2 TxWithWrongValue // 3 TxIncompatible // 4 // deprecated TxNotSwapped // 5 TxSwapFailed // 6 // deprecated TxProcessed // 7 MatchTxEmpty // 8 MatchTxNotStable // 9 MatchTxStable // 10 TxWithWrongMemo // 11 TxWithBigValue // 12 TxSenderNotRegistered // 13 MatchTxFailed // 14 SwapInBlacklist // 15 ManualMakeFail // 16 BindAddrIsContract // 17 KeepStatus = 255 Reswapping = 256 )
swap status values
func GetStatusByTokenVerifyError ¶
func GetStatusByTokenVerifyError(err error) SwapStatus
GetStatusByTokenVerifyError get status by token verify error
func (SwapStatus) CanManualMakeFail ¶
func (status SwapStatus) CanManualMakeFail() bool
CanManualMakeFail can manual make fail
func (SwapStatus) CanReverify ¶
func (status SwapStatus) CanReverify() bool
CanReverify can reverify
func (SwapStatus) String ¶
func (status SwapStatus) String() string
nolint:gocyclo // allow big simple switch