remove SHH from light version of JSON_RPC. Now it peroxided.

This commit is contained in:
Yaroslav Dmytrotsa 2015-09-03 11:03:52 +03:00
parent b76a72f367
commit c3261a469e
14 changed files with 11 additions and 494 deletions

View File

@ -10,7 +10,6 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import org.ethereum.android.jsonrpc.light.whisper.FilterManager;
import org.ethereum.facade.Ethereum;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.light.method.*;
@ -45,21 +44,8 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
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();
addRemoteServer("http://139.162.13.89:8545/");
}

View File

@ -52,6 +52,17 @@ public class proxy extends JsonRpcServerMethod {
proxyMethods.add("eth_getFilterLogs");
proxyMethods.add("eth_getLogs");
proxyMethods.add("shh_version");
proxyMethods.add("shh_post");
proxyMethods.add("shh_newIdentity");
proxyMethods.add("shh_hasIdentity");
proxyMethods.add("shh_newGroup");
proxyMethods.add("shh_addToGroup");
proxyMethods.add("shh_newFilter");
proxyMethods.add("shh_uninstallFilter");
proxyMethods.add("shh_getFilterChanges");
proxyMethods.add("shh_getMessages");
//TODO: issue methods - they generate transaction but must call them in blockchain.
proxyMethods.add("eth_call");
proxyMethods.add("eth_estimateGas");

View File

@ -1,32 +0,0 @@
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

@ -1,29 +0,0 @@
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

@ -1,29 +0,0 @@
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

@ -1,32 +0,0 @@
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

@ -1,35 +0,0 @@
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

@ -1,23 +0,0 @@
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

@ -1,23 +0,0 @@
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

@ -1,60 +0,0 @@
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

@ -1,29 +0,0 @@
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

@ -1,22 +0,0 @@
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

@ -1,86 +0,0 @@
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

@ -1,80 +0,0 @@
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();
}
}
}