Browse Source

getLastHashes fix.

AZ improvements.
JSAPI string fix.
cl-refactor
Gav Wood 10 years ago
parent
commit
10c08d6204
  1. 6
      alethzero/MainWin.cpp
  2. 10
      exp/main.cpp
  3. 2
      libethereum/Executive.cpp
  4. 30
      libethereum/State.cpp
  5. 6
      libethereum/State.h
  6. 4
      libjsqrc/ethereumjs/dist/ethereum.js
  7. 2
      libjsqrc/ethereumjs/dist/ethereum.js.map
  8. 2
      libjsqrc/ethereumjs/dist/ethereum.min.js
  9. 4
      libjsqrc/ethereumjs/lib/abi.js
  10. 4
      standard.js

6
alethzero/MainWin.cpp

@ -279,7 +279,7 @@ Address Main::getNameReg() const
Address Main::getCurrencies() const Address Main::getCurrencies() const
{ {
return abiOut<Address>(ethereum()->call(c_newConfig, abiIn("lookup(uint256)", (u256)2))); return abiOut<Address>(ethereum()->call(c_newConfig, abiIn("lookup(uint256)", (u256)3)));
} }
void Main::installNameRegWatch() void Main::installNameRegWatch()
@ -2140,7 +2140,9 @@ QString Main::prettyU256(dev::u256 _n) const
unsigned inc = 0; unsigned inc = 0;
QString raw; QString raw;
ostringstream s; ostringstream s;
if (!(_n >> 64)) if (_n > szabo && _n < 1000000 * ether)
s << "<span style=\"color: #215\">" << formatBalance(_n) << "</span> <span style=\"color: #448\">(0x" << hex << (uint64_t)_n << ")</span>";
else if (!(_n >> 64))
s << "<span style=\"color: #008\">" << (uint64_t)_n << "</span> <span style=\"color: #448\">(0x" << hex << (uint64_t)_n << ")</span>"; s << "<span style=\"color: #008\">" << (uint64_t)_n << "</span> <span style=\"color: #448\">(0x" << hex << (uint64_t)_n << ")</span>";
else if (!~(_n >> 64)) else if (!~(_n >> 64))
s << "<span style=\"color: #008\">" << (int64_t)_n << "</span> <span style=\"color: #448\">(0x" << hex << (int64_t)_n << ")</span>"; s << "<span style=\"color: #008\">" << (int64_t)_n << "</span> <span style=\"color: #448\">(0x" << hex << (int64_t)_n << ")</span>";

10
exp/main.cpp

@ -75,10 +75,10 @@ int main()
cnote << i;*/ cnote << i;*/
return 0; return 0;
} }
#else #elif 0
int main() int main()
{ {
KeyPair u = KeyPair::create(); KeyPair u = KeyPair::create();
KeyPair cb = KeyPair::create(); KeyPair cb = KeyPair::create();
OverlayDB db; OverlayDB db;
State s(cb.address(), db, BaseState::Empty); State s(cb.address(), db, BaseState::Empty);
@ -95,5 +95,11 @@ int main()
cnote << "State after transaction: " << s; cnote << "State after transaction: " << s;
cnote << before.diff(s); cnote << before.diff(s);
} }
#else
int main()
{
cnote << KeyPair(Secret("0000000000000000000000000000000000000000000000000000000000000000")).address();
cnote << KeyPair(Secret("1111111111111111111111111111111111111111111111111111111111111111")).address();
}
#endif #endif

2
libethereum/Executive.cpp

@ -35,7 +35,7 @@ using namespace dev::eth;
Executive::Executive(State& _s, BlockChain const& _bc, unsigned _level): Executive::Executive(State& _s, BlockChain const& _bc, unsigned _level):
m_s(_s), m_s(_s),
m_lastHashes(_s.getLastHashes(_bc)), m_lastHashes(_s.getLastHashes(_bc, (unsigned)_s.info().number - 1)),
m_depth(_level) m_depth(_level)
{} {}

30
libethereum/State.cpp

@ -418,7 +418,7 @@ TransactionReceipts State::sync(BlockChain const& _bc, TransactionQueue& _tq, bo
TransactionReceipts ret; TransactionReceipts ret;
auto ts = _tq.transactions(); auto ts = _tq.transactions();
auto lh = getLastHashes(_bc); auto lh = getLastHashes(_bc, _bc.number());
for (int goodTxs = 1; goodTxs;) for (int goodTxs = 1; goodTxs;)
{ {
@ -498,7 +498,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce)
GenericTrieDB<MemoryDB> receiptsTrie(&rm); GenericTrieDB<MemoryDB> receiptsTrie(&rm);
receiptsTrie.init(); receiptsTrie.init();
LastHashes lh = getLastHashes(_bc); LastHashes lh = getLastHashes(_bc, (unsigned)m_previousBlock.number);
// All ok with the block generally. Play back the transactions now... // All ok with the block generally. Play back the transactions now...
unsigned i = 0; unsigned i = 0;
@ -527,7 +527,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce)
cwarn << "Bad receipts state root."; cwarn << "Bad receipts state root.";
cwarn << "Block:" << toHex(_block); cwarn << "Block:" << toHex(_block);
cwarn << "Block RLP:" << RLP(_block); cwarn << "Block RLP:" << RLP(_block);
cwarn << "Want: " << receiptsTrie.root() << ", got: " << m_currentBlock.receiptsRoot; cwarn << "Calculated: " << receiptsTrie.root();
for (unsigned j = 0; j < i; ++j) for (unsigned j = 0; j < i; ++j)
{ {
RLPStream k; RLPStream k;
@ -538,6 +538,16 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce)
cwarn << "Hex: " << toHex(b); cwarn << "Hex: " << toHex(b);
cwarn << TransactionReceipt(&b); cwarn << TransactionReceipt(&b);
} }
cwarn << "Recorded: " << m_currentBlock.receiptsRoot;
auto rs = _bc.receipts(bi.hash);
for (unsigned j = 0; j < rs.receipts.size(); ++j)
{
auto b = rs.receipts[j].rlp();
cwarn << j << ": ";
cwarn << "RLP: " << RLP(b);
cwarn << "Hex: " << toHex(b);
cwarn << rs.receipts[j];
}
BOOST_THROW_EXCEPTION(InvalidReceiptsStateRoot()); BOOST_THROW_EXCEPTION(InvalidReceiptsStateRoot());
} }
@ -1000,19 +1010,29 @@ bool State::isTrieGood(bool _enforceRefs, bool _requireNoLeftOvers) const
return true; return true;
} }
LastHashes State::getLastHashes(BlockChain const& _bc) const LastHashes State::getLastHashes(BlockChain const& _bc, unsigned _n) const
{ {
LastHashes ret; LastHashes ret;
ret.resize(256); ret.resize(256);
if (c_protocolVersion > 49) if (c_protocolVersion > 49)
{ {
ret[0] = _bc.currentHash(); ret[0] = _bc.numberHash(_n);
for (unsigned i = 1; i < 256; ++i) for (unsigned i = 1; i < 256; ++i)
ret[i] = ret[i - 1] ? _bc.details(ret[i - 1]).parent : h256(); ret[i] = ret[i - 1] ? _bc.details(ret[i - 1]).parent : h256();
} }
return ret; return ret;
} }
u256 State::execute(BlockChain const& _bc, bytes const& _rlp, bytes* o_output, bool _commit)
{
return execute(getLastHashes(_bc, _bc.number()), &_rlp, o_output, _commit);
}
u256 State::execute(BlockChain const& _bc, bytesConstRef _rlp, bytes* o_output, bool _commit)
{
return execute(getLastHashes(_bc, _bc.number()), _rlp, o_output, _commit);
}
// TODO: maintain node overlay revisions for stateroots -> each commit gives a stateroot + OverlayDB; allow overlay copying for rewind operations. // TODO: maintain node overlay revisions for stateroots -> each commit gives a stateroot + OverlayDB; allow overlay copying for rewind operations.
u256 State::execute(LastHashes const& _lh, bytesConstRef _rlp, bytes* o_output, bool _commit) u256 State::execute(LastHashes const& _lh, bytesConstRef _rlp, bytes* o_output, bool _commit)
{ {

6
libethereum/State.h

@ -147,12 +147,12 @@ public:
/// Like sync but only operate on _tq, killing the invalid/old ones. /// Like sync but only operate on _tq, killing the invalid/old ones.
bool cull(TransactionQueue& _tq) const; bool cull(TransactionQueue& _tq) const;
LastHashes getLastHashes(BlockChain const& _bc) const; LastHashes getLastHashes(BlockChain const& _bc, unsigned _n) const;
/// Execute a given transaction. /// Execute a given transaction.
/// This will append @a _t to the transaction list and change the state accordingly. /// This will append @a _t to the transaction list and change the state accordingly.
u256 execute(BlockChain const& _bc, bytes const& _rlp, bytes* o_output = nullptr, bool _commit = true) { return execute(getLastHashes(_bc), &_rlp, o_output, _commit); } u256 execute(BlockChain const& _bc, bytes const& _rlp, bytes* o_output = nullptr, bool _commit = true);
u256 execute(BlockChain const& _bc, bytesConstRef _rlp, bytes* o_output = nullptr, bool _commit = true) { return execute(getLastHashes(_bc), _rlp, o_output, _commit); } u256 execute(BlockChain const& _bc, bytesConstRef _rlp, bytes* o_output = nullptr, bool _commit = true);
u256 execute(LastHashes const& _lh, bytes const& _rlp, bytes* o_output = nullptr, bool _commit = true) { return execute(_lh, &_rlp, o_output, _commit); } u256 execute(LastHashes const& _lh, bytes const& _rlp, bytes* o_output = nullptr, bool _commit = true) { return execute(_lh, &_rlp, o_output, _commit); }
u256 execute(LastHashes const& _lh, bytesConstRef _rlp, bytes* o_output = nullptr, bool _commit = true); u256 execute(LastHashes const& _lh, bytesConstRef _rlp, bytes* o_output = nullptr, bool _commit = true);

4
libjsqrc/ethereumjs/dist/ethereum.js

@ -91,8 +91,8 @@ var setupInputTypes = function () {
return value.toString(16); return value.toString(16);
else if (typeof value === "string" && value.indexOf('0x') === 0) else if (typeof value === "string" && value.indexOf('0x') === 0)
return value.substr(2); return value.substr(2);
else if (typeof value === "string") // else if (typeof value === "string")
return web3.toHex(value); // return web3.toHex(value);
else else
return (+value).toString(16); return (+value).toString(16);
}; };

2
libjsqrc/ethereumjs/dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/dist/ethereum.min.js

File diff suppressed because one or more lines are too long

4
libjsqrc/ethereumjs/lib/abi.js

@ -90,8 +90,8 @@ var setupInputTypes = function () {
return value.toString(16); return value.toString(16);
else if (typeof value === "string" && value.indexOf('0x') === 0) else if (typeof value === "string" && value.indexOf('0x') === 0)
return value.substr(2); return value.substr(2);
else if (typeof value === "string") // else if (typeof value === "string")
return web3.toHex(value); // return web3.toHex(value);
else else
return (+value).toString(16); return (+value).toString(16);
}; };

4
standard.js

@ -1,10 +1,13 @@
var compile = function(name) { return web3.eth.solidity(env.contents("../../dapp-bin/" + name + "/" + name + ".sol")); }; var compile = function(name) { return web3.eth.solidity(env.contents("../../dapp-bin/" + name + "/" + name + ".sol")); };
var create = function(code) { return web3.eth.transact({ 'code': code }); }; var create = function(code) { return web3.eth.transact({ 'code': code }); };
var createVal = function(code, val) { return web3.eth.transact(val ? { 'code': code, 'value': val } : { 'code': code }); };
var send = function(from, val, to) { return web3.eth.transact({ 'from': from, 'value': val, 'to': to }); }; var send = function(from, val, to) { return web3.eth.transact({ 'from': from, 'value': val, 'to': to }); };
var initService = function(name, dep) { return dep.then(function(){ return compile(name).then(create); }); }; var initService = function(name, dep) { return dep.then(function(){ return compile(name).then(create); }); };
var initServiceVal = function(name, dep, val) { return dep.then(function(){ return compile(name).then(function(c) { createVal(c, val); }); }); };
var addrConfig = compile("config").then(create); var addrConfig = compile("config").then(create);
var addrNameReg = initService("namereg", addrConfig); var addrNameReg = initService("namereg", addrConfig);
var addrGavsino = initServiceVal("gavmble", addrNameReg, "1000000000000000000");
var abiNameReg = [{"constant":true,"inputs":[{"name":"name","type":"string32"}],"name":"addressOf","outputs":[{"name":"addr","type":"address"}]},{"constant":false,"inputs":[],"name":"kill","outputs":[]},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"string32"}]},{"constant":false,"inputs":[{"name":"name","type":"string32"}],"name":"register","outputs":[]},{"constant":false,"inputs":[],"name":"unregister","outputs":[]}]; var abiNameReg = [{"constant":true,"inputs":[{"name":"name","type":"string32"}],"name":"addressOf","outputs":[{"name":"addr","type":"address"}]},{"constant":false,"inputs":[],"name":"kill","outputs":[]},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"string32"}]},{"constant":false,"inputs":[{"name":"name","type":"string32"}],"name":"register","outputs":[]},{"constant":false,"inputs":[],"name":"unregister","outputs":[]}];
var regName = function(account, name) { return web3.contract(addrNameReg, abiNameReg).register(name).transact({'from': account, 'gas': 10000}); }; var regName = function(account, name) { return web3.contract(addrNameReg, abiNameReg).register(name).transact({'from': account, 'gas': 10000}); };
@ -26,6 +29,7 @@ addrConfig.then(function() {
regName(accounts[1], 'Gav Would'); regName(accounts[1], 'Gav Would');
}); });
regName(accounts[0], 'Gav'); regName(accounts[0], 'Gav');
// TODO: once we have the exchange. // TODO: once we have the exchange.
// approve(accounts[0], exchange).then(function(){ offer(accounts[0], coin, '5000', '0', '5000000000000000000'); }); // approve(accounts[0], exchange).then(function(){ offer(accounts[0], coin, '5000', '0', '5000000000000000000'); });
// funded.then(function(){ approve(accounts[1], exchange); }); // funded.then(function(){ approve(accounts[1], exchange); });

Loading…
Cancel
Save