Class Transaction

java.lang.Object
com.norswap.nanoeth.transactions.UnsignedTransaction
com.norswap.nanoeth.transactions.Transaction
All Implemented Interfaces:
RLPLayoutable

public final class Transaction
extends UnsignedTransaction
implements RLPLayoutable
A "normalized transaction", as defined in EIP-1559 (part of the 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 Details

    • signature

      public final Signature signature
      Signature of the transaction by the sender.
  • Constructor Details

  • Method Details

    • from

      public static Transaction from​(RLP rlp) throws RLPParsingException
      Parses a RLP sequence into a transaction.
      Throws:
      RLPParsingException - if the RLP object does not properly parse to a transaction
    • recoverSender

      public Address 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

      public RLP plainRLP()
      Returns the RLP encoding of this transaction, without the TransactionEnvelopeType (if any). This is a sequence of transaction fields.
      See Also:
      rlpLayout()
    • rlpLayout

      public RLP 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 a TransactionEnvelopeType.

      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 interface RLPLayoutable
    • 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

      public String toHexString()
      Returns an hex string (e.g. "0x123") corresponding to the RLP 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 of encodedUnsignedTransaction 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

      public Hash hash()
      Returns the transaction hash. This is recomputed anew each time it is requested.
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class UnsignedTransaction
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class UnsignedTransaction
    • toString

      public String toString()
      Overrides:
      toString in class UnsignedTransaction