diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp
index 8b5ae8302..2d08df6d5 100644
--- a/alethzero/MainWin.cpp
+++ b/alethzero/MainWin.cpp
@@ -438,39 +438,23 @@ void Main::on_contracts_currentItemChanged()
stringstream s;
auto mem = state().contractMemory(h);
u256 next = 0;
- unsigned numerics = 0;
- bool unexpectedNumeric = false;
for (auto const& i: mem)
{
if (next < i.first)
{
unsigned j;
- for (j = 0; j <= numerics && next + j < i.first; ++j)
- s << (j < numerics || unexpectedNumeric ? " 0" : " STOP");
- unexpectedNumeric = false;
- numerics -= min(numerics, j);
+ for (j = 0; next + j < i.first; ++j)
+ s << " 0";
if (next + j < i.first)
s << " ...
@" << showbase << hex << i.first << " ";
}
else if (!next)
s << "@" << showbase << hex << i.first << " ";
- auto iit = c_instructionInfo.find((Instruction)(unsigned)i.second);
- if (numerics || iit == c_instructionInfo.end() || (u256)(unsigned)iit->first != i.second) // not an instruction or expecting an argument...
- {
- if (numerics)
- numerics--;
- else
- unexpectedNumeric = true;
- s << " " << showbase << hex << i.second;
- }
- else
- {
- auto const& ii = iit->second;
- s << " " << ii.name << "";
- numerics = ii.additional;
- }
+ s << " " << showbase << hex << i.second;
next = i.first + 1;
}
+ s << "
Code:";
+ s << "
" << disassemble(state().contractCode(h));
ui->contractInfo->appendHtml(QString::fromStdString(s.str()));
}
m_client->unlock();
@@ -568,11 +552,15 @@ u256 Main::fee() const
u256 Main::value() const
{
+ if (ui->valueUnits->currentIndex() == -1)
+ return 0;
return ui->value->value() * units()[units().size() - 1 - ui->valueUnits->currentIndex()].first;
}
u256 Main::gasPrice() const
{
+ if (ui->gasPriceUnits->currentIndex() == -1)
+ return 0;
return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first;
}
diff --git a/libethereum/Instruction.cpp b/libethereum/Instruction.cpp
index b295eb535..98d7863ca 100644
--- a/libethereum/Instruction.cpp
+++ b/libethereum/Instruction.cpp
@@ -414,7 +414,7 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
{
bytes codes;
vector locs;
- if (compileLispFragment(d, e, _quiet, codes, locs))
+ if (compileLispFragment(d, e, _quiet, codes, locs) != -1)
{
appendCode(o_code, o_locs, codes, locs);
while (compileLispFragment(d, e, _quiet, codes, locs) != -1)
diff --git a/libethereum/State.cpp b/libethereum/State.cpp
index c1a7acf7b..17b5d1cfa 100644
--- a/libethereum/State.cpp
+++ b/libethereum/State.cpp
@@ -655,26 +655,20 @@ void State::execute(bytesConstRef _rlp)
subBalance(sender, cost);
if (t.isCreation())
- {
- create(t, sender, &gas);
- }
+ create(sender, t.value, t.gasPrice, &gas, &t.data, &t.init);
else
- {
- cnote << "Passing" << formatBalance(t.value) << "to receiver";
- addBalance(t.receiveAddress, t.value);
-
- if (isContractAddress(t.receiveAddress))
- // Once we get here, there's no going back.
- call(t.receiveAddress, sender, t.value, t.gasPrice, bytesConstRef(&t.data), &gas, bytesRef());
- }
+ call(t.receiveAddress, sender, t.value, t.gasPrice, bytesConstRef(&t.data), &gas, bytesRef());
cnote << "Refunding" << formatBalance(gas * t.gasPrice) << "to sender (=" << gas << "*" << formatBalance(t.gasPrice) << ")";
addBalance(sender, gas * t.gasPrice);
u256 gasSpent = (t.gas - gas) * t.gasPrice;
- unsigned c_feesKept = 8;
+/* unsigned c_feesKept = 8;
u256 feesEarned = gasSpent - (gasSpent / c_feesKept);
cnote << "Transferring" << (100.0 - 100.0 / c_feesKept) << "% of" << formatBalance(gasSpent) << "=" << formatBalance(feesEarned) << "to miner (" << formatBalance(gasSpent - feesEarned) << "is burnt).";
+*/
+ u256 feesEarned = gasSpent;
+ cnote << "Transferring" << formatBalance(gasSpent) << "to miner.";
addBalance(m_currentBlock.coinbaseAddress, feesEarned);
// Add to the user-originated transactions that we've executed.
@@ -682,69 +676,63 @@ void State::execute(bytesConstRef _rlp)
m_transactionSet.insert(t.sha3());
}
-bool State::call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256* _gas, bytesRef _out)
+bool State::call(Address _receiveAddress, Address _sendAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256* _gas, bytesRef _out)
{
- VM vm(*_gas);
- ExtVM evm(*this, _myAddress, _txSender, _txValue, _gasPrice, _txData, &contractCode(_myAddress));
- bool revert = false;
+ cnote << "Transferring" << formatBalance(_value) << "to receiver.";
+ addBalance(_receiveAddress, _value);
- try
- {
- auto out = vm.go(evm);
- memcpy(_out.data(), out.data(), std::min(out.size(), _out.size()));
- }
- catch (OutOfGas const& /*_e*/)
+ if (isContractAddress(_receiveAddress))
{
- clog(StateChat) << "Out of Gas! Reverting.";
- revert = true;
- }
- catch (VMException const& _e)
- {
- clog(StateChat) << "VM Exception: " << _e.description();
- }
- catch (Exception const& _e)
- {
- clog(StateChat) << "Exception in VM: " << _e.description();
- }
- catch (std::exception const& _e)
- {
- clog(StateChat) << "std::exception in VM: " << _e.what();
- }
+ VM vm(*_gas);
+ ExtVM evm(*this, _receiveAddress, _sendAddress, _value, _gasPrice, _data, &contractCode(_receiveAddress));
+ bool revert = false;
- // Write state out only in the case of a non-excepted transaction.
- if (revert)
- evm.revert();
-
- *_gas = vm.gas();
+ try
+ {
+ auto out = vm.go(evm);
+ memcpy(_out.data(), out.data(), std::min(out.size(), _out.size()));
+ }
+ catch (OutOfGas const& /*_e*/)
+ {
+ clog(StateChat) << "Out of Gas! Reverting.";
+ revert = true;
+ }
+ catch (VMException const& _e)
+ {
+ clog(StateChat) << "VM Exception: " << _e.description();
+ }
+ catch (Exception const& _e)
+ {
+ clog(StateChat) << "Exception in VM: " << _e.description();
+ }
+ catch (std::exception const& _e)
+ {
+ clog(StateChat) << "std::exception in VM: " << _e.what();
+ }
- return !revert;
-}
+ // Write state out only in the case of a non-excepted transaction.
+ if (revert)
+ evm.revert();
-h160 State::create(Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, bytesConstRef _init)
-{
- Transaction t;
- t.value = _endowment;
- t.gasPrice = _gasPrice;
- t.gas = *_gas;
- t.nonce = transactionsFrom(_txSender);
- t.init = _init.toBytes();
- t.data = _code.toBytes();
+ *_gas = vm.gas();
- return create(t, _txSender, _gas);
+ return !revert;
+ }
+ return true;
}
-Address State::create(Transaction const& _t, Address _sender, u256* _gas)
+h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, bytesConstRef _init)
{
- Address newAddress = right160(_t.sha3(false));
+ Address newAddress = right160(sha3(rlpList(_sender, transactionsFrom(_sender))));
while (isContractAddress(newAddress) || isNormalAddress(newAddress))
newAddress = (u160)newAddress + 1;
// Set up new account...
- m_cache[newAddress] = AddressState(0, 0, &_t.data);
+ m_cache[newAddress] = AddressState(0, 0, _code);
// Execute _init.
VM vm(*_gas);
- ExtVM evm(*this, newAddress, _sender, _t.value, _t.gasPrice, bytesConstRef(), &_t.init);
+ ExtVM evm(*this, newAddress, _sender, _endowment, _gasPrice, bytesConstRef(), _init);
bool revert = false;
// Increment associated nonce for sender.
diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp
index 713e4bb29..ca5c7ad93 100644
--- a/libethereum/Transaction.cpp
+++ b/libethereum/Transaction.cpp
@@ -119,7 +119,7 @@ void Transaction::sign(Secret _priv)
void Transaction::fillStream(RLPStream& _s, bool _sig) const
{
- _s.appendList((_sig ? 3 : 0) + (isCreation() ? 6 : 7));
+ _s.appendList((_sig ? 3 : 0) + (isCreation() ? 7 : 6));
_s << nonce << value << receiveAddress << gasPrice << gas << data;
if (isCreation())
_s << init;