diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/JsonRpcServer.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/JsonRpcServer.java index 4ad0ceb1..502504d1 100644 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/JsonRpcServer.java +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/JsonRpcServer.java @@ -33,6 +33,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer 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_sha3(this.ethereum)); diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/method/eth_transactionHistory.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/method/eth_transactionHistory.java new file mode 100644 index 00000000..d639a773 --- /dev/null +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/full/method/eth_transactionHistory.java @@ -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 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; + } + + } +} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java index f0b91b42..6822c566 100644 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java @@ -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_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_post(this.ethereum)); this.dispatcher.register(new shh_newIdentity(this.ethereum)); diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/eth_transactionHistory.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/eth_transactionHistory.java new file mode 100644 index 00000000..928fd3f1 --- /dev/null +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/eth_transactionHistory.java @@ -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 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; + } + + } +} \ No newline at end of file