mongodb

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

README

Mongodb Collections

SyncInfo

Name Type Key
Number uint64 bson:"number"
Hash string bson:"hash"
Timestamp uint64 bson:"timestamp"

Blocks

Name Type Key
Number uint64 bson:"number"
Hash string bson:"hash"
ParentHash string bson:"parentHash"
Nonce string bson:"nonce"
Miner string bson:"miner"
Difficulty string bson:"difficulty"
GasLimit uint64 bson:"gasLimit"
GasUsed uint64 bson:"gasUsed"
Timestamp uint64 bson:"timestamp"

Transactions

Name Type Key
Hash string bson:"hash"
BlockNumber uint64 bson:"blockNumber"
BlockHash string bson:"blockHash"
TransactionIndex int bson:"transactionIndex"
From string bson:"from"
To string bson:"to"
Value string bson:"value"
Nonce uint64 bson:"nonce"
GasLimit uint64 bson:"gasLimit"
GasUsed uint64 bson:"gasUsed"
GasPrice string bson:"gasPrice"
Status uint64 bson:"status"
Timestamp uint64 bson:"timestamp"
Erc20Receipts []*Erc20Receipt bson:"erc20Receipts,omitempty"
ExchangeReceipts []*ExchangeReceipt bson:"exchangeReceipts,omitempty"

Note that Erc20Receipts and ExchangeReceipts is an array because a tx may have multiple receipt logs. And these fileds may be omitted if not exist.

Erc20Receipt

LogType can be Transfer or Approval

Erc20 is ERC20 contract address

Name Type Key
LogType string bson:"logType"
LogIndex int bson:"logIndex"
Erc20 string bson:"erc20"
From string bson:"from"
To string bson:"to"
Value string bson:"value"
ExchangeReceipt

LogType can be AddLiquidity, RemoveLiquidity, TokenPurchase or EthPurchase

Pairs is read from config file

Name Type Key
LogType string bson:"txnsType"
LogIndex int bson:"logIndex"
Exchange string bson:"exchange"
Pairs string bson:"pairs"
Address string bson:"address"
TokenFromAmount string bson:"tokenFromAmount"
TokenToAmount string bson:"tokenToAmount"

Liquidity

one record per day

Name Type Key
Exchange string bson:"exchange"
Pairs string bson:"pairs"
Coin string bson:"coin"
Token string bson:"token"
Liquidity string bson:"liquidity"
BlockNumber uint64 bson:"blockNumber"
BlockHash string bson:"blockHash"
Timestamp uint64 bson:"timestamp"

Volume

one record per day

Name Type Key
Exchange string bson:"exchange"
Pairs string bson:"pairs"
CoinVolume24h string bson:"cvolume24h"
TokenVolume24h string bson:"tvolume24h"
BlockNumber uint64 bson:"blockNumber"
BlockHash string bson:"blockHash"
Timestamp uint64 bson:"timestamp"

Accounts

Name Type Key
Exchange string bson:"exchange"
Pairs string bson:"pairs"
Account string bson:"account"

LiquidityBalances

Name Type Key
Exchange string bson:"exchange"
Pairs string bson:"pairs"
Account string bson:"account"
BlockNumber uint64 bson:"blockNumber"
Liquidity string bson:"liquidity"

VolumeHistory

Name Type Key
Exchange string bson:"exchange"
Pairs string bson:"pairs"
Account string bson:"account"
CoinAmount string bson:"coinAmount"
TokenAmount string bson:"tokenAmount"
BlockNumber uint64 bson:"blockNumber"
Timestamp uint64 bson:"timestamp"
TxHash string bson:"txhash"
LogType string bson:"logType"
LogIndex int bson:"logIndex"

Documentation

Index

Constants

View Source
const (

	// KeyOfLatestSyncInfo key
	KeyOfLatestSyncInfo string = "latest"
)

Variables

This section is empty.

Functions

func AddAccount

func AddAccount(ma *MgoAccount) error

AddAccount add exchange account

func AddBlock

func AddBlock(mb *MgoBlock, overwrite bool) (err error)

AddBlock add block

func AddDistributeInfo

func AddDistributeInfo(ma *MgoDistributeInfo) error

AddDistributeInfo add distributeInfo

func AddLiquidRewardResult

func AddLiquidRewardResult(mr *MgoLiquidRewardResult) (err error)

AddLiquidRewardResult add volume reward result

func AddLiquidity

func AddLiquidity(ml *MgoLiquidity, overwrite bool) (err error)

AddLiquidity add liquidity

func AddLiquidityBalance

func AddLiquidityBalance(ma *MgoLiquidityBalance) error

AddLiquidityBalance add liquidity balance

func AddTokenAccount

func AddTokenAccount(ma *MgoTokenAccount) error

AddTokenAccount add token account

func AddTransaction

func AddTransaction(mt *MgoTransaction, overwrite bool) error

AddTransaction add tx

func AddVolume

func AddVolume(mv *MgoVolume, overwrite bool) (err error)

AddVolume add volume

func AddVolumeHistory

func AddVolumeHistory(mv *MgoVolumeHistory, overwrite bool) (err error)

AddVolumeHistory add volume history

func AddVolumeRewardResult

func AddVolumeRewardResult(mr *MgoVolumeRewardResult) (err error)

AddVolumeRewardResult add volume reward result

func CalcRewardsInBatch added in v0.1.4

func CalcRewardsInBatch(stats []AccountStatSlice, rewards []*big.Int)

CalcRewardsInBatch calc rewards in batch

func CalcWeightedRewards

func CalcWeightedRewards(stats []AccountStatSlice, totalReward *big.Int, weights []uint64)

CalcWeightedRewards calc weighted rewards

func DivideRewards

func DivideRewards(totalReward *big.Int, totalShareSlice []*big.Int) (rewards []*big.Int)

DivideRewards divide rewards

func FindAllAccounts

func FindAllAccounts(exchange string) (accounts []common.Address)

FindAllAccounts find accounts

func FindAllTokenAccounts

func FindAllTokenAccounts(token string) (accounts []common.Address)

FindAllTokenAccounts find accounts

func FindLiquidityBalance

func FindLiquidityBalance(exchange, account string, blockNumber uint64) (string, error)

FindLiquidityBalance find liquidity balance

func GetKeyOfExchangeAndAccount

func GetKeyOfExchangeAndAccount(exchange, account string) string

GetKeyOfExchangeAndAccount get key

func GetKeyOfExchangeAndTimestamp

func GetKeyOfExchangeAndTimestamp(exchange string, timestamp uint64) string

GetKeyOfExchangeAndTimestamp get key

func GetKeyOfLiquidityBalance

func GetKeyOfLiquidityBalance(exchange, account string, blockNumber uint64) string

GetKeyOfLiquidityBalance get key

func GetKeyOfRewardResult

func GetKeyOfRewardResult(exchange, account string, start uint64) string

GetKeyOfRewardResult get key

func GetKeyOfTokenAndAccount

func GetKeyOfTokenAndAccount(token, account string) string

GetKeyOfTokenAndAccount get key

func GetKeyOfVolumeHistory

func GetKeyOfVolumeHistory(txhash string, logIndex int) string

GetKeyOfVolumeHistory get key

func MongoServerInit

func MongoServerInit(addrs []string, dbname, user, pass string)

MongoServerInit int mongodb server session

func TryDoTimes

func TryDoTimes(name string, f func() error) (err error)

TryDoTimes try do again if meet error

func UpdateSyncInfo

func UpdateSyncInfo(number uint64, hash string, timestamp uint64) error

UpdateSyncInfo update sync info

func UpdateVolumeWithReceipt

func UpdateVolumeWithReceipt(exr *ExchangeReceipt, blockHash string, blockNumber, timestamp uint64) error

UpdateVolumeWithReceipt update volume

Types

type AccountStat

type AccountStat struct {
	Account common.Address
	Reward  *big.Int
	Share   *big.Int // volume or liquidity
	Number  uint64   // txcount or height
}

AccountStat account statistics

func (*AccountStat) String

func (s *AccountStat) String() string

type AccountStatSlice

type AccountStatSlice []*AccountStat

AccountStatSlice slice sort by reward in reverse order

func ConvertToSortedSlice

func ConvertToSortedSlice(statMap map[common.Address]*AccountStat) AccountStatSlice

ConvertToSortedSlice convert to sorted slice

func FindAccountVolumes

func FindAccountVolumes(exchange string, startHeight, endHeight uint64, useTimestamp bool) AccountStatSlice

FindAccountVolumes find account volumes

func (AccountStatSlice) CalcRewards

func (s AccountStatSlice) CalcRewards(totalReward *big.Int)

CalcRewards calc rewards by shares

func (AccountStatSlice) CalcTotalReward

func (s AccountStatSlice) CalcTotalReward() *big.Int

CalcTotalReward calc the summary

func (AccountStatSlice) CalcTotalShare

func (s AccountStatSlice) CalcTotalShare() *big.Int

CalcTotalShare calc the summary

func (AccountStatSlice) IsAccountExist

func (s AccountStatSlice) IsAccountExist(account common.Address) bool

IsAccountExist is account exist in slice

func (AccountStatSlice) Len

func (s AccountStatSlice) Len() int

func (AccountStatSlice) Less

func (s AccountStatSlice) Less(i, j int) bool

func (AccountStatSlice) SumWeightShares

func (s AccountStatSlice) SumWeightShares(weight uint64) (totalWeightShare *big.Int)

SumWeightShares sum weight shares (do not change slice itself)

func (AccountStatSlice) Swap

func (s AccountStatSlice) Swap(i, j int)

type Erc20Receipt

type Erc20Receipt struct {
	LogType  string `bson:"logType"`
	LogIndex int    `bson:"logIndex"`
	Erc20    string `bson:"erc20"`
	From     string `bson:"from"`
	To       string `bson:"to"`
	Value    string `bson:"value"`
}

Erc20Receipt erc20 tx receipt

type ExchangeReceipt

type ExchangeReceipt struct {
	LogType         string `bson:"txnsType"`
	LogIndex        int    `bson:"logIndex"`
	Exchange        string `bson:"exchange"`
	Pairs           string `bson:"pairs"`
	Address         string `bson:"address"`
	TokenFromAmount string `bson:"tokenFromAmount"`
	TokenToAmount   string `bson:"tokenToAmount"`
}

ExchangeReceipt exchange tx receipt

type MgoAccount

type MgoAccount struct {
	Key      string `bson:"_id"` // exchange + account
	Exchange string `bson:"exchange"`
	Pairs    string `bson:"pairs"`
	Account  string `bson:"account"`
}

MgoAccount exchange account

type MgoBlock

type MgoBlock struct {
	Key        string `bson:"_id"` // = hash
	Number     uint64 `bson:"number"`
	Hash       string `bson:"hash"`
	ParentHash string `bson:"parentHash"`
	Nonce      string `bson:"nonce"`
	Miner      string `bson:"miner"`
	Difficulty string `bson:"difficulty"`
	GasLimit   uint64 `bson:"gasLimit"`
	GasUsed    uint64 `bson:"gasUsed"`
	Timestamp  uint64 `bson:"timestamp"`
}

MgoBlock block

func FindBlocksInRange

func FindBlocksInRange(start, end uint64) ([]*MgoBlock, error)

FindBlocksInRange find blocks

type MgoDistributeInfo

type MgoDistributeInfo struct {
	Key          bson.ObjectId `bson:"_id"`
	Exchange     string        `bson:"exchange"`
	Pairs        string        `bson:"pairs"`
	ByWhat       string        `bson:"bywhat"`
	Start        uint64        `bson:"start"`
	End          uint64        `bson:"end"`
	RewardToken  string        `bson:"rewardToken"`
	Rewards      string        `bson:"rewards"`
	SampleHeight uint64        `bson:"sampleHeight,omitempty"`
	Timestamp    uint64        `bson:"timestamp"`
}

MgoDistributeInfo distribute info

type MgoLiquidRewardResult

type MgoLiquidRewardResult struct {
	Key         string `bson:"_id"` // exchange + account + start
	Exchange    string `bson:"exchange"`
	Pairs       string `bson:"pairs"`
	Start       uint64 `bson:"start"`
	End         uint64 `bson:"end"`
	RewardToken string `bson:"rewardToken"`
	Account     string `bson:"account"`
	Reward      string `bson:"reward"`
	Liquidity   string `bson:"liquidity"`
	Height      uint64 `bson:"height"`
	RewardTx    string `bson:"rewardTx"`
	Timestamp   uint64 `bson:"timestamp"`
}

MgoLiquidRewardResult liquidity reward

func FindLiquidRewardResult

func FindLiquidRewardResult(key string) (*MgoLiquidRewardResult, error)

FindLiquidRewardResult find liquid reward result

type MgoLiquidity

type MgoLiquidity struct {
	Key         string `bson:"_id"` // exchange + timestamp
	Exchange    string `bson:"exchange"`
	Pairs       string `bson:"pairs"`
	Coin        string `bson:"coin"`
	Token       string `bson:"token"`
	Liquidity   string `bson:"liquidity"`
	BlockNumber uint64 `bson:"blockNumber"`
	BlockHash   string `bson:"blockHash"`
	Timestamp   uint64 `bson:"timestamp"`
}

MgoLiquidity liquidity

func FindLatestLiquidity

func FindLatestLiquidity(exchange string) (*MgoLiquidity, error)

FindLatestLiquidity find latest liquidity

func FindLiquidity

func FindLiquidity(key string) (*MgoLiquidity, error)

FindLiquidity find by key

type MgoLiquidityBalance

type MgoLiquidityBalance struct {
	Key         string `bson:"_id"` // exchange + account + blockNumber
	Exchange    string `bson:"exchange"`
	Pairs       string `bson:"pairs"`
	Account     string `bson:"account"`
	BlockNumber uint64 `bson:"blockNumber"`
	Liquidity   string `bson:"liquidity"`
}

MgoLiquidityBalance liquidity balance

type MgoSyncInfo

type MgoSyncInfo struct {
	Key       string `bson:"_id"`
	Number    uint64 `bson:"number"`
	Hash      string `bson:"hash"`
	Timestamp uint64 `bson:"timestamp"`
}

MgoSyncInfo sync info

func FindLatestSyncInfo

func FindLatestSyncInfo() (*MgoSyncInfo, error)

FindLatestSyncInfo find latest sync info

type MgoTokenAccount

type MgoTokenAccount struct {
	Key     string `bson:"_id"` // token + account
	Token   string `bson:"token"`
	Account string `bson:"account"`
}

MgoTokenAccount token account

type MgoTransaction

type MgoTransaction struct {
	Key              string `bson:"_id"` // = hash
	Hash             string `bson:"hash"`
	BlockNumber      uint64 `bson:"blockNumber"`
	BlockHash        string `bson:"blockHash"`
	TransactionIndex int    `bson:"transactionIndex"`
	From             string `bson:"from"`
	To               string `bson:"to"`
	Value            string `bson:"value"`
	Nonce            uint64 `bson:"nonce"`
	GasLimit         uint64 `bson:"gasLimit"`
	GasUsed          uint64 `bson:"gasUsed"`
	GasPrice         string `bson:"gasPrice"`
	Status           uint64 `bson:"status"`
	Timestamp        uint64 `bson:"timestamp"`

	Erc20Receipts    []*Erc20Receipt    `bson:"erc20Receipts,omitempty"`
	ExchangeReceipts []*ExchangeReceipt `bson:"exchangeReceipts,omitempty"`
}

MgoTransaction tx

type MgoVolume

type MgoVolume struct {
	Key            string `bson:"_id"` // exchange + timestamp
	Exchange       string `bson:"exchange"`
	Pairs          string `bson:"pairs"`
	CoinVolume24h  string `bson:"cvolume24h"`
	TokenVolume24h string `bson:"tvolume24h"`
	BlockNumber    uint64 `bson:"blockNumber"`
	BlockHash      string `bson:"blockHash"`
	Timestamp      uint64 `bson:"timestamp"`
}

MgoVolume volumn

func FindLatestVolume

func FindLatestVolume(exchange string) (*MgoVolume, error)

FindLatestVolume find latest volume

func FindVolume

func FindVolume(key string) (*MgoVolume, error)

FindVolume find by key

type MgoVolumeHistory

type MgoVolumeHistory struct {
	Key         string `bson:"_id"` // txhash + logIndex
	Exchange    string `bson:"exchange"`
	Pairs       string `bson:"pairs"`
	Account     string `bson:"account"`
	CoinAmount  string `bson:"coinAmount"`
	TokenAmount string `bson:"tokenAmount"`
	BlockNumber uint64 `bson:"blockNumber"`
	Timestamp   uint64 `bson:"timestamp"`
	TxHash      string `bson:"txhash"`
	LogType     string `bson:"logType"`
	LogIndex    int    `bson:"logIndex"`
}

MgoVolumeHistory volmue tx history

type MgoVolumeRewardResult

type MgoVolumeRewardResult struct {
	Key         string `bson:"_id"` // exchange + account + start
	Exchange    string `bson:"exchange"`
	Pairs       string `bson:"pairs"`
	Start       uint64 `bson:"start"`
	End         uint64 `bson:"end"`
	RewardToken string `bson:"rewardToken"`
	Account     string `bson:"account"`
	Reward      string `bson:"reward"`
	Volume      string `bson:"volume"`
	TxCount     uint64 `bson:"txcount"`
	RewardTx    string `bson:"rewardTx"`
	Timestamp   uint64 `bson:"timestamp"`
}

MgoVolumeRewardResult volume reward

func FindVolumeRewardResult

func FindVolumeRewardResult(key string) (*MgoVolumeRewardResult, error)

FindVolumeRewardResult find volume reward result

Jump to

Keyboard shortcuts

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