|
@ -298,16 +298,16 @@ static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts): |
|
|
WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts): |
|
|
AbstractWebThreeStubServer(_conn), m_accounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this))) |
|
|
AbstractWebThreeStubServer(_conn), m_ethAccounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this))) |
|
|
{ |
|
|
{ |
|
|
m_accounts->setAccounts(_accounts); |
|
|
m_ethAccounts->setAccounts(_accounts); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void WebThreeStubServerBase::setIdentities(vector<dev::KeyPair> const& _ids) |
|
|
void WebThreeStubServerBase::setIdentities(vector<dev::KeyPair> const& _ids) |
|
|
{ |
|
|
{ |
|
|
m_ids.clear(); |
|
|
m_shhIds.clear(); |
|
|
for (auto i: _ids) |
|
|
for (auto i: _ids) |
|
|
m_ids[i.pub()] = i.secret(); |
|
|
m_shhIds[i.pub()] = i.secret(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
string WebThreeStubServerBase::web3_sha3(string const& _param1) |
|
|
string WebThreeStubServerBase::web3_sha3(string const& _param1) |
|
@ -353,7 +353,7 @@ string WebThreeStubServerBase::eth_gasPrice() |
|
|
Json::Value WebThreeStubServerBase::eth_accounts() |
|
|
Json::Value WebThreeStubServerBase::eth_accounts() |
|
|
{ |
|
|
{ |
|
|
Json::Value ret(Json::arrayValue); |
|
|
Json::Value ret(Json::arrayValue); |
|
|
for (auto const& i: m_accounts->getAllAccounts()) |
|
|
for (auto const& i: m_ethAccounts->getAllAccounts()) |
|
|
ret.append(toJS(i)); |
|
|
ret.append(toJS(i)); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
@ -499,7 +499,7 @@ string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json) |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
|
|
|
|
|
|
if (!t.from) |
|
|
if (!t.from) |
|
|
t.from = m_accounts->getDefaultTransactAccount(); |
|
|
t.from = m_ethAccounts->getDefaultTransactAccount(); |
|
|
if (t.creation) |
|
|
if (t.creation) |
|
|
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; |
|
|
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; |
|
|
if (t.gasPrice == UndefinedU256) |
|
|
if (t.gasPrice == UndefinedU256) |
|
@ -507,9 +507,9 @@ string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json) |
|
|
if (t.gas == UndefinedU256) |
|
|
if (t.gas == UndefinedU256) |
|
|
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice); |
|
|
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice); |
|
|
|
|
|
|
|
|
if (m_accounts->isRealAccount(t.from)) |
|
|
if (m_ethAccounts->isRealAccount(t.from)) |
|
|
authenticate(t, false); |
|
|
authenticate(t, false); |
|
|
else if (m_accounts->isProxyAccount(t.from)) |
|
|
else if (m_ethAccounts->isProxyAccount(t.from)) |
|
|
authenticate(t, true); |
|
|
authenticate(t, true); |
|
|
|
|
|
|
|
|
return ret; |
|
|
return ret; |
|
@ -528,7 +528,7 @@ string WebThreeStubServerBase::eth_signTransaction(Json::Value const& _json) |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
|
|
|
|
|
|
if (!t.from) |
|
|
if (!t.from) |
|
|
t.from = m_accounts->getDefaultTransactAccount(); |
|
|
t.from = m_ethAccounts->getDefaultTransactAccount(); |
|
|
if (t.creation) |
|
|
if (t.creation) |
|
|
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; |
|
|
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; |
|
|
if (t.gasPrice == UndefinedU256) |
|
|
if (t.gasPrice == UndefinedU256) |
|
@ -536,9 +536,9 @@ string WebThreeStubServerBase::eth_signTransaction(Json::Value const& _json) |
|
|
if (t.gas == UndefinedU256) |
|
|
if (t.gas == UndefinedU256) |
|
|
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice); |
|
|
t.gas = min<u256>(client()->gasLimitRemaining() / 5, client()->balanceAt(t.from) / t.gasPrice); |
|
|
|
|
|
|
|
|
if (m_accounts->isRealAccount(t.from)) |
|
|
if (m_ethAccounts->isRealAccount(t.from)) |
|
|
authenticate(t, false); |
|
|
authenticate(t, false); |
|
|
else if (m_accounts->isProxyAccount(t.from)) |
|
|
else if (m_ethAccounts->isProxyAccount(t.from)) |
|
|
authenticate(t, true); |
|
|
authenticate(t, true); |
|
|
|
|
|
|
|
|
return toJS((t.creation ? Transaction(t.value, t.gasPrice, t.gas, t.data) : Transaction(t.value, t.gasPrice, t.gas, t.to, t.data)).sha3(WithoutSignature)); |
|
|
return toJS((t.creation ? Transaction(t.value, t.gasPrice, t.gas, t.data) : Transaction(t.value, t.gasPrice, t.gas, t.to, t.data)).sha3(WithoutSignature)); |
|
@ -579,7 +579,7 @@ string WebThreeStubServerBase::eth_call(Json::Value const& _json, string const& |
|
|
{ |
|
|
{ |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
TransactionSkeleton t = toTransaction(_json); |
|
|
if (!t.from) |
|
|
if (!t.from) |
|
|
t.from = m_accounts->getDefaultTransactAccount(); |
|
|
t.from = m_ethAccounts->getDefaultTransactAccount(); |
|
|
// if (!m_accounts->isRealAccount(t.from))
|
|
|
// if (!m_accounts->isRealAccount(t.from))
|
|
|
// return ret;
|
|
|
// return ret;
|
|
|
if (t.gasPrice == UndefinedU256) |
|
|
if (t.gasPrice == UndefinedU256) |
|
@ -587,7 +587,7 @@ string WebThreeStubServerBase::eth_call(Json::Value const& _json, string const& |
|
|
if (t.gas == UndefinedU256) |
|
|
if (t.gas == UndefinedU256) |
|
|
t.gas = client()->gasLimitRemaining(); |
|
|
t.gas = client()->gasLimitRemaining(); |
|
|
|
|
|
|
|
|
return toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice, jsToBlockNumber(_blockNumber), FudgeFactor::Lenient).output); |
|
|
return toJS(client()->call(m_ethAccounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice, jsToBlockNumber(_blockNumber), FudgeFactor::Lenient).output); |
|
|
} |
|
|
} |
|
|
catch (...) |
|
|
catch (...) |
|
|
{ |
|
|
{ |
|
@ -879,7 +879,7 @@ string WebThreeStubServerBase::eth_register(string const& _address) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
return toJS(m_accounts->addProxyAccount(jsToAddress(_address))); |
|
|
return toJS(m_ethAccounts->addProxyAccount(jsToAddress(_address))); |
|
|
} |
|
|
} |
|
|
catch (...) |
|
|
catch (...) |
|
|
{ |
|
|
{ |
|
@ -891,7 +891,7 @@ bool WebThreeStubServerBase::eth_unregister(string const& _accountId) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
return m_accounts->removeProxyAccount(jsToInt(_accountId)); |
|
|
return m_ethAccounts->removeProxyAccount(jsToInt(_accountId)); |
|
|
} |
|
|
} |
|
|
catch (...) |
|
|
catch (...) |
|
|
{ |
|
|
{ |
|
@ -906,9 +906,9 @@ Json::Value WebThreeStubServerBase::eth_fetchQueuedTransactions(string const& _a |
|
|
auto id = jsToInt(_accountId); |
|
|
auto id = jsToInt(_accountId); |
|
|
Json::Value ret(Json::arrayValue); |
|
|
Json::Value ret(Json::arrayValue); |
|
|
// TODO: throw an error on no account with given id
|
|
|
// TODO: throw an error on no account with given id
|
|
|
for (TransactionSkeleton const& t: m_accounts->getQueuedTransactions(id)) |
|
|
for (TransactionSkeleton const& t: m_ethAccounts->getQueuedTransactions(id)) |
|
|
ret.append(toJson(t)); |
|
|
ret.append(toJson(t)); |
|
|
m_accounts->clearQueue(id); |
|
|
m_ethAccounts->clearQueue(id); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
catch (...) |
|
|
catch (...) |
|
@ -934,11 +934,11 @@ bool WebThreeStubServerBase::shh_post(Json::Value const& _json) |
|
|
{ |
|
|
{ |
|
|
shh::Message m = toMessage(_json); |
|
|
shh::Message m = toMessage(_json); |
|
|
Secret from; |
|
|
Secret from; |
|
|
if (m.from() && m_ids.count(m.from())) |
|
|
if (m.from() && m_shhIds.count(m.from())) |
|
|
{ |
|
|
{ |
|
|
cwarn << "Silently signing message from identity" << m.from() << ": User validation hook goes here."; |
|
|
cwarn << "Silently signing message from identity" << m.from() << ": User validation hook goes here."; |
|
|
// TODO: insert validification hook here.
|
|
|
// TODO: insert validification hook here.
|
|
|
from = m_ids[m.from()]; |
|
|
from = m_shhIds[m.from()]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
face()->inject(toSealed(_json, m, from)); |
|
|
face()->inject(toSealed(_json, m, from)); |
|
@ -953,7 +953,7 @@ bool WebThreeStubServerBase::shh_post(Json::Value const& _json) |
|
|
string WebThreeStubServerBase::shh_newIdentity() |
|
|
string WebThreeStubServerBase::shh_newIdentity() |
|
|
{ |
|
|
{ |
|
|
KeyPair kp = KeyPair::create(); |
|
|
KeyPair kp = KeyPair::create(); |
|
|
m_ids[kp.pub()] = kp.secret(); |
|
|
m_shhIds[kp.pub()] = kp.secret(); |
|
|
return toJS(kp.pub()); |
|
|
return toJS(kp.pub()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -961,7 +961,7 @@ bool WebThreeStubServerBase::shh_hasIdentity(string const& _identity) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
return m_ids.count(jsToPublic(_identity)) > 0; |
|
|
return m_shhIds.count(jsToPublic(_identity)) > 0; |
|
|
} |
|
|
} |
|
|
catch (...) |
|
|
catch (...) |
|
|
{ |
|
|
{ |
|
@ -1021,7 +1021,7 @@ Json::Value WebThreeStubServerBase::shh_getFilterChanges(string const& _filterId |
|
|
|
|
|
|
|
|
int id = jsToInt(_filterId); |
|
|
int id = jsToInt(_filterId); |
|
|
auto pub = m_shhWatches[id]; |
|
|
auto pub = m_shhWatches[id]; |
|
|
if (!pub || m_ids.count(pub)) |
|
|
if (!pub || m_shhIds.count(pub)) |
|
|
for (h256 const& h: face()->checkWatch(id)) |
|
|
for (h256 const& h: face()->checkWatch(id)) |
|
|
{ |
|
|
{ |
|
|
auto e = face()->envelope(h); |
|
|
auto e = face()->envelope(h); |
|
@ -1029,7 +1029,7 @@ Json::Value WebThreeStubServerBase::shh_getFilterChanges(string const& _filterId |
|
|
if (pub) |
|
|
if (pub) |
|
|
{ |
|
|
{ |
|
|
cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; |
|
|
cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; |
|
|
m = e.open(face()->fullTopic(id), m_ids[pub]); |
|
|
m = e.open(face()->fullTopic(id), m_shhIds[pub]); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
m = e.open(face()->fullTopic(id)); |
|
|
m = e.open(face()->fullTopic(id)); |
|
@ -1054,7 +1054,7 @@ Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId) |
|
|
|
|
|
|
|
|
int id = jsToInt(_filterId); |
|
|
int id = jsToInt(_filterId); |
|
|
auto pub = m_shhWatches[id]; |
|
|
auto pub = m_shhWatches[id]; |
|
|
if (!pub || m_ids.count(pub)) |
|
|
if (!pub || m_shhIds.count(pub)) |
|
|
for (h256 const& h: face()->watchMessages(id)) |
|
|
for (h256 const& h: face()->watchMessages(id)) |
|
|
{ |
|
|
{ |
|
|
auto e = face()->envelope(h); |
|
|
auto e = face()->envelope(h); |
|
@ -1062,7 +1062,7 @@ Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId) |
|
|
if (pub) |
|
|
if (pub) |
|
|
{ |
|
|
{ |
|
|
cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; |
|
|
cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; |
|
|
m = e.open(face()->fullTopic(id), m_ids[pub]); |
|
|
m = e.open(face()->fullTopic(id), m_shhIds[pub]); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
m = e.open(face()->fullTopic(id)); |
|
|
m = e.open(face()->fullTopic(id)); |
|
@ -1081,14 +1081,14 @@ Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId) |
|
|
void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _toProxy) |
|
|
void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _toProxy) |
|
|
{ |
|
|
{ |
|
|
if (_toProxy) |
|
|
if (_toProxy) |
|
|
m_accounts->queueTransaction(_t); |
|
|
m_ethAccounts->queueTransaction(_t); |
|
|
else if (_t.to) |
|
|
else if (_t.to) |
|
|
client()->submitTransaction(m_accounts->secretKey(_t.from), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice); |
|
|
client()->submitTransaction(m_ethAccounts->secretKey(_t.from), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice); |
|
|
else |
|
|
else |
|
|
client()->submitTransaction(m_accounts->secretKey(_t.from), _t.value, _t.data, _t.gas, _t.gasPrice); |
|
|
client()->submitTransaction(m_ethAccounts->secretKey(_t.from), _t.value, _t.data, _t.gas, _t.gasPrice); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void WebThreeStubServerBase::setAccounts(const vector<KeyPair>& _accounts) |
|
|
void WebThreeStubServerBase::setAccounts(const vector<KeyPair>& _accounts) |
|
|
{ |
|
|
{ |
|
|
m_accounts->setAccounts(_accounts); |
|
|
m_ethAccounts->setAccounts(_accounts); |
|
|
} |
|
|
} |
|
|