additional changes after latest Skype call with Roman.

This commit is contained in:
Yaroslav Dmytrotsa 2015-06-26 15:55:14 +03:00
parent 33be741881
commit 7e61c3765c
26 changed files with 131 additions and 97 deletions

View File

@ -37,6 +37,8 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import org.ethereum.android.jsonrpc.method.*;
import java.net.InetAddress;
public final class JsonRpcServer {
@ -123,8 +125,8 @@ public final class JsonRpcServer {
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
// b.localAddress(InetAddress.getLocalHost(), PORT);
b.localAddress(PORT);
b.localAddress(InetAddress.getLocalHost(), PORT);
// b.localAddress(PORT);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new JsonRpcServerInitializer());

View File

@ -204,7 +204,7 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
i = 0;
for (Transaction transaction : block.getTransactionsList()) {
if (detailed) {
JSONObject tx = transactionToJS(transaction);
JSONObject tx = transactionToJS(block, transaction);
tx.put("transactionIndex", "0x" + Integer.toHexString(i));
tx.put("blockHash", "0x" + Hex.toHexString(block.getHash()));
tx.put("blockNumber", "0x" + Long.toHexString(block.getNumber()));
@ -216,7 +216,6 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
}
res.put("transactions", transactionsJA);
//TODO: ask if I correctly get uncle's hash (takes form -core right now)
JSONArray unclesJA = new JSONArray();
for (BlockHeader uncle : block.getUncleList()) {
unclesJA.add("0x" + Hex.toHexString(HashUtil.sha3(uncle.getEncoded())));
@ -226,7 +225,7 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
return res;
}
protected JSONObject transactionToJS (Transaction transaction) {
protected JSONObject transactionToJS (Block block, Transaction transaction) {
JSONObject res = new JSONObject();
res.put("hash", "0x" + Hex.toHexString(transaction.getHash()));
@ -245,13 +244,22 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
res.put("input", "0x" + Hex.toHexString(transaction.getData()));
/*
No way to get this data from inside of transaction.
TODO: Ask roman to include it into transaction class.
res.put("transactionIndex", "0x" + "");
res.put("blockHash", "0x" + "");
res.put("blockNumber", "0x" + "");
*/
if (block == null) {
res.put("transactionIndex", null);
res.put("blockHash", null);
res.put("blockNumber", null);
} else {
long txi = 0;
for (Transaction tx : block.getTransactionsList()) {
if (Arrays.equals(tx.getHash(), transaction.getHash()))
break;
txi++;
}
res.put("transactionIndex", "0x" + Long.toHexString(txi));
res.put("blockHash", "0x" + Hex.toHexString(block.getHash()));
res.put("blockNumber", "0x" + Long.toHexString(block.getNumber()));
}
return res;
}
}

View File

@ -13,20 +13,19 @@ import org.spongycastle.util.encoders.Hex;
import java.util.ArrayList;
import java.util.Arrays;
/*
Right now LogInfo not contains information about Transaction and Transaction not have information about block.
TODO: talk to Roman about create links between LogInfo and Transaction and between Transaction and Block.
*/
public class FilterLog extends FilterBase {
private ArrayList<LogInfo> logs = new ArrayList<LogInfo>();
private ArrayList<FilterLogData> logs = new ArrayList<FilterLogData>();
long blockFrom;
long blockTo;
ArrayList<byte[]> addresses = new ArrayList<>();
ArrayList<byte[]> topics = new ArrayList<>();
private Ethereum ethereum;
public FilterLog (Ethereum ethereum, JSONObject data) {
this.ethereum = ethereum;
blockFrom = ethereum.getBlockchain().getBestBlock().getNumber();
if (data.containsKey("fromBlock") && !((String)data.get("fromBlock")).equals("")) {
String fromS = (String)data.get("fromBlock");
@ -74,16 +73,17 @@ public class FilterLog extends FilterBase {
}
}
/*
TODO: Right now Bloom from -core can be used only to check total mach of 2 same class objects. Will be nice to have possibility to check contains.
*/
public void processEvent(Object data) {
if (data instanceof LogInfo) {
if (data instanceof FilterLogData) {
synchronized (logs) {
LogInfo li = (LogInfo)data;
//TODO: check if li inside blockFrom - blockTo
FilterLogData li = (FilterLogData)data;
if ((blockFrom >= 0 && li.block.getNumber() < blockFrom) || (blockTo >= 0 && li.block.getNumber() > blockTo))
return;
if (checkLogInfo(li))
/*
TODO: Roman must implement Bloom contain. When it will be done - we can use just Bloom.
*/
if (checkLogInfo(li.li))
logs.add(li);
}
}
@ -93,7 +93,7 @@ TODO: Right now Bloom from -core can be used only to check total mach of 2 same
updateLastRequest();
JSONArray res = new JSONArray();
synchronized (logs) {
for(LogInfo item : logs) {
for(FilterLogData item : logs) {
res.add(logInfoToJS(item));
}
logs.clear();
@ -104,7 +104,6 @@ TODO: Right now Bloom from -core can be used only to check total mach of 2 same
public JSONArray toJS(Ethereum ethereum) {
JSONArray res = new JSONArray();
// Process mined blocks
if (blockFrom >= 0) {
long i = blockFrom;
while (true) {
@ -116,7 +115,7 @@ TODO: Right now Bloom from -core can be used only to check total mach of 2 same
if (txr != null) {
for (LogInfo li : txr.getLogInfoList()) {
if (checkLogInfo(li))
res.add(logInfoToJS(li));
res.add(logInfoToJS(new FilterLogData(block, txr, li)));
}
}
}
@ -124,16 +123,13 @@ TODO: Right now Bloom from -core can be used only to check total mach of 2 same
}
}
/*
Process pending transactions. But not sure if BlockChain can return TransactionReceipt for pending transaction.
*/
if (blockFrom < 0 || blockTo < 0) {
for (Transaction tx : ethereum.getPendingTransactions()) {
TransactionReceipt txr = ethereum.getBlockchain().getTransactionReceiptByHash(tx.getHash());
if (txr != null) {
for (LogInfo li : txr.getLogInfoList()) {
if (checkLogInfo(li))
res.add(logInfoToJS(li));
res.add(logInfoToJS(new FilterLogData(null, txr, li)));
}
}
}
@ -171,29 +167,63 @@ Process pending transactions. But not sure if BlockChain can return TransactionR
return true;
}
private JSONObject logInfoToJS(LogInfo li) {
private JSONObject logInfoToJS(FilterLogData data) {
JSONObject res = new JSONObject();
/*
TODO: check here if log's transaction / block mined or pending.
*/
if (data.block == null) {
res.put("type", "pending");
res.put("logIndex", null);
res.put("transactionIndex", null);
res.put("transactionHash", null);
res.put("blockHash", null);
res.put("blockNumber", null);
} else {
res.put("type", "mined");
long txi = 0;
long lii = 0;
/*
TODO: for me it's a little strange way.
*/
for (Transaction tx : data.block.getTransactionsList()) {
for (LogInfo li : ethereum.getBlockchain().getTransactionReceiptByHash(tx.getHash()).getLogInfoList()) {
if (li.getBloom().equals(data.li.getBloom()))
break;
lii++;
}
if (Arrays.equals(tx.getHash(), data.txr.getTransaction().getHash())) {
break;
}
txi++;
}
res.put("logIndex", "0x" + Long.toHexString(lii));
res.put("transactionIndex", "0x" + Long.toHexString(txi));
res.put("transactionHash", "0x" + Hex.toHexString(data.txr.getTransaction().getHash()));
res.put("blockHash", "0x" + Hex.toHexString(data.block.getHash()));
res.put("blockNumber", "0x" + Long.toHexString(data.block.getNumber()));
}
res.put("address", Hex.toHexString(li.getAddress()));
res.put("address", "0x" + Hex.toHexString(data.li.getAddress()));
res.put("data", Hex.toHexString(li.getData()));
res.put("data", "0x" + Hex.toHexString(data.li.getData()));
JSONArray topics = new JSONArray();
for (DataWord topic : li.getTopics()) {
topics.add(Hex.toHexString(topic.getData()));
for (DataWord topic : data.li.getTopics()) {
topics.add("0x" + Hex.toHexString(topic.getData()));
}
res.put("topics", topics);
return res;
}
public static class FilterLogData {
public Block block;
public TransactionReceipt txr;
public LogInfo li;
public FilterLogData( Block block, TransactionReceipt txr, LogInfo li) {
this.block = block;
this.txr = txr;
this.li = li;
}
}
}

View File

@ -7,6 +7,7 @@ import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.vm.LogInfo;
import java.util.Hashtable;
import java.util.List;
@ -55,6 +56,9 @@ public class FilterManager extends EthereumListenerAdapter {
public void onBlock(Block block, List<TransactionReceipt> receipts) {
processEvent(block);
for(TransactionReceipt tx : receipts) {
for (LogInfo li : tx.getLogInfoList()) {
processEvent(new FilterLog.FilterLogData(block, tx, li));
}
processEvent(tx.getTransaction());
}
}

View File

@ -8,12 +8,8 @@ import org.ethereum.core.*;
import org.spongycastle.util.encoders.Hex;
/*
Present big issue - current ethereumj-core not have coinbase "functionality".
On each app start - it create 2 addresses: "cow", coinbase.secret ("monkey") --- WorldManager.java -> init
Also because not present mining functionality - no wat to identify what address will be coinbase (mining success payment place to)
TODO: change this after fix in ethereumj-core
TODO: -core not handle mining so coinbase not present in it. Right now returned second address from Wallet. Must be changed in app where implemented mining
*/
public class eth_coinbase extends JsonRpcServerMethod {
public eth_coinbase (Ethereum ethereum) {

View File

@ -13,8 +13,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Example taken from -studio. Not sure if we must call encodeMachineCodeForVMRun in end
TODO: get advice from Roman about encodeMachineCodeForVMRun
TODO: Serpent will be depricated in future.
*/
public class eth_compileSerpent extends JsonRpcServerMethod {
@ -41,7 +40,7 @@ public class eth_compileSerpent extends JsonRpcServerMethod {
} else {
asmResult = SerpentCompiler.compile(code);
machineCode = SerpentCompiler.compileAssemblyToMachine(asmResult);
// machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
}
} catch (Throwable th) {
return new JSONRPC2Response(JSONRPC2Error.INTERNAL_ERROR, req.getID());

View File

@ -10,7 +10,7 @@ import java.math.BigInteger;
import java.util.List;
/*
TODO: -core not have solidity compiler
ATODO: -core not have solidity compiler. Need try to use cpp solidity compiler using JNI
*/
public class eth_compileSolidity extends JsonRpcServerMethod {

View File

@ -10,10 +10,6 @@ import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.List;
/*
By specification this method can receive hash of pending block but from -core it's not possible.
TODO: get advice from Roman about pending block
*/
public class eth_getBlockByHash extends JsonRpcServerMethod {
public eth_getBlockByHash (Ethereum ethereum) {

View File

@ -10,10 +10,6 @@ import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.List;
/*
By specification this method can receive number of pending block but from -core it's not possible.
TODO: get advice from Roman about pending block
*/
public class eth_getBlockByNumber extends JsonRpcServerMethod {
public eth_getBlockByNumber (Ethereum ethereum) {
@ -33,8 +29,9 @@ public class eth_getBlockByNumber extends JsonRpcServerMethod {
if (blockNumber == -1) {
blockNumber = ethereum.getBlockchain().getBestBlock().getNumber();
}
// TODO: here we must load pending block but -core not "group" it.
if (blockNumber == -2) {
return new JSONRPC2Response(null, req.getID());
}
Block block = ethereum.getBlockchain().getBlockByNumber(blockNumber);

View File

@ -7,10 +7,6 @@ import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.List;
/*
Not sure if pending can have code. Also code by itself related to repository not very clear for me.
TODO: ask Roman advice for this method.
*/
public class eth_getCode extends JsonRpcServerMethod {
public eth_getCode (Ethereum ethereum) {

View File

@ -16,7 +16,9 @@ public class eth_getCompilers extends JsonRpcServerMethod {
ArrayList<String> tmp = new ArrayList<String>();
tmp.add("serpent");
//TODO: add lll and solidity when they will be implemented in -core
/*
TODO: add lll and solidity when we find good libs for them. They not planned to be implemented in -core.
*/
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());
return res;

View File

@ -9,10 +9,6 @@ import org.ethereum.vm.DataWord;
import org.spongycastle.util.encoders.Hex;
import java.util.List;
/*
As I see getStorageValue not check Pending Transactions.
TODO: ask roman advice for this method.
*/
public class eth_getStorageAt extends JsonRpcServerMethod {
public eth_getStorageAt(Ethereum ethereum) { super(ethereum); }

View File

@ -36,7 +36,7 @@ public class eth_getTransactionByBlockHashAndIndex extends JsonRpcServerMethod {
if (block.getTransactionsList().size() <= index)
return new JSONRPC2Response(null, req.getID());
JSONObject tx = transactionToJS(block.getTransactionsList().get(index));
JSONObject tx = transactionToJS(block, block.getTransactionsList().get(index));
tx.put("transactionIndex", "0x" + Integer.toHexString(index));
tx.put("blockHash", "0x" + Hex.toHexString(block.getHash()));
tx.put("blockNumber", "0x" + Long.toHexString(block.getNumber()));

View File

@ -8,6 +8,7 @@ import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
@ -32,22 +33,21 @@ public class eth_getTransactionByBlockNumberAndIndex extends JsonRpcServerMethod
if (blockNumber == -1) {
blockNumber = ethereum.getBlockchain().getBestBlock().getNumber();
}
// TODO: here we must load pending block but -core not "group" it.
Block block = null;
JSONObject tx = null;
if (blockNumber == -2) {
}
Block block = ethereum.getBlockchain().getBlockByNumber(blockNumber);
if (ethereum.getPendingTransactions().size() <= index)
return new JSONRPC2Response(null, req.getID());
tx = transactionToJS(null, (Transaction)ethereum.getPendingTransactions().toArray()[index]);
} else {
block = ethereum.getBlockchain().getBlockByNumber(blockNumber);
if (block == null)
return new JSONRPC2Response(null, req.getID());
if (block.getTransactionsList().size() <= index)
return new JSONRPC2Response(null, req.getID());
JSONObject tx = transactionToJS(block.getTransactionsList().get(index));
tx.put("transactionIndex", "0x" + Integer.toHexString(index));
tx.put("blockHash", "0x" + Hex.toHexString(block.getHash()));
tx.put("blockNumber", "0x" + Long.toHexString(block.getNumber()));
tx = transactionToJS(block, block.getTransactionsList().get(index));
}
JSONRPC2Response res = new JSONRPC2Response(tx, req.getID());
return res;

View File

@ -7,6 +7,9 @@ import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import java.util.List;
/*
ATODO: talk with Adrian to get relation between Transaction and Block from db.
*/
public class eth_getTransactionByHash extends JsonRpcServerMethod {
public eth_getTransactionByHash (Ethereum ethereum) {
@ -26,7 +29,7 @@ public class eth_getTransactionByHash extends JsonRpcServerMethod {
if (transaction == null)
return new JSONRPC2Response(null, req.getID());
JSONRPC2Response res = new JSONRPC2Response(transactionToJS(transaction.getTransaction()), req.getID());
JSONRPC2Response res = new JSONRPC2Response(transactionToJS(null, transaction.getTransaction()), req.getID());
return res;
}

View File

@ -31,7 +31,7 @@ public class eth_getUncleByBlockHashAndIndex extends JsonRpcServerMethod {
if (block.getUncleList().size() <= index)
return new JSONRPC2Response(null, req.getID());
Block uncle = ethereum.getBlockchain().getBlockByHash(HashUtil.sha3(block.getUncleList().get(index).getEncoded()));
Block uncle = new Block(block.getUncleList().get(index), null, null);
JSONRPC2Response res = new JSONRPC2Response(blockToJS(uncle, false), req.getID());
return res;

View File

@ -8,6 +8,7 @@ import org.ethereum.crypto.HashUtil;
import org.ethereum.facade.Ethereum;
import java.util.List;
public class eth_getUncleByBlockNumberAndIndex extends JsonRpcServerMethod {
public eth_getUncleByBlockNumberAndIndex (Ethereum ethereum) {
@ -27,7 +28,7 @@ public class eth_getUncleByBlockNumberAndIndex extends JsonRpcServerMethod {
if (blockNumber == -1) {
blockNumber = ethereum.getBlockchain().getBestBlock().getNumber();
}
// TODO: here we must load pending block but -core not "group" it.
if (blockNumber == -2) {
}
@ -39,7 +40,7 @@ public class eth_getUncleByBlockNumberAndIndex extends JsonRpcServerMethod {
if (block.getUncleList().size() <= index)
return new JSONRPC2Response(null, req.getID());
Block uncle = ethereum.getBlockchain().getBlockByHash(HashUtil.sha3(block.getUncleList().get(index).getEncoded()));
Block uncle = new Block(block.getUncleList().get(index), null, null);
JSONRPC2Response res = new JSONRPC2Response(blockToJS(uncle, false), req.getID());
return res;

View File

@ -6,7 +6,7 @@ import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: right now -core not auto start mining so no way to get information about state
TODO: must be changed in app that implement mining
*/
public class eth_getWork extends JsonRpcServerMethod {

View File

@ -6,7 +6,7 @@ import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: right now -core not have "finished" mining architecture so not have hashrate
TODO: must be changed in app that implement mining
*/
public class eth_hashrate extends JsonRpcServerMethod {

View File

@ -6,7 +6,7 @@ import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: right now -core not auto start mining and also not have marker to identify if it's happening
TODO: must be changed in app that implement mining
*/
public class eth_mining extends JsonRpcServerMethod {

View File

@ -15,6 +15,10 @@ import java.util.concurrent.TimeUnit;
import static org.ethereum.core.Denomination.SZABO;
import static org.ethereum.config.SystemProperties.CONFIG;
/*
TODO: get more information from Roman, he think about this right now about 20 - 32 result.
*/
public class eth_sendTransaction extends JsonRpcServerMethod {
public eth_sendTransaction (Ethereum ethereum) {

View File

@ -9,7 +9,7 @@ import org.ethereum.facade.Ethereum;
import java.util.List;
/*
TODO: right now -core not auto start mining so no way to get information about state
TODO: must be changed in app that implement mining
*/
public class eth_submitWork extends JsonRpcServerMethod {

View File

@ -6,7 +6,7 @@ import org.ethereum.android.jsonrpc.JsonRpcServerMethod;
import org.ethereum.facade.Ethereum;
/*
TODO: request go version how this must be identified. Cpp version just return "".
TODO: maybe in future AdminState will have information about this.
*/
public class net_version extends JsonRpcServerMethod {

View File

@ -51,7 +51,7 @@ public class shh_post extends JsonRpcServerMethod {
int ttl = jsToInt((String)obj.get("ttl"));
//TODO:
//TODO: implement after Adrian merge with dev
JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
return res;

View File

@ -54,7 +54,7 @@ public class Filter {
}
public void processEvent(Object data) {
//TODO: parse incomming data when we will know what comes.
//TODO: parse incomming data when we will know what comes.
}
public JSONArray toJS() {

View File

@ -11,7 +11,7 @@ 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 todo that.
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 {