txs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const BASEGAS_CREATEQSC int64 = 10000 //创建qsc需要的最少qos数

Variables

This section is empty.

Functions

func CheckAddr

func CheckAddr(addr btypes.Address) (ret bool)

功能:检查 commmon.Address 的合法性 todo: types.Address的其他规则需在此处检测

func CreateAndSaveAccount

func CreateAndSaveAccount(ctx bcontext.Context, addr btypes.Address) (acc *account.QOSAccount, success bool)

通过地址创建QOSAccount 若账户存在,返回账户 & false

func FetchBankerCA

func FetchBankerCA() (caBanker *[]byte)

todo: 暂模拟

func FetchQscCA

func FetchQscCA() (caQsc *[]byte)

func GetAccount

func GetAccount(ctx bcontext.Context, addr btypes.Address) (acc *account.QOSAccount)

通过地址获取QOSAccount

func RegisterCodec

func RegisterCodec(cdc *amino.Codec)

func SaveAccount

func SaveAccount(ctx bcontext.Context, acc *account.QOSAccount) bool

func VerifyCA

func VerifyCA(pubkey crypto.PubKey, ca *CA) bool

todo: 暂模拟

Types

type AddrCoin

type AddrCoin struct {
	Address btypes.Address `json:"address"` //用户地址
	Amount  btypes.BigInt  `json:"amount"`  //金额
}

type CA

type CA struct {
	Qcpname   string        `json:"qcpname"`
	Banker    bool          `json:"banker"`
	Pubkey    crypto.PubKey `json:"pubkey"`
	Signature []byte        `json:"signature"`
	Info      string        `json:"info"`
}

CA结构体 todo: CA具体格式确定后会更改

type TransItem

type TransItem struct {
	Address btypes.Address `json:"addr"` // 账户地址
	QOS     btypes.BigInt  `json:"qos"`  // QOS
	QSCs    types.QSCs     `json:"qscs"` // QSCs
}

type TransferTx

type TransferTx struct {
	Senders   []TransItem `json:"senders"`   // 发送集合
	Receivers []TransItem `json:"receivers"` // 接收集合
}

func (TransferTx) CalcGas

func (tx TransferTx) CalcGas() btypes.BigInt

Gas TODO

func (TransferTx) Exec

func (tx TransferTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcp *txs.TxQcp)

转账

func (TransferTx) GetGasPayer

func (tx TransferTx) GetGasPayer() btypes.Address

Senders[0]

func (TransferTx) GetSignData

func (tx TransferTx) GetSignData() (ret []byte)

签名字节

func (TransferTx) GetSigner

func (tx TransferTx) GetSigner() []btypes.Address

所有Senders

func (TransferTx) ValidateData

func (tx TransferTx) ValidateData(ctx context.Context) bool

数据校验 1.Senders、Receivers不为空,地址不重复,币值大于0 2.Senders、Receivers 币值总和对应币种相等 3.Senders中账号对应币种币值足够

type TxCreateQSC

type TxCreateQSC struct {
	QscName     string         `json:"qscname"`     //从CA信息获取
	CreateAddr  btypes.Address `json:"createaddr"`  //QSC创建账户
	QscPubkey   crypto.PubKey  `json:"qscpubkey"`   //从CA信息获取
	Banker      btypes.Address `json:"banker"`      //从CA信息获取
	Extrate     string         `json:"extrate"`     //qcs:qos汇率(amino不支持binary形式的浮点数序列化,精度同qos erc20 [.0000])
	CAqsc       []byte         `json:"caqsc"`       //CA信息
	CAbanker    []byte         `json:"cabanker"`    //CA信息
	Description string         `json:"description"` //描述信息
	AccInit     []AddrCoin     `json:"accinit"`     //初始化时接受qsc的账户
}

功能:"创建QSC" 对应的Tx结构

func NewCreateQsc

func NewCreateQsc(cdc *go_amino.Codec, caqsc *[]byte, cabank *[]byte,
	createAddr btypes.Address, accs *[]AddrCoin,
	extrate string, dsp string) (rTx *TxCreateQSC)

创建 TxCreateQSC结构体 备注:CA提供两个证书,联盟链证书 & Banker证书(banker字段)

两种证书通过 qscName 字段关联起来

func (TxCreateQSC) CalcGas

func (tx TxCreateQSC) CalcGas() btypes.BigInt

功能:计算gas 规则:基准值 + 每个初始化用户收10qos

func (TxCreateQSC) Exec

func (tx TxCreateQSC) Exec(ctx context.Context) (ret btypes.Result, crossTxQcps *btxs.TxQcp)

功能:tx执行 描述:

		保存链信息并检查是否已经创建(qscname, pubkey, 是否已经注册)
     查询banker是否存在,若不存在,
		向账户 AccInit 分发qsc

func (TxCreateQSC) GetGasPayer

func (tx TxCreateQSC) GetGasPayer() (ret btypes.Address)

gas付费人

func (TxCreateQSC) GetSignData

func (tx TxCreateQSC) GetSignData() (ret []byte)

获取签名字段

func (TxCreateQSC) GetSigner

func (tx TxCreateQSC) GetSigner() (ret []btypes.Address)

功能:获取签名者

func (TxCreateQSC) ValidateData

func (tx TxCreateQSC) ValidateData(ctx context.Context) bool

功能:检测合法性 备注:

1,成员字段的合法性
2,creator的账户余额是否够gas抵扣

type TxIssueQsc

type TxIssueQsc struct {
	QscName string        `json:"qscName"` //发币账户名
	Amount  types.BigInt  `json:"amount"`  //金额
	Banker  types.Address `json:"banker"`  //banker地址
}

功能:发币 对应的Tx结构

func NewTxIssueQsc

func NewTxIssueQsc(qsc string, amount types.BigInt, banker types.Address) (rTx *TxIssueQsc)

构建 TxIsssueQsc 结构体

func (*TxIssueQsc) CalcGas

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

计算gas 此处设置gas = 0

func (*TxIssueQsc) Exec

func (tx *TxIssueQsc) Exec(ctx context.Context) (ret types.Result, crossTxQcps *btxs.TxQcp)

功能:tx执行 发币过程:banker向自己的账户发币

func (*TxIssueQsc) GetGasPayer

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

gas付费人 no gas, no payer

func (*TxIssueQsc) GetSignData

func (tx *TxIssueQsc) GetSignData() (ret []byte)

获取签名字段

func (*TxIssueQsc) GetSigner

func (tx *TxIssueQsc) GetSigner() (singer []types.Address)

功能:签名者

func (*TxIssueQsc) ValidateData

func (tx *TxIssueQsc) ValidateData(ctx context.Context) bool

功能:检测TxIssuQsc结构体字段是否合法

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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