Class Transaction
- All Implemented Interfaces:
RLPLayoutable
public final class Transaction extends UnsignedTransaction implements RLPLayoutable
London
hard fork).
Such a transaction can be created from any of the TransactionFormat
.
Creating the transaction does not verify its signature. To do so, call verifySignature()
.
-
Field Summary
Fields Modifier and Type Field Description Signature
signature
Signature of the transaction by the sender.Fields inherited from class com.norswap.nanoeth.transactions.UnsignedTransaction
accessList, chainId, format, gasLimit, maxFeePerGas, maxPriorityFeePerGas, nonce, payload, to, value
-
Constructor Summary
Constructors Constructor Description Transaction(TransactionFormat format, Natural chainId, Natural nonce, Natural maxFeePerGas, Natural maxPriorityFeePerGas, Natural gasLimit, Address to, Natural value, byte[] payload, AccessList accessList, Signature signature)
-
Method Summary
Modifier and Type Method Description byte[]
binary()
Returns the binary encoding of this transaction, for construction of the transaction trie, or transmission over the network.boolean
equals(Object o)
static Transaction
from(RLP rlp)
Parses a RLP sequence into a transaction.Hash
hash()
Returns the transaction hash.int
hashCode()
RLP
plainRLP()
Returns the RLP encoding of this transaction, without theTransactionEnvelopeType
(if any).Address
recoverSender()
Returns the address of the transaction sender.RLP
rlpLayout()
Returns the RLP-encoding of this transaction for inclusion in a block.String
toHexString()
Returns an hex string (e.g.String
toString()
boolean
verifySignature()
Returns true if the transaction's signature is valid.boolean
verifySignature(byte[] encodedUnsignedTransaction)
Returns true if the transaction's includes a valid signature ofencodedUnsignedTransaction
which should be the RLP encoding of the unsigned version of this transaction.Methods inherited from class com.norswap.nanoeth.transactions.UnsignedTransaction
isContractCreation, sign, signingRLP
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.norswap.nanoeth.rlp.RLPLayoutable
rlpEncode, rlpHexString
-
Field Details
-
signature
Signature of the transaction by the sender.
-
-
Constructor Details
-
Transaction
public Transaction(TransactionFormat format, Natural chainId, Natural nonce, Natural maxFeePerGas, Natural maxPriorityFeePerGas, Natural gasLimit, Address to, Natural value, byte[] payload, AccessList accessList, Signature signature)
-
-
Method Details
-
from
Parses a RLP sequence into a transaction.- Throws:
RLPParsingException
- if the RLP object does not properly parse to a transaction
-
recoverSender
Returns the address of the transaction sender.The address is recomputed from the RLP-encoded transaction and the signature each time this method is called.
-
plainRLP
Returns the RLP encoding of this transaction, without theTransactionEnvelopeType
(if any). This is a sequence of transaction fields.- See Also:
rlpLayout()
-
rlpLayout
Returns the RLP-encoding of this transaction for inclusion in a block.This is identical from the plain encoding generated by
plainRLP()
} for transactions that do not have aTransactionEnvelopeType
.For those who have an envelope type, the encoding is a RLP byte array comprising one byte for the type, followed by the plain RLP encoding for the transaction.
Do not use this to obtain a binary encoding of the transaction, at it wraps typed transactions in an RLP byte array. Use
binary()
instead.- Specified by:
rlpLayout
in interfaceRLPLayoutable
-
binary
public byte[] binary()Returns the binary encoding of this transaction, for construction of the transaction trie, or transmission over the network.The encoding is as described in
rlpLayout()
, with the only difference that for typed transactions, we just want the transaction type + opaque byte array representing the transaction, but not the RLP size prefix. -
toHexString
Returns an hex string (e.g. "0x123") corresponding to theRLP encoding
of this transaction. -
verifySignature
public boolean verifySignature()Returns true if the transaction's signature is valid.Use
verifySignature(byte[])
for faster verification if you know the RLP encoding of the unsigned version of this transaction (which avoids recomputing it). -
verifySignature
public boolean verifySignature(byte[] encodedUnsignedTransaction)Returns true if the transaction's includes a valid signature ofencodedUnsignedTransaction
which should be the RLP encoding of the unsigned version of this transaction.Use
verifySignature()
if you do not know the RLP encoding of the unsigned version. -
hash
Returns the transaction hash. This is recomputed anew each time it is requested. -
equals
- Overrides:
equals
in classUnsignedTransaction
-
hashCode
public int hashCode()- Overrides:
hashCode
in classUnsignedTransaction
-
toString
- Overrides:
toString
in classUnsignedTransaction
-