tx

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: LGPL-3.0 Imports: 11 Imported by: 42

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxExpiration = int64(90 * time.Second)
)

values

Functions

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 // contract name
	ActionName string // method name of contract
	Data       string // 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) FromPb added in v1.1.0

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 added in v1.1.0

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

ToBytes converts Action to a specific byte slice.

func (*Action) ToPb added in v1.1.0

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 added in v1.1.0

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

FromPb convert Receipt from proto buf data structure.

func (*Receipt) ToBytes added in v1.1.0

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

ToBytes converts Receipt to a specific byte slice.

func (*Receipt) ToPb added in v1.1.0

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 added in v1.1.0

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

FromPb convert Status from proto buf data structure.

func (*Status) ToBytes added in v1.1.0

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

ToBytes converts Return to a specific byte slice.

func (*Status) ToPb added in v1.1.0

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 added in v1.1.0

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"`
	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"`
	// contains filtered or unexported fields
}

Tx Transaction structure

func NewTx

func NewTx(actions []*Action, signers []string, gasLimit, gasRatio, expiration, delay int64) *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 added in v1.1.0

func (t *Tx) CheckGas() error

CheckGas checks whether the transaction's gas is valid.

func (*Tx) Decode

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

Decode tx from byte array

func (*Tx) Encode

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

Encode tx to byte array

func (*Tx) FromPb added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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

ToBytes converts tx to bytes.

func (*Tx) ToPb added in v1.1.0

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

ToPb convert tx to txpb.Tx for transmission.

func (*Tx) VerifyDefer added in v1.1.0

func (t *Tx) VerifyDefer(referredTx *Tx) error

VerifyDefer verifes whether the defer tx is matched with the referred tx.

func (*Tx) VerifySelf

func (t *Tx) VerifySelf() error

VerifySelf verify tx's signature

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 added in v1.1.0

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) String

func (r *TxReceipt) String() string

func (*TxReceipt) ToBytes added in v1.1.0

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

ToBytes converts TxReceipt to a specific byte slice.

func (*TxReceipt) ToPb added in v1.1.0

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