Browse Source

transact

cl-refactor
Joey Zhou 11 years ago
parent
commit
a7ee7bef2a
  1. 67
      eth/main.cpp

67
eth/main.cpp

@ -24,6 +24,8 @@
#include <chrono>
#include <fstream>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <libethsupport/FileSystem.h>
#include <libethcore/Instruction.h>
#include <libethereum/Defaults.h>
@ -31,6 +33,7 @@
#include <libethereum/PeerNetwork.h>
#include <libethereum/BlockChain.h>
#include <libethereum/State.h>
#include <libethcore/CommonEth.h>
#if ETH_READLINE
#include <readline/readline.h>
#include <readline/history.h>
@ -41,6 +44,7 @@
#include "BuildInfo.h"
using namespace std;
using namespace eth;
using namespace boost::algorithm;
using eth::Instruction;
using eth::c_instructionInfo;
@ -71,9 +75,9 @@ void interactiveHelp()
<< " block Gives the current block height." << endl
<< " balance Gives the current balance." << endl
<< " peers List the peers that are connected" << endl
<< " transact Execute a given transaction. TODO." << endl
<< " send Execute a given transaction with current secret. TODO." << endl
<< " create Create a new contract with current secret. TODO." << endl
<< " transact Execute a given transaction." << endl
<< " send Execute a given transaction with current secret." << endl
<< " contract Create a new contract with current secret." << endl
<< " inspect <contract> Dumps a contract to <APPDATA>/<contract>.evm." << endl
<< " exit Exits the application." << endl;
}
@ -156,7 +160,7 @@ string pretty(h160 _a, eth::State _st)
}
return ns;
}
bytes parse_data(string _args);
int main(int argc, char** argv)
{
unsigned short listenPort = 30303;
@ -399,11 +403,62 @@ int main(int argc, char** argv)
else if (cmd == "balance")
{
ClientGuard g(&c);
cout << "Current balance: " << c.postState().balance(us.address()) << endl;
cout << "Current balance: " << formatBalance(c.postState().balance(us.address())) << " = " << c.postState().balance(us.address()) << " wei" << endl;
}
else if (cmd == "transact")
{
//TODO.
ClientGuard g(&c);
auto const& bc = c.blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
if(iss.peek()!=-1){
string hexAddr;
u256 amount;
u256 gasPrice;
u256 gas;
string sechex;
string sdata;
iss >> hexAddr >> amount >> gasPrice >> gas >> sechex >> sdata;
cnote << "Data:";
cnote << sdata;
bytes data = parse_data(sdata);
cnote << "Bytes:";
string sbd = asString(data);
bytes bbd = asBytes(sbd);
stringstream ssbd;
ssbd << bbd;
cnote << ssbd.str();
int ssize = sechex.length();
int size = hexAddr.length();
u256 minGas = (u256)c.state().callGas(data.size(), 0);
if (size < 40)
{
if (size > 0)
cwarn << "Invalid address length: " << size;
}
else if (amount < 0)
cwarn << "Invalid amount: " << amount;
else if (gasPrice < info.minGasPrice)
cwarn << "Minimum gas price is " << info.minGasPrice;
else if (gas < minGas)
cwarn << "Minimum gas amount is " << minGas;
else if (ssize < 40)
{
if (ssize > 0)
cwarn << "Invalid secret length:" << ssize;
}
else
{
Secret secret = h256(fromHex(sechex));
Address dest = h160(fromHex(hexAddr));
c.transact(secret, amount, dest, data, gas, gasPrice);
}
} else {
cwarn << "Require parameters: transact ADDRESS AMOUNT GASPRICE GAS SECRET DATA";
}
}
else if (cmd == "send")
{

Loading…
Cancel
Save