Browse Source

Minor GUI fixes.

cl-refactor
Gav Wood 11 years ago
parent
commit
bb836d0989
  1. 28
      alethzero/MainWin.cpp
  2. 2
      libethereum/Instruction.cpp
  3. 48
      libethereum/State.cpp
  4. 2
      libethereum/Transaction.cpp

28
alethzero/MainWin.cpp

@ -438,39 +438,23 @@ void Main::on_contracts_currentItemChanged()
stringstream s; stringstream s;
auto mem = state().contractMemory(h); auto mem = state().contractMemory(h);
u256 next = 0; u256 next = 0;
unsigned numerics = 0;
bool unexpectedNumeric = false;
for (auto const& i: mem) for (auto const& i: mem)
{ {
if (next < i.first) if (next < i.first)
{ {
unsigned j; unsigned j;
for (j = 0; j <= numerics && next + j < i.first; ++j) for (j = 0; next + j < i.first; ++j)
s << (j < numerics || unexpectedNumeric ? " 0" : " <b>STOP</b>"); s << " 0";
unexpectedNumeric = false;
numerics -= min(numerics, j);
if (next + j < i.first) if (next + j < i.first)
s << " ...<br/>@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;"; s << " ...<br/>@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;";
} }
else if (!next) else if (!next)
s << "@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;"; s << "@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;";
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; s << " " << showbase << hex << i.second;
}
else
{
auto const& ii = iit->second;
s << " <b>" << ii.name << "</b>";
numerics = ii.additional;
}
next = i.first + 1; next = i.first + 1;
} }
s << "<br/><br/>Code:";
s << "<br/>" << disassemble(state().contractCode(h));
ui->contractInfo->appendHtml(QString::fromStdString(s.str())); ui->contractInfo->appendHtml(QString::fromStdString(s.str()));
} }
m_client->unlock(); m_client->unlock();
@ -568,11 +552,15 @@ u256 Main::fee() const
u256 Main::value() const u256 Main::value() const
{ {
if (ui->valueUnits->currentIndex() == -1)
return 0;
return ui->value->value() * units()[units().size() - 1 - ui->valueUnits->currentIndex()].first; return ui->value->value() * units()[units().size() - 1 - ui->valueUnits->currentIndex()].first;
} }
u256 Main::gasPrice() const u256 Main::gasPrice() const
{ {
if (ui->gasPriceUnits->currentIndex() == -1)
return 0;
return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first; return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first;
} }

2
libethereum/Instruction.cpp

@ -414,7 +414,7 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
{ {
bytes codes; bytes codes;
vector<unsigned> locs; vector<unsigned> locs;
if (compileLispFragment(d, e, _quiet, codes, locs)) if (compileLispFragment(d, e, _quiet, codes, locs) != -1)
{ {
appendCode(o_code, o_locs, codes, locs); appendCode(o_code, o_locs, codes, locs);
while (compileLispFragment(d, e, _quiet, codes, locs) != -1) while (compileLispFragment(d, e, _quiet, codes, locs) != -1)

48
libethereum/State.cpp

@ -655,26 +655,20 @@ void State::execute(bytesConstRef _rlp)
subBalance(sender, cost); subBalance(sender, cost);
if (t.isCreation()) if (t.isCreation())
{ create(sender, t.value, t.gasPrice, &gas, &t.data, &t.init);
create(t, sender, &gas);
}
else 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) << ")"; cnote << "Refunding" << formatBalance(gas * t.gasPrice) << "to sender (=" << gas << "*" << formatBalance(t.gasPrice) << ")";
addBalance(sender, gas * t.gasPrice); addBalance(sender, gas * t.gasPrice);
u256 gasSpent = (t.gas - gas) * t.gasPrice; u256 gasSpent = (t.gas - gas) * t.gasPrice;
unsigned c_feesKept = 8; /* unsigned c_feesKept = 8;
u256 feesEarned = gasSpent - (gasSpent / c_feesKept); 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)."; 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); addBalance(m_currentBlock.coinbaseAddress, feesEarned);
// Add to the user-originated transactions that we've executed. // Add to the user-originated transactions that we've executed.
@ -682,10 +676,15 @@ void State::execute(bytesConstRef _rlp)
m_transactionSet.insert(t.sha3()); 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)
{ {
cnote << "Transferring" << formatBalance(_value) << "to receiver.";
addBalance(_receiveAddress, _value);
if (isContractAddress(_receiveAddress))
{
VM vm(*_gas); VM vm(*_gas);
ExtVM evm(*this, _myAddress, _txSender, _txValue, _gasPrice, _txData, &contractCode(_myAddress)); ExtVM evm(*this, _receiveAddress, _sendAddress, _value, _gasPrice, _data, &contractCode(_receiveAddress));
bool revert = false; bool revert = false;
try try
@ -718,33 +717,22 @@ bool State::call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gas
*_gas = vm.gas(); *_gas = vm.gas();
return !revert; return !revert;
}
return true;
} }
h160 State::create(Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, bytesConstRef _init) h160 State::create(Address _sender, 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();
return create(t, _txSender, _gas);
}
Address State::create(Transaction const& _t, Address _sender, u256* _gas)
{ {
Address newAddress = right160(_t.sha3(false)); Address newAddress = right160(sha3(rlpList(_sender, transactionsFrom(_sender))));
while (isContractAddress(newAddress) || isNormalAddress(newAddress)) while (isContractAddress(newAddress) || isNormalAddress(newAddress))
newAddress = (u160)newAddress + 1; newAddress = (u160)newAddress + 1;
// Set up new account... // Set up new account...
m_cache[newAddress] = AddressState(0, 0, &_t.data); m_cache[newAddress] = AddressState(0, 0, _code);
// Execute _init. // Execute _init.
VM vm(*_gas); 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; bool revert = false;
// Increment associated nonce for sender. // Increment associated nonce for sender.

2
libethereum/Transaction.cpp

@ -119,7 +119,7 @@ void Transaction::sign(Secret _priv)
void Transaction::fillStream(RLPStream& _s, bool _sig) const 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; _s << nonce << value << receiveAddress << gasPrice << gas << data;
if (isCreation()) if (isCreation())
_s << init; _s << init;

Loading…
Cancel
Save