mempool

package
v0.0.0-...-3606b63 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reg

func Reg(name string, create Create)

Reg 注册一个create

Types

type AccountTxIndex

type AccountTxIndex struct {
	// contains filtered or unexported fields
}

AccountTxIndex 账户和交易索引

func NewAccountTxIndex

func NewAccountTxIndex(maxperaccount int) *AccountTxIndex

NewAccountTxIndex 创建一个新的索引

func (*AccountTxIndex) CanPush

func (cache *AccountTxIndex) CanPush(tx *types.Transaction) bool

CanPush 是否可以push 进 account index

func (*AccountTxIndex) GetAccTxs

func (cache *AccountTxIndex) GetAccTxs(addrs *types.ReqAddrs) *types.TransactionDetails

GetAccTxs 用来获取对应账户地址(列表)中的全部交易详细信息

func (*AccountTxIndex) Push

func (cache *AccountTxIndex) Push(tx *types.Transaction) error

Push push transaction to AccountTxIndex

func (*AccountTxIndex) Remove

func (cache *AccountTxIndex) Remove(tx *types.Transaction)

Remove 根据交易哈希删除对应账户的对应交易

func (*AccountTxIndex) TxNumOfAccount

func (cache *AccountTxIndex) TxNumOfAccount(addr string) int

TxNumOfAccount 返回账户在Mempool中交易数量

type Create

type Create func(cfg *types.Mempool, sub []byte) queue.Module

Create 创建一个mempool模块

func Load

func Load(name string) (create Create, err error)

Load 加载一个create

type Item

type Item struct {
	Value     *types.Transaction
	Priority  int64
	EnterTime int64
}

Item 为Mempool中包装交易的数据结构

type LastTxCache

type LastTxCache struct {
	// contains filtered or unexported fields
}

LastTxCache 最后放入cache的交易

func NewLastTxCache

func NewLastTxCache(size int) *LastTxCache

NewLastTxCache 创建最后交易的cache

func (*LastTxCache) GetLatestTx

func (cache *LastTxCache) GetLatestTx() (txs []*types.Transaction)

GetLatestTx 返回最新十条加入到txCache的交易

func (*LastTxCache) Push

func (cache *LastTxCache) Push(tx *types.Transaction)

Push tx into LastTxCache

func (*LastTxCache) Remove

func (cache *LastTxCache) Remove(tx *types.Transaction)

Remove remove tx of last cache

type Mempool

type Mempool struct {
	// contains filtered or unexported fields
}

Mempool mempool 基础类

func NewMempool

func NewMempool(cfg *types.Mempool) *Mempool

NewMempool 新建mempool 实例

func (*Mempool) CheckExpireValid

func (mem *Mempool) CheckExpireValid(msg *queue.Message) (bool, error)

CheckExpireValid 检查交易过期有效性,过期返回false,未过期返回true

func (*Mempool) Close

func (mem *Mempool) Close()

Close 关闭mempool

func (*Mempool) GetAccTxs

func (mem *Mempool) GetAccTxs(addrs *types.ReqAddrs) *types.TransactionDetails

GetAccTxs 用来获取对应账户地址(列表)中的全部交易详细信息

func (*Mempool) GetHeader

func (mem *Mempool) GetHeader() *types.Header

GetHeader 获取Mempool.header

func (*Mempool) GetLastHeader

func (mem *Mempool) GetLastHeader() (interface{}, error)

GetLastHeader 获取LastHeader的height和blockTime

func (*Mempool) GetLatestTx

func (mem *Mempool) GetLatestTx() []*types.Transaction

GetLatestTx 返回最新十条加入到mempool的交易

func (*Mempool) GetProperFeeRate

func (mem *Mempool) GetProperFeeRate(req *types.ReqProperFee) int64

GetProperFeeRate 获取合适的手续费率

func (*Mempool) Height

func (mem *Mempool) Height() int64

Height 获取区块高度

func (*Mempool) PushTx

func (mem *Mempool) PushTx(tx *types.Transaction) error

PushTx 将交易推入mempool,并返回结果(error)

func (*Mempool) RemoveTxs

func (mem *Mempool) RemoveTxs(hashList *types.TxHashList) error

RemoveTxs 从mempool中删除给定Hash的txs

func (*Mempool) RemoveTxsOfBlock

func (mem *Mempool) RemoveTxsOfBlock(block *types.Block) bool

RemoveTxsOfBlock 移除mempool中已被Blockchain打包的tx

func (*Mempool) SetMinFee

func (mem *Mempool) SetMinFee(fee int64)

SetMinFee 设置最小交易费用

func (*Mempool) SetQueueCache

func (mem *Mempool) SetQueueCache(qcache QueueCache)

SetQueueCache 设置排队策略

func (*Mempool) SetQueueClient

func (mem *Mempool) SetQueueClient(client queue.Client)

SetQueueClient 初始化mempool模块

func (*Mempool) Size

func (mem *Mempool) Size() int

Size 返回mempool中txCache大小

func (*Mempool) TxNumOfAccount

func (mem *Mempool) TxNumOfAccount(addr string) int64

TxNumOfAccount 返回账户在mempool中交易数量

func (*Mempool) Wait

func (mem *Mempool) Wait()

Wait wait mempool ready

type QueueCache

type QueueCache interface {
	Exist(hash string) bool
	GetItem(hash string) (*Item, error)
	Push(tx *Item) error
	Remove(hash string) error
	Size() int
	Walk(count int, cb func(tx *Item) bool)
	GetProperFee() int64
}

QueueCache 排队交易处理

type SHashTxCache

type SHashTxCache struct {
	// contains filtered or unexported fields
}

SHashTxCache 通过shorthash缓存交易

func NewSHashTxCache

func NewSHashTxCache(size int) *SHashTxCache

NewSHashTxCache 创建通过短hash交易的cache

func (*SHashTxCache) Exist

func (cache *SHashTxCache) Exist(shash string) bool

Exist 是否存在

func (*SHashTxCache) GetSHashTxCache

func (cache *SHashTxCache) GetSHashTxCache(sHash string) *types.Transaction

GetSHashTxCache 返回shorthash对应的tx交易信息

func (*SHashTxCache) Push

func (cache *SHashTxCache) Push(tx *types.Transaction)

Push tx into SHashTxCache

func (*SHashTxCache) Remove

func (cache *SHashTxCache) Remove(tx *types.Transaction)

Remove remove tx of SHashTxCache

type SimpleQueue

type SimpleQueue struct {
	// contains filtered or unexported fields
}

SimpleQueue 简单队列模式(默认提供一个队列,便于测试)

func NewSimpleQueue

func NewSimpleQueue(subConfig SubConfig) *SimpleQueue

NewSimpleQueue 创建队列

func (*SimpleQueue) Exist

func (cache *SimpleQueue) Exist(hash string) bool

Exist 是否存在

func (*SimpleQueue) GetItem

func (cache *SimpleQueue) GetItem(hash string) (*Item, error)

GetItem 获取数据通过 key

func (*SimpleQueue) GetProperFee

func (cache *SimpleQueue) GetProperFee() int64

GetProperFee 获取合适的手续费

func (*SimpleQueue) Push

func (cache *SimpleQueue) Push(tx *Item) error

Push 把给定tx添加到SimpleQueue;如果tx已经存在SimpleQueue中或Mempool已满则返回对应error

func (*SimpleQueue) Remove

func (cache *SimpleQueue) Remove(hash string) error

Remove 删除数据

func (*SimpleQueue) Size

func (cache *SimpleQueue) Size() int

Size 数据总数

func (*SimpleQueue) Walk

func (cache *SimpleQueue) Walk(count int, cb func(value *Item) bool)

Walk 遍历整个队列

type SubConfig

type SubConfig struct {
	PoolCacheSize int64 `json:"poolCacheSize"`
	ProperFee     int64 `json:"properFee"`
}

SubConfig 配置信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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