add custom eth_transactionHistory method, that receive data from https://etherchain.org/apidoc
This commit is contained in:
parent
a64d216537
commit
e8c11ac795
|
@ -33,6 +33,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
||||||
|
|
||||||
this.dispatcher = new Dispatcher();
|
this.dispatcher = new Dispatcher();
|
||||||
|
|
||||||
|
// Custom methods to receive Address Transaction History
|
||||||
|
this.dispatcher.register(new eth_transactionHistory(this.ethereum));
|
||||||
|
|
||||||
this.dispatcher.register(new web3_clientVersion(this.ethereum));
|
this.dispatcher.register(new web3_clientVersion(this.ethereum));
|
||||||
this.dispatcher.register(new web3_sha3(this.ethereum));
|
this.dispatcher.register(new web3_sha3(this.ethereum));
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package org.ethereum.android.jsonrpc.full.method;
|
||||||
|
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Error;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.server.MessageContext;
|
||||||
|
|
||||||
|
import net.minidev.json.JSONValue;
|
||||||
|
|
||||||
|
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
|
||||||
|
import org.ethereum.facade.Ethereum;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class eth_transactionHistory extends JsonRpcServerMethod {
|
||||||
|
|
||||||
|
public eth_transactionHistory(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 {
|
||||||
|
|
||||||
|
String urlS = "https://etherchain.org/api/account/"+params.get(0)+"/tx/";
|
||||||
|
if (params.size() == 1) {
|
||||||
|
urlS += "0";
|
||||||
|
} else {
|
||||||
|
urlS += params.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String rres = "";
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlS);
|
||||||
|
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
try {
|
||||||
|
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
|
||||||
|
InputStreamReader isw = new InputStreamReader(in);
|
||||||
|
int data = isw.read();
|
||||||
|
while (data != -1) {
|
||||||
|
rres += (char) data;
|
||||||
|
data = isw.read();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
urlConnection.disconnect();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONRPC2Response res = new JSONRPC2Response(JSONValue.parse(rres), req.getID());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
||||||
this.dispatcher.register(new eth_sign(this.ethereum));
|
this.dispatcher.register(new eth_sign(this.ethereum));
|
||||||
this.dispatcher.register(new eth_sendTransaction(this.ethereum));
|
this.dispatcher.register(new eth_sendTransaction(this.ethereum));
|
||||||
|
|
||||||
|
// Custom methods to receive Address Transaction History
|
||||||
|
this.dispatcher.register(new eth_transactionHistory(this.ethereum));
|
||||||
|
|
||||||
this.dispatcher.register(new shh_version(this.ethereum));
|
this.dispatcher.register(new shh_version(this.ethereum));
|
||||||
this.dispatcher.register(new shh_post(this.ethereum));
|
this.dispatcher.register(new shh_post(this.ethereum));
|
||||||
this.dispatcher.register(new shh_newIdentity(this.ethereum));
|
this.dispatcher.register(new shh_newIdentity(this.ethereum));
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.ethereum.android.jsonrpc.light.method;
|
||||||
|
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Error;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;
|
||||||
|
import com.thetransactioncompany.jsonrpc2.server.MessageContext;
|
||||||
|
|
||||||
|
import net.minidev.json.JSONObject;
|
||||||
|
import net.minidev.json.JSONValue;
|
||||||
|
import net.minidev.json.parser.JSONParser;
|
||||||
|
|
||||||
|
import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod;
|
||||||
|
import org.ethereum.core.Transaction;
|
||||||
|
import org.ethereum.facade.Ethereum;
|
||||||
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class eth_transactionHistory extends JsonRpcServerMethod {
|
||||||
|
|
||||||
|
public eth_transactionHistory(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 {
|
||||||
|
|
||||||
|
String urlS = "https://etherchain.org/api/account/"+params.get(0)+"/tx/";
|
||||||
|
if (params.size() == 1) {
|
||||||
|
urlS += "0";
|
||||||
|
} else {
|
||||||
|
urlS += params.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String rres = "";
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlS);
|
||||||
|
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
try {
|
||||||
|
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
|
||||||
|
InputStreamReader isw = new InputStreamReader(in);
|
||||||
|
int data = isw.read();
|
||||||
|
while (data != -1) {
|
||||||
|
rres += (char) data;
|
||||||
|
data = isw.read();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
urlConnection.disconnect();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONRPC2Response res = new JSONRPC2Response(JSONValue.parse(rres), req.getID());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue