Documentation
¶
Index ¶
- Constants
- Variables
- func IntrinsicGas(clauses ...*Clause) (uint64, error)
- type BlockRef
- type Builder
- func (b *Builder) BlockRef(br BlockRef) *Builder
- func (b *Builder) Build() *Transaction
- func (b *Builder) ChainTag(tag byte) *Builder
- func (b *Builder) Clause(c *Clause) *Builder
- func (b *Builder) Clauses(clauses []*Clause) *Builder
- func (b *Builder) DependsOn(txID *thor.Bytes32) *Builder
- func (b *Builder) Expiration(exp uint32) *Builder
- func (b *Builder) Features(feat Features) *Builder
- func (b *Builder) Gas(gas uint64) *Builder
- func (b *Builder) GasPriceCoef(coef uint8) *Builder
- func (b *Builder) MaxFeePerGas(maxFeePerGas *big.Int) *Builder
- func (b *Builder) MaxPriorityFeePerGas(maxPriorityFeePerGas *big.Int) *Builder
- func (b *Builder) Nonce(nonce uint64) *Builder
- type Clause
- func (c *Clause) Data() []byte
- func (c *Clause) DecodeRLP(s *rlp.Stream) error
- func (c *Clause) EncodeRLP(w io.Writer) error
- func (c *Clause) IsCreatingContract() bool
- func (c *Clause) String() string
- func (c *Clause) To() *thor.Address
- func (c *Clause) Value() *big.Int
- func (c *Clause) WithData(data []byte) *Clause
- func (c *Clause) WithValue(value *big.Int) *Clause
- type Event
- type Events
- type Features
- type Output
- type Receipt
- type Receipts
- type Transaction
- func MustSign(tx *Transaction, pk *ecdsa.PrivateKey) *Transaction
- func MustSignDelegated(tx *Transaction, originPK *ecdsa.PrivateKey, delegatorPK *ecdsa.PrivateKey) *Transaction
- func Sign(tx *Transaction, pk *ecdsa.PrivateKey) (*Transaction, error)
- func SignDelegated(tx *Transaction, originPK *ecdsa.PrivateKey, delegatorPK *ecdsa.PrivateKey) (*Transaction, error)
- func (t *Transaction) BlockRef() (br BlockRef)
- func (t *Transaction) ChainTag() byte
- func (t *Transaction) Clauses() []*Clause
- func (t *Transaction) DecodeRLP(s *rlp.Stream) error
- func (t *Transaction) Delegator() (*thor.Address, error)
- func (t *Transaction) DelegatorSigningHash(origin thor.Address) (hash thor.Bytes32)
- func (t *Transaction) DependsOn() *thor.Bytes32
- func (t *Transaction) EffectiveGasPrice(baseFee *big.Int, legacyTxBaseGasPrice *big.Int) *big.Int
- func (t *Transaction) EffectivePriorityFeePerGas(baseFee *big.Int, legacyTxBaseGasPrice *big.Int, provedWork *big.Int) *big.Int
- func (t *Transaction) EncodeRLP(w io.Writer) error
- func (t *Transaction) EvaluateWork(origin thor.Address) func(nonce uint64) *big.Int
- func (t *Transaction) Expiration() uint32
- func (t *Transaction) Features() Features
- func (t *Transaction) Gas() uint64
- func (t *Transaction) GasPriceCoef() uint8
- func (t *Transaction) Hash() (hash thor.Bytes32)
- func (t *Transaction) ID() (id thor.Bytes32)
- func (t *Transaction) IntrinsicGas() (uint64, error)
- func (t *Transaction) IsExpired(blockNum uint32) bool
- func (t *Transaction) MarshalBinary() ([]byte, error)
- func (t *Transaction) MaxFeePerGas() *big.Int
- func (t *Transaction) MaxPriorityFeePerGas() *big.Int
- func (t *Transaction) Nonce() uint64
- func (t *Transaction) Origin() (thor.Address, error)
- func (t *Transaction) OverallGasPrice(legacyTxBaseGasPrice *big.Int, provedWork *big.Int) *big.Int
- func (t *Transaction) ProvedWork(headBlockNum uint32, getBlockID func(uint32) (thor.Bytes32, error)) (*big.Int, error)
- func (t *Transaction) Signature() []byte
- func (t *Transaction) SigningHash() (hash thor.Bytes32)
- func (t *Transaction) Size() thor.StorageSize
- func (t *Transaction) String() string
- func (t *Transaction) TestFeatures(supported Features) error
- func (t *Transaction) Type() uint8
- func (t *Transaction) UnmarshalBinary(b []byte) error
- func (t *Transaction) UnprovedWork() *big.Int
- func (t *Transaction) WithSignature(sig []byte) *Transaction
- type Transactions
- type Transfer
- type Transfers
- type Type
Constants ¶
const ( TypeLegacy = Type(0x00) TypeDynamicFee = Type(0x51) )
Starting from 0x51 to avoid ambiguity with Ethereum tx type codes.
Variables ¶
var (
ErrTxTypeNotSupported = errors.New("transaction type not supported")
)
Functions ¶
func IntrinsicGas ¶
IntrinsicGas calculate intrinsic gas cost for tx with such clauses.
Types ¶
type BlockRef ¶
type BlockRef [8]byte
BlockRef is block reference.
func NewBlockRef ¶
NewBlockRef create block reference with block number.
func NewBlockRefFromID ¶
NewBlockRefFromID create block reference from block id.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder to make it easy to build transaction.
func NewBuilder ¶ added in v2.3.0
func (*Builder) Expiration ¶
Expiration set expiration.
func (*Builder) GasPriceCoef ¶
GasPriceCoef set gas price coef.
func (*Builder) MaxFeePerGas ¶ added in v2.3.0
MaxFeePerGas set max fee per gas.
func (*Builder) MaxPriorityFeePerGas ¶ added in v2.3.0
MaxPriorityFeePerGas set max priority fee per gas.
type Clause ¶
type Clause struct {
// contains filtered or unexported fields
}
Clause is the basic execution unit of a transaction.
func (*Clause) IsCreatingContract ¶
IsCreatingContract return if this clause is going to create a contract.
type Event ¶
type Event struct { // address of the contract that generated the event Address thor.Address // list of topics provided by the contract. Topics []thor.Bytes32 // supplied by the contract, usually ABI-encoded Data []byte }
Event represents a contract event log. These events are generated by the LOG opcode and stored/indexed by the node.
type Features ¶
type Features uint32
Features bitset contains tx features.
const ( // DelegationFeature See VIP-191 for more detail. (https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md) DelegationFeature Features = 1 )
func (Features) IsDelegated ¶
IsDelegated returns whether tx is delegated.
func (*Features) SetDelegated ¶
SetDelegated set tx delegated flag.
type Output ¶
type Output struct { // events produced by the clause Events Events // transfer occurred in clause Transfers Transfers }
Output output of clause execution.
type Receipt ¶
type Receipt struct { // transaction type this receipt is associated with Type byte // gas used by this tx GasUsed uint64 // the one who paid for gas GasPayer thor.Address // energy paid for used gas Paid *big.Int // energy reward given to block proposer Reward *big.Int // if the tx reverted Reverted bool // outputs of clauses in tx Outputs []*Output }
Receipt represents the results of a transaction.
func (*Receipt) DecodeRLP ¶ added in v2.3.0
DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt from an RLP stream.
func (*Receipt) EncodeRLP ¶ added in v2.3.0
EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt into an RLP stream. If no post state is present, byzantium fork is assumed.
func (*Receipt) MarshalBinary ¶ added in v2.3.0
MarshalBinary returns the consensus encoding of the receipt.
func (*Receipt) UnmarshalBinary ¶ added in v2.3.0
UnmarshalBinary decodes the consensus encoding of receipts. It supports legacy RLP receipts and EIP-2718 typed receipts.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is an immutable tx type.
func MustSign ¶ added in v2.1.5
func MustSign(tx *Transaction, pk *ecdsa.PrivateKey) *Transaction
MustSign signs a transaction using the provided private key and the default signing function. It panics if the signing process fails, returning a signed transaction upon success.
func MustSignDelegated ¶ added in v2.1.5
func MustSignDelegated(tx *Transaction, originPK *ecdsa.PrivateKey, delegatorPK *ecdsa.PrivateKey) *Transaction
MustSignDelegated signs a transaction as a delegator using the provided private keys and the default signing function. It panics if the signing process fails, returning a signed transaction upon success.
func Sign ¶ added in v2.1.5
func Sign(tx *Transaction, pk *ecdsa.PrivateKey) (*Transaction, error)
Sign signs a transaction using the provided private key and the default signing function. It returns the signed transaction or an error if the signing process fails.
func SignDelegated ¶ added in v2.1.5
func SignDelegated(tx *Transaction, originPK *ecdsa.PrivateKey, delegatorPK *ecdsa.PrivateKey) (*Transaction, error)
SignDelegated signs a transaction with both origin and delegator's private key and the default signing function. It returns the signed transaction or an error if the signing process fails.
func (*Transaction) BlockRef ¶
func (t *Transaction) BlockRef() (br BlockRef)
BlockRef returns block reference, which is first 8 bytes of block hash.
func (*Transaction) Clauses ¶
func (t *Transaction) Clauses() []*Clause
Clauses returns clauses in tx.
func (*Transaction) DecodeRLP ¶
func (t *Transaction) DecodeRLP(s *rlp.Stream) error
DecodeRLP implements rlp.Decoder
func (*Transaction) Delegator ¶
func (t *Transaction) Delegator() (*thor.Address, error)
Delegator returns delegator address who would like to pay for gas fee.
func (*Transaction) DelegatorSigningHash ¶
func (t *Transaction) DelegatorSigningHash(origin thor.Address) (hash thor.Bytes32)
DelegatorSigningHash returns hash of tx components for delegator to sign, by assuming originator address. According to VIP-191, it's identical to tx id.
func (*Transaction) DependsOn ¶
func (t *Transaction) DependsOn() *thor.Bytes32
DependsOn returns depended tx hash.
func (*Transaction) EffectiveGasPrice ¶ added in v2.3.1
EffectiveGasPrice calculates the effective gas price of a transaction,which is the gas price sender have to pay per gas unit. The proved work is NOT included.For legacy transactions, baseGasPrice is required. For dynamic fee transactions,baseFee is required. It is caller's responsibility to ensure the fields are passed correctly.
func (*Transaction) EffectivePriorityFeePerGas ¶ added in v2.3.1
func (t *Transaction) EffectivePriorityFeePerGas(baseFee *big.Int, legacyTxBaseGasPrice *big.Int, provedWork *big.Int) *big.Int
EffectivePriorityFeePerGas returns the effective priority fee per gas for the transaction. If maxFeePerGas is less than baseFee, an error is returned. For legacy transactions, the overall gas price which includes the proved work is used as both maxPriorityFeePerGas and maxFeePerGas. It is caller's responsibility to ensure the fields are passed correctly.
func (*Transaction) EncodeRLP ¶
func (t *Transaction) EncodeRLP(w io.Writer) error
EncodeRLP implements rlp.Encoder
func (*Transaction) EvaluateWork ¶
EvaluateWork try to compute work when tx origin assumed. This is mostly used for a client trying to gain higher priority in the mempool for the legacy transactions.
NOTE: This method only works for legacy transactions.
func (*Transaction) Expiration ¶
func (t *Transaction) Expiration() uint32
Expiration returns expiration in unit block. A valid transaction requires: blockNum in [blockRef.Num... blockRef.Num + Expiration]
func (*Transaction) GasPriceCoef ¶
func (t *Transaction) GasPriceCoef() uint8
GasPriceCoef returns gas price coef. gas price = bgp + bgp * gpc / 255.
NOTE: This method only works for legacy transactions.
func (*Transaction) Hash ¶
func (t *Transaction) Hash() (hash thor.Bytes32)
Hash returns hash of tx. Unlike ID, it's the hash of RLP encoded tx.
func (*Transaction) ID ¶
func (t *Transaction) ID() (id thor.Bytes32)
ID returns id of tx. ID = hash(signingHash, origin). It returns zero Bytes32 if origin not available.
func (*Transaction) IntrinsicGas ¶
func (t *Transaction) IntrinsicGas() (uint64, error)
IntrinsicGas returns intrinsic gas of tx.
func (*Transaction) IsExpired ¶
func (t *Transaction) IsExpired(blockNum uint32) bool
IsExpired returns whether the tx is expired according to the given blockNum.
func (*Transaction) MarshalBinary ¶ added in v2.3.0
func (t *Transaction) MarshalBinary() ([]byte, error)
MarshalBinary returns the canonical encoding of the transaction. For legacy transactions, it returns the RLP encoding. For typed transactions, it returns the type RLP encoding of the tx.
func (*Transaction) MaxFeePerGas ¶ added in v2.3.0
func (t *Transaction) MaxFeePerGas() *big.Int
MaxFeePerGas returns max fee per gas.
func (*Transaction) MaxPriorityFeePerGas ¶ added in v2.3.0
func (t *Transaction) MaxPriorityFeePerGas() *big.Int
MaxPriorityFeePerGas returns max priority fee per gas.
func (*Transaction) Origin ¶
func (t *Transaction) Origin() (thor.Address, error)
Origin extract address of tx originator from signature.
func (*Transaction) OverallGasPrice ¶
OverallGasPrice calculate overall gas price which includes proved work for legacy transactions. overallGasPrice = gasPrice + baseGasPrice * wgas/gas.
NOTE: This method only works for legacy transactions.
func (*Transaction) ProvedWork ¶
func (t *Transaction) ProvedWork(headBlockNum uint32, getBlockID func(uint32) (thor.Bytes32, error)) (*big.Int, error)
ProvedWork returns proved work for legacy transactions. Unproved work will be considered as proved work if block ref is the prefix of a block's ID, and tx delay is less equal to MaxTxWorkDelay.
NOTE: This method only works for legacy transactions.
func (*Transaction) Signature ¶
func (t *Transaction) Signature() []byte
Signature returns signature.
func (*Transaction) SigningHash ¶
func (t *Transaction) SigningHash() (hash thor.Bytes32)
SigningHash returns hash of tx excludes signature.
func (*Transaction) Size ¶
func (t *Transaction) Size() thor.StorageSize
Size returns size in bytes when RLP encoded.
func (*Transaction) String ¶
func (t *Transaction) String() string
func (*Transaction) TestFeatures ¶
func (t *Transaction) TestFeatures(supported Features) error
TestFeatures test if the tx is compatible with given supported features. An error returned if it is incompatible.
func (*Transaction) Type ¶ added in v2.3.0
func (t *Transaction) Type() uint8
Type returns the transaction type.
func (*Transaction) UnmarshalBinary ¶ added in v2.3.0
func (t *Transaction) UnmarshalBinary(b []byte) error
UnmarshalBinary decodes the canonical encoding of transactions. It supports legacy RLP transactions and typed transactions.
func (*Transaction) UnprovedWork ¶
func (t *Transaction) UnprovedWork() *big.Int
UnprovedWork returns unproved work for legacy transactions. It returns 0, if tx is not signed or not a legacy transaction.
NOTE: This method only works for legacy transactions.
func (*Transaction) WithSignature ¶
func (t *Transaction) WithSignature(sig []byte) *Transaction
WithSignature create a new tx with signature set. For delegated tx, sig is joined with signatures of originator and delegator.
type Transactions ¶
type Transactions []*Transaction
Transactions a slice of transactions.
func (Transactions) RootHash ¶
func (txs Transactions) RootHash() thor.Bytes32
RootHash computes merkle root hash of transactions.