db

package
v0.0.0-...-0584d29 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionBlocks                    = "blocks"
	CollectionBP                        = "blockproducer"
	CollectionTxs                       = "txs"
	CollectionFlatTx                    = "flatxs"
	CollectionAccount                   = "accounts"
	CollectionAccountTx                 = "accountTx"
	CollectionAccountPubkey             = "accountPubkey"
	CollectionContract                  = "contracts"
	CollectionContractTx                = "contractTx"
	CollectionTaskCursor                = "taskCursors"
	CollectionBlockPay                  = "blockPays"
	CollectionApplyIOST                 = "applyIOST"
	CollectionVoteTx                    = "voteTx"
	CollectionProducerAward             = "producerAward"
	CollectionUserAward                 = "userAward"
	CollectionProducerContributionAward = "producerContributionAward"
	CollectionUserContributionAward     = "userContributionAward"
	CollectionFailedAward               = "failedUserAward"
	CollectionAwardInfo                 = "awardInfo"
	CollectionProducerLevelInfo         = "producerLevel"
)
View Source
const AccountCursorName = "Account_cursor"

Variables

View Source
var (
	MongoLink     string
	MongoUser     = ""
	MongoPassWord = ""
	Db            string
)

Functions

func AddApply

func AddApply(txHash, accountPubKey, accountName, email, remoteIP string) error

func GetAccountLastPage

func GetAccountLastPage(eachPage int64) (int64, error)

func GetAccountTaskCursor

func GetAccountTaskCursor() (bson.ObjectId, error)

func GetAccountTxNumber

func GetAccountTxNumber(name string) (int, error)

func GetAccountsTotalLen

func GetAccountsTotalLen() (int, error)

func GetBlockByHash

func GetBlockByHash(hash string) (*rpcpb.Block, *[]string, error)

func GetBlockByHeight

func GetBlockByHeight(height int64) (*rpcpb.Block, error)

func GetBlockLastPage

func GetBlockLastPage(eachPage int64) int64

func GetBlockPayListByHeight

func GetBlockPayListByHeight(heightList []int64) (map[int64]*BlockPay, error)

func GetBlockTxnHashes

func GetBlockTxnHashes(blockNumber int64) (*[]string, error)

func GetBlocks

func GetBlocks(start, limit int) ([]*rpcpb.Block, error)

func GetCollection

func GetCollection(c string) *mgo.Collection

func GetContractTxNumber

func GetContractTxNumber(ID string) (int, error)

func GetDb

func GetDb() (*mgo.Database, error)

func GetFirstBlockNumberAfter

func GetFirstBlockNumberAfter(time int64) (int64, error)

func GetFlatTxPageCntWithBlk

func GetFlatTxPageCntWithBlk(eachPage int64, blk int64) (int64, error)

func GetFlatTxTotalPageCnt

func GetFlatTxTotalPageCnt(eachPage int64, account string, block int64) (int64, error)

func GetLastBlockNumber

func GetLastBlockNumber() (int64, error)

func GetLastBlockNumberBefore

func GetLastBlockNumberBefore(time int64) (int64, error)

func GetTopBlock

func GetTopBlock() (*rpcpb.Block, error)

func GetTotalFlatTxnLen

func GetTotalFlatTxnLen(address string, block int64) (int, error)

/ get length of transaction list using account and block number

func GetTxCountByNumber

func GetTxCountByNumber(number int64) (int, error)

func GetTxTotalPageCnt

func GetTxTotalPageCnt(eachPage, blockNumber int64) (int64, error)

func InitConfig

func InitConfig()

func ProcessTxs

func ProcessTxs(txs []*rpcpb.Transaction, blockNumber int64) error

func ProcessTxsForAccount

func ProcessTxsForAccount(txs []*rpcpb.Transaction, blockTime int64, blockNumber int64)

func SaveAwardInfo

func SaveAwardInfo(aInfo AwardInfo) error

func SaveProducerAward

func SaveProducerAward(producerAwards []ProducerAward) error

func SaveProducerContributionAward

func SaveProducerContributionAward(producerAwards []ProducerAward) error

func SaveProducerLevelInfo

func SaveProducerLevelInfo(aInfo ProducerLevelInfo) error

func SaveUserAward

func SaveUserAward(userAwards []UserAward) error

func SaveUserContributionAward

func SaveUserContributionAward(userAwards []UserAward) error

func UpdateAccountTaskCursor

func UpdateAccountTaskCursor(cursor bson.ObjectId) error

Types

type Account

type Account struct {
	Name        string         `bson:"name" json:"name"`
	CreateTime  int64          `bson:"createTime" json:"create_time"`
	Creator     string         `bson:"creator" json:"creator"`
	AccountInfo *rpcpb.Account `bson:"accountInfo" json:"account_info"`
}

func GetAccountByName

func GetAccountByName(name string) (*Account, error)

func GetAccounts

func GetAccounts(start, limit int) ([]*Account, error)

func GetAccountsByNames

func GetAccountsByNames(names []string) ([]*Account, error)

func NewAccount

func NewAccount(name string, time int64, creator string) *Account

type AccountPubkey

type AccountPubkey struct {
	Name   string `bson:"name"`
	Pubkey string `bson:"pubkey"`
}

func GetAccountPubkeyByName

func GetAccountPubkeyByName(name string) ([]*AccountPubkey, error)

func GetAccountPubkeyByPubkey

func GetAccountPubkeyByPubkey(pubkey string) ([]*AccountPubkey, error)

type AccountTx

type AccountTx struct {
	Name          string `bson:"name"`
	Time          int64  `bson:"time"`
	TxHash        string `bson:"txHash"`
	TransferToken string `bson:"token"`
}

func GetAccountTxByName

func GetAccountTxByName(name string, start, limit int) ([]*AccountTx, error)

type ActionRaw

type ActionRaw struct {
	Contract   string `bson:"contract" json:"contract"`
	ActionName string `bson:"actionName" json:"actionName"`
	Data       string `bson:"data" json:"data"`
}

type ApplyAccount

type ApplyAccount struct {
	TxHash     string
	PubKey     string
	Name       string
	Email      string
	RemoteIP   string
	InsertTime int64
}

type AwardInfo

type AwardInfo struct {
	Aid         string `json:"aid" form:"aid" query:"aid"`
	StartTime   int64  `json:"start_time" form:"start_time" query:"start_time"`
	EndTime     int64  `json:"end_time" form:"end_time" query:"end_time"`
	TotalAmount int64  `json:"total_amount" form:"total_amount" query:"total_amount"`
	CountTime   int64  `json:"count_time" form:"count_time" query:"count_time"`
}

func GetAwardInfo

func GetAwardInfo(aid string) (ainfo AwardInfo, err error)

func GetVoteAwardInfo

func GetVoteAwardInfo(id string) ([]*AwardInfo, error)

func GetVoteAwardList

func GetVoteAwardList() ([]*AwardInfo, error)

type BPProduce

type BPProduce struct {
	Witness        string `bson:"witness" json:"witness"`
	StartTime      int64  `bson:"startTime" json:"startTime"`
	EndTime        int64  `bson:"endTime" json:"endTime"`
	Count          int64  `bson:"count" json:"count"`
	MaxBlockNumber int    `bson:"maxBlockNumber" json:"maxBlockNumber"`
	MinBlockNumber int    `bson:"minBlockNumber" json:"minBlockNumber"`
}

func GetBPProduceByStartTime

func GetBPProduceByStartTime(startTime int64) ([]BPProduce, error)

func GetLastBPProduce

func GetLastBPProduce() ([]BPProduce, error)

type BPStore

type BPStore struct {
	Id             string `bson:"_id" json:"_id"`
	Count          int64  `bson:"count" json:"count"`
	MaxBlockNumber int    `bson:"maxBlockNumber" json:"maxBlockNumber"`
	MinBlockNumber int    `bson:"minBlockNumber" json:"minBlockNumber"`
}

func GetBPProduce

func GetBPProduce(pubkeys []string, startTime time.Time, endTime time.Time) ([]BPStore, error)

type Block

type Block struct {
	ParentHash  string `bson:"parentHash"`
	Hash        string `bson:"hash"`
	TxsHash     string `bson:"txsHash"`
	MerkleHash  string `bson:"merkleHash"`
	BlockNumber int64  `bson:"blockNumber"`
	TxNumber    int64  `bson:"txNumber"`
	Witness     string `bson:"witness"`
	Time        int64  `bson:"time"`
	Version     int64  `bson:"version"`
	Info        string `bson:"info"`
}

type BlockPay

type BlockPay struct {
	Height        int64   `json:"height" bson:"_id,omitempty"`
	AvgGasPrice   float64 `json:"avg_gas_price"`
	TotalGasLimit int64   `json:"total_gas_limit"`
}

func GetBlockPayByHeight

func GetBlockPayByHeight(height int64) (*BlockPay, error)

func GetTopBlockPay

func GetTopBlockPay() (*BlockPay, error)

type Contract

type Contract struct {
	ID           string          `bson:"id"`
	Domain       string          `bson:"domain"`
	CreateTime   int64           `bson:"createTime"`
	Creator      string          `bson:"creator"`
	Balance      float64         `bson:"balance"`
	ContractInfo *rpcpb.Contract `bson:"contractInfo"`
}

func NewContract

func NewContract(id string, time int64, creator string) *Contract

type ContractTx

type ContractTx struct {
	ID     string `bson:"id"`
	Time   int64  `bson:"time"`
	TxHash string `bson:"txHash"`
}

func GetContractTxByID

func GetContractTxByID(ID string, start, limit int) ([]*ContractTx, error)

type FailBlock

type FailBlock struct {
	BlockNumber int64 `bson:"blockNumber"`
	RetryTimes  int64 `bson:"retryTimes"`
	Processed   bool  `bson:"processed"`
}

record failed sync block

type FlatTx

type FlatTx struct {
	Id          bson.ObjectId  `bson:"_id,omitempty" json:"id"`
	BlockNumber int64          `bson:"blockNumber" json:"blockNumber"`
	Time        int64          `bson:"time" json:"time"`
	Hash        string         `bson:"hash" json:"hash"`
	Expiration  int64          `bson:"expiration" json:"expiration"`
	GasPrice    int64          `bson:"gasPrice" json:"gasPrice"`
	GasLimit    int64          `bson:"gasLimit" json:"gasLimit"`
	Action      ActionRaw      `bson:"action" json:"action"`
	Signers     []string       `bson:"signers" json:"signers"`
	Signs       []SignatureRaw `bson:"signs" json:"signs"`
	Publisher   string         `bson:"publisher" json:"publisher"`
	From        string         `bson:"from" json:"from"`
	To          string         `bson:"to" json:"to"`
	Amount      float64        `bson:"amount" json:"amount"`           // 转发数量
	ActionIndex int            `bson:"actionIndex" json:"actionIndex"` // action 索引
	ActionName  string         `bson:"actionName" json:"actionName"`   // action 类型
	Receipt     TxReceiptRaw   `bson:"receipt" json:"receipt"`
}

将 Tx.Actions 打平后的数据结构, 如果actionName == Transfer 则会解析出 from, to, amount

func GetFlatTxnDetailByHash

func GetFlatTxnDetailByHash(txHash string) (*FlatTx, error)

func GetFlatTxnSlice

func GetFlatTxnSlice(start, limit, block int, address string) ([]*FlatTx, error)

/ get at most `limit` flat txns from start using block and account address

type PledgeInfo

type PledgeInfo struct {
	MyPledge    map[string]float64 `json:"my_pledge"`
	PledgeForMe map[string]float64 `json:"pledge_for_me"`
}

func GetAccountPledge

func GetAccountPledge(name string) (*PledgeInfo, error)

type ProducerAward

type ProducerAward struct {
	Aid   string  `json:"aid" form:"aid" query:"aid"`
	Pid   string  `json:"pid" form:"pid" query:"pid"`
	Vote  float64 `json:"vote" form:"vote" query:"vote"`
	Award float64 `json:"award" form:"award" query:"award"`
}

func GetProducerAward

func GetProducerAward(id string) ([]*ProducerAward, error)

func GetProducerContributionAward

func GetProducerContributionAward(id string) ([]*ProducerAward, error)

type ProducerLevel

type ProducerLevel struct {
	Pid   string `json:"pid" form:"pid" query:"pid"`
	Level int    `json:"level" form:"level" query:"level"`
}

type ProducerLevelInfo

type ProducerLevelInfo struct {
	Aid string `json:"aid" form:"aid" query:"aid"`
	//ProducerLevels []*ProducerLevel `json:"producerlevels" form:"producerlevels" query:"producerlevels"`
	ProducerLevels []*ProducerLevel `json:"producerlevels" form:"producerlevels" query:"producerlevels"`
}

func GetProducerLevelInfo

func GetProducerLevelInfo(aid string) (pInfo ProducerLevelInfo, err error)

type ReceiptRaw

type ReceiptRaw struct {
	Type    int32  `bson:"type" json:"type"`
	Content string `bson:"content" json:"content"`
}

type SignatureRaw

type SignatureRaw struct {
	Algorithm int32  `bson:"algorithm" json:"algorithm"`
	Sig       string `bson:"sig" json:"sig"`
	PubKey    string `bson:"pubKey" json:"pubKey"`
}

type TaskCursor

type TaskCursor struct {
	Name   string        `json:"name"`
	Cursor bson.ObjectId `json:"cursor"`
}

type TmpTx

type TmpTx struct {
	Id          bson.ObjectId `bson:"_id,omitempty"`
	Hash        string        `bson:"hash"`
	BlockNumber int64         `bson:"blockNumber"`
	Mark        int64         `bson:"mark"`
}

type Tx

type Tx struct {
	ExternalId  bson.ObjectId  `bson:"externalId"`
	BlockNumber int64          `bson:"blockNumber"`
	Time        int64          `bson:"time"`
	Hash        string         `bson:"hash"`
	Expiration  int64          `bson:"expiration"`
	GasPrice    int64          `bson:"gasPrice"`
	GasLimit    int64          `bson:"gasLimit"`
	Mark        int64          `bson:"mark"`
	Actions     []ActionRaw    `bson:"actions"`
	Signers     []string       `bson:"signers"`
	Signs       []SignatureRaw `bson:"signs"`
	Publisher   SignatureRaw   `bson:"publisher"`
	Receipt     TxReceiptRaw   `bson:"receipt"`
}

func GetTxnDetailByHash

func GetTxnDetailByHash(txHash string) (*Tx, error)

type TxReceiptRaw

type TxReceiptRaw struct {
	GasUsage      int64        `bson:"gasUsage"`
	SuccActionNum int32        `bson:"succActionNum"`
	Receipts      []ReceiptRaw `bson:"receipts"`
	StatusCode    int32        `bson:"statusCode"`
	StatusMessage string       `bson:"statusMessage"`
}

type TxStore

type TxStore struct {
	BlockNumber int64              `json:"block_number"`
	Tx          *rpcpb.Transaction `json:"tx"`
}

func GetTxByHash

func GetTxByHash(hash string) (*TxStore, error)

func GetTxs

func GetTxs(blockNumber int64, start, limit int) ([]*TxStore, error)

func GetTxsByHash

func GetTxsByHash(hashes []string) ([]*TxStore, error)

type UserAward

type UserAward struct {
	Aid      string  `json:"aid" form:"aid" query:"aid"`
	Username string  `json:"username" form:"username" query:"username"`
	Pid      string  `json:"pid" form:"pid" query:"pid"`
	Vote     float64 `json:"vote" form:"vote" query:"vote"`
	Award    float64 `json:"award" form:"award" query:"award"`
}

func GetUserAward

func GetUserAward(id string) ([]*UserAward, error)

func GetUserContributionAward

func GetUserContributionAward(id string) ([]*UserAward, error)

type VoteTx

type VoteTx struct {
	Actions     []*rpcpb.Action  `bson:"action" json:"action"`
	TxReceipt   *rpcpb.TxReceipt `bson:"txReceipt" json:"txReceipt"`
	BlockNumber int64            `bson:"blockNumber"`
}

func GetVoteTxs

func GetVoteTxs(endBlock int64) (voteTx []*VoteTx, err error)

Jump to

Keyboard shortcuts

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