tx

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

tx

交易逻辑实现。

Documentation

Overview

package txn deals with tx data

Index

Constants

View Source
const (
	TxVersion                = 1
	RootTxVersion            = 0
	DefaultMaxConfirmedDelay = 300
)

Variables

View Source
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")
)

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 GenerateEmptyTx

func GenerateEmptyTx(desc []byte) (*pb.Transaction, error)

生成只有Desc的空交易

func GenerateRootTx

func GenerateRootTx(js []byte) (*pb.Transaction, error)

通过创世块配置生成创世区块交易

func GenerateVoteAwardTx

func GenerateVoteAwardTx(address []byte, awardAmount string, desc []byte) (*pb.Transaction, error)

生成投票奖励的交易

func ParseContractTransferRequest

func ParseContractTransferRequest(requests []*protos.InvokeRequest) (string, *big.Int, error)

func SplitToDags

func SplitToDags(block *pb.InternalBlock) [][]*pb.Transaction

func TopSortDFS

func TopSortDFS(g TxGraph) (order []string, cyclic bool, childDAGSize []int)

TopSortDFS 对依赖关系图进行拓扑排序 输入:依赖关系图,就是个map 输出: order: 排序后的有序数组,依赖者排在前面,被依赖的排在后面

cyclic: 如果发现有环形依赖关系则输出这个数组

实现参考: https://rosettacode.org/wiki/Topological_sort#Go 在我们映射中,RefTx是边的源点

Types

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
	AvgDelay          int64
	// contains filtered or unexported fields
}

func NewTx

func NewTx(sctx *context.StateCtx, stateDB kvdb.Database) (*Tx, error)

func (*Tx) GetUnconfirmedTx

func (t *Tx) GetUnconfirmedTx(dedup bool) ([]*pb.Transaction, error)

GetUnconfirmedTx 挖掘一批unconfirmed的交易打包,返回的结果要保证是按照交易执行的先后顺序 maxSize: 打包交易最大的长度(in byte), -1 表示不限制

func (*Tx) LoadUnconfirmedTxFromDisk

func (t *Tx) LoadUnconfirmedTxFromDisk() error

从disk还原unconfirm表到内存, 初始化的时候

func (*Tx) QueryTx

func (t *Tx) QueryTx(txid []byte) (*pb.Transaction, error)

QueryTx 查询一笔交易,从unconfirm表中查询

func (*Tx) SetMaxConfirmedDelay

func (t *Tx) SetMaxConfirmedDelay(seconds uint32)

func (*Tx) SortUnconfirmedTx

func (t *Tx) SortUnconfirmedTx() (map[string]*pb.Transaction, TxGraph, map[string]bool, error)

加载所有未确认的订单表到内存 参数: dedup : true-删除已经确认tx, false-保留已经确认tx 返回: txMap : txid -> Transaction

txGraph:  txid ->  [依赖此txid的tx]

type TxGraph

type TxGraph map[string][]string

交易依赖关系图

Jump to

Keyboard shortcuts

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