|
@ -35,65 +35,65 @@ using namespace dev::eth; |
|
|
|
|
|
|
|
|
static Json::Value toJson(const dev::eth::BlockInfo& bi) |
|
|
static Json::Value toJson(const dev::eth::BlockInfo& bi) |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
res["hash"] = boost::lexical_cast<string>(bi.hash); |
|
|
res["hash"] = boost::lexical_cast<string>(bi.hash); |
|
|
|
|
|
|
|
|
res["parentHash"] = toJS(bi.parentHash); |
|
|
res["parentHash"] = toJS(bi.parentHash); |
|
|
res["sha3Uncles"] = toJS(bi.sha3Uncles); |
|
|
res["sha3Uncles"] = toJS(bi.sha3Uncles); |
|
|
res["miner"] = toJS(bi.coinbaseAddress); |
|
|
res["miner"] = toJS(bi.coinbaseAddress); |
|
|
res["stateRoot"] = toJS(bi.stateRoot); |
|
|
res["stateRoot"] = toJS(bi.stateRoot); |
|
|
res["transactionsRoot"] = toJS(bi.transactionsRoot); |
|
|
res["transactionsRoot"] = toJS(bi.transactionsRoot); |
|
|
res["difficulty"] = toJS(bi.difficulty); |
|
|
res["difficulty"] = toJS(bi.difficulty); |
|
|
res["number"] = (int)bi.number; |
|
|
res["number"] = (int)bi.number; |
|
|
res["minGasPrice"] = toJS(bi.minGasPrice); |
|
|
res["minGasPrice"] = toJS(bi.minGasPrice); |
|
|
res["gasLimit"] = (int)bi.gasLimit; |
|
|
res["gasLimit"] = (int)bi.gasLimit; |
|
|
res["timestamp"] = (int)bi.timestamp; |
|
|
res["timestamp"] = (int)bi.timestamp; |
|
|
res["extraData"] = jsFromBinary(bi.extraData); |
|
|
res["extraData"] = jsFromBinary(bi.extraData); |
|
|
res["nonce"] = toJS(bi.nonce); |
|
|
res["nonce"] = toJS(bi.nonce); |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Json::Value toJson(const dev::eth::PastMessage& t) |
|
|
static Json::Value toJson(const dev::eth::PastMessage& t) |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
res["input"] = jsFromBinary(t.input); |
|
|
res["input"] = jsFromBinary(t.input); |
|
|
res["output"] = jsFromBinary(t.output); |
|
|
res["output"] = jsFromBinary(t.output); |
|
|
res["to"] = toJS(t.to); |
|
|
res["to"] = toJS(t.to); |
|
|
res["from"] = toJS(t.from); |
|
|
res["from"] = toJS(t.from); |
|
|
res["value"] = jsToDecimal(toJS(t.value)); |
|
|
res["value"] = jsToDecimal(toJS(t.value)); |
|
|
res["origin"] = toJS(t.origin); |
|
|
res["origin"] = toJS(t.origin); |
|
|
res["timestamp"] = toJS(t.timestamp); |
|
|
res["timestamp"] = toJS(t.timestamp); |
|
|
res["coinbase"] = toJS(t.coinbase); |
|
|
res["coinbase"] = toJS(t.coinbase); |
|
|
res["block"] = toJS(t.block); |
|
|
res["block"] = toJS(t.block); |
|
|
Json::Value path; |
|
|
Json::Value path; |
|
|
for (int i: t.path) |
|
|
for (int i: t.path) |
|
|
path.append(i); |
|
|
path.append(i); |
|
|
res["path"] = path; |
|
|
res["path"] = path; |
|
|
res["number"] = (int)t.number; |
|
|
res["number"] = (int)t.number; |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Json::Value toJson(const dev::eth::PastMessages& pms) |
|
|
static Json::Value toJson(const dev::eth::PastMessages& pms) |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
for (dev::eth::PastMessage const & t: pms) |
|
|
for (dev::eth::PastMessage const & t: pms) |
|
|
res.append(toJson(t)); |
|
|
res.append(toJson(t)); |
|
|
|
|
|
|
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Json::Value toJson(const dev::eth::Transaction& t) |
|
|
static Json::Value toJson(const dev::eth::Transaction& t) |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
res["hash"] = toJS(t.sha3()); |
|
|
res["hash"] = toJS(t.sha3()); |
|
|
res["input"] = jsFromBinary(t.data); |
|
|
res["input"] = jsFromBinary(t.data); |
|
|
res["to"] = toJS(t.receiveAddress); |
|
|
res["to"] = toJS(t.receiveAddress); |
|
|
res["from"] = toJS(t.sender()); |
|
|
res["from"] = toJS(t.sender()); |
|
|
res["gas"] = (int)t.gas; |
|
|
res["gas"] = (int)t.gas; |
|
|
res["gasPrice"] = toJS(t.gasPrice); |
|
|
res["gasPrice"] = toJS(t.gasPrice); |
|
|
res["nonce"] = toJS(t.nonce); |
|
|
res["nonce"] = toJS(t.nonce); |
|
|
res["value"] = toJS(t.value); |
|
|
res["value"] = toJS(t.value); |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3): |
|
|
EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3): |
|
@ -104,12 +104,12 @@ EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDi |
|
|
|
|
|
|
|
|
dev::eth::Interface* EthStubServer::client() const |
|
|
dev::eth::Interface* EthStubServer::client() const |
|
|
{ |
|
|
{ |
|
|
return m_web3.ethereum(); |
|
|
return m_web3.ethereum(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::balanceAt(const string &address, const int& block) |
|
|
std::string EthStubServer::balanceAt(const string &address, const int& block) |
|
|
{ |
|
|
{ |
|
|
return toJS(client()->balanceAt(jsToAddress(address), block)); |
|
|
return toJS(client()->balanceAt(jsToAddress(address), block)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dev::FixedHash<32> EthStubServer::numberOrHash(Json::Value const &json) const |
|
|
dev::FixedHash<32> EthStubServer::numberOrHash(Json::Value const &json) const |
|
@ -133,93 +133,93 @@ Json::Value EthStubServer::block(const Json::Value ¶ms) |
|
|
|
|
|
|
|
|
static TransactionJS toTransaction(const Json::Value &json) |
|
|
static TransactionJS toTransaction(const Json::Value &json) |
|
|
{ |
|
|
{ |
|
|
TransactionJS ret; |
|
|
TransactionJS ret; |
|
|
if (!json.isObject() || json.empty()){ |
|
|
if (!json.isObject() || json.empty()){ |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!json["from"].empty()) |
|
|
if (!json["from"].empty()) |
|
|
ret.from = jsToSecret(json["from"].asString()); |
|
|
ret.from = jsToSecret(json["from"].asString()); |
|
|
if (!json["to"].empty()) |
|
|
if (!json["to"].empty()) |
|
|
ret.to = jsToAddress(json["to"].asString()); |
|
|
ret.to = jsToAddress(json["to"].asString()); |
|
|
if (!json["value"].empty()) |
|
|
if (!json["value"].empty()) |
|
|
ret.value = jsToU256(json["value"].asString()); |
|
|
ret.value = jsToU256(json["value"].asString()); |
|
|
if (!json["gas"].empty()) |
|
|
if (!json["gas"].empty()) |
|
|
ret.gas = jsToU256(json["gas"].asString()); |
|
|
ret.gas = jsToU256(json["gas"].asString()); |
|
|
if (!json["gasPrice"].empty()) |
|
|
if (!json["gasPrice"].empty()) |
|
|
ret.gasPrice = jsToU256(json["gasPrice"].asString()); |
|
|
ret.gasPrice = jsToU256(json["gasPrice"].asString()); |
|
|
|
|
|
|
|
|
if (!json["data"].empty() || json["code"].empty() || json["dataclose"].empty()) |
|
|
if (!json["data"].empty() || json["code"].empty() || json["dataclose"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (json["data"].isString()) |
|
|
if (json["data"].isString()) |
|
|
ret.data = jsToBytes(json["data"].asString()); |
|
|
ret.data = jsToBytes(json["data"].asString()); |
|
|
else if (json["code"].isString()) |
|
|
else if (json["code"].isString()) |
|
|
ret.data = jsToBytes(json["code"].asString()); |
|
|
ret.data = jsToBytes(json["code"].asString()); |
|
|
else if (json["data"].isArray()) |
|
|
else if (json["data"].isArray()) |
|
|
for (auto i: json["data"]) |
|
|
for (auto i: json["data"]) |
|
|
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32))); |
|
|
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32))); |
|
|
else if (json["code"].isArray()) |
|
|
else if (json["code"].isArray()) |
|
|
for (auto i: json["code"]) |
|
|
for (auto i: json["code"]) |
|
|
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32))); |
|
|
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32))); |
|
|
else if (json["dataclose"].isArray()) |
|
|
else if (json["dataclose"].isArray()) |
|
|
for (auto i: json["dataclose"]) |
|
|
for (auto i: json["dataclose"]) |
|
|
dev::operator +=(ret.data, jsToBytes(i.asString())); |
|
|
dev::operator +=(ret.data, jsToBytes(i.asString())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::call(const Json::Value &json) |
|
|
std::string EthStubServer::call(const Json::Value &json) |
|
|
{ |
|
|
{ |
|
|
std::string ret; |
|
|
std::string ret; |
|
|
if (!client()) |
|
|
if (!client()) |
|
|
return ret; |
|
|
return ret; |
|
|
TransactionJS t = toTransaction(json); |
|
|
TransactionJS t = toTransaction(json); |
|
|
if (!t.to) |
|
|
if (!t.to) |
|
|
return ret; |
|
|
return ret; |
|
|
if (!t.from && m_keys.size()) |
|
|
if (!t.from && m_keys.size()) |
|
|
t.from = m_keys[0].secret(); |
|
|
t.from = m_keys[0].secret(); |
|
|
if (!t.gasPrice) |
|
|
if (!t.gasPrice) |
|
|
t.gasPrice = 10 * dev::eth::szabo; |
|
|
t.gasPrice = 10 * dev::eth::szabo; |
|
|
if (!t.gas) |
|
|
if (!t.gas) |
|
|
t.gas = client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice; |
|
|
t.gas = client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice; |
|
|
ret = toJS(client()->call(t.from, t.value, t.to, t.data, t.gas, t.gasPrice)); |
|
|
ret = toJS(client()->call(t.from, t.value, t.to, t.data, t.gas, t.gasPrice)); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::codeAt(const string &address, const int& block) |
|
|
std::string EthStubServer::codeAt(const string &address, const int& block) |
|
|
{ |
|
|
{ |
|
|
return client() ? jsFromBinary(client()->codeAt(jsToAddress(address), block)) : ""; |
|
|
return client() ? jsFromBinary(client()->codeAt(jsToAddress(address), block)) : ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::coinbase() |
|
|
std::string EthStubServer::coinbase() |
|
|
{ |
|
|
{ |
|
|
return client() ? toJS(client()->address()) : ""; |
|
|
return client() ? toJS(client()->address()) : ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double EthStubServer::countAt(const string &address, const int& block) |
|
|
double EthStubServer::countAt(const string &address, const int& block) |
|
|
{ |
|
|
{ |
|
|
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(address), block) : 0; |
|
|
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(address), block) : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int EthStubServer::defaultBlock() |
|
|
int EthStubServer::defaultBlock() |
|
|
{ |
|
|
{ |
|
|
return client() ? client()->getDefault() : 0; |
|
|
return client() ? client()->getDefault() : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::fromAscii(const int& padding, const std::string& s) |
|
|
std::string EthStubServer::fromAscii(const int& padding, const std::string& s) |
|
|
{ |
|
|
{ |
|
|
return jsFromBinary(s, padding); |
|
|
return jsFromBinary(s, padding); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double EthStubServer::fromFixed(const string &s) |
|
|
double EthStubServer::fromFixed(const string &s) |
|
|
{ |
|
|
{ |
|
|
return jsFromFixed(s); |
|
|
return jsFromFixed(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::gasPrice() |
|
|
std::string EthStubServer::gasPrice() |
|
|
{ |
|
|
{ |
|
|
return toJS(10 * dev::eth::szabo); |
|
|
return toJS(10 * dev::eth::szabo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool EthStubServer::listening() |
|
|
bool EthStubServer::listening() |
|
@ -229,88 +229,88 @@ bool EthStubServer::listening() |
|
|
|
|
|
|
|
|
bool EthStubServer::mining() |
|
|
bool EthStubServer::mining() |
|
|
{ |
|
|
{ |
|
|
return client() ? client()->isMining() : false; |
|
|
return client() ? client()->isMining() : false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::key() |
|
|
std::string EthStubServer::key() |
|
|
{ |
|
|
{ |
|
|
if (!m_keys.size()) |
|
|
if (!m_keys.size()) |
|
|
return std::string(); |
|
|
return std::string(); |
|
|
return toJS(m_keys[0].sec()); |
|
|
return toJS(m_keys[0].sec()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Json::Value EthStubServer::keys() |
|
|
Json::Value EthStubServer::keys() |
|
|
{ |
|
|
{ |
|
|
Json::Value ret; |
|
|
Json::Value ret; |
|
|
for (auto i: m_keys) |
|
|
for (auto i: m_keys) |
|
|
ret.append(toJS(i.secret())); |
|
|
ret.append(toJS(i.secret())); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::lll(const string &s) |
|
|
std::string EthStubServer::lll(const string &s) |
|
|
{ |
|
|
{ |
|
|
return toJS(dev::eth::compileLLL(s)); |
|
|
return toJS(dev::eth::compileLLL(s)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static dev::eth::MessageFilter toMessageFilter(const Json::Value &json) |
|
|
static dev::eth::MessageFilter toMessageFilter(const Json::Value &json) |
|
|
{ |
|
|
{ |
|
|
dev::eth::MessageFilter filter; |
|
|
dev::eth::MessageFilter filter; |
|
|
if (!json.isObject() || json.empty()){ |
|
|
if (!json.isObject() || json.empty()){ |
|
|
return filter; |
|
|
return filter; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!json["earliest"].empty()) |
|
|
if (!json["earliest"].empty()) |
|
|
filter.withEarliest(json["earliest"].asInt()); |
|
|
filter.withEarliest(json["earliest"].asInt()); |
|
|
if (!json["latest"].empty()) |
|
|
if (!json["latest"].empty()) |
|
|
filter.withLatest(json["lastest"].asInt()); |
|
|
filter.withLatest(json["lastest"].asInt()); |
|
|
if (!json["max"].empty()) |
|
|
if (!json["max"].empty()) |
|
|
filter.withMax(json["max"].asInt()); |
|
|
filter.withMax(json["max"].asInt()); |
|
|
if (!json["skip"].empty()) |
|
|
if (!json["skip"].empty()) |
|
|
filter.withSkip(json["skip"].asInt()); |
|
|
filter.withSkip(json["skip"].asInt()); |
|
|
if (!json["from"].empty()) |
|
|
if (!json["from"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (json["from"].isArray()) |
|
|
if (json["from"].isArray()) |
|
|
for (auto i : json["from"]) |
|
|
for (auto i : json["from"]) |
|
|
filter.from(jsToAddress(i.asString())); |
|
|
filter.from(jsToAddress(i.asString())); |
|
|
else |
|
|
else |
|
|
filter.from(jsToAddress(json["from"].asString())); |
|
|
filter.from(jsToAddress(json["from"].asString())); |
|
|
} |
|
|
} |
|
|
if (!json["to"].empty()) |
|
|
if (!json["to"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (json["to"].isArray()) |
|
|
if (json["to"].isArray()) |
|
|
for (auto i : json["to"]) |
|
|
for (auto i : json["to"]) |
|
|
filter.from(jsToAddress(i.asString())); |
|
|
filter.from(jsToAddress(i.asString())); |
|
|
else |
|
|
else |
|
|
filter.from(jsToAddress(json["to"].asString())); |
|
|
filter.from(jsToAddress(json["to"].asString())); |
|
|
} |
|
|
} |
|
|
if (!json["altered"].empty()) |
|
|
if (!json["altered"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (json["altered"].isArray()) |
|
|
if (json["altered"].isArray()) |
|
|
for (auto i: json["altered"]) |
|
|
for (auto i: json["altered"]) |
|
|
if (i.isObject()) |
|
|
if (i.isObject()) |
|
|
filter.altered(jsToAddress(i["id"].asString()), jsToU256(i["at"].asString())); |
|
|
filter.altered(jsToAddress(i["id"].asString()), jsToU256(i["at"].asString())); |
|
|
else |
|
|
else |
|
|
filter.altered((jsToAddress(i.asString()))); |
|
|
filter.altered((jsToAddress(i.asString()))); |
|
|
else if (json["altered"].isObject()) |
|
|
else if (json["altered"].isObject()) |
|
|
filter.altered(jsToAddress(json["altered"]["id"].asString()), jsToU256(json["altered"]["at"].asString())); |
|
|
filter.altered(jsToAddress(json["altered"]["id"].asString()), jsToU256(json["altered"]["at"].asString())); |
|
|
else |
|
|
else |
|
|
filter.altered(jsToAddress(json["altered"].asString())); |
|
|
filter.altered(jsToAddress(json["altered"].asString())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return filter; |
|
|
return filter; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Json::Value EthStubServer::messages(const Json::Value &json) |
|
|
Json::Value EthStubServer::messages(const Json::Value &json) |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
if (!client()) |
|
|
if (!client()) |
|
|
return res; |
|
|
return res; |
|
|
return toJson(client()->messages(toMessageFilter(json))); |
|
|
return toJson(client()->messages(toMessageFilter(json))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int EthStubServer::number() |
|
|
int EthStubServer::number() |
|
|
{ |
|
|
{ |
|
|
return client() ? client()->number() + 1 : 0; |
|
|
return client() ? client()->number() + 1 : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int EthStubServer::peerCount() |
|
|
int EthStubServer::peerCount() |
|
@ -320,59 +320,59 @@ int EthStubServer::peerCount() |
|
|
|
|
|
|
|
|
std::string EthStubServer::secretToAddress(const string &s) |
|
|
std::string EthStubServer::secretToAddress(const string &s) |
|
|
{ |
|
|
{ |
|
|
return toJS(KeyPair(jsToSecret(s)).address()); |
|
|
return toJS(KeyPair(jsToSecret(s)).address()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool EthStubServer::setCoinbase(const std::string &address) |
|
|
bool EthStubServer::setCoinbase(const std::string &address) |
|
|
{ |
|
|
{ |
|
|
client()->setAddress(jsToAddress(address)); |
|
|
client()->setAddress(jsToAddress(address)); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool EthStubServer::setListening(const bool &listening) |
|
|
bool EthStubServer::setListening(const bool &listening) |
|
|
{ |
|
|
{ |
|
|
if (listening) |
|
|
if (listening) |
|
|
m_web3.startNetwork(); |
|
|
m_web3.startNetwork(); |
|
|
else |
|
|
else |
|
|
m_web3.stopNetwork(); |
|
|
m_web3.stopNetwork(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool EthStubServer::setMining(const bool &mining) |
|
|
bool EthStubServer::setMining(const bool &mining) |
|
|
{ |
|
|
{ |
|
|
if (!client()) |
|
|
if (!client()) |
|
|
return Json::nullValue; |
|
|
return Json::nullValue; |
|
|
|
|
|
|
|
|
if (mining) |
|
|
if (mining) |
|
|
client()->startMining(); |
|
|
client()->startMining(); |
|
|
else |
|
|
else |
|
|
client()->stopMining(); |
|
|
client()->stopMining(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::sha3(const string &s) |
|
|
std::string EthStubServer::sha3(const string &s) |
|
|
{ |
|
|
{ |
|
|
return toJS(dev::eth::sha3(jsToBytes(s))); |
|
|
return toJS(dev::eth::sha3(jsToBytes(s))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::stateAt(const string &address, const int& block, const string &storage) |
|
|
std::string EthStubServer::stateAt(const string &address, const int& block, const string &storage) |
|
|
{ |
|
|
{ |
|
|
return client() ? toJS(client()->stateAt(jsToAddress(address), jsToU256(storage), block)) : ""; |
|
|
return client() ? toJS(client()->stateAt(jsToAddress(address), jsToU256(storage), block)) : ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::toAscii(const string &s) |
|
|
std::string EthStubServer::toAscii(const string &s) |
|
|
{ |
|
|
{ |
|
|
return jsToBinary(s); |
|
|
return jsToBinary(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::toDecimal(const string &s) |
|
|
std::string EthStubServer::toDecimal(const string &s) |
|
|
{ |
|
|
{ |
|
|
return jsToDecimal(s); |
|
|
return jsToDecimal(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::toFixed(const double &s) |
|
|
std::string EthStubServer::toFixed(const double &s) |
|
|
{ |
|
|
{ |
|
|
return jsToFixed(s); |
|
|
return jsToFixed(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string EthStubServer::transact(const Json::Value &json) |
|
|
std::string EthStubServer::transact(const Json::Value &json) |
|
@ -383,22 +383,22 @@ std::string EthStubServer::transact(const Json::Value &json) |
|
|
TransactionJS t = toTransaction(json); |
|
|
TransactionJS t = toTransaction(json); |
|
|
if (!t.from && m_keys.size()) |
|
|
if (!t.from && m_keys.size()) |
|
|
{ |
|
|
{ |
|
|
auto b = m_keys.front(); |
|
|
auto b = m_keys.front(); |
|
|
for (auto a: m_keys) |
|
|
for (auto a: m_keys) |
|
|
if (client()->balanceAt(KeyPair(a).address()) > client()->balanceAt(KeyPair(b).address())) |
|
|
if (client()->balanceAt(KeyPair(a).address()) > client()->balanceAt(KeyPair(b).address())) |
|
|
b = a; |
|
|
b = a; |
|
|
t.from = b.secret(); |
|
|
t.from = b.secret(); |
|
|
} |
|
|
} |
|
|
if (!t.gasPrice) |
|
|
if (!t.gasPrice) |
|
|
t.gasPrice = 10 * dev::eth::szabo; |
|
|
t.gasPrice = 10 * dev::eth::szabo; |
|
|
if (!t.gas) |
|
|
if (!t.gas) |
|
|
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice); |
|
|
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice); |
|
|
if (t.to) |
|
|
if (t.to) |
|
|
client()->transact(t.from, t.value, t.to, t.data, t.gas, t.gasPrice); |
|
|
client()->transact(t.from, t.value, t.to, t.data, t.gas, t.gasPrice); |
|
|
else |
|
|
else |
|
|
ret = toJS(client()->transact(t.from, t.value, t.data, t.gas, t.gasPrice)); |
|
|
ret = toJS(client()->transact(t.from, t.value, t.data, t.gas, t.gasPrice)); |
|
|
client()->flushTransactions(); |
|
|
client()->flushTransactions(); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Json::Value EthStubServer::transaction(const int &i, const Json::Value ¶ms) |
|
|
Json::Value EthStubServer::transaction(const int &i, const Json::Value ¶ms) |
|
|