transaction

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthTxType           = byte(0)
	NeoTxType           = byte(1)
	SignatureLength     = 64
	MaxScriptLength     = math.MaxUint16
	MaxTransactionSize  = 102400
	EthLegacyBaseLength = 100
)
View Source
const (
	// MaxInvocationScript is the maximum length of allowed invocation
	// script. It should fit 11/21 multisignature for the committee.
	MaxInvocationScript = 1024

	// MaxVerificationScript is the maximum allowed length of verification
	// script. It should be appropriate for 11/21 multisignature committee.
	MaxVerificationScript = 1024
)

Variables

View Source
var (
	ErrNegativeValue   = errors.New("negative value")
	ErrZeroFromAddress = errors.New("zero from address")
	ErrWitnessUnmatch  = errors.New("witness not match from")
)

Various errors for transaction validation.

View Source
var (
	ErrInvalidTxType    = errors.New("invalid tx type")
	ErrTipVeryHigh      = errors.New("max priority fee per gas higher than 2^256-1")
	ErrFeeCapVeryHigh   = errors.New("max fee per gas higher than 2^256-1")
	ErrTipAboveFeeCap   = errors.New("max priority fee per gas higher than max fee per gas")
	ErrValueVeryHigh    = errors.New("value higher than 2^256-1")
	ErrGasPriceVeryHigh = errors.New("gas price higher than 2^256-1")
)
View Source
var (
	ErrInvalidSignature      = errors.New("invalid signature")
	ErrInvalidSignatureCount = errors.New("invalid signatures count")
)
View Source
var (
	ErrInvalidChainID = errors.New("invalid chainId")
)
View Source
var (
	ErrNoSender = errors.New("no sender in trimmed tx")
)

ErrInvalidWitnessNum returns when the number of witnesses does not match signers.

View Source
var (
	ErrUnsupportType = errors.New("unsupport tx type")
)

Functions

func CalculateNetworkFee

func CalculateNetworkFee(tx *Transaction, feePerByte uint64) uint64

func RlpSize

func RlpSize(v interface{}) int

Types

type EthTx

type EthTx struct {
	types.Transaction
	ChainID uint64
	Sender  common.Address
}

func NewEthTx

func NewEthTx(tx *types.Transaction) (*EthTx, error)

func NewEthTxFromBytes

func NewEthTxFromBytes(data []byte) (*EthTx, error)

func (*EthTx) DecodeBinary

func (t *EthTx) DecodeBinary(r *nio.BinReader)

func (*EthTx) EncodeBinary

func (t *EthTx) EncodeBinary(w *nio.BinWriter)

func (*EthTx) IsValid

func (t *EthTx) IsValid() error

func (EthTx) MarshalJSON

func (t EthTx) MarshalJSON() ([]byte, error)

func (*EthTx) UnmarshalJSON

func (t *EthTx) UnmarshalJSON(data []byte) error

func (*EthTx) Verify

func (t *EthTx) Verify(chainId uint64) (err error)

func (*EthTx) WithSignature

func (t *EthTx) WithSignature(chainId uint64, sig []byte) error

type EthTxJson

type EthTxJson struct {
	Type       hexutil.Uint      `json:"type"`
	Hash       common.Hash       `json:"hash"`
	Nonce      hexutil.Uint64    `json:"nonce"`
	GasPrice   *hexutil.Big      `json:"gasPrice,omitempty"`
	GasTipCap  *hexutil.Big      `json:"maxPriorityFeePerGas,omitempty"`
	GasFeeCap  *hexutil.Big      `json:"maxFeePerGas,omitempty"`
	Gas        hexutil.Uint64    `json:"gas"`
	To         *common.Address   `json:"to"`
	Value      hexutil.Big       `json:"value"`
	AccessList *types.AccessList `json:"accessList,omitempty"`
	Data       hexutil.Bytes     `json:"input"`
	V          hexutil.Big       `json:"v"`
	R          hexutil.Big       `json:"r"`
	S          hexutil.Big       `json:"s"`
	ChainID    hexutil.Uint      `json:"chainId"`
	Sender     common.Address    `json:"from"`
}

type NeoTx

type NeoTx struct {
	Nonce    uint64
	GasPrice *big.Int
	Gas      uint64
	From     common.Address
	To       *common.Address
	Value    *big.Int
	Data     []byte
	Witness  Witness

	Trimmed bool
	// contains filtered or unexported fields
}

func New

func New(data []byte, gas uint64) *NeoTx

New returns a new transaction to execute given script and pay given system fee.

func NewNeoTxFromBytes

func NewNeoTxFromBytes(b []byte) (*NeoTx, error)

func (*NeoTx) Bytes

func (t *NeoTx) Bytes() ([]byte, error)

Bytes converts the transaction to []byte.

func (*NeoTx) DecodeBinary

func (t *NeoTx) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*NeoTx) DecodeHashableFields

func (t *NeoTx) DecodeHashableFields(buf []byte) error

DecodeHashableFields decodes a part of transaction which should be hashed.

func (*NeoTx) EncodeBinary

func (t *NeoTx) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

func (*NeoTx) EncodeHashableFields

func (t *NeoTx) EncodeHashableFields() ([]byte, error)

EncodeHashableFields returns serialized transaction's fields which are hashed.

func (*NeoTx) Hash

func (t *NeoTx) Hash() common.Hash

Hash returns the hash of the transaction.

func (NeoTx) MarshalJSON

func (t NeoTx) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*NeoTx) Size

func (t *NeoTx) Size() int

Size returns size of the serialized transaction.

func (*NeoTx) UnmarshalJSON

func (t *NeoTx) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

type NeoTxJson

type NeoTxJson struct {
	TxID     common.Hash     `json:"hash"`
	Size     hexutil.Uint    `json:"size"`
	Nonce    hexutil.Uint64  `json:"nonce"`
	GasPrice hexutil.Big     `json:"gasPrice"`
	Gas      hexutil.Uint64  `json:"gas"`
	From     common.Address  `json:"from"`
	To       *common.Address `json:"to"`
	Value    hexutil.Big     `json:"value"`
	Data     hexutil.Bytes   `json:"input"`
	Witness  Witness         `json:"witness"`
	R        hexutil.Big     `json:"r"`
	S        hexutil.Big     `json:"s"`
	V        hexutil.Big     `json:"v"`
}

transactionJSON is a wrapper for NeoTx and used for correct marhalling of transaction.Data.

type Transaction

type Transaction struct {
	Type  byte
	EthTx *EthTx
	NeoTx *NeoTx

	Trimmed bool
	// contains filtered or unexported fields
}

func NewTransactionFromBytes

func NewTransactionFromBytes(b []byte) (*Transaction, error)

func NewTrimmedTX

func NewTrimmedTX(hash common.Hash) *Transaction

func NewTx

func NewTx(t interface{}) *Transaction

func (*Transaction) AccessList

func (t *Transaction) AccessList() types.AccessList

func (*Transaction) Bytes

func (t *Transaction) Bytes() ([]byte, error)

func (Transaction) Cost

func (t Transaction) Cost() *big.Int

func (*Transaction) Data

func (t *Transaction) Data() []byte

func (*Transaction) DecodeBinary

func (t *Transaction) DecodeBinary(r *io.BinReader)

func (*Transaction) EncodeBinary

func (t *Transaction) EncodeBinary(w *io.BinWriter)

func (Transaction) FeePerByte

func (t Transaction) FeePerByte() uint64

func (*Transaction) From

func (t *Transaction) From() common.Address

func (*Transaction) Gas

func (t *Transaction) Gas() uint64

func (*Transaction) GasPrice

func (t *Transaction) GasPrice() *big.Int

func (*Transaction) Hash

func (t *Transaction) Hash() common.Hash

func (Transaction) IsValid

func (t Transaction) IsValid() error

func (Transaction) MarshalJSON

func (t Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Nonce

func (t *Transaction) Nonce() uint64

func (Transaction) SignHash

func (t Transaction) SignHash(chainId uint64) common.Hash

func (*Transaction) Size

func (t *Transaction) Size() int

func (*Transaction) To

func (t *Transaction) To() *common.Address

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(b []byte) error

func (*Transaction) Value

func (t *Transaction) Value() *big.Int

func (*Transaction) Verify

func (t *Transaction) Verify(chainId uint64) error

func (*Transaction) WithSignature

func (t *Transaction) WithSignature(chainId uint64, sig []byte) error

func (*Transaction) WithWitness

func (t *Transaction) WithWitness(witness Witness) error

type Witness

type Witness struct {
	InvocationScript   []byte
	VerificationScript []byte
}

Witness contains 2 scripts.

func (Witness) Address

func (w Witness) Address() common.Address

ScriptHash returns the hash of the VerificationScript.

func (*Witness) DecodeBinary

func (w *Witness) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Witness) EncodeBinary

func (w *Witness) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

func (Witness) MarshalJSON

func (w Witness) MarshalJSON() ([]byte, error)

func (*Witness) UnmarshalJSON

func (w *Witness) UnmarshalJSON(b []byte) error

func (*Witness) VerifyHashable

func (w *Witness) VerifyHashable(chainId uint64, hh hash.Hashable) error

Jump to

Keyboard shortcuts

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