Fixed custom address initialization.

Fixed missing methods reference.
Fixed ethereum initialization
This commit is contained in:
Adrian Tiberius 2015-08-17 16:18:17 +02:00
parent 67a0f7d35e
commit 5b83fbae43
17 changed files with 167 additions and 233 deletions

View File

@ -1,22 +1,13 @@
package org.ethereum.android;
import org.ethereum.android.manager.BlockLoader;
import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.core.Wallet;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.BlockStore;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.core.Blockchain;
import org.ethereum.core.Repository;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.AdminInfo;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.client.PeerClient;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.PeerInfo;
import org.ethereum.net.rlpx.Node;
import org.ethereum.net.server.ChannelManager;
@ -30,7 +21,6 @@ import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -46,48 +36,34 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
private static final Logger logger = LoggerFactory.getLogger("facade");
BlockStore blockStore;
Blockchain blockchain;
Repository repository;
EthereumListener listener;
WorldManager worldManager;
AdminInfo adminInfo;
ChannelManager channelManager;
PeerServer peerServer;
PeerDiscovery peerDiscovery;
BlockLoader blockLoader;
org.ethereum.manager.BlockLoader blockLoader;
Provider<PeerClient> peerClientProvider;
Wallet wallet;
private PeerClient activePeer;
@Inject
public Ethereum(Blockchain blockchain, BlockStore blockStore, Repository repository, AdminInfo adminInfo,
ChannelManager channelManager, BlockLoader blockLoader,
Provider<PeerClient> peerClientProvider, EthereumListener listener,
PeerDiscovery peerDiscovery, Wallet wallet) {
public Ethereum(WorldManager worldManager, AdminInfo adminInfo,
ChannelManager channelManager, org.ethereum.manager.BlockLoader blockLoader,
Provider<PeerClient> peerClientProvider, EthereumListener listener, PeerServer peerServer) {
System.out.println();
logger.info("EthereumImpl constructor");
this.blockchain = blockchain;
this.blockStore = blockStore;
this.repository = repository;
this.worldManager = worldManager;
this.adminInfo = adminInfo;
this.channelManager = channelManager;
this.blockLoader = blockLoader;
this.peerClientProvider = peerClientProvider;
this.listener = listener;
this.peerDiscovery = peerDiscovery;
this.wallet = wallet;
this.peerServer = peerServer;
this.worldManager.setEthereum(this);
}
@Override
@ -98,14 +74,7 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
public void init(List<String> privateKeys) {
if (privateKeys != null) {
for (String privateKey: privateKeys) {
wallet.importKey(Hex.decode(privateKey));
}
}
// Load the blockchain
loadBlockchain();
this.worldManager.init(privateKeys);
// Start peer server
if (CONFIG.listenPort() > 0) {
@ -119,72 +88,6 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
}
}
public byte[] createRandomAccount() {
byte[] randomPrivateKey = HashUtil.sha3(HashUtil.randomPeerId());
wallet.importKey(randomPrivateKey);
return randomPrivateKey;
}
public void loadBlockchain() {
if (!CONFIG.databaseReset())
blockStore.load();
Block bestBlock = blockStore.getBestBlock();
if (bestBlock == null) {
logger.info("DB is empty - adding Genesis");
Genesis genesis = (Genesis)Genesis.getInstance();
for (ByteArrayWrapper key : genesis.getPremine().keySet()) {
repository.createAccount(key.getData());
repository.addBalance(key.getData(), genesis.getPremine().get(key).getBalance());
}
blockStore.saveBlock(Genesis.getInstance(), Genesis.getInstance().getCumulativeDifficulty(), true);
blockchain.setBestBlock(Genesis.getInstance());
blockchain.setTotalDifficulty(Genesis.getInstance().getCumulativeDifficulty());
listener.onBlock(Genesis.getInstance(), new ArrayList<TransactionReceipt>() );
repository.dumpState(Genesis.getInstance(), 0, 0, null);
logger.info("Genesis block loaded");
} else {
blockchain.setBestBlock(bestBlock);
BigInteger totalDifficulty = blockStore.getTotalDifficulty();
blockchain.setTotalDifficulty(totalDifficulty);
logger.info("*** Loaded up to block [{}] totalDifficulty [{}] with stateRoot [{}]",
blockchain.getBestBlock().getNumber(),
blockchain.getTotalDifficulty().toString(),
Hex.toHexString(blockchain.getBestBlock().getStateRoot()));
}
if (CONFIG.rootHashStart() != null) {
// update world state by dummy hash
byte[] rootHash = Hex.decode(CONFIG.rootHashStart());
logger.info("Loading root hash from property file: [{}]", CONFIG.rootHashStart());
this.repository.syncToRoot(rootHash);
} else {
// Update world state to latest loaded block from db
this.repository.syncToRoot(blockchain.getBestBlock().getStateRoot());
}
/* todo: return it when there is no state conflicts on the chain
boolean dbValid = this.repository.getWorldState().validate() || bestBlock.isGenesis();
if (!dbValid){
logger.error("The DB is not valid for that blockchain");
System.exit(-1); // todo: reset the repository and blockchain
}
*/
}
/**
* Find a peer but not this one
*
@ -193,7 +96,6 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
*/
@Override
public PeerInfo findOnlinePeer(PeerInfo peer) {
Set<PeerInfo> excludePeers = new HashSet<>();
excludePeers.add(peer);
return findOnlinePeer(excludePeers);
@ -201,22 +103,20 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
@Override
public PeerInfo findOnlinePeer() {
Set<PeerInfo> excludePeers = new HashSet<>();
return findOnlinePeer(excludePeers);
}
@Override
public PeerInfo findOnlinePeer(Set<PeerInfo> excludePeers) {
logger.info("Looking for online peers...");
final EthereumListener listener = this.listener;
listener.trace("Looking for online peer");
startPeerDiscovery();
worldManager.startPeerDiscovery();
final Set<PeerInfo> peers = getPeers();
final Set<PeerInfo> peers = worldManager.getPeerDiscovery().getPeers();
for (PeerInfo peer : peers) { // it blocks until a peer is available.
if (peer.isOnline() && !excludePeers.contains(peer)) {
logger.info("Found peer: {}", peer.toString());
@ -244,80 +144,71 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
@Override
public Set<PeerInfo> getPeers() {
return peerDiscovery.getPeers();
return worldManager.getPeerDiscovery().getPeers();
}
@Override
public void startPeerDiscovery() {
if (!peerDiscovery.isStarted())
peerDiscovery.start();
worldManager.startPeerDiscovery();
}
@Override
public void stopPeerDiscovery() {
if (peerDiscovery.isStarted())
peerDiscovery.stop();
worldManager.stopPeerDiscovery();
}
@Override
public void connect(InetAddress addr, int port, String remoteId) {
connect(addr.getHostName(), port, remoteId);
}
@Override
public void connect(String ip, int port, String remoteId) {
public void connect(final String ip, final int port, final String remoteId) {
logger.info("Connecting to: {}:{}", ip, port);
if (activePeer == null)
activePeer = peerClientProvider.get();
activePeer.connect(ip, port, remoteId);
final PeerClient peerClient = peerClientProvider.get();
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
peerClient.connect(ip, port, remoteId);
}
});
}
@Override
public void connect(Node node) {
connect(node.getHost(), node.getPort(), Hex.toHexString(node.getId()));
}
@Override
public org.ethereum.facade.Blockchain getBlockchain() {
return (org.ethereum.facade.Blockchain)blockchain;
return (org.ethereum.facade.Blockchain)worldManager.getBlockchain();
}
@Override
public void addListener(EthereumListener listener) {
((CompositeEthereumListener) this.listener).addListener(listener);
worldManager.addListener(listener);
}
@Override
public void close() {
stopPeerDiscovery();
repository.close();
blockchain.close();
worldManager.close();
}
@Override
public PeerClient getDefaultPeer() {
if (activePeer == null) {
activePeer = peerClientProvider.get();
PeerClient peer = worldManager.getActivePeer();
if (peer == null) {
peer = peerClientProvider.get();
worldManager.setActivePeer(peer);
}
return activePeer;
return peer;
}
@Override
public boolean isConnected() {
return activePeer != null;
return worldManager.getActivePeer() != null;
}
@Override
@ -348,50 +239,49 @@ public class Ethereum implements org.ethereum.facade.Ethereum {
@Override
public Wallet getWallet() {
return wallet;
return worldManager.getWallet();
}
@Override
public org.ethereum.facade.Repository getRepository() {
return worldManager.getRepository();
}
return (org.ethereum.facade.Repository)repository;
@Override
public org.ethereum.facade.Repository getSnapshootTo(byte[] root){
Repository repository = (Repository) worldManager.getRepository();
org.ethereum.facade.Repository snapshot = (org.ethereum.facade.Repository) repository.getSnapshotTo(root);
return snapshot;
}
@Override
public AdminInfo getAdminInfo() {
return adminInfo;
}
@Override
public ChannelManager getChannelManager() {
return channelManager;
}
@Override
public Set<Transaction> getPendingTransactions() {
return blockchain.getPendingTransactions();
return getBlockchain().getPendingTransactions();
}
@Override
public BlockLoader getBlockLoader() {
public org.ethereum.manager.BlockLoader getBlockLoader(){
return blockLoader;
}
@Override
public void exitOn(long number) {
blockchain.setExitOn(number);
worldManager.getBlockchain().setExitOn(number);
}
@Override
public org.ethereum.facade.Repository getSnapshootTo(byte[] root) {
return null;
}
}

View File

@ -7,11 +7,21 @@ import org.ethereum.android.db.OrmLiteBlockStoreDatabase;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Blockchain;
import org.ethereum.android.manager.BlockLoader;
import org.ethereum.core.Repository;
import org.ethereum.datasource.HashMapDB;
import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.android.datasource.LevelDbDataSource;
import org.ethereum.db.BlockStore;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.db.RepositoryImpl;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.AdminInfo;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.client.PeerClient;
import org.ethereum.net.server.ChannelManager;
import org.ethereum.net.server.PeerServer;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.Serializer;
@ -48,6 +58,19 @@ public class EthereumModule extends org.ethereum.di.modules.EthereumModule {
this.storeAllBlocks = storeAllBlocks;
}
@Override
protected Ethereum createEthereum(WorldManager worldManager, AdminInfo adminInfo, ChannelManager channelManager,
org.ethereum.manager.BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener, PeerServer peerServer) {
return new org.ethereum.android.Ethereum(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener, peerServer);
}
@Override
protected Repository createRepository() {
LevelDbDataSource detailsDS = new LevelDbDataSource();
LevelDbDataSource stateDS = new LevelDbDataSource();
return new RepositoryImpl(detailsDS, stateDS);
}
@Override
protected BlockStore createBlockStore() {

View File

@ -13,6 +13,7 @@ import org.ethereum.core.Account;
import org.ethereum.core.AccountState;
import org.ethereum.core.Block;
import org.ethereum.core.BlockHeader;
import org.ethereum.core.Blockchain;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.crypto.HashUtil;
@ -302,8 +303,8 @@ public abstract class JsonRpcServerMethod implements RequestHandler {
for (Transaction tx : block.getTransactionsList()) {
if (Arrays.equals(tx.getHash(), transaction.getTransaction().getHash()))
break;
// TODO: Missing method on blockchain
//txli += this.ethereum.getBlockchain().getTransactionReceiptByHash(transaction.getTransaction().getHash()).getLogInfoList().size();
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
txli += blockchain.getTransactionReceiptByHash(transaction.getTransaction().getHash()).getLogInfoList().size();
txi++;
}
res.put("transactionIndex", "0x" + Long.toHexString(txi));

View File

@ -4,6 +4,7 @@ import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.ethereum.core.Block;
import org.ethereum.core.Blockchain;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
@ -111,16 +112,14 @@ TODO: Roman must implement Bloom contain. When it will be done - we can use just
if (block == null)
break;
for (Transaction tx : block.getTransactionsList()) {
// TODO: Missing method on blockchain
/*
TransactionReceipt txr = ethereum.getBlockchain().getTransactionReceiptByHash(tx.getHash());
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
TransactionReceipt txr = blockchain.getTransactionReceiptByHash(tx.getHash());
if (txr != null) {
for (LogInfo li : txr.getLogInfoList()) {
if (checkLogInfo(li))
res.add(logInfoToJS(new FilterLogData(block, txr, li)));
}
}
*/
}
i++;
}
@ -128,16 +127,14 @@ TODO: Roman must implement Bloom contain. When it will be done - we can use just
if (blockFrom < 0 || blockTo < 0) {
for (Transaction tx : ethereum.getPendingTransactions()) {
// TODO: Missing method on blockchain
/*
TransactionReceipt txr = ethereum.getBlockchain().getTransactionReceiptByHash(tx.getHash());
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
TransactionReceipt txr = blockchain.getTransactionReceiptByHash(tx.getHash());
if (txr != null) {
for (LogInfo li : txr.getLogInfoList()) {
if (checkLogInfo(li))
res.add(logInfoToJS(new FilterLogData(null, txr, li)));
}
}
*/
}
}
@ -191,14 +188,12 @@ TODO: Roman must implement Bloom contain. When it will be done - we can use just
TODO: for me it's a little strange way.
*/
for (Transaction tx : data.block.getTransactionsList()) {
// TODO: Missing method on blockchain
/*
for (LogInfo li : ethereum.getBlockchain().getTransactionReceiptByHash(tx.getHash()).getLogInfoList()) {
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
for (LogInfo li : blockchain.getTransactionReceiptByHash(tx.getHash()).getLogInfoList()) {
if (li.getBloom().equals(data.li.getBloom()))
break;
lii++;
}
*/
if (Arrays.equals(tx.getHash(), data.txr.getTransaction().getHash())) {
break;
}

View File

@ -4,6 +4,7 @@ import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Repository;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.Program;
@ -36,8 +37,8 @@ public class eth_call extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
VM vm = new VM();
@ -46,8 +47,8 @@ public class eth_call extends JsonRpcServerMethod {
byte[] result = program.getResult().getHReturn();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(root);
}
String tmp = "0x" + Hex.toHexString(result);

View File

@ -4,6 +4,7 @@ import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import net.minidev.json.JSONObject;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Repository;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.Program;
@ -36,8 +37,8 @@ public class eth_estimateGas extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
VM vm = new VM();
@ -46,8 +47,8 @@ public class eth_estimateGas extends JsonRpcServerMethod {
long result = program.getResult().getGasUsed();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(root);
}
String tmp = "0x" + Long.toHexString(result);

View File

@ -4,6 +4,7 @@ import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Repository;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
@ -29,8 +30,8 @@ public class eth_getBalance extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
BigInteger balance = ethereum.getRepository().getBalance(address);
@ -41,8 +42,8 @@ public class eth_getBalance extends JsonRpcServerMethod {
}
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(root);
}
String tmp = "0x" + balance.toString(16);

View File

@ -3,6 +3,7 @@ package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Repository;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
import java.util.List;
@ -27,15 +28,15 @@ public class eth_getCode extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
String tmp = "0x" + Hex.toHexString(ethereum.getRepository().getCode(address));
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(root);
}
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());

View File

@ -4,6 +4,7 @@ import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServer;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Repository;
import org.ethereum.facade.Ethereum;
import org.ethereum.vm.DataWord;
import org.spongycastle.util.encoders.Hex;
@ -28,15 +29,15 @@ public class eth_getStorageAt extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
String tmp = "0x" + Hex.toHexString(ethereum.getRepository().getStorageValue(address, new DataWord(key)).getData());
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
Repository repository = (Repository)ethereum.getRepository();
repository.syncToRoot(root);
}
JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID());

View File

@ -4,6 +4,7 @@ import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.core.Blockchain;
import org.ethereum.facade.Ethereum;
import java.util.List;
@ -21,9 +22,8 @@ public class eth_getTransactionByHash extends JsonRpcServerMethod {
} else {
byte[] address = jsToAddress((String) params.get(0));
// TODO: Missing method on repository
/*
TransactionReceipt transaction = ethereum.getBlockchain().getTransactionReceiptByHash(address);
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
TransactionReceipt transaction = blockchain.getTransactionReceiptByHash(address);
if (transaction == null)
@ -31,8 +31,6 @@ public class eth_getTransactionByHash extends JsonRpcServerMethod {
JSONRPC2Response res = new JSONRPC2Response(transactionToJS(null, transaction.getTransaction()), req.getID());
return res;
*/
return null;
}
}

View File

@ -5,6 +5,7 @@ import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServer;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.AccountState;
import org.ethereum.core.Repository;
import org.ethereum.core.Transaction;
import org.ethereum.facade.Ethereum;
import org.spongycastle.util.encoders.Hex;
@ -18,6 +19,7 @@ public class eth_getTransactionCount extends JsonRpcServerMethod {
protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) {
Repository repository = (Repository)ethereum.getRepository();
List<Object> params = req.getPositionalParams();
if (params.size() != 2) {
return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID());
@ -30,16 +32,14 @@ public class eth_getTransactionCount extends JsonRpcServerMethod {
byte[] root = ethereum.getBlockchain().getBestBlock().getStateRoot();
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
repository.syncToRoot(ethereum.getBlockchain().getBlockByNumber(blockNumber).getStateRoot());
}
BigInteger nonce = BigInteger.ZERO;
// TODO: Missing method on repository
//AccountState accountState = ethereum.getRepository().getAccountState(address);
//if (accountState != null)
// nonce = accountState.getNonce();
AccountState accountState = repository.getAccountState(address);
if (accountState != null)
nonce = accountState.getNonce();
if (blockNumber == -1) {
synchronized (ethereum.getBlockchain().getPendingTransactions()) {
@ -52,8 +52,7 @@ public class eth_getTransactionCount extends JsonRpcServerMethod {
}
if (blockNumber >= 0) {
// TODO: Missing method on repository
//ethereum.getRepository().syncToRoot(root);
repository.syncToRoot(root);
}
String tmp = "0x" + nonce.toString(16);

View File

@ -3,6 +3,7 @@ package org.ethereum.android.jsonrpc.full.method;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import org.ethereum.android.jsonrpc.full.JsonRpcServerMethod;
import org.ethereum.core.Blockchain;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import java.util.List;
@ -21,17 +22,14 @@ public class eth_getTransactionReceipt extends JsonRpcServerMethod {
} else {
byte[] address = jsToAddress((String) params.get(0));
// TODO: Missing method on blockchain
/*
TransactionReceipt transaction = ethereum.getBlockchain().getTransactionReceiptByHash(address);
Blockchain blockchain = (Blockchain)ethereum.getBlockchain();
TransactionReceipt transaction = blockchain.getTransactionReceiptByHash(address);
if (transaction == null)
return new JSONRPC2Response(null, req.getID());
JSONRPC2Response res = new JSONRPC2Response(transactionReceiptToJS(null, transaction), req.getID());
return res;
*/
return null;
}
}

View File

@ -19,6 +19,7 @@ import org.ethereum.android.service.events.PeerDisconnectEventData;
import org.ethereum.android.service.events.PendingTransactionsEventData;
import org.ethereum.android.service.events.TraceEventData;
import org.ethereum.android.service.events.VMTraceCreatedEventData;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
@ -69,26 +70,28 @@ public class EthereumService extends Service {
ethereum.close();
}
protected class InitializeTask extends AsyncTask<Ethereum, Message, Void> {
protected class InitializeTask extends AsyncTask<Ethereum, Message, Ethereum> {
public InitializeTask() {
}
protected Void doInBackground(Ethereum... args) {
protected Ethereum doInBackground(Ethereum... args) {
initializeEthereum();
return null;
return initializeEthereum();
}
protected void onPostExecute(Void results) {
protected void onPostExecute(Ethereum results) {
if (results != null) {
EthereumService.ethereum = results;
}
}
}
protected void initializeEthereum() {
protected Ethereum initializeEthereum() {
Ethereum ethereum = null;
if (!isInitialized) {
System.setProperty("sun.arch.data.model", "32");
System.setProperty("leveldb.mmap", "false");
@ -116,6 +119,8 @@ public class EthereumService extends Service {
System.out.println(" Already initialized");
System.out.println("x " + (ethereum != null));
}
return ethereum;
}
@Override
@ -195,11 +200,13 @@ public class EthereumService extends Service {
@Override
public void onEthStatusUpdated(Node node, StatusMessage status) {
// TODO: add boardcast event
System.out.println(node.getHost() + " = " + status.toString());
}
@Override
public void onNodeDiscovered(Node node) {
// TODO: add broadcast event
System.out.println(node.toString());
}
}
}

View File

@ -90,9 +90,11 @@ public class SystemProperties {
Properties props = new Properties();
InputStream is = ClassLoader.getSystemResourceAsStream("version.properties");
props.load(is);
this.projectVersion = props.getProperty("versionNumber");
this.projectVersion = this.projectVersion.replaceAll("'", "");
if (is != null) {
props.load(is);
this.projectVersion = props.getProperty("versionNumber");
this.projectVersion = this.projectVersion.replaceAll("'", "");
}
if (this.projectVersion == null) this.projectVersion = "-.-.-";

View File

@ -33,6 +33,7 @@ import org.ethereum.net.rlpx.discover.NodeManager;
import org.ethereum.net.rlpx.discover.PeerConnectionTester;
import org.ethereum.net.server.ChannelManager;
import org.ethereum.net.server.EthereumChannelInitializer;
import org.ethereum.net.server.PeerServer;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.rlpx.MessageCodec;
import org.ethereum.vm.ProgramInvokeFactory;
@ -64,8 +65,13 @@ public class EthereumModule {
@Provides
@Singleton
public Ethereum provideEthereum(WorldManager worldManager, AdminInfo adminInfo, ChannelManager channelManager,
BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener) {
return new EthereumImpl(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener);
BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener, PeerServer peerServer) {
return createEthereum(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener, peerServer);
}
protected Ethereum createEthereum(WorldManager worldManager, AdminInfo adminInfo, ChannelManager channelManager,
BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener, PeerServer peerServer) {
return new EthereumImpl(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener, peerServer);
}
@Provides
@ -75,6 +81,12 @@ public class EthereumModule {
return new WorldManager(blockchain, repository, wallet, peerDiscovery, blockStore, channelManager, adminInfo, listener, nodeManager, syncManager);
}
@Provides
@Singleton
public PeerServer providePeerServer(ChannelManager channelManager, EthereumChannelInitializer ethereumChannelInitializer, EthereumListener listener) {
return new PeerServer(channelManager, ethereumChannelInitializer, listener);
}
@Provides
@Singleton
public Blockchain provideBlockchain(BlockStore blockStore, Repository repository,
@ -123,6 +135,10 @@ public class EthereumModule {
@Provides
@Singleton
public Repository provideRepository() {
return createRepository();
}
protected Repository createRepository() {
MapDBDataSource detailsDS = new MapDBDataSource();
MapDBDataSource stateDS = new MapDBDataSource();
return new RepositoryImpl(detailsDS, stateDS);

View File

@ -57,8 +57,7 @@ public class EthereumImpl implements Ethereum {
@Inject
public EthereumImpl(WorldManager worldManager, AdminInfo adminInfo,
ChannelManager channelManager, BlockLoader blockLoader,
Provider<PeerClient> peerClientProvider, EthereumListener listener) {
System.out.println();
Provider<PeerClient> peerClientProvider, EthereumListener listener, PeerServer peerServer) {
logger.info("EthereumImpl constructor");
this.worldManager = worldManager;
this.adminInfo = adminInfo;
@ -66,8 +65,9 @@ public class EthereumImpl implements Ethereum {
this.blockLoader = blockLoader;
this.peerClientProvider = peerClientProvider;
this.listener = listener;
this.peerServer = peerServer;
this.worldManager.setEthereum(this);
this.worldManager.init(null);
this.init();
}

View File

@ -18,6 +18,8 @@ import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -77,16 +79,14 @@ public class WorldManager {
this.syncManager.setBlockChain(this.blockchain);
this.channelManager.setSyncManager(this.syncManager);
this.init();
}
public void init() {
byte[] cowAddr = HashUtil.sha3("cow".getBytes());
wallet.importKey(cowAddr);
String secret = CONFIG.coinbaseSecret();
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
wallet.importKey(cbAddr);
public void init(List<String> privateKeys) {
if (privateKeys != null) {
for (String privateKey: privateKeys) {
wallet.importKey(Hex.decode(privateKey));
}
}
loadBlockchain();
syncManager.init();