Browse Source

Merge pull request #117 from caktux/inspect

Add 'inspect' command that writes contracts to file
cl-refactor
Gav Wood 11 years ago
parent
commit
b413316203
  1. 59
      eth/main.cpp

59
eth/main.cpp

@ -29,9 +29,12 @@
#include "BlockChain.h"
#include "State.h"
#include "FileSystem.h"
#include "Instruction.h"
#include "BuildInfo.h"
using namespace std;
using namespace eth;
using eth::Instruction;
using eth::c_instructionInfo;
bool isTrue(std::string const& _m)
{
@ -83,6 +86,7 @@ void interactiveHelp()
<< " balance Gives the current balance." << endl
<< " transact <secret> <dest> <amount> Executes a given transaction." << endl
<< " send <dest> <amount> Executes a given transaction with current secret." << endl
<< " inspect <contract> Dumps a contract to <APPDATA>/<contract>.evm." << endl
<< " exit Exits the application." << endl;
}
@ -288,6 +292,61 @@ int main(int argc, char** argv)
Address dest = h160(fromHex(rechex));
c.transact(us.secret(), dest, amount);
}
else if (cmd == "inspect")
{
string rechex;
cin >> rechex;
c.lock();
auto h = h160(fromHex(rechex));
stringstream s;
auto mem = c.state().contractMemory(h);
u256 next = 0;
unsigned numerics = 0;
bool unexpectedNumeric = false;
for (auto 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);
if (next + j < i.first)
s << "\n@" << 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;
}
next = i.first + 1;
}
string outFile = getDataDir() + "/" + rechex + ".evm";
ofstream ofs;
ofs.open(outFile, ofstream::binary);
ofs.write(s.str().c_str(), s.str().length());
ofs.close();
c.unlock();
}
else if (cmd == "help")
{
interactiveHelp();

Loading…
Cancel
Save