Documentation
¶
Overview ¶
package txn deals with tx data
Index ¶
- Constants
- Variables
- func GenerateAutoTxWithRWSets(inputs []*protos.TxInputExt, outputs []*protos.TxOutputExt) (*protos.Transaction, error)
- func GenerateAwardTx(address, awardAmount string, desc []byte) (*protos.Transaction, error)
- func GenerateEmptyTx(desc []byte) (*protos.Transaction, error)
- func GenerateRootTx(js []byte) (*protos.Transaction, error)
- func ParseContractTransferRequest(requests []*protos.InvokeRequest) (string, *big.Int, error)
- func SplitToDags(block *protos.InternalBlock) [][]*protos.Transaction
- func TopSortDFS(g TxGraph) (order []string, cyclic bool, childDAGSize []int)
- type Mempool
- func (m *Mempool) BatchConfirmTx(txs []*protos.Transaction)
- func (m *Mempool) BatchConfirmTxID(txids []string)
- func (m *Mempool) BatchDeleteTx(txs []*protos.Transaction)
- func (m *Mempool) ConfirmTx(tx *protos.Transaction) error
- func (m *Mempool) ConfirmTxID(txid string)
- func (m *Mempool) DeleteTxAndChildren(txid string) []*protos.Transaction
- func (m *Mempool) FindConflictByTx(tx *protos.Transaction) []*protos.Transaction
- func (m *Mempool) Full() bool
- func (m *Mempool) GetTx(txid string) (*protos.Transaction, bool)
- func (m *Mempool) GetTxCounnt() int
- func (m *Mempool) HasTx(txid string) bool
- func (m *Mempool) PutTx(tx *protos.Transaction) error
- func (m *Mempool) Range(f func(tx *protos.Transaction) bool)
- type Node
- type RootJSON
- type TxGraph
- type TxHandler
- func (t *TxHandler) GetDelayedTxs() []*protos.Transaction
- func (t *TxHandler) GetUnconfirmedTx(dedup bool, sizeLimit int) ([]*protos.Transaction, error)
- func (t *TxHandler) LoadUnconfirmedTxFromDisk() error
- func (t *TxHandler) QueryTx(txid []byte) (*protos.Transaction, error)
- func (t *TxHandler) SetMaxConfirmedDelay(seconds uint32)
- func (t *TxHandler) SortUnconfirmedTx(sizeLimit int) ([]*protos.Transaction, []*protos.Transaction, error)
Constants ¶
const ( TxVersion = 1 RootTxVersion = 0 DefaultMaxConfirmedDelay = 300 )
Variables ¶
var ( ErrNegativeAmount = errors.New("amount in transaction can not be negative number") ErrTxNotFound = errors.New("transaction not found") ErrUnexpected = errors.New("this is a unexpected error") )
var ( // ErrTxExist tx already in mempool when put tx. ErrTxExist = errors.New("tx already in mempool") )
Functions ¶
func GenerateAutoTxWithRWSets ¶
func GenerateAutoTxWithRWSets(inputs []*protos.TxInputExt, outputs []*protos.TxOutputExt) (*protos.Transaction, error)
生成只有读写集的空交易
func GenerateAwardTx ¶
func GenerateAwardTx(address, awardAmount string, desc []byte) (*protos.Transaction, error)
生成奖励TX
func SplitToDags ¶
func SplitToDags(block *protos.InternalBlock) [][]*protos.Transaction
func TopSortDFS ¶
TopSortDFS 对依赖关系图进行拓扑排序 输入:TxGraph: 依赖关系图 输出: order: 排序后的有序数组,依赖者排在前面,被依赖的排在后面
cyclic: 如果发现有环形依赖关系则输出这个数组
Types ¶
type Mempool ¶
type Mempool struct { Tx *TxHandler // contains filtered or unexported fields }
Mempool tx mempool.
func NewMempool ¶
NewMempool new mempool.
func (*Mempool) BatchConfirmTx ¶
func (m *Mempool) BatchConfirmTx(txs []*protos.Transaction)
BatchConfirmTx 批量确认交易
func (*Mempool) BatchConfirmTxID ¶
BatchConfirmTxID 批量确认交易ID
func (*Mempool) BatchDeleteTx ¶
func (m *Mempool) BatchDeleteTx(txs []*protos.Transaction)
BatchDeleteTx 从 mempool 删除所有 txs。
func (*Mempool) ConfirmTx ¶
func (m *Mempool) ConfirmTx(tx *protos.Transaction) error
ConfirmTx confirm tx. 将 tx 从未确认交易表放入确认交易表,或者删除。
func (*Mempool) DeleteTxAndChildren ¶
func (m *Mempool) DeleteTxAndChildren(txid string) []*protos.Transaction
DeleteTxAndChildren delete tx from mempool. 返回交易是从子交易到父交易顺序。
func (*Mempool) FindConflictByTx ¶
func (m *Mempool) FindConflictByTx(tx *protos.Transaction) []*protos.Transaction
FindConflictByTx 找出所有与 tx 冲突的交易。返回数组中,前面是子交易,后面是父交易。 保证事物原子性,此接口不删除交易,只返回交易列表。
type RootJSON ¶
type RootJSON struct { Version string `json:"version"` Consensus struct { Miner string `json:"miner"` } `json:"consensus"` Predistribution []struct { Address string `json:"address"` Quota string `json:"quota"` } `json:"predistribution"` }
RootJSON xuper.json对应的struct,目前先只写了utxovm关注的字段
type TxHandler ¶
type TxHandler struct { UnconfirmTxAmount int64 // UnconfirmTxInMem *sync.Map // 使用新版 mempool 就不用这个字段了。 AvgDelay int64 Mempool *Mempool // contains filtered or unexported fields }
func NewTxHandler ¶
func (*TxHandler) GetDelayedTxs ¶
func (t *TxHandler) GetDelayedTxs() []*protos.Transaction
GetDelayedTxs 获取当前 mempool 中超时的交易。
func (*TxHandler) GetUnconfirmedTx ¶
GetUnconfirmedTx 挖掘一批unconfirmed的交易打包,返回的结果要保证是按照交易执行的先后顺序 maxSize: 打包交易最大的长度(in byte), -1(小于0) 表示不限制
func (*TxHandler) LoadUnconfirmedTxFromDisk ¶
从disk还原unconfirm表到内存, 初始化的时候
func (*TxHandler) QueryTx ¶
func (t *TxHandler) QueryTx(txid []byte) (*protos.Transaction, error)
QueryTx 查询一笔交易,从unconfirm表中查询
func (*TxHandler) SetMaxConfirmedDelay ¶
func (*TxHandler) SortUnconfirmedTx ¶
func (t *TxHandler) SortUnconfirmedTx(sizeLimit int) ([]*protos.Transaction, []*protos.Transaction, error)
SortUnconfirmedTx 返回未确认交易列表以及延迟时间过长交易。