mongodb

package
v0.0.0-...-872243e Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: GPL-3.0, LGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ETH, ERC20BNB, ERC20GUSD, ERC20MKR, ERC20HT
	DIVE18 = float64(1000000000000000000)
	//BTC, BCH, USDT
	DIVE8 = float64(100000000)
	//TRX, XRP
	DIVE6 = float64(1000000)
	//EVT1
	DIVE5 = float64(100000)
	//EOS
	DIVE4 = float64(10000)
	//ATOM
	DIVE3 = float64(1000)

	MUL1E9  = 1e9
	MUL1E10 = 1e10

	QuantityAccuracy int = 9
)
View Source
const (
	SUCCESS = iota + 1
	FAILURE

	EXIST = iota + 1
	FINISHED

	INSERT = iota + 1
	UPDATE
)

Variables

View Source
var (
	Session  *mgo.Session
	InitOnce bool
)
View Source
var (
	Mongo      bool   = false
	MongoSlave bool   = false
	MongoIP    string = "localhost" // default port: 27017
	URL        string
	MatchTrade string = ""
)
View Source
var (
	BlockLock         sync.Mutex
	DexBlockLock      sync.Mutex
	OrderCacheLock    sync.Mutex
	OrderLock         sync.Mutex
	DexTxnsLock       sync.Mutex
	OrderAndCacheLock sync.Mutex

	ConfirmBlockNumber uint64 = 6
	ConfirmBlockTime   uint64 = 0
)
View Source
var LOGPRINTALL bool = false // true: print all log, false: do nothing

Functions

func AddAccount

func AddAccount(table string, ma *mgoAccount)

func AddAddress

func AddAddress(address, publicKey string)

func AddBlock

func AddBlock(table string, mb *mgoBlock)

func AddDcrmAccount

func AddDcrmAccount(table string, mda *mgoDcrmAccount)

func AddDcrmAddress

func AddDcrmAddress(address, cointype, dcrmAddress string, lockin, lockout int)

func AddDexBlock

func AddDexBlock(table string, mdb *mgoDexBlock)

func AddDexTx

func AddDexTx(table string, mdt *mgoDexTx)

func AddHistory

func AddHistory(srcTx *types.Transaction)

func AddOrder

func AddOrder(table string, mo *mgoOrder) bool

func AddOrderCache

func AddOrderCache(table string, moc *mgoOrderCache, iu int)

func AddTransaction

func AddTransaction(table string, mt *mgoTransaction)

func CheckOrderCacheTxForODB

func CheckOrderCacheTxForODB(table, txHash string) bool

func ClearDb

func ClearDb(table string)

func ConvertStringToFloat64

func ConvertStringToFloat64(value string, cointype string) float64

func Decode

func Decode(s string) (interface{}, error)

func DeleteBlock

func DeleteBlock(table string, num uint64)

func DeleteDcrmAccount

func DeleteDcrmAccount(table, address, cointype string)

func DeleteDexBlock

func DeleteDexBlock(table string, Number uint64)

func DeleteDexBlock(table string, Number uint64, Trade string) {

func DeleteTransaction

func DeleteTransaction(table string, mt *mgoTransaction)

func FindAccount

func FindAccount(table, address string) []mgoAccount

func FindBlock

func FindBlock(table string, num uint64) []mgoBlock

func FindDcrmAccount

func FindDcrmAccount(table, initAddress, cointype string) []mgoDcrmAccount

func FindDexBlock

func FindDexBlock(table string, Number uint64, Trade string) []mgoDexBlock

func FindDexTx

func FindDexTx(table, Hash string, Height uint64) []mgoDexTx

func FindOrder

func FindOrder(table string, hash string) []mgoOrder

func FindOrderCache

func FindOrderCache(table string, hash string) []mgoOrderCache

func FindTransaction

func FindTransaction(table, Hash string) []mgoTransaction

func FindTransactionToAccount

func FindTransactionToAccount(table string, address common.Address) []mgoTransaction

func FindTransferHistory

func FindTransferHistory(table, key string) []mgoHistory

func InsertOrderAndCache

func InsertOrderAndCache(msg string)

call from InsertToOrderBook() xprotocol/exchange.go

func InsertOrderCache

func InsertOrderCache(hash, price, quantity, trade, side string)

func IsDcrmLockOut

func IsDcrmLockOut(data []byte) bool

func IsDexOrder

func IsDexOrder(data []byte) bool

func IsSyncedBlock

func IsSyncedBlock(blockHash string) bool

func LightSync

func LightSync(block *types.Block, txs []*types.Transaction)

func MongoInit

func MongoInit()

func RemoveDexBlock

func RemoveDexBlock(table string, mdb *mgoDexBlock)

func RemoveDexTx

func RemoveDexTx(table string, mdt *mgoDexTx)

func RemoveOrderCache

func RemoveOrderCache(price, trade, side string)

func RevSync

func RevSync(block *types.Block, receipts types.Receipts)

func StartSync

func StartSync(path string)

func Sync

func Sync(block *types.Block, receipts types.Receipts, state *state.StateDB)

func SyncGenesisAccount

func SyncGenesisAccount(address string, time uint64, balance string)

func SyncGenesisBlock

func SyncGenesisBlock(block *types.Block)

func UnCompress

func UnCompress(s string) (string, error)

func UpdataTransferHistoryStatus

func UpdataTransferHistoryStatus(tx *types.Transaction, reverse bool)

func UpdataTransferHistoryStatus2

func UpdataTransferHistoryStatus2(table, hash string, success bool)

func UpdateAccount

func UpdateAccount(ma *mgoAccount, value string, time uint64, add bool, fee string)

func UpdateAccountPublicKey

func UpdateAccountPublicKey(table, address, pubkey string)

func UpdateBalance

func UpdateBalance(table, address, valueString string, value float64)

func UpdateBalance4State

func UpdateBalance4State(ma *mgoAccount, state *state.StateDB, time uint64)

func UpdateComfirm

func UpdateComfirm(table, address string, value float64)

func UpdateDcrmAccount

func UpdateDcrmAccount(mda *mgoDcrmAccount, value string, time uint64, add bool, fee string, cointype string)

func UpdateDcrmBalance

func UpdateDcrmBalance(table, address, cointype, valueString string, value float64)

func UpdateDcrmBalance4State

func UpdateDcrmBalance4State(mda *mgoDcrmAccount, state *state.StateDB)

func UpdateOrder

func UpdateOrder(hash string, remain string)

func UpdateOrderAddCache

func UpdateOrderAddCache(tx *types.Transaction)

func UpdateOrderCacheFromShare

func UpdateOrderCacheFromShare(msg interface{})

func UpdateOrderFromShare

func UpdateOrderFromShare(tx *types.Transaction)

func UpdateOrderOrg

func UpdateOrderOrg(table string, mo *mgoOrder)

func UpdateOrderStatus

func UpdateOrderStatus(hash string, status int)
func UpdateOrderCache(table string, hash string, quantity, price float64, v *orderbook.XvcOrder) {
	logPrintAll("==== UpdateOrderCache() ====", "hash", hash, "remain", quantity)

	orderCacheTimer := time.NewTimer(time.Duration(1) * time.Second)
	defer orderCacheTimer.Stop()
	oci, _ := orderCacheInfo.Load(hash)
	logPrintAll("==== UpdateOrderCache() ====", "hash", hash, "exist(1)/finish(2)", oci)
	count := 1
	maxwait := 5 * 100
	for {
		oci, _ := orderCacheInfo.Load(hash)
		if oci == EXIST {
			break
		} else if oci == FINISHED {
			collectionTable := getCollection(table)
			OrderCacheLock.Lock()
			collectionTable.Remove(bson.M{"_id": hash})
			OrderCacheLock.Unlock()
			logPrintAll("==== UpdateOrderCache() ====", "remove: hash", hash, "remain", quantity)
			return
		}
		count++
		if count > maxwait {
			logPrintAll("=== UpdateOrderCache() ====", "error not found orderCache hash", hash)
			break
		}
		<-orderCacheTimer.C
		orderCacheTimer.Reset(time.Duration(1) * time.Second)
	}
	collectionTable := getCollection(table)
	if quantity < (1 / DIVE8) {
		UpdateOrderStatus(hash, SUCCESS)
		OrderCacheLock.Lock()
		collectionTable.Remove(bson.M{"_id": hash})
		OrderCacheLock.Unlock()
		logPrintAll("==== UpdateOrderCache() ====", "remove: hash", hash, "remain", quantity)
		orderCacheInfo.Store(hash, FINISHED)
	} else {
		total := price * quantity
		OrderCacheLock.Lock()
		collectionTable.Update(bson.M{"_id": hash}, bson.M{"$set": bson.M{
			"volume": quantity,
			"total":  total,
		}})
		OrderCacheLock.Unlock()
		logPrintAll("==== UpdateOrderCache() ====", "update: hash", hash, "remain", quantity)
	}
}

Types

type BlockInfo

type BlockInfo struct {
	Number          uint64 `bson:"number"`
	TotalDifficulty uint64 `bson:"totalDifficulty"`
	Timestamp       uint64 `bson:"timestamp"`
}

type CurrentVolume

type CurrentVolume struct {
	Id  string
	Vol string
}

type MatchRes

type MatchRes struct {
	Price     string
	Done      []*XvcOrder
	Volumes   string
	Orders    int
	CurVolume []*CurrentVolume
}

func DecodeMatchRes

func DecodeMatchRes(s string) (*MatchRes, error)

func GetMrFromMatch

func GetMrFromMatch(data string) *MatchRes

type ODBInfo

type ODBInfo struct {
	Trade   string //ETH/BTC
	Price   string
	Volumes string
	Orders  int
}

type OrderStatus

type OrderStatus struct {
	ODS []OrderTrade
}

type OrderTrade

type OrderTrade struct {
	TRADE  string
	STATUS string
}

type SendMsg

type SendMsg struct {
	MsgType string
	Nonce   string
	WorkId  int
	Msg     string
}

type XvcOrder

type XvcOrder struct {
	Id        string
	From      common.Address
	Trade     string //ETH/BTC
	Ordertype string //LimitOrder
	Side      string //Buy/Sell
	Timestamp int64
	//Quantity  decimal.Decimal
	//Price     decimal.Decimal
	Quantity string
	Price    string
	Rule     string //GTE/IOC
}

Jump to

Keyboard shortcuts

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