Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::eth::TransactionBase Class Reference

Encodes a transaction, ready to be exported to or freshly imported from RLP. More...

#include <TransactionBase.h>

Inheritance diagram for dev::eth::TransactionBase:
dev::eth::Transaction dev::eth::LocalisedTransaction

Public Member Functions

 TransactionBase ()
 Constructs a null transaction. More...
 
 TransactionBase (TransactionSkeleton const &_ts, Secret const &_s=Secret())
 Constructs a transaction from a transaction skeleton & optional secret. More...
 
 TransactionBase (u256 const &_value, u256 const &_gasPrice, u256 const &_gas, Address const &_dest, bytes const &_data, u256 const &_nonce, Secret const &_secret)
 Constructs a signed message-call transaction. More...
 
 TransactionBase (u256 const &_value, u256 const &_gasPrice, u256 const &_gas, bytes const &_data, u256 const &_nonce, Secret const &_secret)
 Constructs a signed contract-creation transaction. More...
 
 TransactionBase (u256 const &_value, u256 const &_gasPrice, u256 const &_gas, Address const &_dest, bytes const &_data, u256 const &_nonce=0)
 Constructs an unsigned message-call transaction. More...
 
 TransactionBase (u256 const &_value, u256 const &_gasPrice, u256 const &_gas, bytes const &_data, u256 const &_nonce=0)
 Constructs an unsigned contract-creation transaction. More...
 
 TransactionBase (bytesConstRef _rlp, CheckTransaction _checkSig)
 Constructs a transaction from the given RLP. More...
 
 TransactionBase (bytes const &_rlp, CheckTransaction _checkSig)
 Constructs a transaction from the given RLP. More...
 
bool operator== (TransactionBase const &_c) const
 Checks equality of transactions. More...
 
bool operator!= (TransactionBase const &_c) const
 Checks inequality of transactions. More...
 
Address const & sender () const
 
Address const & safeSender () const noexcept
 Like sender() but will never throw. More...
 
void forceSender (Address const &_a)
 Force the sender to a particular value. This will result in an invalid transaction RLP. More...
 
void checkLowS () const
 
void checkChainId (int chainId=-4) const
 
 operator bool () const
 
bool isCreation () const
 
void streamRLP (RLPStream &_s, IncludeSignature _sig=WithSignature, bool _forEip155hash=false) const
 
bytes rlp (IncludeSignature _sig=WithSignature) const
 
h256 sha3 (IncludeSignature _sig=WithSignature) const
 
u256 value () const
 
u256 gasPrice () const
 
u256 gas () const
 
Address receiveAddress () const
 
Address to () const
 Synonym for receiveAddress(). More...
 
Address from () const
 Synonym for safeSender(). More...
 
bytes const & data () const
 
u256 nonce () const
 
void setNonce (u256 const &_n)
 Sets the nonce to the given value. Clears any signature. More...
 
bool hasSignature () const
 
bool hasZeroSignature () const
 
bool isReplayProtected () const
 
SignatureStruct const & signature () const
 
void sign (Secret const &_priv)
 Sign the transaction. More...
 
int64_t baseGasRequired (EVMSchedule const &_es) const
 

Static Public Member Functions

static int64_t baseGasRequired (bool _contractCreation, bytesConstRef _data, EVMSchedule const &_es)
 Get the fee associated for a transaction with the given data. More...
 

Protected Types

enum  Type { NullTransaction, ContractCreation, MessageCall }
 Type of transaction. More...
 

Protected Member Functions

void clearSignature ()
 Clears the signature. More...
 

Static Protected Member Functions

static bool isZeroSignature (u256 const &_r, u256 const &_s)
 

Protected Attributes

Type m_type = NullTransaction
 Is this a contract-creation transaction or a message-call transaction? More...
 
u256 m_nonce
 The transaction-count of the sender. More...
 
u256 m_value
 The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions. More...
 
Address m_receiveAddress
 The receiving address of the transaction. More...
 
u256 m_gasPrice
 The base fee and thus the implied exchange rate of ETH to GAS. More...
 
u256 m_gas
 The total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended. More...
 
bytes m_data
 The data associated with the transaction, or the initialiser if it's a creation transaction. More...
 
boost::optional< SignatureStructm_vrs
 The signature of the transaction. Encodes the sender. More...
 
int m_chainId = -4
 EIP155 value for calculating transaction hash https://github.com/ethereum/EIPs/issues/155. More...
 
h256 m_hashWith
 Cached hash of transaction with signature. More...
 
boost::optional< Addressm_sender
 Cached sender, determined from signature. More...
 

Detailed Description

Encodes a transaction, ready to be exported to or freshly imported from RLP.

Definition at line 49 of file TransactionBase.h.

Member Enumeration Documentation

◆ Type

Type of transaction.

Enumerator
NullTransaction 

Null transaction.

ContractCreation 

Transaction to create contracts - receiveAddress() is ignored.

MessageCall 

Transaction to invoke a message call - receiveAddress() is used.

Definition at line 164 of file TransactionBase.h.

Constructor & Destructor Documentation

◆ TransactionBase() [1/8]

dev::eth::TransactionBase::TransactionBase ( )
inline

Constructs a null transaction.

Definition at line 53 of file TransactionBase.h.

◆ TransactionBase() [2/8]

TransactionBase::TransactionBase ( TransactionSkeleton const &  _ts,
Secret const &  _s = Secret() 
)

Constructs a transaction from a transaction skeleton & optional secret.

Definition at line 33 of file TransactionBase.cpp.

◆ TransactionBase() [3/8]

dev::eth::TransactionBase::TransactionBase ( u256 const &  _value,
u256 const &  _gasPrice,
u256 const &  _gas,
Address const &  _dest,
bytes const &  _data,
u256 const &  _nonce,
Secret const &  _secret 
)
inline

Constructs a signed message-call transaction.

Definition at line 59 of file TransactionBase.h.

◆ TransactionBase() [4/8]

dev::eth::TransactionBase::TransactionBase ( u256 const &  _value,
u256 const &  _gasPrice,
u256 const &  _gas,
bytes const &  _data,
u256 const &  _nonce,
Secret const &  _secret 
)
inline

Constructs a signed contract-creation transaction.

Definition at line 62 of file TransactionBase.h.

◆ TransactionBase() [5/8]

dev::eth::TransactionBase::TransactionBase ( u256 const &  _value,
u256 const &  _gasPrice,
u256 const &  _gas,
Address const &  _dest,
bytes const &  _data,
u256 const &  _nonce = 0 
)
inline

Constructs an unsigned message-call transaction.

Definition at line 65 of file TransactionBase.h.

◆ TransactionBase() [6/8]

dev::eth::TransactionBase::TransactionBase ( u256 const &  _value,
u256 const &  _gasPrice,
u256 const &  _gas,
bytes const &  _data,
u256 const &  _nonce = 0 
)
inline

Constructs an unsigned contract-creation transaction.

Definition at line 68 of file TransactionBase.h.

◆ TransactionBase() [7/8]

TransactionBase::TransactionBase ( bytesConstRef  _rlp,
CheckTransaction  _checkSig 
)
explicit

Constructs a transaction from the given RLP.

Definition at line 47 of file TransactionBase.cpp.

◆ TransactionBase() [8/8]

dev::eth::TransactionBase::TransactionBase ( bytes const &  _rlp,
CheckTransaction  _checkSig 
)
inlineexplicit

Constructs a transaction from the given RLP.

Definition at line 74 of file TransactionBase.h.

Member Function Documentation

◆ baseGasRequired() [1/2]

int64_t TransactionBase::baseGasRequired ( bool  _contractCreation,
bytesConstRef  _data,
EVMSchedule const &  _es 
)
static

Get the fee associated for a transaction with the given data.

Definition at line 200 of file TransactionBase.cpp.

◆ baseGasRequired() [2/2]

int64_t dev::eth::TransactionBase::baseGasRequired ( EVMSchedule const &  _es) const
inline
Returns
amount of gas required for the basic payment.

Definition at line 157 of file TransactionBase.h.

◆ checkChainId()

void TransactionBase::checkChainId ( int  chainId = -4) const
Exceptions
InvalidSValueif the chain id is neither -4 nor equal to chainId Note that "-4" is the chain ID of the pre-155 rules, which should also be considered valid after EIP155

Definition at line 194 of file TransactionBase.cpp.

◆ checkLowS()

void TransactionBase::checkLowS ( ) const
Exceptions
TransactionIsUnsignedif signature was not initialized
InvalidSValueif the signature has an invalid S value.

Definition at line 185 of file TransactionBase.cpp.

◆ clearSignature()

void dev::eth::TransactionBase::clearSignature ( )
inlineprotected

Clears the signature.

Definition at line 174 of file TransactionBase.h.

◆ data()

bytes const& dev::eth::TransactionBase::data ( ) const
inline
Returns
the data associated with this (message-call) transaction. Synonym for initCode().

Definition at line 133 of file TransactionBase.h.

◆ forceSender()

void dev::eth::TransactionBase::forceSender ( Address const &  _a)
inline

Force the sender to a particular value. This will result in an invalid transaction RLP.

Definition at line 87 of file TransactionBase.h.

◆ from()

Address dev::eth::TransactionBase::from ( ) const
inline

Synonym for safeSender().

Definition at line 130 of file TransactionBase.h.

◆ gas()

u256 dev::eth::TransactionBase::gas ( ) const
inline
Returns
the total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.

Definition at line 121 of file TransactionBase.h.

◆ gasPrice()

u256 dev::eth::TransactionBase::gasPrice ( ) const
inline
Returns
the base fee and thus the implied exchange rate of ETH to GAS.

Definition at line 118 of file TransactionBase.h.

◆ hasSignature()

bool dev::eth::TransactionBase::hasSignature ( ) const
inline
Returns
true if the transaction was signed

Definition at line 142 of file TransactionBase.h.

◆ hasZeroSignature()

bool dev::eth::TransactionBase::hasZeroSignature ( ) const
inline
Returns
true if the transaction was signed with zero signature

Definition at line 145 of file TransactionBase.h.

◆ isCreation()

bool dev::eth::TransactionBase::isCreation ( ) const
inline
Returns
true if transaction is contract-creation.

Definition at line 102 of file TransactionBase.h.

◆ isReplayProtected()

bool dev::eth::TransactionBase::isReplayProtected ( ) const
inline
Returns
true if the transaction uses EIP155 replay protection

Definition at line 148 of file TransactionBase.h.

◆ isZeroSignature()

static bool dev::eth::TransactionBase::isZeroSignature ( u256 const &  _r,
u256 const &  _s 
)
inlinestaticprotected

Definition at line 171 of file TransactionBase.h.

◆ nonce()

u256 dev::eth::TransactionBase::nonce ( ) const
inline
Returns
the transaction-count of the sender.

Definition at line 136 of file TransactionBase.h.

◆ operator bool()

dev::eth::TransactionBase::operator bool ( ) const
inlineexplicit
Returns
true if transaction is non-null.

Definition at line 99 of file TransactionBase.h.

◆ operator!=()

bool dev::eth::TransactionBase::operator!= ( TransactionBase const &  _c) const
inline

Checks inequality of transactions.

Definition at line 79 of file TransactionBase.h.

◆ operator==()

bool dev::eth::TransactionBase::operator== ( TransactionBase const &  _c) const
inline

Checks equality of transactions.

Definition at line 77 of file TransactionBase.h.

◆ receiveAddress()

Address dev::eth::TransactionBase::receiveAddress ( ) const
inline
Returns
the receiving address of the message-call transaction (undefined for contract-creation transactions).

Definition at line 124 of file TransactionBase.h.

◆ rlp()

bytes dev::eth::TransactionBase::rlp ( IncludeSignature  _sig = WithSignature) const
inline
Returns
the RLP serialisation of this transaction.

Definition at line 109 of file TransactionBase.h.

◆ safeSender()

Address const & TransactionBase::safeSender ( ) const
noexcept

Like sender() but will never throw.

Returns
a null Address if the signature is invalid.

Definition at line 104 of file TransactionBase.cpp.

◆ sender()

Address const & TransactionBase::sender ( ) const
Returns
sender of the transaction from the signature (and hash).
Exceptions
TransactionIsUnsignedif signature was not initialized

Definition at line 116 of file TransactionBase.cpp.

◆ setNonce()

void dev::eth::TransactionBase::setNonce ( u256 const &  _n)
inline

Sets the nonce to the given value. Clears any signature.

Definition at line 139 of file TransactionBase.h.

◆ sha3()

h256 TransactionBase::sha3 ( IncludeSignature  _sig = WithSignature) const
Returns
the SHA3 hash of the RLP serialisation of this transaction.

Definition at line 212 of file TransactionBase.cpp.

◆ sign()

void TransactionBase::sign ( Secret const &  _priv)

Sign the transaction.

Definition at line 144 of file TransactionBase.cpp.

◆ signature()

SignatureStruct const & TransactionBase::signature ( ) const
Returns
the signature of the transaction (the signature has the sender encoded in it)
Exceptions
TransactionIsUnsignedif signature was not initialized

Definition at line 136 of file TransactionBase.cpp.

◆ streamRLP()

void TransactionBase::streamRLP ( RLPStream _s,
IncludeSignature  _sig = WithSignature,
bool  _forEip155hash = false 
) const

Serialises this transaction to an RLPStream.

Exceptions
TransactionIsUnsignedif including signature was requested but it was not initialized

Definition at line 152 of file TransactionBase.cpp.

◆ to()

Address dev::eth::TransactionBase::to ( ) const
inline

Synonym for receiveAddress().

Definition at line 127 of file TransactionBase.h.

◆ value()

u256 dev::eth::TransactionBase::value ( ) const
inline
Returns
the amount of ETH to be transferred by this (message-call) transaction, in Wei. Synonym for endowment().

Definition at line 115 of file TransactionBase.h.

Member Data Documentation

◆ m_chainId

int dev::eth::TransactionBase::m_chainId = -4
protected

EIP155 value for calculating transaction hash https://github.com/ethereum/EIPs/issues/155.

Definition at line 184 of file TransactionBase.h.

◆ m_data

bytes dev::eth::TransactionBase::m_data
protected

The data associated with the transaction, or the initialiser if it's a creation transaction.

Definition at line 182 of file TransactionBase.h.

◆ m_gas

u256 dev::eth::TransactionBase::m_gas
protected

The total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.

Definition at line 181 of file TransactionBase.h.

◆ m_gasPrice

u256 dev::eth::TransactionBase::m_gasPrice
protected

The base fee and thus the implied exchange rate of ETH to GAS.

Definition at line 180 of file TransactionBase.h.

◆ m_hashWith

h256 dev::eth::TransactionBase::m_hashWith
mutableprotected

Cached hash of transaction with signature.

Definition at line 186 of file TransactionBase.h.

◆ m_nonce

u256 dev::eth::TransactionBase::m_nonce
protected

The transaction-count of the sender.

Definition at line 177 of file TransactionBase.h.

◆ m_receiveAddress

Address dev::eth::TransactionBase::m_receiveAddress
protected

The receiving address of the transaction.

Definition at line 179 of file TransactionBase.h.

◆ m_sender

boost::optional<Address> dev::eth::TransactionBase::m_sender
mutableprotected

Cached sender, determined from signature.

Definition at line 187 of file TransactionBase.h.

◆ m_type

Type dev::eth::TransactionBase::m_type = NullTransaction
protected

Is this a contract-creation transaction or a message-call transaction?

Definition at line 176 of file TransactionBase.h.

◆ m_value

u256 dev::eth::TransactionBase::m_value
protected

The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions.

Definition at line 178 of file TransactionBase.h.

◆ m_vrs

boost::optional<SignatureStruct> dev::eth::TransactionBase::m_vrs
protected

The signature of the transaction. Encodes the sender.

Definition at line 183 of file TransactionBase.h.


The documentation for this class was generated from the following files: