Documentation
¶
Overview ¶
package txn deals with tx data
Index ¶
- Constants
- Variables
- func GenerateAutoTxWithRWSets(inputs []*protos.TxInputExt, outputs []*protos.TxOutputExt) (*pb.Transaction, error)
- func GenerateAwardTx(address, awardAmount string, desc []byte) (*pb.Transaction, error)
- func GenerateEmptyTx(desc []byte) (*pb.Transaction, error)
- func GenerateRootTx(js []byte) (*pb.Transaction, error)
- func GenerateVoteAwardTx(address []byte, awardAmount string, desc []byte) (*pb.Transaction, error)
- func ParseContractTransferRequest(requests []*protos.InvokeRequest) (string, *big.Int, error)
- func SplitToDags(block *pb.InternalBlock) [][]*pb.Transaction
- func TopSortDFS(g TxGraph) (order []string, cyclic bool, childDAGSize []int)
- type Mempool
- func (m *Mempool) BatchConfirmTx(txs []*pb.Transaction)
- func (m *Mempool) BatchConfirmTxID(txids []string)
- func (m *Mempool) BatchDeleteTx(txs []*pb.Transaction)
- func (m *Mempool) ConfirmTx(tx *pb.Transaction) error
- func (m *Mempool) ConfirmTxID(txid string)
- func (m *Mempool) DeleteTxAndChildren(txid string) []*pb.Transaction
- func (m *Mempool) FindConflictByTx(tx *pb.Transaction) []*pb.Transaction
- func (m *Mempool) Full() bool
- func (m *Mempool) GetTx(txid string) (*pb.Transaction, bool)
- func (m *Mempool) GetTxCounnt() int
- func (m *Mempool) HasTx(txid string) bool
- func (m *Mempool) PutTx(tx *pb.Transaction) error
- func (m *Mempool) Range(f func(tx *pb.Transaction) bool)
- type Node
- type RootJSON
- type Tx
- func (t *Tx) GetDelayedTxs() []*pb.Transaction
- func (t *Tx) GetUnconfirmedTx(dedup bool, sizeLimit int) ([]*pb.Transaction, error)
- func (t *Tx) LoadUnconfirmedTxFromDisk() error
- func (t *Tx) QueryTx(txid []byte) (*pb.Transaction, error)
- func (t *Tx) SetMaxConfirmedDelay(seconds uint32)
- func (t *Tx) SortUnconfirmedTx(sizeLimit int) ([]*pb.Transaction, []*pb.Transaction, error)
- type TxGraph
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) (*pb.Transaction, error)
生成只有读写集的空交易
func GenerateAwardTx ¶
func GenerateAwardTx(address, awardAmount string, desc []byte) (*pb.Transaction, error)
生成奖励TX
func GenerateVoteAwardTx ¶
生成投票奖励的交易
func SplitToDags ¶
func SplitToDags(block *pb.InternalBlock) [][]*pb.Transaction
func TopSortDFS ¶
TopSortDFS 对依赖关系图进行拓扑排序 输入:依赖关系图,就是个map 输出: order: 排序后的有序数组,依赖者排在前面,被依赖的排在后面
cyclic: 如果发现有环形依赖关系则输出这个数组
实现参考: https://rosettacode.org/wiki/Topological_sort#Go 在我们映射中,RefTx是边的源点
Types ¶
type Mempool ¶ added in v1.0.2
type Mempool struct {
Tx *Tx
// contains filtered or unexported fields
}
Mempool tx mempool.
func NewMempool ¶ added in v1.0.2
NewMempool new mempool.
func (*Mempool) BatchConfirmTx ¶ added in v1.0.2
func (m *Mempool) BatchConfirmTx(txs []*pb.Transaction)
BatchConfirmTx 批量确认交易
func (*Mempool) BatchConfirmTxID ¶ added in v1.0.2
BatchConfirmTxID 批量确认交易ID
func (*Mempool) BatchDeleteTx ¶ added in v1.0.2
func (m *Mempool) BatchDeleteTx(txs []*pb.Transaction)
BatchDeleteTx 从 mempool 删除所有 txs。
func (*Mempool) ConfirmTx ¶ added in v1.0.2
func (m *Mempool) ConfirmTx(tx *pb.Transaction) error
ConfirmTx confirm tx. 将 tx 从未确认交易表放入确认交易表,或者删除。
func (*Mempool) ConfirmTxID ¶ added in v1.0.2
ConfirmTxID txid
func (*Mempool) DeleteTxAndChildren ¶ added in v1.0.2
func (m *Mempool) DeleteTxAndChildren(txid string) []*pb.Transaction
DeleteTxAndChildren delete tx from mempool. 返回交易是从子交易到父交易顺序。
func (*Mempool) FindConflictByTx ¶ added in v1.0.2
func (m *Mempool) FindConflictByTx(tx *pb.Transaction) []*pb.Transaction
FindConflictByTx 找多所有与 tx 冲突的交易。返回数组中,前面是子交易,后面是父交易。 保证事物原子性,此接口不删除交易,只返回交易列表,如果需要删除需要调用删除交易相关接口。
func (*Mempool) GetTx ¶ added in v1.0.2
func (m *Mempool) GetTx(txid string) (*pb.Transaction, bool)
GetTx 从 mempool 中查询一笔交易,先查未确认交易表,然后是孤儿交易表。
func (*Mempool) GetTxCounnt ¶ added in v1.0.2
GetTxCounnt get 获取未确认交易与孤儿交易总数
type Node ¶ added in v1.0.2
type Node struct {
// contains filtered or unexported fields
}
Node tx wrapper.
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 Tx ¶
type Tx struct {
UnconfirmTxAmount int64
// UnconfirmTxInMem *sync.Map // 使用新版 mempool 就不用这个字段了。
AvgDelay int64
Mempool *Mempool
// contains filtered or unexported fields
}
func (*Tx) GetDelayedTxs ¶ added in v1.0.2
func (t *Tx) GetDelayedTxs() []*pb.Transaction
GetDelayedTxs 获取当前 mempool 中超时的交易。
func (*Tx) GetUnconfirmedTx ¶
GetUnconfirmedTx 挖掘一批unconfirmed的交易打包,返回的结果要保证是按照交易执行的先后顺序 maxSize: 打包交易最大的长度(in byte), -1(小于0) 表示不限制
func (*Tx) LoadUnconfirmedTxFromDisk ¶
从disk还原unconfirm表到内存, 初始化的时候
func (*Tx) QueryTx ¶
func (t *Tx) QueryTx(txid []byte) (*pb.Transaction, error)
QueryTx 查询一笔交易,从unconfirm表中查询
func (*Tx) SetMaxConfirmedDelay ¶
func (*Tx) SortUnconfirmedTx ¶
func (t *Tx) SortUnconfirmedTx(sizeLimit int) ([]*pb.Transaction, []*pb.Transaction, error)
SortUnconfirmedTx 返回未确认交易列表以及延迟时间过长交易。