txs

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 8 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extends2Byte

func Extends2Byte(ext []tcommon.KVPair) (ret []byte)

功能:将common.KVPair转化成[]byte todo: test(amino序列化及反序列化的正确性)

func RegisterCodec

func RegisterCodec(cdc *go_amino.Codec)

func Sig2Byte

func Sig2Byte(sgn Signature) (ret []byte)

函数:Signature结构转化为 []byte

Types

type ITx

type ITx interface {
	ValidateData(ctx context.Context) error //检测

	//执行业务逻辑,
	// crossTxQcp: 需要进行跨链处理的TxQcp。
	// 业务端实现中crossTxQcp只需包含`to` 和 `txStd`
	Exec(ctx context.Context) (result types.Result, crossTxQcp *TxQcp)
	GetSigner() []types.Address //签名者
	CalcGas() types.BigInt      //计算gas
	GetGasPayer() types.Address //gas付费人
	GetSignData() []byte        //获取签名字段
}

功能:抽象具体的Tx结构体

type QcpTxResult

type QcpTxResult struct {
	Result              types.Result `json:"result"`              //对应TxQcp执行结果
	QcpOriginalSequence int64        `json:"qcporiginalsequence"` //此结果对应的TxQcp.Sequence
	QcpOriginalExtends  string       `json:"qcpextends"`          //此结果对应的 TxQcp.Extends
	Info                string       `json:"info"`                //结果信息
}

qos端对TxQcp的执行结果

func NewQcpTxResult

func NewQcpTxResult(result types.Result, qcpSequence int64, qcpExtends, info string) *QcpTxResult

功能:构建 QcpTxReasult 结构体

func (*QcpTxResult) CalcGas

func (tx *QcpTxResult) CalcGas() types.BigInt

功能:计算gas 备注:暂返回0,后期可根据实际情况调整

func (*QcpTxResult) Exec

func (tx *QcpTxResult) Exec(ctx context.Context) (result types.Result, crossTxQcps *TxQcp)

功能:tx执行 备注:用户根据tx.QcpOriginalSequence,需自行实现此接口

func (*QcpTxResult) GetGasPayer

func (tx *QcpTxResult) GetGasPayer() types.Address

功能:获取gas付费人 备注:返回空(因暂时gas为0,无人需要付gas)

func (*QcpTxResult) GetSignData

func (tx *QcpTxResult) GetSignData() []byte

获取签名字段

func (*QcpTxResult) GetSigner

func (tx *QcpTxResult) GetSigner() []types.Address

功能:获取签名者 备注:qos对QcpTxResult不做签名,故返回空

func (*QcpTxResult) IsOk added in v0.0.2

func (tx *QcpTxResult) IsOk() bool

func (*QcpTxResult) ValidateData

func (tx *QcpTxResult) ValidateData(ctx context.Context) error

功能:检测结构体字段的合法性

type Signature

type Signature struct {
	Pubkey    crypto.PubKey `json:"pubkey"`    //可选
	Signature []byte        `json:"signature"` //签名内容
	Nonce     int64         `json:"nonce"`     //nonce的值
}

签名结构体

type TxQcp

type TxQcp struct {
	TxStd       *TxStd    `json:"txstd"`       //TxStd结构
	From        string    `json:"from"`        //qscName
	To          string    `json:"to"`          //qosName
	Sequence    int64     `json:"sequence"`    //发送Sequence
	Sig         Signature `json:"sig"`         //签名
	BlockHeight int64     `json:"blockheight"` //Tx所在block高度
	TxIndex     int64     `json:"txindex"`     //Tx在block的位置
	IsResult    bool      `json:"isresult"`    //是否为Result
	Extends     string    `json:"extends"`     //扩展字段
}

功能:

func NewTxQCP

func NewTxQCP(txStd *TxStd, from string, to string, seqence int64,
	blockheigh int64, txindex int64, isResult bool, extends string) (rTx *TxQcp)

构建TxQCP结构体

func (*TxQcp) BuildSignatureBytes added in v0.0.7

func (tx *TxQcp) BuildSignatureBytes() []byte

func (*TxQcp) SignTx added in v0.0.2

func (tx *TxQcp) SignTx(prvkey crypto.PrivKey) (signedbyte []byte, err error)

func (*TxQcp) Type

func (tx *TxQcp) Type() string

Type: just for implements types.Tx

func (*TxQcp) ValidateBasicData

func (tx *TxQcp) ValidateBasicData(isCheckTx bool, currentChaindID string) (err types.Error)

ValidateBasicData 校验txQcp基础数据是否合法

type TxStd

type TxStd struct {
	ITxs      []ITx        `json:"itx"`      //ITx接口,将被具体Tx结构实例化
	Signature []Signature  `json:"sigature"` //签名数组
	ChainID   string       `json:"chainid"`  //ChainID: 执行ITx.exec方法的链ID
	MaxGas    types.BigInt `json:"maxgas"`   //Gas消耗的最大值
}

标准Tx结构体

func NewTxStd

func NewTxStd(itx ITx, cid string, mgas types.BigInt) (rTx *TxStd)

构建结构体 调用 NewTxStd后,需调用TxStd.SignTx填充TxStd.Signature(每个TxStd.Signer())

func NewTxsStd added in v0.2.0

func NewTxsStd(cid string, mgas types.BigInt, itx ...ITx) (rTx *TxStd)

func (*TxStd) BuildSignatureBytes added in v0.0.7

func (tx *TxStd) BuildSignatureBytes(nonce int64, fromChainID string) []byte

BuildSignatureBytes 生成待签名字节切片. nonce: account nonce + 1 currentChainID: 当前链chainID

func (*TxStd) GetSigners added in v0.0.8

func (tx *TxStd) GetSigners() []types.Address

func (*TxStd) SignTx added in v0.0.2

func (tx *TxStd) SignTx(privkey crypto.PrivKey, nonce int64, fromChainID, toChainID string) (signedbyte []byte, err error)

签名:每个签名者外部调用此方法 当tx不包含在跨链交易中时,fromChainID为 ""

func (*TxStd) Type

func (tx *TxStd) Type() string

Type: just for implements types.Tx

func (*TxStd) ValidateBasicData

func (tx *TxStd) ValidateBasicData(ctx context.Context, isCheckTx bool, currentChaindID string) (err types.Error)

ValidateBasicData 对txStd进行基础的数据校验

Jump to

Keyboard shortcuts

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