Browse Source

Unify block numbers into BlockNumber type.

Uniformally handle 'latest' & 'pending'.
cl-refactor
Gav Wood 10 years ago
parent
commit
e57d6ae633
  1. 12
      alethzero/MainWin.cpp
  2. 4
      alethzero/Transact.cpp
  3. 8
      eth/main.cpp
  4. 11
      libethcore/Common.h
  5. 24
      libethereum/Client.cpp
  6. 21
      libethereum/Client.h
  7. 22
      libethereum/Interface.h
  8. 4
      libethereum/LogFilter.cpp
  9. 9
      libethereum/LogFilter.h
  10. 16
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  11. 18
      mix/MixClient.cpp
  12. 19
      mix/MixClient.h
  13. 12
      neth/main.cpp
  14. 20
      third/MainWin.cpp

12
alethzero/MainWin.cpp

@ -312,7 +312,7 @@ void Main::installBalancesWatch()
Address coinsAddr = getCurrencies(); Address coinsAddr = getCurrencies();
// TODO: Update for new currencies reg. // TODO: Update for new currencies reg.
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1))); altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys) for (auto i: m_myKeys)
for (auto c: altCoins) for (auto c: altCoins)
@ -616,10 +616,10 @@ QString Main::lookup(QString const& _a) const
h256 ret; h256 ret;
// TODO: fix with the new DNSreg contract // TODO: fix with the new DNSreg contract
// if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, 0)) // if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, PendingBlock))
// ret = ethereum()->stateAt(dnsReg, n); // ret = ethereum()->stateAt(dnsReg, n);
/* if (!ret) /* if (!ret)
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, PendingBlock))
ret = ethereum()->stateAt(nameReg, n2); ret = ethereum()->stateAt(nameReg, n2);
*/ */
if (ret && !((u256)ret >> 32)) if (ret && !((u256)ret >> 32))
@ -937,7 +937,7 @@ void Main::refreshBalances()
u256 totalBalance = 0; u256 totalBalance = 0;
/* map<Address, tuple<QString, u256, u256>> altCoins; /* map<Address, tuple<QString, u256, u256>> altCoins;
Address coinsAddr = getCurrencies(); Address coinsAddr = getCurrencies();
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
{ {
auto n = ethereum()->stateAt(coinsAddr, i + 1); auto n = ethereum()->stateAt(coinsAddr, i + 1);
auto addr = right160(ethereum()->stateAt(coinsAddr, n)); auto addr = right160(ethereum()->stateAt(coinsAddr, n));
@ -1357,7 +1357,7 @@ void Main::on_transactionQueue_currentItemChanged()
auto r = receipt.rlp(); auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>"; s << "<div>Receipt: " << toString(RLP(r)) << "</div>";
s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>"; s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>";
s << renderDiff(ethereum()->diff(i, 0)); s << renderDiff(ethereum()->diff(i, PendingBlock));
// s << "Pre: " << fs.rootHash() << "<br/>"; // s << "Pre: " << fs.rootHash() << "<br/>";
// s << "Post: <b>" << ts.rootHash() << "</b>"; // s << "Post: <b>" << ts.rootHash() << "</b>";
} }
@ -1550,7 +1550,7 @@ void Main::on_debugCurrent_triggered()
unsigned txi = item->data(Qt::UserRole + 1).toInt(); unsigned txi = item->data(Qt::UserRole + 1).toInt();
bytes t = ethereum()->blockChain().transaction(h, txi); bytes t = ethereum()->blockChain().transaction(h, txi);
State s(ethereum()->state(txi, h)); State s(ethereum()->state(txi, h));
Executive e(s, ethereum()->blockChain(), 0); Executive e(s, ethereum()->blockChain(), PendingBlock);
Debugger dw(this, this); Debugger dw(this, this);
dw.populate(e, Transaction(t, CheckSignature::Sender)); dw.populate(e, Transaction(t, CheckSignature::Sender));
dw.exec(); dw.exec();

4
alethzero/Transact.cpp

@ -301,7 +301,7 @@ void Transact::rejigData()
auto to = m_context->fromString(ui->destination->currentText()); auto to = m_context->fromString(ui->destination->currentText());
QString natspec; QString natspec;
QString errs; QString errs;
if (ethereum()->codeAt(to, 0).size()) if (ethereum()->codeAt(to, PendingBlock).size())
{ {
string userNotice = m_natSpecDB->getUserNotice(ethereum()->postState().codeHash(to), m_data); string userNotice = m_natSpecDB->getUserNotice(ethereum()->postState().codeHash(to), m_data);
if (userNotice.empty()) if (userNotice.empty())
@ -362,7 +362,7 @@ Secret Transact::findSecret(u256 _totalReq) const
{ {
if (ethereum()) if (ethereum())
for (auto const& i: m_myKeys) for (auto const& i: m_myKeys)
if (ethereum()->balanceAt(i.address(), 0) >= _totalReq) if (ethereum()->balanceAt(i.address(), PendingBlock) >= _totalReq)
return i.secret(); return i.secret();
return Secret(); return Secret();
} }

8
eth/main.cpp

@ -687,7 +687,7 @@ int main(int argc, char** argv)
auto acs =c->addresses(); auto acs =c->addresses();
string ss; string ss;
for (auto const& i: acs) for (auto const& i: acs)
if ( c->codeAt(i, 0).size()) if ( c->codeAt(i, PendingBlock).size())
{ {
ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]"; ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl; cout << ss << endl;
@ -698,7 +698,7 @@ int main(int argc, char** argv)
auto acs =c->addresses(); auto acs =c->addresses();
string ss; string ss;
for (auto const& i: acs) for (auto const& i: acs)
if ( c->codeAt(i, 0).empty()) if ( c->codeAt(i, PendingBlock).empty())
{ {
ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]"; ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl; cout << ss << endl;
@ -890,10 +890,10 @@ int main(int argc, char** argv)
try try
{ {
auto storage =c->storageAt(h, 0); auto storage =c->storageAt(h, PendingBlock);
for (auto const& i: storage) for (auto const& i: storage)
s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl; s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl;
s << endl << disassemble( c->codeAt(h, 0)) << endl; s << endl << disassemble( c->codeAt(h, PendingBlock)) << endl;
string outFile = getDataDir() + "/" + rechex + ".evm"; string outFile = getDataDir() + "/" + rechex + ".evm";
ofstream ofs; ofstream ofs;

11
libethcore/Common.h

@ -71,5 +71,16 @@ static const u256 wei = exp10<0>();
using Nonce = h64; using Nonce = h64;
using BlockNumber = unsigned;
static const BlockNumber LatestBlock = (BlockNumber)-2;
static const BlockNumber PendingBlock = (BlockNumber)-1;
enum class RelativeBlock: BlockNumber
{
Latest = LatestBlock,
Pending = PendingBlock
};
} }
} }

24
libethereum/Client.cpp

@ -491,7 +491,7 @@ void Client::submitTransaction(Secret _secret, u256 _value, Address _dest, bytes
m_tq.attemptImport(t.rlp()); m_tq.attemptImport(t.rlp());
} }
ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
ExecutionResult ret; ExecutionResult ret;
try try
@ -514,7 +514,7 @@ ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes c
return ret; return ret;
} }
ExecutionResult Client::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) ExecutionResult Client::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
ExecutionResult ret; ExecutionResult ret;
try try
@ -739,12 +739,12 @@ unsigned Client::numberOf(int _n) const
return m_bc.details().number + max(-(int)m_bc.details().number, 1 + _n); return m_bc.details().number + max(-(int)m_bc.details().number, 1 + _n);
} }
State Client::asOf(int _h) const State Client::asOf(unsigned _h) const
{ {
ReadGuard l(x_stateDB); ReadGuard l(x_stateDB);
if (_h == 0) if (_h == PendingBlock)
return m_postMine; return m_postMine;
else if (_h == -1) else if (_h == LatestBlock)
return m_preMine; return m_preMine;
else else
return State(m_stateDB, m_bc, m_bc.numberHash(numberOf(_h))); return State(m_stateDB, m_bc, m_bc.numberHash(numberOf(_h)));
@ -768,7 +768,7 @@ eth::State Client::state(unsigned _txi) const
return m_postMine.fromPending(_txi); return m_postMine.fromPending(_txi);
} }
StateDiff Client::diff(unsigned _txi, int _block) const StateDiff Client::diff(unsigned _txi, BlockNumber _block) const
{ {
State st = asOf(_block); State st = asOf(_block);
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
@ -780,7 +780,7 @@ StateDiff Client::diff(unsigned _txi, h256 _block) const
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
std::vector<Address> Client::addresses(int _block) const std::vector<Address> Client::addresses(BlockNumber _block) const
{ {
vector<Address> ret; vector<Address> ret;
for (auto const& i: asOf(_block).addresses()) for (auto const& i: asOf(_block).addresses())
@ -788,27 +788,27 @@ std::vector<Address> Client::addresses(int _block) const
return ret; return ret;
} }
u256 Client::balanceAt(Address _a, int _block) const u256 Client::balanceAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).balance(_a); return asOf(_block).balance(_a);
} }
std::map<u256, u256> Client::storageAt(Address _a, int _block) const std::map<u256, u256> Client::storageAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).storage(_a); return asOf(_block).storage(_a);
} }
u256 Client::countAt(Address _a, int _block) const u256 Client::countAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).transactionsFrom(_a); return asOf(_block).transactionsFrom(_a);
} }
u256 Client::stateAt(Address _a, u256 _l, int _block) const u256 Client::stateAt(Address _a, u256 _l, BlockNumber _block) const
{ {
return asOf(_block).storage(_a, _l); return asOf(_block).storage(_a, _l);
} }
bytes Client::codeAt(Address _a, int _block) const bytes Client::codeAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).code(_a); return asOf(_block).code(_a);
} }

21
libethereum/Client.h

@ -225,11 +225,11 @@ public:
virtual void flushTransactions() override; virtual void flushTransactions() override;
/// Makes the given call. Nothing is recorded into the state. /// Makes the given call. Nothing is recorded into the state.
virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) override; virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = PendingBlock) override;
/// Does the given creation. Nothing is recorded into the state. /// Does the given creation. Nothing is recorded into the state.
/// @returns the pair of the Address of the created contract together with its code. /// @returns the pair of the Address of the created contract together with its code.
virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) override; virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = PendingBlock) override;
/// Makes the given call. Nothing is recorded into the state. This cheats by creating a null address and endowing it with a lot of ETH. /// Makes the given call. Nothing is recorded into the state. This cheats by creating a null address and endowing it with a lot of ETH.
ExecutionResult call(Address _dest, bytes const& _data = bytes(), u256 _gas = 125000, u256 _value = 0, u256 _gasPrice = 1 * ether); ExecutionResult call(Address _dest, bytes const& _data = bytes(), u256 _gas = 125000, u256 _value = 0, u256 _gasPrice = 1 * ether);
@ -244,11 +244,11 @@ public:
using Interface::codeAt; using Interface::codeAt;
using Interface::storageAt; using Interface::storageAt;
virtual u256 balanceAt(Address _a, int _block) const; virtual u256 balanceAt(Address _a, BlockNumber _block) const;
virtual u256 countAt(Address _a, int _block) const; virtual u256 countAt(Address _a, BlockNumber _block) const;
virtual u256 stateAt(Address _a, u256 _l, int _block) const; virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const;
virtual bytes codeAt(Address _a, int _block) const; virtual bytes codeAt(Address _a, BlockNumber _block) const;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const; virtual std::map<u256, u256> storageAt(Address _a, BlockNumber _block) const;
virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override; virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;
virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override; virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override;
@ -282,11 +282,11 @@ public:
/// Differences between transactions. /// Differences between transactions.
using Interface::diff; using Interface::diff;
virtual StateDiff diff(unsigned _txi, h256 _block) const; virtual StateDiff diff(unsigned _txi, h256 _block) const;
virtual StateDiff diff(unsigned _txi, int _block) const; virtual StateDiff diff(unsigned _txi, BlockNumber _block) const;
/// Get a list of all active addresses. /// Get a list of all active addresses.
using Interface::addresses; using Interface::addresses;
virtual std::vector<Address> addresses(int _block) const; virtual std::vector<Address> addresses(BlockNumber _block) const;
/// Get the remaining gas limit in this block. /// Get the remaining gas limit in this block.
virtual u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); } virtual u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); }
@ -383,7 +383,8 @@ private:
/// Return the actual block number of the block with the given int-number (positive is the same, INT_MIN is genesis block, < 0 is negative age, thus -1 is most recently mined, 0 is pending. /// Return the actual block number of the block with the given int-number (positive is the same, INT_MIN is genesis block, < 0 is negative age, thus -1 is most recently mined, 0 is pending.
unsigned numberOf(int _b) const; unsigned numberOf(int _b) const;
State asOf(int _h) const; /// Returns the state object for the full block (i.e. the terminal state) for index _h.
/// Works properly with LatestBlock and PendingBlock.
State asOf(unsigned _h) const; State asOf(unsigned _h) const;
VersionChecker m_vc; ///< Dummy object to check & update the protocol version. VersionChecker m_vc; ///< Dummy object to check & update the protocol version.

22
libethereum/Interface.h

@ -73,16 +73,16 @@ public:
virtual void flushTransactions() = 0; virtual void flushTransactions() = 0;
/// Makes the given call. Nothing is recorded into the state. /// Makes the given call. Nothing is recorded into the state.
virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) = 0; virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = 0) = 0;
/// Does the given creation. Nothing is recorded into the state. /// Does the given creation. Nothing is recorded into the state.
/// @returns the pair of the Address of the created contract together with its code. /// @returns the pair of the Address of the created contract together with its code.
virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) = 0; virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = 0) = 0;
// [STATE-QUERY API] // [STATE-QUERY API]
int getDefault() const { return m_default; } int getDefault() const { return m_default; }
void setDefault(int _block) { m_default = _block; } void setDefault(BlockNumber _block) { m_default = _block; }
u256 balanceAt(Address _a) const { return balanceAt(_a, m_default); } u256 balanceAt(Address _a) const { return balanceAt(_a, m_default); }
u256 countAt(Address _a) const { return countAt(_a, m_default); } u256 countAt(Address _a) const { return countAt(_a, m_default); }
@ -90,11 +90,11 @@ public:
bytes codeAt(Address _a) const { return codeAt(_a, m_default); } bytes codeAt(Address _a) const { return codeAt(_a, m_default); }
std::map<u256, u256> storageAt(Address _a) const { return storageAt(_a, m_default); } std::map<u256, u256> storageAt(Address _a) const { return storageAt(_a, m_default); }
virtual u256 balanceAt(Address _a, int _block) const = 0; virtual u256 balanceAt(Address _a, BlockNumber _block) const = 0;
virtual u256 countAt(Address _a, int _block) const = 0; virtual u256 countAt(Address _a, BlockNumber _block) const = 0;
virtual u256 stateAt(Address _a, u256 _l, int _block) const = 0; virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const = 0;
virtual bytes codeAt(Address _a, int _block) const = 0; virtual bytes codeAt(Address _a, BlockNumber _block) const = 0;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const = 0; virtual std::map<u256, u256> storageAt(Address _a, BlockNumber _block) const = 0;
// [LOGS API] // [LOGS API]
@ -135,11 +135,11 @@ public:
/// Differences between transactions. /// Differences between transactions.
StateDiff diff(unsigned _txi) const { return diff(_txi, m_default); } StateDiff diff(unsigned _txi) const { return diff(_txi, m_default); }
virtual StateDiff diff(unsigned _txi, h256 _block) const = 0; virtual StateDiff diff(unsigned _txi, h256 _block) const = 0;
virtual StateDiff diff(unsigned _txi, int _block) const = 0; virtual StateDiff diff(unsigned _txi, BlockNumber _block) const = 0;
/// Get a list of all active addresses. /// Get a list of all active addresses.
virtual Addresses addresses() const { return addresses(m_default); } virtual Addresses addresses() const { return addresses(m_default); }
virtual Addresses addresses(int _block) const = 0; virtual Addresses addresses(BlockNumber _block) const = 0;
/// Get the fee associated for a transaction with the given data. /// Get the fee associated for a transaction with the given data.
template <class T> static bigint txGas(T const& _data, u256 _gas = 0) { bigint ret = c_txGas + _gas; for (auto i: _data) ret += i ? c_txDataNonZeroGas : c_txDataZeroGas; return ret; } template <class T> static bigint txGas(T const& _data, u256 _gas = 0) { bigint ret = c_txGas + _gas; for (auto i: _data) ret += i ? c_txDataNonZeroGas : c_txDataZeroGas; return ret; }
@ -177,7 +177,7 @@ public:
virtual MineProgress miningProgress() const = 0; virtual MineProgress miningProgress() const = 0;
protected: protected:
int m_default = -1; int m_default = PendingBlock;
}; };
class Watch; class Watch;

4
libethereum/LogFilter.cpp

@ -46,7 +46,7 @@ h256 LogFilter::sha3() const
return dev::sha3(s.out()); return dev::sha3(s.out());
} }
static bool isNoLater(RelativeBlock _logBlockRelation, u256 _logBlockNumber, int _latest) static bool isNoLater(RelativeBlock _logBlockRelation, u256 _logBlockNumber, unsigned _latest)
{ {
if (_latest == PendingBlock) if (_latest == PendingBlock)
return true; return true;
@ -56,7 +56,7 @@ static bool isNoLater(RelativeBlock _logBlockRelation, u256 _logBlockNumber, int
return _logBlockNumber <= _latest; return _logBlockNumber <= _latest;
} }
static bool isNoEarlier(RelativeBlock _logBlockRelation, u256 _logBlockNumber, int _earliest) static bool isNoEarlier(RelativeBlock _logBlockRelation, u256 _logBlockNumber, unsigned _earliest)
{ {
if (_earliest == PendingBlock) if (_earliest == PendingBlock)
return _logBlockRelation == RelativeBlock::Pending; return _logBlockRelation == RelativeBlock::Pending;

9
libethereum/LogFilter.h

@ -42,15 +42,6 @@ std::ostream& operator<<(std::ostream& _out, dev::eth::LogFilter const& _s);
class State; class State;
enum class RelativeBlock
{
Latest,
Pending
};
static const unsigned LatestBlock = (unsigned)-2;
static const unsigned PendingBlock = (unsigned)-1;
class LogFilter class LogFilter
{ {
public: public:

16
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -139,7 +139,7 @@ static Json::Value toJson(map<u256, u256> const& _storage)
return res; return res;
} }
static unsigned jsToBlockIndex(std::string const& _js) static unsigned toBlockNumber(std::string const& _js)
{ {
if (_js == "latest") if (_js == "latest")
return LatestBlock; return LatestBlock;
@ -159,9 +159,9 @@ static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to
// check only !empty. it should throw exceptions if input params are incorrect // check only !empty. it should throw exceptions if input params are incorrect
if (!_json["fromBlock"].empty()) if (!_json["fromBlock"].empty())
filter.withEarliest(jsToBlockIndex(_json["fromBlock"].asString())); filter.withEarliest(toBlockNumber(_json["fromBlock"].asString()));
if (!_json["toBlock"].empty()) if (!_json["toBlock"].empty())
filter.withLatest(jsToBlockIndex(_json["toBlock"].asString())); filter.withLatest(toBlockNumber(_json["toBlock"].asString()));
if (!_json["address"].empty()) if (!_json["address"].empty())
{ {
if (_json["address"].isArray()) if (_json["address"].isArray())
@ -239,16 +239,6 @@ static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message
return res; return res;
} }
// TODO: convert to jsToBlockNumber, downstream. too.
static int toBlockNumber(string const& _string)
{
if (_string.compare("latest") == 0)
return -1;
if (_string.compare("pending") == 0)
return 0;
return jsToInt(_string);
}
WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts): WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts):
AbstractWebThreeStubServer(_conn), m_accounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this))) AbstractWebThreeStubServer(_conn), m_accounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this)))
{ {

18
mix/MixClient.cpp

@ -283,7 +283,7 @@ void MixClient::flushTransactions()
{ {
} }
dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
u256 n; u256 n;
State temp; State temp;
@ -299,7 +299,7 @@ dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _
return lastExecution().result; return lastExecution().result;
} }
dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
u256 n; u256 n;
State temp; State temp;
@ -315,27 +315,27 @@ dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes c
return lastExecution().result; return lastExecution().result;
} }
u256 MixClient::balanceAt(Address _a, int _block) const u256 MixClient::balanceAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).balance(_a); return asOf(_block).balance(_a);
} }
u256 MixClient::countAt(Address _a, int _block) const u256 MixClient::countAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).transactionsFrom(_a); return asOf(_block).transactionsFrom(_a);
} }
u256 MixClient::stateAt(Address _a, u256 _l, int _block) const u256 MixClient::stateAt(Address _a, u256 _l, BlockNumber _block) const
{ {
return asOf(_block).storage(_a, _l); return asOf(_block).storage(_a, _l);
} }
bytes MixClient::codeAt(Address _a, int _block) const bytes MixClient::codeAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).code(_a); return asOf(_block).code(_a);
} }
std::map<u256, u256> MixClient::storageAt(Address _a, int _block) const std::map<u256, u256> MixClient::storageAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).storage(_a); return asOf(_block).storage(_a);
} }
@ -567,13 +567,13 @@ eth::StateDiff MixClient::diff(unsigned _txi, h256 _block) const
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
eth::StateDiff MixClient::diff(unsigned _txi, int _block) const eth::StateDiff MixClient::diff(unsigned _txi, BlockNumber _block) const
{ {
State st = asOf(_block); State st = asOf(_block);
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
Addresses MixClient::addresses(int _block) const Addresses MixClient::addresses(BlockNumber _block) const
{ {
Addresses ret; Addresses ret;
for (auto const& i: asOf(_block).addresses()) for (auto const& i: asOf(_block).addresses())

19
mix/MixClient.h

@ -25,6 +25,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <libethcore/Common.h>
#include <libethereum/Interface.h> #include <libethereum/Interface.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include "MachineStates.h" #include "MachineStates.h"
@ -52,13 +53,13 @@ public:
Address submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override; Address submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override;
void inject(bytesConstRef _rlp) override; void inject(bytesConstRef _rlp) override;
void flushTransactions() override; void flushTransactions() override;
dev::eth::ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) override; dev::eth::ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber) override;
dev::eth::ExecutionResult create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) override; dev::eth::ExecutionResult create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber) override;
u256 balanceAt(Address _a, int _block) const override; u256 balanceAt(Address _a, eth::BlockNumber _block) const override;
u256 countAt(Address _a, int _block) const override; u256 countAt(Address _a, eth::BlockNumber _block) const override;
u256 stateAt(Address _a, u256 _l, int _block) const override; u256 stateAt(Address _a, u256 _l, eth::BlockNumber _block) const override;
bytes codeAt(Address _a, int _block) const override; bytes codeAt(Address _a, eth::BlockNumber _block) const override;
std::map<u256, u256> storageAt(Address _a, int _block) const override; std::map<u256, u256> storageAt(Address _a, eth::BlockNumber _block) const override;
eth::LocalisedLogEntries logs(unsigned _watchId) const override; eth::LocalisedLogEntries logs(unsigned _watchId) const override;
eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override; eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override;
unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override; unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override;
@ -79,8 +80,8 @@ public:
unsigned number() const override; unsigned number() const override;
eth::Transactions pending() const override; eth::Transactions pending() const override;
eth::StateDiff diff(unsigned _txi, h256 _block) const override; eth::StateDiff diff(unsigned _txi, h256 _block) const override;
eth::StateDiff diff(unsigned _txi, int _block) const override; eth::StateDiff diff(unsigned _txi, eth::BlockNumber _block) const override;
Addresses addresses(int _block) const override; Addresses addresses(eth::BlockNumber _block) const override;
u256 gasLimitRemaining() const override; u256 gasLimitRemaining() const override;
void setAddress(Address _us) override; void setAddress(Address _us) override;
Address address() const override; Address address() const override;

12
neth/main.cpp

@ -954,7 +954,7 @@ int main(int argc, char** argv)
auto s = t.receiveAddress() ? auto s = t.receiveAddress() ?
boost::format(" %1% %2%> %3%: %4% [%5%]") % boost::format(" %1% %2%> %3%: %4% [%5%]") %
toString(t.safeSender()) % toString(t.safeSender()) %
(c->codeAt(t.receiveAddress(), 0).size() ? '*' : '-') % (c->codeAt(t.receiveAddress(), PendingBlock).size() ? '*' : '-') %
toString(t.receiveAddress()) % toString(t.receiveAddress()) %
toString(formatBalance(t.value())) % toString(formatBalance(t.value())) %
toString((unsigned)t.nonce()) : toString((unsigned)t.nonce()) :
@ -979,7 +979,7 @@ int main(int argc, char** argv)
auto s = t.receiveAddress() ? auto s = t.receiveAddress() ?
boost::format("%1% %2%> %3%: %4% [%5%]") % boost::format("%1% %2%> %3%: %4% [%5%]") %
toString(t.safeSender()) % toString(t.safeSender()) %
(c->codeAt(t.receiveAddress(), 0).size() ? '*' : '-') % (c->codeAt(t.receiveAddress(), PendingBlock).size() ? '*' : '-') %
toString(t.receiveAddress()) % toString(t.receiveAddress()) %
toString(formatBalance(t.value())) % toString(formatBalance(t.value())) %
toString((unsigned)t.nonce()) : toString((unsigned)t.nonce()) :
@ -999,25 +999,25 @@ int main(int argc, char** argv)
int cc = 1; int cc = 1;
auto acs = c->addresses(); auto acs = c->addresses();
for (auto const& i: acs) for (auto const& i: acs)
if (c->codeAt(i, 0).size()) if (c->codeAt(i, PendingBlock).size())
{ {
auto s = boost::format("%1%%2% : %3% [%4%]") % auto s = boost::format("%1%%2% : %3% [%4%]") %
toString(i) % toString(i) %
pretty(i, c->postState()) % pretty(i, c->postState()) %
toString(formatBalance(c->balanceAt(i))) % toString(formatBalance(c->balanceAt(i))) %
toString((unsigned)c->countAt(i, 0)); toString((unsigned)c->countAt(i, PendingBlock));
mvwaddnstr(contractswin, cc++, x, s.str().c_str(), qwidth); mvwaddnstr(contractswin, cc++, x, s.str().c_str(), qwidth);
if (cc > qheight - 2) if (cc > qheight - 2)
break; break;
} }
for (auto const& i: acs) for (auto const& i: acs)
if (c->codeAt(i, 0).empty()) if (c->codeAt(i, PendingBlock).empty())
{ {
auto s = boost::format("%1%%2% : %3% [%4%]") % auto s = boost::format("%1%%2% : %3% [%4%]") %
toString(i) % toString(i) %
pretty(i, c->postState()) % pretty(i, c->postState()) %
toString(formatBalance(c->balanceAt(i))) % toString(formatBalance(c->balanceAt(i))) %
toString((unsigned)c->countAt(i, 0)); toString((unsigned)c->countAt(i, PendingBlock));
mvwaddnstr(addswin, y++, x, s.str().c_str(), width / 2 - 4); mvwaddnstr(addswin, y++, x, s.str().c_str(), width / 2 - 4);
if (y > height * 3 / 5 - 4) if (y > height * 3 / 5 - 4)
break; break;

20
third/MainWin.cpp

@ -212,13 +212,13 @@ void Main::installWatches()
void Main::installNameRegWatch() void Main::installNameRegWatch()
{ {
ethereum()->uninstallWatch(m_nameRegFilter); ethereum()->uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, 0))), [=](LocalisedLogEntries const&){ onNameRegChange(); }); m_nameRegFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, PendingBlock))), [=](LocalisedLogEntries const&){ onNameRegChange(); });
} }
void Main::installCurrenciesWatch() void Main::installCurrenciesWatch()
{ {
ethereum()->uninstallWatch(m_currenciesFilter); ethereum()->uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, 1))), [=](LocalisedLogEntries const&){ onCurrenciesChange(); }); m_currenciesFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, LatestBlock))), [=](LocalisedLogEntries const&){ onCurrenciesChange(); });
} }
void Main::installBalancesWatch() void Main::installBalancesWatch()
@ -226,8 +226,8 @@ void Main::installBalancesWatch()
dev::eth::LogFilter tf; dev::eth::LogFilter tf;
vector<Address> altCoins; vector<Address> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1)); Address coinsAddr = right160(ethereum()->stateAt(c_config, LatestBlock));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1))); altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys) for (auto i: m_myKeys)
for (auto c: altCoins) for (auto c: altCoins)
@ -294,7 +294,7 @@ QString Main::pretty(dev::Address _a) const
{ {
h256 n; h256 n;
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, PendingBlock))
n = ethereum()->stateAt(nameReg, (u160)(_a)); n = ethereum()->stateAt(nameReg, (u160)(_a));
return fromRaw(n); return fromRaw(n);
@ -321,7 +321,7 @@ Address Main::fromString(QString const& _a) const
memset(n.data() + sn.size(), 0, 32 - sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size());
if (_a.size()) if (_a.size())
{ {
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, PendingBlock))
if (h256 a = ethereum()->stateAt(nameReg, n)) if (h256 a = ethereum()->stateAt(nameReg, n))
return right160(a); return right160(a);
} }
@ -350,10 +350,10 @@ QString Main::lookup(QString const& _a) const
*/ */
h256 ret; h256 ret;
if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, 0)) if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, PendingBlock))
ret = ethereum()->stateAt(dnsReg, n); ret = ethereum()->stateAt(dnsReg, n);
/* if (!ret) /* if (!ret)
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, PendingBlock))
ret = ethereum()->stateAt(nameReg, n2); ret = ethereum()->stateAt(nameReg, n2);
*/ */
if (ret && !((u256)ret >> 32)) if (ret && !((u256)ret >> 32))
@ -476,8 +476,8 @@ void Main::refreshBalances()
ui->ourAccounts->clear(); ui->ourAccounts->clear();
u256 totalBalance = 0; u256 totalBalance = 0;
map<Address, pair<QString, u256>> altCoins; map<Address, pair<QString, u256>> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1)); Address coinsAddr = right160(ethereum()->stateAt(c_config, LatestBlock));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins[right160(ethereum()->stateAt(coinsAddr, ethereum()->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(ethereum()->stateAt(coinsAddr, i + 1)), 0); altCoins[right160(ethereum()->stateAt(coinsAddr, ethereum()->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(ethereum()->stateAt(coinsAddr, i + 1)), 0);
for (auto i: m_myKeys) for (auto i: m_myKeys)
{ {

Loading…
Cancel
Save