Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Commit

Permalink
major refactoring + EthereumTest uses Homestead config now
Browse files Browse the repository at this point in the history
  • Loading branch information
adridadou committed Feb 1, 2017
1 parent b672d99 commit f247207
Show file tree
Hide file tree
Showing 30 changed files with 80 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ It can create an account from a String (seed) or from a File (keystore)

####EthereumFacadeProvider
This is the provider used to connect through EthereumJ.
The different pre-defined configurations can be found at org.adridadou.ethereum.provider.EthereumJConfigs
The different pre-defined configurations can be found at org.adridadou.ethereum.ethj.provider.EthereumJConfigs
You can use the function "from" that takes a configuration.
This returns a Provider Builder. You can then extend the configuration. This is useful when you want to connect to Ropsten but with fast sync (for example)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum;

import org.adridadou.ethereum.event.EthereumEventHandler;
import org.adridadou.ethereum.values.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.adridadou.ethereum;

import com.google.common.collect.Sets;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.converters.input.*;
import org.adridadou.ethereum.converters.output.*;
import org.adridadou.ethereum.smartcontract.SmartContract;
import org.adridadou.ethereum.values.*;
import org.adridadou.exception.EthereumApiException;
import org.ethereum.core.CallTransaction;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/adridadou/ethereum/EthereumFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.CompletableFuture;

import com.google.common.base.Charsets;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.converters.input.InputTypeConverter;
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeConverter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum;

import static org.adridadou.ethereum.values.EthValue.wei;

Expand All @@ -13,7 +13,6 @@
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.event.*;
import org.adridadou.ethereum.smartcontract.SmartContract;
import org.adridadou.ethereum.values.CompiledContract;
import org.adridadou.ethereum.values.ContractAbi;
import org.adridadou.ethereum.values.EthAccount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.smartcontract;
package org.adridadou.ethereum;

import java.util.Arrays;
import java.util.List;
Expand All @@ -7,8 +7,6 @@
import java.util.stream.Collectors;

import com.google.common.collect.Lists;
import org.adridadou.ethereum.blockchain.EthereumBackend;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.values.EthAccount;
import org.adridadou.ethereum.values.EthAddress;
import org.adridadou.ethereum.values.EthData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.ethj;

import org.adridadou.ethereum.values.config.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.ethj;

import org.adridadou.ethereum.EthereumBackend;
import org.adridadou.ethereum.event.EthereumEventHandler;
import org.adridadou.ethereum.provider.LocalExecutionServiceImpl;
import org.adridadou.ethereum.values.*;
import org.adridadou.ethereum.values.config.ChainId;
import org.ethereum.core.*;
Expand All @@ -16,11 +16,11 @@
*/
public class EthereumReal implements EthereumBackend {
private final Ethereum ethereum;
private final LocalExecutionServiceImpl localExecutionService;
private final LocalExecutionService localExecutionService;

public EthereumReal(Ethereum ethereum, ChainId chainId) {
this.ethereum = ethereum;
this.localExecutionService = new LocalExecutionServiceImpl((BlockchainImpl)ethereum.getBlockchain(), chainId);
this.localExecutionService = new LocalExecutionService((BlockchainImpl)ethereum.getBlockchain(), chainId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.ethj;

import org.adridadou.ethereum.EthereumBackend;
import org.adridadou.ethereum.event.EthereumEventHandler;
import org.adridadou.ethereum.keystore.AccountProvider;
import org.adridadou.ethereum.provider.LocalExecutionServiceImpl;
import org.adridadou.ethereum.values.*;
import org.adridadou.ethereum.values.config.ChainId;
import org.adridadou.exception.EthereumApiException;
import org.ethereum.config.SystemProperties;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.blockchain.HomesteadConfig;
import org.ethereum.core.Block;
import org.ethereum.core.Repository;
import org.ethereum.core.Transaction;
Expand All @@ -24,28 +25,29 @@
*/
public class EthereumTest implements EthereumBackend {
private final StandaloneBlockchain blockchain;
private final TestConfig config;
private final TestConfig testConfig;
private final BlockingQueue<Transaction> transactions = new ArrayBlockingQueue<>(100);
private final LocalExecutionServiceImpl localExecutionService;
private final LocalExecutionService localExecutionService;

public EthereumTest(TestConfig config) {
SystemProperties.getDefault().setBlockchainConfig(new FrontierConfig(new FrontierConfig.FrontierConstants() {
public EthereumTest(TestConfig testConfig) {
SystemProperties.getDefault().setBlockchainConfig(new HomesteadConfig(new HomesteadConfig.HomesteadConstants() {
@Override
public BigInteger getMINIMUM_DIFFICULTY() {
return BigInteger.ONE;
}
}));

this.blockchain = new StandaloneBlockchain();

blockchain
.withGasLimit(config.getGasLimit())
.withGasPrice(config.getGasPrice())
.withCurrentTime(config.getInitialTime());
.withGasLimit(testConfig.getGasLimit())
.withGasPrice(testConfig.getGasPrice())
.withCurrentTime(testConfig.getInitialTime());

config.getBalances().entrySet()
testConfig.getBalances().entrySet()
.forEach(entry -> blockchain.withAccountBalance(entry.getKey().getAddress().address, entry.getValue().inWei()));

localExecutionService = new LocalExecutionServiceImpl(blockchain.getBlockchain(), ChainId.id(1));
localExecutionService = new LocalExecutionService(blockchain.getBlockchain(), ChainId.id(1));
CompletableFuture.runAsync(() -> {
try {
while(true) {
Expand All @@ -57,7 +59,7 @@ public BigInteger getMINIMUM_DIFFICULTY() {
}
});

this.config = config;
this.testConfig = testConfig;
}

public EthAccount defaultAccount() {
Expand All @@ -66,7 +68,7 @@ public EthAccount defaultAccount() {

@Override
public BigInteger getGasPrice() {
return BigInteger.valueOf(config.getGasPrice());
return BigInteger.valueOf(testConfig.getGasPrice());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.ethj;

/**
* Created by davidroon on 26.12.16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.ethj;

import org.adridadou.ethereum.values.EthAccount;
import org.adridadou.ethereum.values.EthAddress;
Expand All @@ -14,11 +14,11 @@
/**
* Created by davidroon on 30.01.17.
*/
public class LocalExecutionServiceImpl {
public class LocalExecutionService {
private final BlockchainImpl blockchain;
private final ChainId chainId;

public LocalExecutionServiceImpl(BlockchainImpl blockchain, ChainId chainId) {
public LocalExecutionService(BlockchainImpl blockchain, ChainId chainId) {
this.blockchain = blockchain;
this.chainId = chainId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.ethj;

import org.adridadou.ethereum.values.EthAccount;
import org.adridadou.ethereum.values.EthValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.ethj.provider;

import com.typesafe.config.ConfigFactory;
import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.blockchain.*;
import org.adridadou.ethereum.*;
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.ethj.BlockchainConfig;
import org.adridadou.ethereum.ethj.EthereumReal;
import org.adridadou.ethereum.ethj.EthereumTest;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.event.EthereumEventHandler;
import org.adridadou.ethereum.swarm.SwarmService;
import org.adridadou.ethereum.values.config.ChainId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.ethj.provider;

import org.adridadou.ethereum.blockchain.BlockchainConfig;
import org.adridadou.ethereum.blockchain.IncompatibleDatabaseBehavior;
import org.adridadou.ethereum.ethj.BlockchainConfig;
import org.adridadou.ethereum.ethj.IncompatibleDatabaseBehavior;
import org.adridadou.ethereum.ethj.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.values.config.*;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.ethj.provider;

import com.typesafe.config.ConfigFactory;
import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.blockchain.EthereumBackend;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.blockchain.EthereumReal;
import org.adridadou.ethereum.EthereumBackend;
import org.adridadou.ethereum.EthereumProxy;
import org.adridadou.ethereum.ethj.EthereumReal;
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.event.EthereumEventHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.ethj.provider;

import org.adridadou.ethereum.values.EthAccount;
import org.adridadou.ethereum.values.EthValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.adridadou.ethereum.blockchain.EthereumBackend;
import org.adridadou.ethereum.EthereumBackend;
import org.adridadou.ethereum.values.EthData;
import org.adridadou.exception.EthereumApiException;
import org.ethereum.core.Block;
Expand Down Expand Up @@ -52,16 +52,16 @@ public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTran
onTransactionHandler.on(new OnTransactionParameters(txReceipt, EthData.of(transaction.getHash()), transactionStatus, txReceipt.getError(), new ArrayList<>(), transaction.getSender(), transaction.getReceiveAddress()));
}

@Override
public void onTransactionExecuted(TransactionExecutionSummary summary) {
@Override
public void onTransactionExecuted(TransactionExecutionSummary summary) {
summary.getInternalTransactions()
.forEach(internalTransaction -> onTransactionHandler
.on(new OnTransactionParameters(null, EthData.of(internalTransaction.getHash()), TransactionStatus.Executed, "", summary.getLogs(), internalTransaction.getSender(), internalTransaction.getReceiveAddress())));
Transaction transaction = summary.getTransaction();
onTransactionHandler.on(new OnTransactionParameters(null, EthData.of(transaction.getHash()), TransactionStatus.Executed, "", summary.getLogs(), transaction.getSender(), transaction.getReceiveAddress()));
}
}

public TransactionReceipt checkForErrors(final TransactionReceipt receipt) {
public TransactionReceipt checkForErrors(final TransactionReceipt receipt) {
if (receipt.isSuccessful() && receipt.isValid()) {
return receipt;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.rpc;

import org.adridadou.ethereum.EthereumBackend;
import org.adridadou.ethereum.event.EthereumEventHandler;
import org.adridadou.ethereum.values.*;
import org.ethereum.core.Transaction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.rpc;

import org.adridadou.ethereum.event.EthereumEventHandler;
import org.ethereum.listener.EthereumListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.adridadou.ethereum.blockchain;
package org.adridadou.ethereum.rpc;

import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.values.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.rpc.provider;

import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.blockchain.EthereumRPC;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.blockchain.EthereumRpcEventGenerator;
import org.adridadou.ethereum.blockchain.Web3JFacade;
import org.adridadou.ethereum.rpc.EthereumRPC;
import org.adridadou.ethereum.EthereumProxy;
import org.adridadou.ethereum.rpc.EthereumRpcEventGenerator;
import org.adridadou.ethereum.rpc.Web3JFacade;
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.event.EthereumEventHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.rpc.provider;

import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.ethj.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.values.config.InfuraKey;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.adridadou.ethereum.provider;
package org.adridadou.ethereum.rpc.provider;

import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.ethj.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.values.config.*;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/adridadou/ethereum/values/Payable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.adridadou.ethereum.values;

import org.adridadou.ethereum.EthereumContractInvocationHandler;
import org.adridadou.ethereum.smartcontract.SmartContract;
import org.adridadou.ethereum.SmartContract;

import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/adridadou/EthereumProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.adridadou;

import org.adridadou.ethereum.*;
import org.adridadou.ethereum.blockchain.EthereumProxy;
import org.adridadou.ethereum.blockchain.EthereumTest;
import org.adridadou.ethereum.blockchain.TestConfig;
import org.adridadou.ethereum.EthereumProxy;
import org.adridadou.ethereum.ethj.EthereumTest;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.converters.input.InputTypeHandler;
import org.adridadou.ethereum.converters.output.OutputTypeHandler;
import org.adridadou.ethereum.event.EthereumEventHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/adridadou/EventsTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.adridadou;

import org.adridadou.ethereum.EthereumFacade;
import org.adridadou.ethereum.blockchain.TestConfig;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.keystore.AccountProvider;
import org.adridadou.ethereum.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.ethj.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.values.CompiledContract;
import org.adridadou.ethereum.values.EthAccount;
import org.adridadou.ethereum.values.EthAddress;
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/adridadou/TestnetConnectionTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.adridadou;

import org.adridadou.ethereum.*;
import org.adridadou.ethereum.blockchain.TestConfig;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.ethj.provider.EthereumFacadeProvider;
import org.adridadou.ethereum.ethj.provider.PrivateEthereumFacadeProvider;
import org.adridadou.ethereum.keystore.AccountProvider;
import org.adridadou.ethereum.provider.*;
import org.adridadou.ethereum.values.*;

import static org.adridadou.ethereum.provider.EthereumJConfigs.ropsten;
import static org.adridadou.ethereum.provider.PrivateNetworkConfig.config;
import static org.adridadou.ethereum.ethj.provider.EthereumJConfigs.ropsten;
import static org.adridadou.ethereum.ethj.provider.PrivateNetworkConfig.config;
import static org.adridadou.ethereum.values.EthValue.ether;
import static org.junit.Assert.*;

Expand Down Expand Up @@ -98,7 +99,7 @@ private void testMethodCalls(MyContract2 myContract, EthAddress address, Ethereu

@Test
public void main_example_how_the_lib_works() throws Exception {
final EthereumFacade ethereum = fromPrivateNetwork();
final EthereumFacade ethereum = fromTest();
EthAddress address = publishAndMapContract(ethereum);
CompiledContract compiledContract = ethereum.compile(contractSource, "myContract2").get();
MyContract2 myContract = ethereum.createContractProxy(compiledContract, address, mainAccount, MyContract2.class);
Expand Down
Loading

0 comments on commit f247207

Please sign in to comment.