implement light JSON_RPC version and split it from Full version.

List version send all request to remove JSNO-RPC server or proxy and handle only next methods:
eth_coinbase
eth_accounts
eth_sign
eth_sendTransaction
shh_*
This commit is contained in:
Yaroslav Dmytrotsa 2015-07-02 12:28:24 +03:00
parent ae517f349b
commit a8dbead829
91 changed files with 1535 additions and 406 deletions

View File

@ -67,4 +67,5 @@ dependencies {
compile "javax.persistence:persistence-api:1.0.2"
compile group: "com.thetransactioncompany", name: "jsonrpc2-server", version: "1.11"
compile group: "com.thetransactioncompany", name: "jsonrpc2-client", version: "1.15"
}

View File

@ -35,7 +35,8 @@ public class EthereumManager {
.ethereumModule(new EthereumModule(context))
.build().ethereum();
jsonRpcServer = new JsonRpcServer(ethereum);
//TODO: add here switch between full and light version
jsonRpcServer = new org.ethereum.android.jsonrpc.light.JsonRpcServer(ethereum);
}
public void start() {

View File

@ -1,226 +1,8 @@
package org.ethereum.android.jsonrpc;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.http.HttpObject;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.channel.ChannelFuture;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import io.netty.handler.codec.http.HttpHeaders;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import org.ethereum.android.jsonrpc.method.*;
import java.net.InetAddress;
public final class JsonRpcServer {
static final int PORT = 8545;
private Ethereum ethereum;
private Dispatcher dispatcher;
public JsonRpcServer(Ethereum ethereum) {
this.ethereum = ethereum;
this.dispatcher = new Dispatcher();
this.dispatcher.register(new web3_clientVersion(this.ethereum));
this.dispatcher.register(new web3_sha3(this.ethereum));
this.dispatcher.register(new net_version(this.ethereum));
this.dispatcher.register(new net_listening(this.ethereum));
this.dispatcher.register(new net_peerCount(this.ethereum));
this.dispatcher.register(new eth_protocolVersion(this.ethereum));
this.dispatcher.register(new eth_coinbase(this.ethereum));
this.dispatcher.register(new eth_mining(this.ethereum));
this.dispatcher.register(new eth_hashrate(this.ethereum));
this.dispatcher.register(new eth_gasPrice(this.ethereum));
this.dispatcher.register(new eth_accounts(this.ethereum));
this.dispatcher.register(new eth_blockNumber(this.ethereum));
this.dispatcher.register(new eth_getBalance(this.ethereum));
this.dispatcher.register(new eth_getStorageAt(this.ethereum));
this.dispatcher.register(new eth_getTransactionCount(this.ethereum));
this.dispatcher.register(new eth_getBlockTransactionCountByHash(this.ethereum));
this.dispatcher.register(new eth_getBlockTransactionCountByNumber(this.ethereum));
this.dispatcher.register(new eth_getUncleCountByBlockHash(this.ethereum));
this.dispatcher.register(new eth_getUncleCountByBlockNumber(this.ethereum));
this.dispatcher.register(new eth_getCode(this.ethereum));
this.dispatcher.register(new eth_sign(this.ethereum));
this.dispatcher.register(new eth_sendTransaction(this.ethereum));
this.dispatcher.register(new eth_call(this.ethereum));
this.dispatcher.register(new eth_estimateGas(this.ethereum));
this.dispatcher.register(new eth_getBlockByHash(this.ethereum));
this.dispatcher.register(new eth_getBlockByNumber(this.ethereum));
this.dispatcher.register(new eth_getTransactionByHash(this.ethereum));
this.dispatcher.register(new eth_getTransactionByBlockHashAndIndex(this.ethereum));
this.dispatcher.register(new eth_getTransactionByBlockNumberAndIndex(this.ethereum));
this.dispatcher.register(new eth_getUncleByBlockHashAndIndex(this.ethereum));
this.dispatcher.register(new eth_getUncleByBlockNumberAndIndex(this.ethereum));
this.dispatcher.register(new eth_getCompilers(this.ethereum));
this.dispatcher.register(new eth_compileSolidity(this.ethereum));
this.dispatcher.register(new eth_compileLLL(this.ethereum));
this.dispatcher.register(new eth_compileSerpent(this.ethereum));
this.dispatcher.register(new eth_newFilter(this.ethereum));
this.dispatcher.register(new eth_newBlockFilter(this.ethereum));
this.dispatcher.register(new eth_newPendingTransactionFilter(this.ethereum));
this.dispatcher.register(new eth_uninstallFilter(this.ethereum));
this.dispatcher.register(new eth_getFilterChanges(this.ethereum));
this.dispatcher.register(new eth_getFilterLogs(this.ethereum));
this.dispatcher.register(new eth_getLogs(this.ethereum));
this.dispatcher.register(new eth_getWork(this.ethereum));
this.dispatcher.register(new eth_submitWork(this.ethereum));
this.dispatcher.register(new db_putString(this.ethereum));
this.dispatcher.register(new db_getString(this.ethereum));
this.dispatcher.register(new db_putHex(this.ethereum));
this.dispatcher.register(new db_getHex(this.ethereum));
this.dispatcher.register(new shh_version(this.ethereum));
this.dispatcher.register(new shh_post(this.ethereum));
this.dispatcher.register(new shh_newIdentity(this.ethereum));
this.dispatcher.register(new shh_hasIdentity(this.ethereum));
this.dispatcher.register(new shh_newGroup(this.ethereum));
this.dispatcher.register(new shh_addToGroup(this.ethereum));
this.dispatcher.register(new shh_newFilter(this.ethereum));
this.dispatcher.register(new shh_uninstallFilter(this.ethereum));
this.dispatcher.register(new shh_getFilterChanges(this.ethereum));
this.dispatcher.register(new shh_getMessages(this.ethereum));
ethereum.addListener(FilterManager.getInstance());
org.ethereum.android.jsonrpc.whisper.FilterManager.getInstance();
}
public void start() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.localAddress(InetAddress.getLocalHost(), PORT);
// b.localAddress(PORT);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new JsonRpcServerInitializer());
Channel ch = b.bind().sync().channel();
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
class JsonRpcServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new JsonRpcServerHandler());
}
}
class JsonRpcServerHandler extends SimpleChannelInboundHandler<HttpObject> {
private HttpRequest request;
private final StringBuilder responseContent = new StringBuilder();
private HttpPostStandardRequestDecoder decoder;
private String postData;
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (decoder != null) {
decoder.destroy();
}
}
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest req = this.request = (HttpRequest) msg;
if (!req.getUri().equals("/") || !request.getMethod().equals(HttpMethod.POST)) {
responseContent.append("Hi, how are you?!!");
return;
} else {
decoder = new HttpPostStandardRequestDecoder(new DefaultHttpDataFactory(false), req);
postData = "";
}
}
if (decoder != null) {
if (msg instanceof HttpContent) {
HttpContent chunk = (HttpContent) msg;
decoder.offer(chunk);
postData += chunk.content().toString(0, chunk.content().capacity(), CharsetUtil.UTF_8);
if (chunk instanceof LastHttpContent) {
JSONRPC2Request req = JSONRPC2Request.parse(postData);
JSONRPC2Response resp = dispatcher.process(req, null);
responseContent.append(resp);
writeResponse(ctx);
request = null;
decoder.destroy();
decoder = null;
}
}
} else {
writeResponse(ctx);
}
}
private void writeResponse(ChannelHandlerContext ctx) {
ByteBuf buf = Unpooled.copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8);
responseContent.setLength(0);
boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION))
|| request.getProtocolVersion().equals(HttpVersion.HTTP_1_0)
&& !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION));
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
if (!close) {
response.headers().set(CONTENT_LENGTH, buf.readableBytes());
}
ChannelFuture future = ctx.writeAndFlush(response);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
public abstract class JsonRpcServer {
public JsonRpcServer(Ethereum ethereum) {};
public abstract void start() throws Exception;
}

View File

@ -0,0 +1,226 @@
package org.ethereum.android.jsonrpc.full;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.http.HttpObject;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.channel.ChannelFuture;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import io.netty.handler.codec.http.HttpHeaders;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import org.ethereum.android.jsonrpc.full.method.*;
import java.net.InetAddress;
public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcServer{
static final int PORT = 8545;
private Ethereum ethereum;
private Dispatcher dispatcher;
public JsonRpcServer(Ethereum ethereum) {
super(ethereum);
this.ethereum = ethereum;
this.dispatcher = new Dispatcher();
this.dispatcher.register(new web3_clientVersion(this.ethereum));
this.dispatcher.register(new web3_sha3(this.ethereum));
this.dispatcher.register(new net_version(this.ethereum));
this.dispatcher.register(new net_listening(this.ethereum));
this.dispatcher.register(new net_peerCount(this.ethereum));
this.dispatcher.register(new eth_protocolVersion(this.ethereum));
this.dispatcher.register(new eth_coinbase(this.ethereum));
this.dispatcher.register(new eth_mining(this.ethereum));
this.dispatcher.register(new eth_hashrate(this.ethereum));
this.dispatcher.register(new eth_gasPrice(this.ethereum));
this.dispatcher.register(new eth_accounts(this.ethereum));
this.dispatcher.register(new eth_blockNumber(this.ethereum));
this.dispatcher.register(new eth_getBalance(this.ethereum));
this.dispatcher.register(new eth_getStorageAt(this.ethereum));
this.dispatcher.register(new eth_getTransactionCount(this.ethereum));
this.dispatcher.register(new eth_getBlockTransactionCountByHash(this.ethereum));
this.dispatcher.register(new eth_getBlockTransactionCountByNumber(this.ethereum));
this.dispatcher.register(new eth_getUncleCountByBlockHash(this.ethereum));
this.dispatcher.register(new eth_getUncleCountByBlockNumber(this.ethereum));
this.dispatcher.register(new eth_getCode(this.ethereum));
this.dispatcher.register(new eth_sign(this.ethereum));
this.dispatcher.register(new eth_sendTransaction(this.ethereum));
this.dispatcher.register(new eth_call(this.ethereum));
this.dispatcher.register(new eth_estimateGas(this.ethereum));
this.dispatcher.register(new eth_getBlockByHash(this.ethereum));
this.dispatcher.register(new eth_getBlockByNumber(this.ethereum));
this.dispatcher.register(new eth_getTransactionByHash(this.ethereum));
this.dispatcher.register(new eth_getTransactionByBlockHashAndIndex(this.ethereum));
this.dispatcher.register(new eth_getTransactionByBlockNumberAndIndex(this.ethereum));
this.dispatcher.register(new eth_getUncleByBlockHashAndIndex(this.ethereum));
this.dispatcher.register(new eth_getUncleByBlockNumberAndIndex(this.ethereum));
this.dispatcher.register(new eth_getCompilers(this.ethereum));
this.dispatcher.register(new eth_compileSolidity(this.ethereum));
this.dispatcher.register(new eth_compileLLL(this.ethereum));
this.dispatcher.register(new eth_compileSerpent(this.ethereum));
this.dispatcher.register(new eth_newFilter(this.ethereum));
this.dispatcher.register(new eth_newBlockFilter(this.ethereum));
this.dispatcher.register(new eth_newPendingTransactionFilter(this.ethereum));
this.dispatcher.register(new eth_uninstallFilter(this.ethereum));
this.dispatcher.register(new eth_getFilterChanges(this.ethereum));
this.dispatcher.register(new eth_getFilterLogs(this.ethereum));
this.dispatcher.register(new eth_getLogs(this.ethereum));
this.dispatcher.register(new eth_getWork(this.ethereum));
this.dispatcher.register(new eth_submitWork(this.ethereum));
this.dispatcher.register(new db_putString(this.ethereum));
this.dispatcher.register(new db_getString(this.ethereum));
this.dispatcher.register(new db_putHex(this.ethereum));
this.dispatcher.register(new db_getHex(this.ethereum));
this.dispatcher.register(new shh_version(this.ethereum));
this.dispatcher.register(new shh_post(this.ethereum));
this.dispatcher.register(new shh_newIdentity(this.ethereum));
this.dispatcher.register(new shh_hasIdentity(this.ethereum));
this.dispatcher.register(new shh_newGroup(this.ethereum));
this.dispatcher.register(new shh_addToGroup(this.ethereum));
this.dispatcher.register(new shh_newFilter(this.ethereum));
this.dispatcher.register(new shh_uninstallFilter(this.ethereum));
this.dispatcher.register(new shh_getFilterChanges(this.ethereum));
this.dispatcher.register(new shh_getMessages(this.ethereum));
ethereum.addListener(FilterManager.getInstance());
org.ethereum.android.jsonrpc.full.whisper.FilterManager.getInstance();
}
public void start() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.localAddress(InetAddress.getLocalHost(), PORT);
// b.localAddress(PORT);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new JsonRpcServerInitializer());
Channel ch = b.bind().sync().channel();
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
class JsonRpcServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new JsonRpcServerHandler());
}
}
class JsonRpcServerHandler extends SimpleChannelInboundHandler<HttpObject> {
private HttpRequest request;
private final StringBuilder responseContent = new StringBuilder();
private HttpPostStandardRequestDecoder decoder;
private String postData;
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (decoder != null) {
decoder.destroy();
}
}
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest req = this.request = (HttpRequest) msg;
if (!req.getUri().equals("/") || !request.getMethod().equals(HttpMethod.POST)) {
responseContent.append("Hi, how are you?!!");
return;
} else {
decoder = new HttpPostStandardRequestDecoder(new DefaultHttpDataFactory(false), req);
postData = "";
}
}
if (decoder != null) {
if (msg instanceof HttpContent) {
HttpContent chunk = (HttpContent) msg;
decoder.offer(chunk);
postData += chunk.content().toString(0, chunk.content().capacity(), CharsetUtil.UTF_8);
if (chunk instanceof LastHttpContent) {
JSONRPC2Request req = JSONRPC2Request.parse(postData);
JSONRPC2Response resp = dispatcher.process(req, null);
responseContent.append(resp);
writeResponse(ctx);
request = null;
decoder.destroy();
decoder = null;
}
}
} else {
writeResponse(ctx);
}
}
private void writeResponse(ChannelHandlerContext ctx) {
ByteBuf buf = Unpooled.copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8);
responseContent.setLength(0);
boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION))
|| request.getProtocolVersion().equals(HttpVersion.HTTP_1_0)
&& !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION));
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
if (!close) {
response.headers().set(CONTENT_LENGTH, buf.readableBytes());
}
ChannelFuture future = ctx.writeAndFlush(response);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
}

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc;
package org.ethereum.android.jsonrpc.full;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
@ -8,7 +8,7 @@ import net.minidev.json.JSONObject;
import org.ethereum.android.db.BlockTransactionVO;
import org.ethereum.android.db.OrmLiteBlockStoreDatabase;
import org.ethereum.android.jsonrpc.JsonRpcServer;
import org.ethereum.android.jsonrpc.full.JsonRpcServer;
import org.ethereum.core.Account;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
@ -91,7 +91,7 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
throw new Exception("");
}
byte[] from = ((Account) ethereum.getWallet().getAccountCollection().toArray()[1]).getEcKey().getAddress();
byte[] from = getCoinBase();
if (obj.containsKey("from") && !((String)obj.get("from")).equals("")) {
from = jsToAddress((String) obj.get("from"));
}
@ -271,4 +271,8 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
return res;
}
protected byte[] getCoinBase() {
return ((Account) ethereum.getWallet().getAccountCollection().toArray()[0]).getEcKey().getAddress();
}
}

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.filter;
package org.ethereum.android.jsonrpc.full.filter;
import net.minidev.json.JSONArray;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.filter;
package org.ethereum.android.jsonrpc.full.filter;
import net.minidev.json.JSONArray;
import org.ethereum.core.Block;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.filter;
package org.ethereum.android.jsonrpc.full.filter;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.filter;
package org.ethereum.android.jsonrpc.full.filter;
import net.minidev.json.JSONArray;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.filter;
package org.ethereum.android.jsonrpc.full.filter;
import net.minidev.json.JSONArray;
import org.ethereum.core.Transaction;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.core.*;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
public class eth_blockNumber extends JsonRpcServerMethod {

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.Program;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.core.*;
import org.spongycastle.util.encoders.Hex;
@ -18,8 +18,7 @@ public class eth_coinbase extends JsonRpcServerMethod {
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
Wallet w = ethereum.getWallet();
String tmp = "0x" + Hex.toHexString(((Account) w.getAccountCollection().toArray()[1]).getEcKey().getAddress());
String tmp = "0x" + getCoinBase();
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
import org.ethereum.serpent.SerpentCompiler;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
@ -10,7 +10,7 @@ import java.math.BigInteger;
import java.util.List;
/*
ATODO: -core not have solidity compiler. Need try to use cpp solidity compiler using JNI
TODO: -core not have Solidity compiler
*/
public class eth_compileSolidity extends JsonRpcServerMethod {

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.Program;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import static org.ethereum.core.Denomination.SZABO;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.ArrayList;

View File

@ -1,12 +1,12 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterBase;
import org.ethereum.android.jsonrpc.filter.FilterLog;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterBase;
import org.ethereum.android.jsonrpc.full.filter.FilterLog;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,12 +1,12 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterBase;
import org.ethereum.android.jsonrpc.filter.FilterLog;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterBase;
import org.ethereum.android.jsonrpc.full.filter.FilterLog;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,11 +1,11 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterLog;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterLog;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServer;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServer;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.DataWord;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,11 +1,11 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.facade.Ethereum;

View File

@ -1,11 +1,11 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServer;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServer;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Block;
import org.ethereum.crypto.HashUtil;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Block;
import org.ethereum.crypto.HashUtil;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,10 +1,10 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterBlock;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterBlock;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
public class eth_newBlockFilter extends JsonRpcServerMethod {

View File

@ -1,11 +1,11 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterLog;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterLog;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,11 +1,11 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterBlock;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.filter.FilterTransaction;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterBlock;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.filter.FilterTransaction;
import org.ethereum.facade.Ethereum;
public class eth_newPendingTransactionFilter extends JsonRpcServerMethod {

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.net.eth.EthHandler;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Account;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Account;
import org.ethereum.crypto.ECKey;
import org.ethereum.facade.Ethereum;
@ -26,25 +26,24 @@ public class eth_sign extends JsonRpcServerMethod {
} else {
byte[] address = jsToAddress((String) params.get(0));
byte[] data = jsToAddress((String) params.get(1));
String out = null;
byte[] sigData = null;
for (Account ac : ethereum.getWallet().getAccountCollection()) {
if (Arrays.equals(ac.getAddress(), address)) {
ECKey.ECDSASignature sig = ac.getEcKey().doSign(data);
byte[] sigData = new byte[65];
sigData = new byte[65];
sigData[0] = sig.v;
System.arraycopy(bigIntegerToBytes(sig.r, 32), 0, sigData, 1, 32);
System.arraycopy(bigIntegerToBytes(sig.s, 32), 0, sigData, 33, 32);
out = Hex.toHexString(sigData);
break;
}
}
if (out == null) {
if (sigData == null) {
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
}
String tmp = "0x" + out;
String tmp = "0x" + Hex.toHexString(sigData);
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,12 +1,12 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.filter.FilterBase;
import org.ethereum.android.jsonrpc.filter.FilterLog;
import org.ethereum.android.jsonrpc.filter.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.filter.FilterBase;
import org.ethereum.android.jsonrpc.full.filter.FilterLog;
import org.ethereum.android.jsonrpc.full.filter.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
public class net_listening extends JsonRpcServerMethod {

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.net.peerdiscovery.PeerInfo;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.whisper.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.whisper.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,13 +1,13 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.whisper.Filter;
import org.ethereum.android.jsonrpc.whisper.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.whisper.Filter;
import org.ethereum.android.jsonrpc.full.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
@ -6,7 +6,7 @@ import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,9 +1,9 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.whisper.FilterManager;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.net.shh.ShhHandler;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.config.SystemProperties;
import org.ethereum.facade.Ethereum;
import org.ethereum.util.Utils;

View File

@ -1,8 +1,8 @@
package org.ethereum.android.jsonrpc.method;
package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.crypto.SHA3Helper;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.whisper;
package org.ethereum.android.jsonrpc.full.whisper;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

View File

@ -1,4 +1,4 @@
package org.ethereum.android.jsonrpc.whisper;
package org.ethereum.android.jsonrpc.full.whisper;
import net.minidev.json.JSONArray;

View File

@ -0,0 +1,181 @@
package org.ethereum.android.jsonrpc.light;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.http.HttpObject;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.channel.ChannelFuture;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import io.netty.handler.codec.http.HttpHeaders;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import org.ethereum.android.jsonrpc.light.method.*;
import java.net.InetAddress;
public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcServer{
static public final int PORT = 8545;
static public final String RemoteServer = "http://192.168.1.30:8545/";
private Ethereum ethereum;
private Dispatcher dispatcher;
public JsonRpcServer(Ethereum ethereum) {
super(ethereum);
this.ethereum = ethereum;
this.dispatcher = new Dispatcher();
this.dispatcher.register(new eth_coinbase(this.ethereum));
this.dispatcher.register(new eth_accounts(this.ethereum));
this.dispatcher.register(new eth_sign(this.ethereum));
this.dispatcher.register(new eth_sendTransaction(this.ethereum));
this.dispatcher.register(new shh_version(this.ethereum));
this.dispatcher.register(new shh_post(this.ethereum));
this.dispatcher.register(new shh_newIdentity(this.ethereum));
this.dispatcher.register(new shh_hasIdentity(this.ethereum));
this.dispatcher.register(new shh_newGroup(this.ethereum));
this.dispatcher.register(new shh_addToGroup(this.ethereum));
this.dispatcher.register(new shh_newFilter(this.ethereum));
this.dispatcher.register(new shh_uninstallFilter(this.ethereum));
this.dispatcher.register(new shh_getFilterChanges(this.ethereum));
this.dispatcher.register(new shh_getMessages(this.ethereum));
this.dispatcher.register(new proxy(this.ethereum));
FilterManager.getInstance();
}
public void start() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
// b.localAddress(InetAddress.getLocalHost(), PORT);
b.localAddress(PORT);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new JsonRpcServerInitializer());
Channel ch = b.bind().sync().channel();
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
class JsonRpcServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new JsonRpcServerHandler());
}
}
class JsonRpcServerHandler extends SimpleChannelInboundHandler<HttpObject> {
private HttpRequest request;
private final StringBuilder responseContent = new StringBuilder();
private HttpPostStandardRequestDecoder decoder;
private String postData;
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (decoder != null) {
decoder.destroy();
}
}
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest req = this.request = (HttpRequest) msg;
if (!req.getUri().equals("/") || !request.getMethod().equals(HttpMethod.POST)) {
responseContent.append("Hi, how are you?!!");
return;
} else {
decoder = new HttpPostStandardRequestDecoder(new DefaultHttpDataFactory(false), req);
postData = "";
}
}
if (decoder != null) {
if (msg instanceof HttpContent) {
HttpContent chunk = (HttpContent) msg;
decoder.offer(chunk);
postData += chunk.content().toString(0, chunk.content().capacity(), CharsetUtil.UTF_8);
if (chunk instanceof LastHttpContent) {
JSONRPC2Request req = JSONRPC2Request.parse(postData);
JSONRPC2Response resp = dispatcher.process(req, null);
responseContent.append(resp);
writeResponse(ctx);
request = null;
decoder.destroy();
decoder = null;
}
}
} else {
writeResponse(ctx);
}
}
private void writeResponse(ChannelHandlerContext ctx) {
ByteBuf buf = Unpooled.copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8);
responseContent.setLength(0);
boolean close = HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(CONNECTION))
|| request.getProtocolVersion().equals(HttpVersion.HTTP_1_0)
&& !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(CONNECTION));
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
if (!close) {
response.headers().set(CONTENT_LENGTH, buf.readableBytes());
}
ChannelFuture future = ctx.writeAndFlush(response);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
}

View File

@ -0,0 +1,207 @@
package org.ethereum.android.jsonrpc.light;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.core.Account;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import static org.ethereum.core.Denomination.SZABO;
public abstract class JsonRpcServerMethod implements RequestHandler {
private String name = "";
protected Ethereum ethereum;
private JSONRPC2Session jpSession;
public JsonRpcServerMethod(Ethereum ethereum) {
this.ethereum = ethereum;
name = this.getClass().getSimpleName();
}
public String[] handledRequests() {
return new String[]{name};
}
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals(name)) {
return worker(req, ctx);
} else {
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}
}
protected abstract JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx);
protected long getBlockNumber(String height) {
long blockNumber = 0;
switch (height) {
case "earliest":
blockNumber = 0;
break;
case "latest":
blockNumber = -1;
break;
case "pending":
blockNumber = -2;
break;
default:
blockNumber = jsToLong(height);
}
if (blockNumber >= 0)
blockNumber = -1;
return blockNumber;
}
protected byte[] jsToAddress(String data) {
return Hex.decode(data.substring(2));
}
protected int jsToInt(String data) {
return Integer.parseInt(data.substring(2), 16);
}
protected long jsToLong(String data) {
return Long.parseLong(data.substring(2), 16);
}
protected BigInteger jsToBigInteger(String data) {
return new BigInteger(data.substring(2), 16);
}
protected Transaction jsToTransaction(JSONObject obj) throws Exception {
if ((!obj.containsKey("to") || ((String)obj.get("to")).equals("")) && (!obj.containsKey("data") || ((String)obj.get("data")).equals(""))) {
throw new Exception("");
}
byte[] from = getCoinBase();
if (obj.containsKey("from") && !((String)obj.get("from")).equals("")) {
from = jsToAddress((String) obj.get("from"));
}
Account acc = null;
for (Account ac : ethereum.getWallet().getAccountCollection()) {
if (Arrays.equals(ac.getAddress(), from)) {
acc = ac;
break;
}
}
if (acc == null) {
throw new Exception("");
}
byte[] senderPrivKey = acc.getEcKey().getPrivKeyBytes();
// default - from ethereumj-studio
byte[] to = null;
if (obj.containsKey("to") && !((String)obj.get("to")).equals("")) {
to = jsToAddress((String) obj.get("to"));
}
// default - from ethereumj-studio
BigInteger gasPrice = SZABO.value().multiply(BigInteger.TEN);
if (obj.containsKey("gasPrice") && !((String)obj.get("gasPrice")).equals("")) {
gasPrice = jsToBigInteger((String) obj.get("gasPrice"));
}
// default - from cpp-ethereum
BigInteger gas = getBalance(from).divide(gasPrice);
BigInteger gasBBRemaining = getLatestBlockGasRemaining();
if (gasBBRemaining.compareTo(gas) < 0)
gas = gasBBRemaining;
if (obj.containsKey("gas") && !((String)obj.get("gas")).equals("")) {
gas = jsToBigInteger((String) obj.get("gas"));
}
// default - from ethereumj-studio
BigInteger value = new BigInteger("1000");
if (obj.containsKey("value") && !((String)obj.get("value")).equals("")) {
value = jsToBigInteger((String) obj.get("value"));
}
// default - from ethereumj-studio
BigInteger nonce = getTransactionCount(from);
if (obj.containsKey("nonce") && !((String)obj.get("nonce")).equals("")) {
nonce = jsToBigInteger((String) obj.get("nonce"));
}
// default - from ethereumj-studio
byte[] data = new byte[]{};
if (obj.containsKey("data") && !((String)obj.get("data")).equals("")) {
data = jsToAddress((String) obj.get("data"));
}
Transaction tx = ethereum.createTransaction(nonce, gasPrice, gas, to, value, data);
tx.sign(senderPrivKey);
return tx;
}
protected JSONRPC2Response getRemoteData(JSONRPC2Request req) {
if (jpSession == null) {
try {
jpSession = new JSONRPC2Session(new URL(JsonRpcServer.RemoteServer));
} catch (Exception e) {
return null;
}
}
try {
return jpSession.send(req);
} catch (Exception e) {
return null;
}
}
protected byte[] getCoinBase() {
return ((Account) ethereum.getWallet().getAccountCollection().toArray()[0]).getEcKey().getAddress();
}
protected BigInteger getBalance(byte[] account) {
ArrayList<Object> params = new ArrayList<Object>();
params.add("0x" + Hex.toHexString(account));
params.add("latest");
JSONRPC2Request req = new JSONRPC2Request("eth_getBalance", params, 1000);
JSONRPC2Response res = getRemoteData(req);
if (res == null || !res.indicatesSuccess()) {
return BigInteger.ZERO;
} else {
return jsToBigInteger(res.getResult().toString());
}
}
protected BigInteger getLatestBlockGasRemaining() {
ArrayList<Object> params = new ArrayList<Object>();
params.add("latest");
params.add(false);
JSONRPC2Request req = new JSONRPC2Request("eth_getBlockByNumber", params, 1000);
JSONRPC2Response res = getRemoteData(req);
if (res == null || !res.indicatesSuccess()) {
return BigInteger.ZERO;
} else {
JSONObject block = (JSONObject)res.getResult();
return jsToBigInteger((String)block.get("gasLimit")).add(jsToBigInteger((String)block.get("gasUsed")).negate());
}
}
protected BigInteger getTransactionCount(byte[] account) {
ArrayList<Object> params = new ArrayList<Object>();
params.add("0x" + Hex.toHexString(account));
params.add("latest");
JSONRPC2Request req = new JSONRPC2Request("eth_getTransactionCount", params, 1000);
JSONRPC2Response res = getRemoteData(req);
if (res == null || !res.indicatesSuccess()) {
return BigInteger.ZERO;
} else {
return jsToBigInteger(res.getResult().toString());
}
}
}

View File

@ -0,0 +1,29 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.core.*;
import org.spongycastle.util.encoders.Hex;
import java.util.ArrayList;
import java.util.Collection;
public class eth_accounts extends JsonRpcServerMethod {
public eth_accounts (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
Collection<Account> accounts = ethereum.getWallet().getAccountCollection();
ArrayList<String> tmp = new ArrayList<String>();
for (Account ac : accounts) {
tmp.add("0x" + Hex.toHexString(ac.getEcKey().getAddress()));
}
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}
}

View File

@ -0,0 +1,23 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.core.*;
import org.spongycastle.util.encoders.Hex;
public class eth_coinbase extends JsonRpcServerMethod {
public eth_coinbase (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
String tmp = "0x" + getCoinBase();
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}
}

View File

@ -0,0 +1,53 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.core.Account;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.ethereum.core.Denomination.SZABO;
import static org.ethereum.config.SystemProperties.CONFIG;
public class eth_sendTransaction extends JsonRpcServerMethod {
public eth_sendTransaction (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
JSONObject obj = (JSONObject)params.get(0);
Transaction tx;
try {
tx = jsToTransaction(obj);
} catch (Exception e) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
}
ArrayList<Object> rparams = new ArrayList<Object>();
params.add("0x" + Hex.toHexString(tx.getEncoded()));
JSONRPC2Request rreq = new JSONRPC2Request("eth_sendRawTransaction", rparams, req.getID());
JSONRPC2Response rres = getRemoteData(rreq);
if (rres == null) {
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
}
JSONRPC2Response res = new JSONRPC2Response(rres.getResult(), req.getID());
return res;
}
}
}

View File

@ -0,0 +1,52 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.core.Account;
import org.ethereum.crypto.ECKey;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.Arrays;
import java.util.List;
import static org.ethereum.util.ByteUtil.bigIntegerToBytes;
public class eth_sign extends JsonRpcServerMethod {
public eth_sign (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 2) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
byte[] address = jsToAddress((String) params.get(0));
byte[] data = jsToAddress((String) params.get(1));
byte[] sigData = null;
for (Account ac : ethereum.getWallet().getAccountCollection()) {
if (Arrays.equals(ac.getAddress(), address)) {
ECKey.ECDSASignature sig = ac.getEcKey().doSign(data);
sigData = new byte[65];
sigData[0] = sig.v;
System.arraycopy(bigIntegerToBytes(sig.r, 32), 0, sigData, 1, 32);
System.arraycopy(bigIntegerToBytes(sig.s, 32), 0, sigData, 33, 32);
break;
}
}
if (sigData == null) {
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
}
String tmp = "0x" + Hex.toHexString(sigData);
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}
}
}

View File

@ -0,0 +1,90 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.ArrayList;
public class proxy extends JsonRpcServerMethod {
ArrayList<String> proxyMethods;
ArrayList<String> deprecatedMethods;
public proxy (Ethereum ethereum)
{
super(ethereum);
proxyMethods = new ArrayList<>();
proxyMethods.add("web3_clientVersion");
proxyMethods.add("web3_sha3");
proxyMethods.add("net_version");
proxyMethods.add("net_listening");
proxyMethods.add("net_peerCount");
proxyMethods.add("eth_protocolVersion");
proxyMethods.add("eth_gasPrice");
proxyMethods.add("eth_blockNumber");
proxyMethods.add("eth_getBalance");
proxyMethods.add("eth_getStorageAt");
proxyMethods.add("eth_getTransactionCount");
proxyMethods.add("eth_getBlockTransactionCountByHash");
proxyMethods.add("eth_getBlockTransactionCountByNumber");
proxyMethods.add("eth_getUncleCountByBlockHash");
proxyMethods.add("eth_getUncleCountByBlockNumber");
proxyMethods.add("eth_getCode");
proxyMethods.add("eth_getBlockByHash");
proxyMethods.add("eth_getBlockByNumber");
proxyMethods.add("eth_getTransactionByHash");
proxyMethods.add("eth_getTransactionByBlockHashAndIndex");
proxyMethods.add("eth_getTransactionByBlockNumberAndIndex");
proxyMethods.add("eth_getUncleByBlockHashAndIndex");
proxyMethods.add("eth_getUncleByBlockNumberAndIndex");
proxyMethods.add("eth_getCompilers");
proxyMethods.add("eth_compileSolidity");
proxyMethods.add("eth_compileLLL");
proxyMethods.add("eth_compileSerpent");
proxyMethods.add("eth_newFilter");
proxyMethods.add("eth_newBlockFilter");
proxyMethods.add("eth_newPendingTransactionFilter");
proxyMethods.add("eth_uninstallFilter");
proxyMethods.add("eth_getFilterChanges");
proxyMethods.add("eth_getFilterLogs");
proxyMethods.add("eth_getLogs");
//TODO: issue methods - they generate transaction but must call them in blockchain.
proxyMethods.add("eth_call");
proxyMethods.add("eth_estimateGas");
deprecatedMethods = new ArrayList<>();
//db - deprecated in specification
deprecatedMethods.add("db_getHex");
deprecatedMethods.add("db_getString");
deprecatedMethods.add("db_putHex");
deprecatedMethods.add("db_putString");
//mining - deprecated because will be mess over global.
deprecatedMethods.add("eth_getWork");
deprecatedMethods.add("eth_hashrate");
deprecatedMethods.add("eth_mining");
deprecatedMethods.add("eth_submitWork");
}
@Override
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (proxyMethods.contains(req.getMethod())) {
return worker(req, ctx);
} else if (deprecatedMethods.contains(req.getMethod())) {
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
} else {
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
JSONRPC2Response res = getRemoteData(req);
if (res == null) {
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
}
return res;
}
}

View File

@ -0,0 +1,32 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;
/*
TODO: not present clear specification for this method, also cpp and go version not provide it.
*/
public class shh_addToGroup extends JsonRpcServerMethod {
public shh_addToGroup(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
byte[] identity = jsToAddress((String)params.get(0));
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;
}
}
}

View File

@ -0,0 +1,29 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;
public class shh_getFilterChanges extends JsonRpcServerMethod {
public shh_getFilterChanges(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
int id = jsToInt((String)params.get(0));
JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().toJS(id), req.getID());
return res;
}
}
}

View File

@ -0,0 +1,29 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;
public class shh_getMessages extends JsonRpcServerMethod {
public shh_getMessages(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
int id = jsToInt((String)params.get(0));
JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().toJSAll(id), req.getID());
return res;
}
}
}

View File

@ -0,0 +1,32 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import java.util.List;
/*
TODO: done it when shh will be ready in -core
*/
public class shh_hasIdentity extends JsonRpcServerMethod {
public shh_hasIdentity(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
byte[] identity = jsToAddress((String)params.get(0));
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;
}
}
}

View File

@ -0,0 +1,35 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.light.whisper.Filter;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;
public class shh_newFilter extends JsonRpcServerMethod {
public shh_newFilter(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
JSONObject obj = (JSONObject)params.get(0);
int id = FilterManager.getInstance().addFilter(new Filter(obj));
String tmp = "0x" + Integer.toHexString(id);
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}
}
}

View File

@ -0,0 +1,23 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: not present clear specification for this method, also cpp and go version not provide it.
*/
public class shh_newGroup extends JsonRpcServerMethod {
public shh_newGroup(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;
}
}

View File

@ -0,0 +1,23 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: done it when shh will be ready in -core
*/
public class shh_newIdentity extends JsonRpcServerMethod {
public shh_newIdentity(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;
}
}

View File

@ -0,0 +1,60 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.ArrayList;
import java.util.List;
/*
TODO: done it when shh will be ready in -core
*/
public class shh_post extends JsonRpcServerMethod {
public shh_post (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
JSONObject obj = (JSONObject)params.get(0);
byte[] from = null;
if (obj.containsKey("from"))
from = jsToAddress((String)obj.get("from"));
byte[] to = null;
if (obj.containsKey("to"))
to = jsToAddress((String)obj.get("to"));
ArrayList<byte[]> topics = new ArrayList<>();
for (Object item : (JSONArray)obj.get("topics")) {
if (item instanceof String) {
topics.add(jsToAddress((String)item));
}
}
byte[] payload = jsToAddress((String)obj.get("payload"));
int priority = jsToInt((String) obj.get("priority"));
int ttl = jsToInt((String)obj.get("ttl"));
//TODO: implement after Adrian merge with dev
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;
}
}
}

View File

@ -0,0 +1,29 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import java.util.List;
public class shh_uninstallFilter extends JsonRpcServerMethod {
public shh_uninstallFilter(Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
List<Object> params = req.getPositionalParams();
if (params.size() != 1) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
} else {
int id = jsToInt((String)params.get(0));
JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().uninstallFilter(id), req.getID());
return res;
}
}
}

View File

@ -0,0 +1,22 @@
package org.ethereum.android.jsonrpc.light.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
import org.ethereum.net.shh.ShhHandler;
public class shh_version extends JsonRpcServerMethod {
public shh_version (Ethereum ethereum) {
super(ethereum);
}
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
String tmp = "" + ShhHandler.VERSION;
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;
}
}

View File

@ -0,0 +1,86 @@
package org.ethereum.android.jsonrpc.light.whisper;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.ethereum.facade.Ethereum;
import org.ethereum.net.shh.ShhMessage;
import org.spongycastle.util.encoders.Hex;
import java.util.ArrayList;
/*
TODO: replace ShhMessage with real class when Roman finish Shh.
*/
public class Filter {
protected int id;
protected ArrayList<ShhMessage> messages;
byte[] to = null;
boolean isWildcard = false;
ArrayList<ArrayList<byte[]>> or;
ArrayList<byte[]> and;
int sendID = 0;
public Filter (JSONObject data) {
messages = new ArrayList<ShhMessage>();
if (data.containsKey("to")) {
to = Hex.decode(((String)data.get("to")).substring(2));
}
JSONArray topics = (JSONArray)data.get("topics");
for (Object item : topics) {
if (item == null) {
isWildcard = true;
}
else if (item instanceof JSONArray) {
ArrayList<byte[]> tmp = new ArrayList<byte[]>();
for (Object ori : (JSONArray)item) {
if (ori instanceof String) {
tmp.add(Hex.decode(((String)ori).substring(2)));
}
}
or.add(tmp);
} else if (item instanceof String) {
and.add(Hex.decode(((String)item).substring(2)));
}
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void processEvent(Object data) {
//TODO: parse incomming data when we will know what comes.
}
public JSONArray toJS() {
JSONArray res = new JSONArray();
synchronized (messages) {
for (int i = sendID; i < messages.size(); i++) {
res.add(toJS(messages.get(i)));
}
sendID = messages.size();
}
return res;
}
public JSONArray toJSAll() {
JSONArray res = new JSONArray();
synchronized (messages) {
for (int i = 0; i < messages.size(); i++) {
res.add(toJS(messages.get(i)));
}
sendID = messages.size();
}
return res;
}
private JSONObject toJS (ShhMessage data) {
JSONObject res = new JSONObject();
return res;
}
}

View File

@ -0,0 +1,80 @@
package org.ethereum.android.jsonrpc.light.whisper;
import net.minidev.json.JSONArray;
import org.ethereum.facade.Ethereum;
import java.util.Hashtable;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
/*
This class must receive notification from -core about new whisper message. Right now I not see the way to do that.
TODO: ask advice from Roman about how to send notification to this class.
*/
public class FilterManager {
protected static FilterManager instance = null;
public static FilterManager getInstance() {
if (instance == null)
instance = new FilterManager();
return instance;
}
protected Hashtable<Integer, Filter> filters;
protected int last_id = 0;
private FilterManager() {
filters = new Hashtable<Integer, Filter>();
}
public void processEvent(Object data) {
synchronized (filters) {
for (Map.Entry<Integer, Filter> item : filters.entrySet()) {
item.getValue().processEvent(data);
}
}
}
public int addFilter(Filter filter) {
filter.setId(++last_id);
filters.put(filter.getId(), filter);
return filter.getId();
}
public Filter getFilter(int id) {
if (filters.containsKey(id)) {
return filters.get(id);
}
return null;
}
public boolean uninstallFilter(int id) {
synchronized (filters) {
if (!filters.containsKey(id))
return false;
filters.remove(id);
}
return true;
}
public JSONArray toJS(int id) {
synchronized (filters) {
if (!filters.containsKey(id))
return null;
return filters.get(id).toJS();
}
}
public JSONArray toJSAll(int id) {
synchronized (filters) {
if (!filters.containsKey(id))
return null;
return filters.get(id).toJSAll();
}
}
}

View File

@ -62,7 +62,8 @@ public class EthereumAidlService extends EthereumService {
public void startJsonRpcServer() throws RemoteException {
jsonRpcServer = new JsonRpcServer(ethereum);
//TODO: add here switch between full and light version
jsonRpcServer = new org.ethereum.android.jsonrpc.light.JsonRpcServer(ethereum);
}
public void getLog(IAsyncCallback callback) throws RemoteException {

View File

@ -302,7 +302,8 @@ public class EthereumRemoteService extends EthereumService {
protected void startJsonRpc(Message message) {
// TODO: Maybe send back if it started succesfully ?
jsonRpcServer = new JsonRpcServer(ethereum);
//TODO: add here switch between full and light version
jsonRpcServer = new org.ethereum.android.jsonrpc.light.JsonRpcServer(ethereum);
try {
jsonRpcServer.start();
logger.info("Started json rpc server!");