Browse Source

JSON-RPC initial implementation.

cl-refactor
Gav Wood 11 years ago
parent
commit
a1cb0932d8
  1. 2
      alethzero/MainWin.cpp
  2. 69
      eth/EthStubServer.cpp
  3. 21
      eth/EthStubServer.h
  4. 4
      eth/main.cpp
  5. 1
      libethcore/Common.cpp
  6. 2
      libethcore/Common.h
  7. 1
      libethereum/AddressState.cpp
  8. 1
      libethereum/ExtVM.cpp

2
alethzero/MainWin.cpp

@ -97,7 +97,7 @@ string htmlDump(bytes const& _b, unsigned _w = 8)
return ret.str();
}
Address c_config = Address("5620133321fcac7f15a5c570016f6cb6dc263f9d");
Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250");
using namespace boost::process;

69
eth/EthStubServer.cpp

@ -56,6 +56,75 @@ Json::Value EthStubServer::check(Json::Value const& _as)
}
}
Json::Value EthStubServer::create(const std::string& _bCode, const std::string& _sec, const std::string& _xEndowment, const std::string& _xGas, const std::string& _xGasPrice)
{
ClientGuard g(&m_client);
m_client.transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
return Json::Value();
}
std::string EthStubServer::gasPrice()
{
return "100000000000000";
}
bool EthStubServer::isContractAt(const std::string& _a)
{
ClientGuard g(&m_client);
return m_client.postState().addressHasCode(jsToAddress(_a));
}
bool EthStubServer::isListening()
{
return m_client.haveNetwork();
}
bool EthStubServer::isMining()
{
return m_client.isMining();
}
std::string EthStubServer::key()
{
if (!m_keys.size())
return std::string();
return toJS(m_keys[0].sec());
}
Json::Value EthStubServer::keys()
{
Json::Value ret;
for (auto i: m_keys)
ret.append(toJS(i.secret()));
return ret;
}
int EthStubServer::peerCount()
{
ClientGuard g(&m_client);
return m_client.peerCount();
}
std::string EthStubServer::storageAt(const std::string& _a, const std::string& x)
{
ClientGuard g(&m_client);
return toJS(m_client.postState().storage(jsToAddress(_a), jsToU256(x)));
}
Json::Value EthStubServer::transact(const std::string& _aDest, const std::string& _bData, const std::string& _sec, const std::string& _xGas, const std::string& _xGasPrice, const std::string& _xValue)
{
ClientGuard g(&m_client);
m_client.transact(jsToSecret(_sec), jsToU256(_xValue), jsToAddress(_aDest), jsToBytes(_bData), jsToU256(_xGas), jsToU256(_xGasPrice));
return Json::Value();
}
std::string EthStubServer::txCountAt(const std::string& _a)
{
ClientGuard g(&m_client);
return toJS(m_client.postState().transactionsFrom(jsToAddress(_a)));
}
std::string EthStubServer::secretToAddress(const std::string& _a)
{
return toJS(KeyPair(jsToSecret(_a)).address());
}

21
eth/EthStubServer.h

@ -23,19 +23,38 @@
#include <iostream>
#include <jsonrpc/rpc.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "abstractethstubserver.h"
#pragma GCC diagnostic pop
namespace eth { class Client; }
namespace eth { class KeyPair; }
class EthStubServer: public AbstractEthStubServer
{
public:
EthStubServer(jsonrpc::AbstractServerConnector* _conn, eth::Client& _client);
virtual std::string coinbase();
virtual std::string balanceAt(std::string const& _a);
virtual Json::Value check(Json::Value const& _as);
virtual std::string coinbase();
virtual Json::Value create(const std::string& bCode, const std::string& sec, const std::string& xEndowment, const std::string& xGas, const std::string& xGasPrice);
virtual std::string gasPrice();
virtual bool isContractAt(const std::string& a);
virtual bool isListening();
virtual bool isMining();
virtual std::string key();
virtual Json::Value keys();
virtual int peerCount();
virtual std::string storageAt(const std::string& a, const std::string& x);
virtual Json::Value transact(const std::string& aDest, const std::string& bData, const std::string& sec, const std::string& xGas, const std::string& xGasPrice, const std::string& xValue);
virtual std::string txCountAt(const std::string& a);
virtual std::string secretToAddress(const std::string& a);
void setKeys(std::vector<eth::KeyPair> _keys) { m_keys = _keys; }
private:
eth::Client& m_client;
std::vector<eth::KeyPair> m_keys;
};

4
eth/main.cpp

@ -142,8 +142,6 @@ void version()
exit(0);
}
u256 c_minGasPrice = 10000000000000;
u256 c_minGas = 100;
Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250");
string pretty(h160 _a, eth::State _st)
{
@ -291,6 +289,7 @@ int main(int argc, char** argv)
if (jsonrpc > -1)
{
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), c));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
#endif
@ -357,6 +356,7 @@ int main(int argc, char** argv)
unsigned port;
iss >> port;
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(port), c));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
else if (cmd == "jsonstop")

1
libethcore/Common.cpp

@ -24,4 +24,5 @@
using namespace std;
using namespace eth;
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace { char dummy; };

2
libethcore/Common.h

@ -24,7 +24,7 @@
#pragma once
// define version
#define ETH_VERSION 0.5.4
#define ETH_VERSION 0.5.5
// way to many uint to size_t warnings in 32 bit build
#ifdef _M_IX86

1
libethereum/AddressState.cpp

@ -24,5 +24,6 @@
using namespace std;
using namespace eth;
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace { char dummy; };

1
libethereum/ExtVM.cpp

@ -21,4 +21,5 @@
#include "ExtVM.h"
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace { char dummy; };

Loading…
Cancel
Save