Browse Source

Merge pull request #222 from josephyzhou/develop

set secret/address + import/export config
cl-refactor
Gav Wood 11 years ago
parent
commit
20dca7a57a
  1. 84
      eth/main.cpp
  2. 4
      neth/main.cpp

84
eth/main.cpp

@ -418,7 +418,8 @@ int main(int argc, char** argv)
auto h = bc.currentHash(); auto h = bc.currentHash();
auto blockData = bc.block(h); auto blockData = bc.block(h);
BlockInfo info(blockData); BlockInfo info(blockData);
if(iss.peek()!=-1){ if (iss.peek() != -1)
{
string hexAddr; string hexAddr;
u256 amount; u256 amount;
u256 gasPrice; u256 gasPrice;
@ -445,8 +446,6 @@ int main(int argc, char** argv)
if (size > 0) if (size > 0)
cwarn << "Invalid address length: " << size; cwarn << "Invalid address length: " << size;
} }
else if (amount < 0)
cwarn << "Invalid amount: " << amount;
else if (gasPrice < info.minGasPrice) else if (gasPrice < info.minGasPrice)
cwarn << "Minimum gas price is " << info.minGasPrice; cwarn << "Minimum gas price is " << info.minGasPrice;
else if (gas < minGas) else if (gas < minGas)
@ -462,9 +461,9 @@ int main(int argc, char** argv)
Address dest = h160(fromHex(hexAddr)); Address dest = h160(fromHex(hexAddr));
c.transact(secret, amount, dest, data, gas, gasPrice); c.transact(secret, amount, dest, data, gas, gasPrice);
} }
} else {
cwarn << "Require parameters: transact ADDRESS AMOUNT GASPRICE GAS SECRET DATA";
} }
else
cwarn << "Require parameters: transact ADDRESS AMOUNT GASPRICE GAS SECRET DATA";
} }
else if (cmd == "listContracts") else if (cmd == "listContracts")
{ {
@ -502,7 +501,8 @@ int main(int argc, char** argv)
else if (cmd == "send") else if (cmd == "send")
{ {
ClientGuard g(&c); ClientGuard g(&c);
if(iss.peek() != -1){ if (iss.peek() != -1)
{
string hexAddr; string hexAddr;
u256 amount; u256 amount;
int size = hexAddr.length(); int size = hexAddr.length();
@ -513,9 +513,8 @@ int main(int argc, char** argv)
if (size > 0) if (size > 0)
cwarn << "Invalid address length: " << size; cwarn << "Invalid address length: " << size;
} }
else if (amount < 0) { else
cwarn << "Invalid amount: " << amount; {
} else {
auto const& bc = c.blockChain(); auto const& bc = c.blockChain();
auto h = bc.currentHash(); auto h = bc.currentHash();
auto blockData = bc.block(h); auto blockData = bc.block(h);
@ -525,9 +524,9 @@ int main(int argc, char** argv)
c.transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice); c.transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice);
} }
} else { }
else
cwarn << "Require parameters: send ADDRESS AMOUNT"; cwarn << "Require parameters: send ADDRESS AMOUNT";
}
} }
else if (cmd == "contract") else if (cmd == "contract")
{ {
@ -568,12 +567,10 @@ int main(int argc, char** argv)
else if (gas < minGas) else if (gas < minGas)
cwarn << "Minimum gas amount is " << minGas; cwarn << "Minimum gas amount is " << minGas;
else else
{
c.transact(us.secret(), endowment, init, gas, gasPrice); c.transact(us.secret(), endowment, init, gas, gasPrice);
} }
} else { else
cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX"; cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX";
}
} }
else if (cmd == "inspect") else if (cmd == "inspect")
{ {
@ -602,9 +599,60 @@ int main(int argc, char** argv)
} }
else if (cmd == "setSecret") else if (cmd == "setSecret")
{ {
string hexSec; if (iss.peek() != -1)
iss >> hexSec; {
us = KeyPair(h256(fromHex(hexSec))); string hexSec;
iss >> hexSec;
us = KeyPair(h256(fromHex(hexSec)));
}
else
cwarn << "Require parameter: setSecret HEXSECRETKEY";
}
else if (cmd == "setAddress")
{
if (iss.peek() != -1)
{
string hexAddr;
iss >> hexAddr;
if (hexAddr.length() != 40)
cwarn << "Invalid address length: " << hexAddr.length();
else
coinbase = h160(fromHex(hexAddr));
}
else
cwarn << "Require parameter: setAddress HEXADDRESS";
}
else if (cmd == "exportConfig")
{
if (iss.peek() != -1)
{
string path;
iss >> path;
RLPStream config(2);
config << us.secret() << coinbase;
writeFile(path, config.out());
}
else
cwarn << "Require parameter: exportConfig PATH";
}
else if (cmd == "importConfig")
{
if (iss.peek() != -1)
{
string path;
iss >> path;
bytes b = contents(path);
if (b.size())
{
RLP config(b);
us = KeyPair(config[0].toHash<Secret>());
coinbase = config[1].toHash<Address>();
}
else
cwarn << path << "has no content!";
}
else
cwarn << "Require parameter: importConfig PATH";
} }
else if (cmd == "help") else if (cmd == "help")
interactiveHelp(); interactiveHelp();

4
neth/main.cpp

@ -665,8 +665,6 @@ int main(int argc, char** argv)
if (size > 0) if (size > 0)
cwarn << "Invalid address length: " << size; cwarn << "Invalid address length: " << size;
} }
else if (amount < 0)
cwarn << "Invalid amount: " << amount;
else if (gasPrice < info.minGasPrice) else if (gasPrice < info.minGasPrice)
cwarn << "Minimum gas price is " << info.minGasPrice; cwarn << "Minimum gas price is " << info.minGasPrice;
else if (gas < minGas) else if (gas < minGas)
@ -712,8 +710,6 @@ int main(int argc, char** argv)
if (size > 0) if (size > 0)
cwarn << "Invalid address length: " << size; cwarn << "Invalid address length: " << size;
} }
else if (amount <= 0)
cwarn << "Invalid amount: " << amount;
else else
{ {
auto const& bc = c.blockChain(); auto const& bc = c.blockChain();

Loading…
Cancel
Save