tx

package
v0.0.0-...-376a440 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxExpiration = int64(90 * time.Second)
	MaxDelay      = int64(720 * time.Hour) // 30 days
	ChainID       uint32
)

values

Functions

func CheckBadTx

func CheckBadTx(tx *Tx) error

CheckBadTx ...

func SignTxContent

func SignTxContent(tx *Tx, id string, account *account.KeyPair) (*crypto.Signature, error)

SignTxContent sign tx content, only signers should do this

Types

type Action

type Action struct {
	Contract   string `json:"contract"`   // contract name
	ActionName string `json:"actionName"` // method name of contract
	Data       string `json:"data"`       // parameters of method, with json format
}

Action implement

func NewAction

func NewAction(contract string, name string, data string) *Action

NewAction constructor of Action

func (*Action) Decode

func (a *Action) Decode(b []byte) error

Decode action from byte array

func (*Action) Encode

func (a *Action) Encode() []byte

Encode encode action as byte array

func (*Action) Equal

func (a *Action) Equal(ac *Action) bool

Equal returns whether two actions are equal.

func (*Action) FromPb

func (a *Action) FromPb(ac *txpb.Action) *Action

FromPb convert Action from proto buf data structure.

func (*Action) String

func (a *Action) String() string

String return human readable string

func (*Action) ToBytes

func (a *Action) ToBytes() []byte

ToBytes converts Action to a specific byte slice.

func (*Action) ToPb

func (a *Action) ToPb() *txpb.Action

ToPb convert Action to proto buf data structure.

type Receipt

type Receipt struct {
	FuncName string
	Content  string // can be a raw string or a json string
}

Receipt generated when applying transaction

func (*Receipt) FromPb

func (r *Receipt) FromPb(rp *txpb.Receipt) *Receipt

FromPb convert Receipt from proto buf data structure.

func (*Receipt) ToBytes

func (r *Receipt) ToBytes() []byte

ToBytes converts Receipt to a specific byte slice.

func (*Receipt) ToPb

func (r *Receipt) ToPb() *txpb.Receipt

ToPb convert Receipt to proto buf data structure.

type ReceiptType

type ReceiptType int32

ReceiptType type of single receipt

const (
	// SystemDefined system receipt, recording info of calling a method
	SystemDefined ReceiptType = iota
	// UserDefined user defined receipt, usually a json string
	UserDefined
)

type Status

type Status struct {
	Code    StatusCode
	Message string
}

Status status of transaction execution result, including code and message

func (*Status) FromPb

func (s *Status) FromPb(st *txpb.Status) *Status

FromPb convert Status from proto buf data structure.

func (*Status) ToBytes

func (s *Status) ToBytes() []byte

ToBytes converts Return to a specific byte slice.

func (*Status) ToPb

func (s *Status) ToPb() *txpb.Status

ToPb convert Status to proto buf data structure.

type StatusCode

type StatusCode int32

StatusCode status code of transaction execution result

const (
	Success StatusCode = iota
	ErrorGasRunOut
	ErrorBalanceNotEnough
	ErrorParamter // parameter mismatch when calling function
	ErrorRuntime  // runtime error
	ErrorTimeout
	ErrorTxFormat         // tx format errors
	ErrorDuplicateSetCode // more than one set code action in a tx
	ErrorUnknown          // other errors
)

tx execution result

type ToBytesLevel

type ToBytesLevel int

ToBytesLevel judges which fields of tx should be written to bytes.

const (
	Base ToBytesLevel = iota
	Publish
	Full
)

consts

type Tx

type Tx struct {
	Time         int64               `json:"time"`
	Expiration   int64               `json:"expiration"`
	GasRatio     int64               `json:"gas_ratio"`
	GasLimit     int64               `json:"gas_limit"`
	Delay        int64               `json:"delay"`
	ChainID      uint32              `json:"chain_id"`
	Actions      []*Action           `json:"-"`
	Signers      []string            `json:"-"`
	Signs        []*crypto.Signature `json:"-"`
	Publisher    string              `json:"-"`
	PublishSigns []*crypto.Signature `json:"-"`
	ReferredTx   []byte              `json:"referred_tx"`
	AmountLimit  []*contract.Amount  `json:"amountLimit"`
	Reserved     []byte              `json:"reserved"`
	// contains filtered or unexported fields
}

Tx Transaction structure

func NewTx

func NewTx(actions []*Action, signers []string, gasLimit, gasRatio, expiration, delay int64, chainID uint32) *Tx

NewTx return a new Tx

func SignTx

func SignTx(tx *Tx, id string, kps []*account.KeyPair, signs ...*crypto.Signature) (*Tx, error)

SignTx sign the whole tx, including signers' signature, only publisher should do this

func (*Tx) CheckGas

func (t *Tx) CheckGas() error

CheckGas checks whether the transaction's gas is valid.

func (*Tx) CheckSize

func (t *Tx) CheckSize() error

CheckSize checks whether tx size is valid.

func (*Tx) Decode

func (t *Tx) Decode(b []byte) error

Decode tx from byte array

func (*Tx) DeferTx

func (t *Tx) DeferTx() *Tx

DeferTx generates a new transaction that will be packed to blockchain.

func (*Tx) Encode

func (t *Tx) Encode() []byte

Encode tx to byte array

func (*Tx) FromPb

func (t *Tx) FromPb(tr *txpb.Tx) *Tx

FromPb convert tx from txpb.Tx.

func (*Tx) Hash

func (t *Tx) Hash() []byte

Hash return cached hash if exists, or calculate with Sha3.

func (*Tx) IsCreatedBefore

func (t *Tx) IsCreatedBefore(ct int64) bool

IsCreatedBefore checks whether the transaction time is valid compared to the given time ct. ct may be time.Now().UnixNano() or block head time.

func (*Tx) IsDefer

func (t *Tx) IsDefer() bool

IsDefer returns whether the transaction is a defer tx.

Defer transaction is the transaction that's generated by a delay tx.

func (*Tx) IsExpired

func (t *Tx) IsExpired(ct int64) bool

IsExpired checks whether the transaction is expired compared to the given time ct.

func (*Tx) String

func (t *Tx) String() string

String return human-readable tx

func (*Tx) ToBytes

func (t *Tx) ToBytes(l ToBytesLevel) []byte

ToBytes converts tx to bytes.

func (*Tx) ToPb

func (t *Tx) ToPb() *txpb.Tx

ToPb convert tx to txpb.Tx for transmission.

func (*Tx) VerifySelf

func (t *Tx) VerifySelf() error

VerifySelf verify tx's signature and some base fields.

func (*Tx) VerifySigner

func (t *Tx) VerifySigner(sig *crypto.Signature) bool

VerifySigner verify signer's signature

type TxReceipt

type TxReceipt struct {
	TxHash   []byte
	GasUsage int64
	RAMUsage map[string]int64
	Status   *Status
	Returns  []string
	Receipts []*Receipt
}

TxReceipt Transaction Receipt

func NewTxReceipt

func NewTxReceipt(txHash []byte) *TxReceipt

NewTxReceipt generate tx receipt for a tx hash

func (*TxReceipt) Decode

func (r *TxReceipt) Decode(b []byte) error

Decode TxReceipt from byte array

func (*TxReceipt) Encode

func (r *TxReceipt) Encode() []byte

Encode TxReceipt as byte array

func (*TxReceipt) FromPb

func (r *TxReceipt) FromPb(tr *txpb.TxReceipt) *TxReceipt

FromPb convert TxReceipt from proto buf data structure

func (*TxReceipt) Hash

func (r *TxReceipt) Hash() []byte

Hash return byte hash

func (*TxReceipt) ParseCancelDelaytx

func (r *TxReceipt) ParseCancelDelaytx() [][]byte

ParseCancelDelaytx returns the delaytxs' hashes that are canceled.

func (*TxReceipt) String

func (r *TxReceipt) String() string

func (*TxReceipt) ToBytes

func (r *TxReceipt) ToBytes() []byte

ToBytes converts TxReceipt to a specific byte slice.

func (*TxReceipt) ToPb

func (r *TxReceipt) ToPb() *txpb.TxReceipt

ToPb convert TxReceipt to proto buf data structure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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