add custom method eth_getTransactionHistory, it take data from https://etherchain.org/apidoc
This commit is contained in:
parent
205a7ba140
commit
a7de3c452d
|
@ -33,6 +33,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
||||||
|
|
||||||
this.dispatcher = new Dispatcher();
|
this.dispatcher = new Dispatcher();
|
||||||
|
|
||||||
|
//Custom method to receive address transaction history
|
||||||
|
this.dispatcher.register(new eth_getTransactionHistory(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,64 @@
|
||||||
|
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_getTransactionHistory extends JsonRpcServerMethod {
|
||||||
|
|
||||||
|
public eth_getTransactionHistory(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 += 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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONRPC2Response res = new JSONRPC2Response(JSONValue.parse(rres), req.getID());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
||||||
|
|
||||||
this.dispatcher = new Dispatcher();
|
this.dispatcher = new Dispatcher();
|
||||||
|
|
||||||
|
//Custom method to receive address transaction history
|
||||||
|
this.dispatcher.register(new eth_getTransactionHistory(this.ethereum));
|
||||||
|
|
||||||
this.dispatcher.register(new eth_coinbase(this.ethereum));
|
this.dispatcher.register(new eth_coinbase(this.ethereum));
|
||||||
this.dispatcher.register(new eth_accounts(this.ethereum));
|
this.dispatcher.register(new eth_accounts(this.ethereum));
|
||||||
this.dispatcher.register(new eth_sign(this.ethereum));
|
this.dispatcher.register(new eth_sign(this.ethereum));
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
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 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_getTransactionHistory extends JsonRpcServerMethod {
|
||||||
|
|
||||||
|
public eth_getTransactionHistory(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 += 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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONRPC2Response res = new JSONRPC2Response(JSONValue.parse(rres), req.getID());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue