MCPcopy Create free account
hub / github.com/LUX-Core/lux / initialize

Method initialize

src/cpp-ethereum/libethereum/Executive.cpp:194–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194void Executive::initialize(Transaction const& _transaction)
195{
196 m_t = _transaction;
197
198 // Avoid transactions that would take us beyond the block gas limit.
199 u256 startGasUsed = m_envInfo.gasUsed();
200 if (startGasUsed + (bigint)m_t.gas() > m_envInfo.gasLimit())
201 {
202 clog(ExecutiveWarnChannel) << "Cannot fit tx in block" << m_envInfo.number() << ": Require <" << (m_envInfo.gasLimit() - startGasUsed) << " Got" << m_t.gas();
203 m_excepted = TransactionException::BlockGasLimitReached;
204 BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_envInfo.gasLimit() - startGasUsed), (bigint)m_t.gas()));
205 }
206
207 // Check gas cost is enough.
208 m_baseGasRequired = m_t.baseGasRequired(m_sealEngine.evmSchedule(m_envInfo));
209 if (m_baseGasRequired > m_t.gas())
210 {
211 clog(ExecutiveWarnChannel) << "Not enough gas to pay for the transaction: Require >" << m_baseGasRequired << " Got" << m_t.gas();
212 m_excepted = TransactionException::OutOfGasBase;
213 BOOST_THROW_EXCEPTION(OutOfGasBase() << RequirementError((bigint)m_baseGasRequired, (bigint)m_t.gas()));
214 }
215
216 // Avoid invalid transactions.
217 u256 nonceReq;
218 try
219 {
220 nonceReq = m_s.getNonce(m_t.sender());
221 }
222 catch (...)
223 {
224 clog(ExecutiveWarnChannel) << "Invalid Signature";
225 m_excepted = TransactionException::InvalidSignature;
226 throw;
227 }
228 if (m_t.nonce() != nonceReq)
229 {
230 clog(ExecutiveWarnChannel) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce();
231 m_excepted = TransactionException::InvalidNonce;
232 BOOST_THROW_EXCEPTION(InvalidNonce() << RequirementError((bigint)nonceReq, (bigint)m_t.nonce()));
233 }
234
235 // Avoid unaffordable transactions.
236 bigint gasCost = (bigint)m_t.gas() * m_t.gasPrice();
237 bigint totalCost = m_t.value() + gasCost;
238 if (m_s.balance(m_t.sender()) < totalCost)
239 {
240 clog(ExecutiveWarnChannel) << "Not enough cash: Require >" << totalCost << "=" << m_t.gas() << "*" << m_t.gasPrice() << "+" << m_t.value() << " Got" << m_s.balance(m_t.sender()) << "for sender: " << m_t.sender();
241 m_excepted = TransactionException::NotEnoughCash;
242 BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(totalCost, (bigint)m_s.balance(m_t.sender())) << errinfo_comment(m_t.sender().abridged()));
243 }
244 m_gasCost = (u256)gasCost; // Convert back to 256-bit, safe now.
245}
246
247bool Executive::execute()
248{

Callers 4

executeMethod · 0.45
main.cppFile · 0.45
traceTransactionMethod · 0.45
admin_eth_vmTraceMethod · 0.45

Calls 12

gasLimitMethod · 0.80
getNonceMethod · 0.80
gasPriceMethod · 0.80
abridgedMethod · 0.80
gasUsedMethod · 0.45
gasMethod · 0.45
numberMethod · 0.45
baseGasRequiredMethod · 0.45
evmScheduleMethod · 0.45
nonceMethod · 0.45
valueMethod · 0.45
balanceMethod · 0.45

Tested by

no test coverage detected