fix issue with wrong JSON-RPC income data

fix issue with not correctly formatted DATA
This commit is contained in:
Yaroslav Dmytrotsa 2015-08-04 18:17:26 +03:00
parent 1a81061679
commit 8c9d49e0a8
3 changed files with 38 additions and 14 deletions

View File

@ -4,6 +4,9 @@ import com.thetransactioncompany.jsonrpc2.JSONRPC2Request;
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;
import com.thetransactioncompany.jsonrpc2.server.Dispatcher;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONValue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
@ -75,9 +78,20 @@ public class JsonRpcServerHandler extends SimpleChannelInboundHandler<HttpObject
postData += chunk.content().toString(0, chunk.content().capacity(), CharsetUtil.UTF_8);
if (chunk instanceof LastHttpContent) {
Object tmpA = JSONValue.parse(postData);
if (tmpA instanceof JSONArray) {
JSONArray t = new JSONArray();
for (int i = 0; i < ((JSONArray) tmpA).size(); i++) {
JSONRPC2Request req = JSONRPC2Request.parse(((JSONArray) tmpA).get(i).toString());
JSONRPC2Response resp = dispatcher.process(req, null);
t.add(resp);
}
responseContent.append(t);
} else {
JSONRPC2Request req = JSONRPC2Request.parse(postData);
JSONRPC2Response resp = dispatcher.process(req, null);
responseContent.append(resp);
}
writeResponse(ctx);
request = null;
decoder.destroy();

View File

@ -72,20 +72,26 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
return blockNumber;
}
protected String clearJSString(String data) {
if (data.substring(0, 2).equals("0x"))
return data.substring(2);
return data;
}
protected byte[] jsToAddress(String data) {
return Hex.decode(data.substring(2));
return Hex.decode(clearJSString(data));
}
protected int jsToInt(String data) {
return Integer.parseInt(data.substring(2), 16);
return Integer.parseInt(clearJSString(data), 16);
}
protected long jsToLong(String data) {
return Long.parseLong(data.substring(2), 16);
return Long.parseLong(clearJSString(data), 16);
}
protected BigInteger jsToBigInteger(String data) {
return new BigInteger(data.substring(2), 16);
return new BigInteger(clearJSString(data), 16);
}
protected Transaction jsToTransaction(JSONObject obj) throws Exception {

View File

@ -9,12 +9,9 @@ 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 = "";
@ -60,20 +57,26 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
return blockNumber;
}
protected String clearJSString(String data) {
if (data.substring(0, 2).equals("0x"))
return data.substring(2);
return data;
}
protected byte[] jsToAddress(String data) {
return Hex.decode(data.substring(2));
return Hex.decode(clearJSString(data));
}
protected int jsToInt(String data) {
return Integer.parseInt(data.substring(2), 16);
return Integer.parseInt(clearJSString(data), 16);
}
protected long jsToLong(String data) {
return Long.parseLong(data.substring(2), 16);
return Long.parseLong(clearJSString(data), 16);
}
protected BigInteger jsToBigInteger(String data) {
return new BigInteger(data.substring(2), 16);
return new BigInteger(clearJSString(data), 16);
}
protected Transaction jsToTransaction(JSONObject obj) throws Exception {
@ -85,6 +88,7 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
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)) {