More cleaning.

Started implementing BlockStore for android.
This commit is contained in:
Adrian Tiberius 2015-05-27 20:05:59 +02:00
parent 25506f3813
commit 779eddd9f9
39 changed files with 590 additions and 449 deletions

View File

@ -67,10 +67,6 @@ dependencies {
provided 'org.glassfish:javax.annotation:10.0-b28'
compile project(':ethereumj-core')
compile fileTree(include: ['*.jar'], dir: '../libraries')
//compile 'com.android.support:appcompat-v7:21.0.3'
//compile files('./libs/robospring-1.0.7.jar')
//compile 'com.litl:android-leveldb:1.0.3@aar'
//compile "org.slf4j:slf4j-android:1.6.1-RC1"
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.app.Application;
import android.test.ApplicationTestCase;

View File

@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ethereum.ethereum_android" >
package="org.ethereum.android" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="org.ethereum.ethereum_android.EthereumApplication"
android:name="org.ethereum.android.EthereumApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:name="org.ethereum.android.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -22,7 +21,7 @@
</activity>
<service
android:name=".MyService"
android:name="org.ethereum.android.MyService"
android:enabled="true"
android:exported="true" >
</service>

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import org.ethereum.core.AccountState;
import org.ethereum.core.Denomination;

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import org.ethereum.core.AccountState;

View File

@ -0,0 +1,13 @@
package org.ethereum.android;
import android.support.multidex.MultiDexApplication;
public class EthereumApplication extends MultiDexApplication {
@Override public void onCreate() {
super.onCreate();
}
}

View File

@ -11,6 +11,9 @@ import org.ethereum.ethereum_android.di.components.ApplicationComponent;
import org.ethereum.ethereum_android.di.components.DaggerApplicationComponent;
import org.ethereum.ethereum_android.di.modules.ApplicationModule;
/**
* Created by userica on 20.05.2015.
*/
public class EthereumApplication extends MultiDexApplication {
private ApplicationComponent applicationComponent = null;
@ -32,4 +35,4 @@ public class EthereumApplication extends MultiDexApplication {
return applicationComponent;
}
}
}

View File

@ -1,8 +1,5 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.content.Context;
import org.ethereum.EthereumFactory;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
@ -30,6 +27,10 @@ public class EthereumManager {
this.addListener();
}
public void start() {
}
public void connect() {
ethereum.connect(SystemProperties.CONFIG.activePeerIP(),

View File

@ -1,7 +1,6 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
@ -16,20 +15,13 @@ import android.widget.TextView;
import android.view.View.OnClickListener;
import android.widget.Toast;
//import org.springframework.context.ApplicationContext;
import org.ethereum.di.components.DaggerEthereumComponent;
import org.ethereum.di.components.EthereumComponent;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.ethereum_android.di.components.ApplicationComponent;
import org.ethereum.ethereum_android.di.modules.ActivityModule;
import org.ethereum.android.di.components.DaggerEthereumComponent;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
import javax.inject.Inject;
public class MainActivity extends ActionBarActivity implements OnClickListener, NavigationDrawerCallbacks {
// public static ApplicationContext context = null;
private static final String TAG = "MyActivity";
private static Integer quit = 0;
private TextView text1;
@ -97,14 +89,6 @@ public class MainActivity extends ActionBarActivity implements OnClickListener,
t.start();
}
protected ApplicationComponent getApplicationComponent() {
return ((EthereumApplication)getApplication()).getApplicationComponent();
}
protected ActivityModule getActivityModule() {
return new ActivityModule(this);
}
public void onClick(View v) {
switch (v.getId()) {
/*

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.app.Service;
import android.content.Intent;

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.support.v7.widget.RecyclerView;

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
public interface NavigationDrawerCallbacks {
void onNavigationDrawerItemSelected(int position);

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.app.Activity;
import android.app.Fragment;

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android;
package org.ethereum.android;
import android.graphics.drawable.Drawable;

View File

@ -1,7 +1,8 @@
package org.ethereum.datasource;
package org.ethereum.android.datasource;
import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.KeyValueDataSource;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
@ -25,7 +26,7 @@ import android.content.Context;
* @author Roman Mandeleil
* @since 18.01.2015
*/
public class AndroidLevelDbDataSource implements KeyValueDataSource {
public class LevelDbDataSource implements KeyValueDataSource {
private static final Logger logger = LoggerFactory.getLogger("db");
@ -33,10 +34,10 @@ public class AndroidLevelDbDataSource implements KeyValueDataSource {
private DB db;
private Context context;
public AndroidLevelDbDataSource() {
public LevelDbDataSource() {
}
public AndroidLevelDbDataSource(String name) {
public LevelDbDataSource(String name) {
this.name = name;
}

View File

@ -0,0 +1,84 @@
package org.ethereum.android.db;
import java.sql.SQLException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import org.ethereum.db.BlockVO;
/**
* Database helper class used to manage the creation and upgrading of your database. This class also usually provides
* the DAOs used by the other classes.
*/
public class BlockDatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "blocks.db";
private static final int DATABASE_VERSION = 1;
// the DAO object we use to access the SimpleData table
private Dao<BlockVO, Integer> blockDao = null;
public BlockDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/**
* This is called when the database is first created. Usually you should call createTable statements here to create
* the tables that will store your data.
*/
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, BlockVO.class);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
}
/**
* This is called when your application is upgraded and it has a higher version number. This allows you to adjust
* the various data to match the new version number.
*/
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, BlockVO.class, true);
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached
* value.
*/
public Dao<BlockVO, Integer> getBlockDao() throws SQLException {
if (blockDao == null) {
blockDao = getDao(BlockVO.class);
}
return blockDao;
}
/**
* Close the database connections and clear any cached DAOs.
*/
@Override
public void close() {
super.close();
blockDao = null;
}
}

View File

@ -0,0 +1,94 @@
package org.ethereum.android.db;
import org.ethereum.core.Block;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.db.BlockStore;
import org.ethereum.db.BlockVO;
import org.ethereum.util.ByteUtil;
import java.math.BigInteger;
import java.util.List;
public class BlockStoreImpl implements BlockStore {
private BlockDatabaseHelper blockDao;
private TransactionDatabaseHelper transactionDao;
public BlockStoreImpl(BlockDatabaseHelper blockDao, TransactionDatabaseHelper transactionDao) {
this.blockDao = blockDao;
this.transactionDao = transactionDao;
}
public byte[] getBlockHashByNumber(long blockNumber) {
Block block = getBlockByNumber(blockNumber);
if (block != null) return block.getHash();
return ByteUtil.EMPTY_BYTE_ARRAY;
}
public Block getBlockByNumber(long blockNumber) {
/*
List result = sessionFactory.getCurrentSession().
createQuery("from BlockVO where number = :number").
setParameter("number", blockNumber).list();
if (result.size() == 0) return null;
BlockVO vo = (BlockVO) result.get(0);
return new Block(vo.rlp);
*/
return null;
}
public Block getBlockByHash(byte[] hash) {
return null;
}
@SuppressWarnings("unchecked")
public List<byte[]> getListOfHashesStartFrom(byte[] hash, int qty) {
return null;
}
public void deleteBlocksSince(long number) {
}
public void saveBlock(Block block, List<TransactionReceipt> receipts) {
}
public BigInteger getTotalDifficultySince(long number) {
return null;
}
public BigInteger getTotalDifficulty() {
return null;
}
public Block getBestBlock() {
return null;
}
@SuppressWarnings("unchecked")
public List<Block> getAllBlocks() {
return null;
}
public void reset() {
}
public TransactionReceipt getTransactionReceiptByHash(byte[] hash) {
return null;
}
}

View File

@ -0,0 +1,84 @@
package org.ethereum.android.db;
import java.sql.SQLException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import org.ethereum.db.TransactionReceiptVO;
/**
* Database helper class used to manage the creation and upgrading of your database. This class also usually provides
* the DAOs used by the other classes.
*/
public class TransactionDatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "transactions.db";
private static final int DATABASE_VERSION = 1;
// the DAO object we use to access the SimpleData table
private Dao<TransactionReceiptVO, Integer> dao = null;
public TransactionDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/**
* This is called when the database is first created. Usually you should call createTable statements here to create
* the tables that will store your data.
*/
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, TransactionReceiptVO.class);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
}
/**
* This is called when your application is upgraded and it has a higher version number. This allows you to adjust
* the various data to match the new version number.
*/
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, TransactionReceiptVO.class, true);
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached
* value.
*/
public Dao<TransactionReceiptVO, Integer> getBlockDao() throws SQLException {
if (dao == null) {
dao = getDao(TransactionReceiptVO.class);
}
return dao;
}
/**
* Close the database connections and clear any cached DAOs.
*/
@Override
public void close() {
super.close();
dao = null;
}
}

View File

@ -1,4 +1,4 @@
package org.ethereum.ethereum_android.di;
package org.ethereum.android.di;
import java.lang.annotation.Retention;

View File

@ -0,0 +1,18 @@
package org.ethereum.android.di.components;
import android.content.Context;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = EthereumModule.class)
public interface EthereumComponent {
Context context();
Ethereum ethereum();
}

View File

@ -0,0 +1,170 @@
package org.ethereum.android.di.modules;
import android.content.Context;
import org.ethereum.android.datasource.LevelDbDataSource;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.BlockchainImpl;
import org.ethereum.core.Wallet;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.ethereum.db.RepositoryImpl;
import org.ethereum.facade.Blockchain;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import org.ethereum.facade.Repository;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.AdminInfo;
import org.ethereum.manager.BlockLoader;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.MessageQueue;
import org.ethereum.net.client.PeerClient;
import org.ethereum.net.eth.EthHandler;
import org.ethereum.net.p2p.P2pHandler;
import org.ethereum.net.peerdiscovery.DiscoveryChannel;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.WorkerThread;
import org.ethereum.net.server.ChannelManager;
import org.ethereum.net.server.EthereumChannelInitializer;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.wire.MessageCodec;
import org.ethereum.vm.ProgramInvokeFactory;
import org.ethereum.vm.ProgramInvokeFactoryImpl;
import javax.inject.Provider;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class EthereumModule {
private Context context;
public EthereumModule(Context context) {
this.context = context;
}
@Provides
@Singleton
Ethereum provideEthereum(WorldManager worldManager, AdminInfo adminInfo, ChannelManager channelManager,
BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener) {
return new EthereumImpl(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener);
}
@Provides
@Singleton
WorldManager provideWorldManager(Blockchain blockchain, Repository repository, Wallet wallet, PeerDiscovery peerDiscovery
,BlockStore blockStore, ChannelManager channelManager, AdminInfo adminInfo, EthereumListener listener) {
return new WorldManager(blockchain, repository, wallet, peerDiscovery, blockStore, channelManager, adminInfo, listener);
}
@Provides
@Singleton
Blockchain provideBlockchain(BlockStore blockStore, Repository repository,
Wallet wallet, AdminInfo adminInfo,
EthereumListener listener, ChannelManager channelManager) {
return new BlockchainImpl(blockStore, repository, wallet, adminInfo, listener, channelManager);
}
@Provides
@Singleton
BlockStore provideBlockStore() {
return new InMemoryBlockStore();
}
@Provides
@Singleton
Repository provideRepository() {
LevelDbDataSource detailsDS = new LevelDbDataSource();
detailsDS.setContext(context);
LevelDbDataSource stateDS = new LevelDbDataSource();
stateDS.setContext(context);
return new RepositoryImpl(detailsDS, stateDS);
}
@Provides
@Singleton
AdminInfo provideAdminInfo() {
return new AdminInfo();
}
@Provides
@Singleton
EthereumListener provideEthereumListener() {
return new CompositeEthereumListener();
}
@Provides
@Singleton
PeerDiscovery providePeerDiscovery() {
return new PeerDiscovery();
}
@Provides
@Singleton
ChannelManager provideChannelManager(EthereumListener listener) {
return new ChannelManager(listener);
}
@Provides
@Singleton
BlockLoader provideBlockLoader(Blockchain blockchain) {
return new BlockLoader(blockchain);
}
@Provides
@Singleton
ProgramInvokeFactory provideProgramInvokeFactory() {
return new ProgramInvokeFactoryImpl();
}
@Provides
EthHandler provideEthHandler(Blockchain blockchain, EthereumListener listener, Wallet wallet) {
return new EthHandler(blockchain, listener, wallet);
}
@Provides
ShhHandler provideShhHandler(EthereumListener listener) {
return new ShhHandler(listener);
}
@Provides
P2pHandler provideP2pHandler(PeerDiscovery peerDiscovery, EthereumListener listener) {
return new P2pHandler(peerDiscovery, listener);
}
@Provides
MessageCodec provideMessageCodec(EthereumListener listener) {
return new MessageCodec(listener);
}
@Provides
PeerClient providePeerClient(EthereumListener listener, ChannelManager channelManager,
Provider<EthereumChannelInitializer> ethereumChannelInitializerProvider) {
return new PeerClient(listener, channelManager, ethereumChannelInitializerProvider);
}
@Provides
MessageQueue provideMessageQueue(EthereumListener listener) {
return new MessageQueue(listener);
}
@Provides
WorkerThread provideWorkerThread(Provider<DiscoveryChannel> discoveryChannelProvider) {
return new WorkerThread(discoveryChannelProvider);
}
@Provides
String provideRemoteId() {
return SystemProperties.CONFIG.activePeerNodeid();
}
@Provides
@Singleton
Context provideContext() {
return context;
}
}

View File

@ -1,15 +0,0 @@
package org.ethereum.ethereum_android.di.components;
import android.app.Activity;
import dagger.Component;
import org.ethereum.ethereum_android.di.PerActivity;
import org.ethereum.ethereum_android.di.modules.ActivityModule;
@PerActivity
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
public interface ActivityComponent {
Activity activity();
}

View File

@ -1,19 +0,0 @@
package org.ethereum.ethereum_android.di.components;
import android.content.Context;
import org.ethereum.ethereum_android.MainActivity;
import org.ethereum.ethereum_android.di.modules.ApplicationModule;
import org.ethereum.facade.Ethereum;
import dagger.Component;
import javax.inject.Singleton;
@Singleton // Constraints this component to one-per-application or unscoped bindings.
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
void inject(MainActivity mainActivity);
//Exposed to sub-graphs.
Context context();
}

View File

@ -1,10 +0,0 @@
package org.ethereum.ethereum_android.di.components;
import android.content.Context;
import org.ethereum.di.components.EthereumComponent;
public interface EthereumApplicationComponent extends EthereumComponent {
Context context();
}

View File

@ -1,30 +0,0 @@
package org.ethereum.ethereum_android.di.modules;
import android.app.Activity;
import org.ethereum.ethereum_android.di.PerActivity;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class ActivityModule {
private final Activity activity;
public ActivityModule(Activity activity) {
this.activity = activity;
}
@Provides
@PerActivity
Activity activity() {
return this.activity;
}
}

View File

@ -1,29 +0,0 @@
package org.ethereum.ethereum_android.di.modules;
import android.content.Context;
import org.ethereum.ethereum_android.EthereumApplication;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class ApplicationModule {
private final EthereumApplication application;
public ApplicationModule(EthereumApplication application) {
this.application = application;
}
@Provides @Singleton
Context provideApplicationContext() {
return this.application;
}
}

View File

@ -16,7 +16,7 @@
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment android:id="@+id/fragment_drawer"
android:name="org.ethereum.ethereum_android.NavigationDrawerFragment"
android:name="org.ethereum.android.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent" android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer" />

View File

@ -51,7 +51,14 @@ android {
sourceSets {
main {
java {
exclude '**/BlockStoreImpl.java'
exclude '**/CommonConfig.java'
exclude '**/DefaultConfig.java'
exclude '**/RemoteConfig.java'
exclude '**/EthereumFactory.java'
exclude '**/Start.java'
srcDirs += generatedSrcDir
}
}
}
@ -74,7 +81,7 @@ ext {
leveldbVersion = '0.7'
scastleVersion = '1.51.0.0'
log4jVersion = '1.2.17'
hibernateVersion = '4.3.7.Final'
hibernateVersion = '4.3.10.Final'
junitVersion = '4.11'
}
@ -88,7 +95,7 @@ dependencies {
exclude group: 'commons-logging', module: 'commons-logging'
}
compile('io.netty:netty-all:4.1.0.Beta5') {
compile('io.netty:netty-all:4.0.28.Final') {
exclude group: 'commons-logging', module: 'commons-logging'
}
compile "com.madgag.spongycastle:core:${scastleVersion}"
@ -120,6 +127,7 @@ dependencies {
compile 'org.hsqldb:hsqldb:1.8.0.10' // best performance - do not upgrade!
compile 'javax.persistence:persistence-api:1.0.2'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile('redis.clients:jedis:2.6.0') {
exclude group: 'org.apache.commons', module: 'commons-pool2'

View File

@ -4,7 +4,7 @@ import org.ethereum.core.Block;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.util.ByteUtil;
//import org.hibernate.SessionFactory;
import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
@ -21,7 +21,7 @@ import java.util.List;
* @author Roman Mandeleil
* @since 12.11.2014
*/
/*
public class BlockStoreImpl implements BlockStore {
private SessionFactory sessionFactory;
@ -31,7 +31,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
public byte[] getBlockHashByNumber(long blockNumber) {
Block block = getBlockByNumber(blockNumber);
@ -40,7 +39,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
public Block getBlockByNumber(long blockNumber) {
List result = sessionFactory.getCurrentSession().
@ -54,7 +52,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
public Block getBlockByHash(byte[] hash) {
List result = sessionFactory.getCurrentSession().
@ -68,7 +65,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<byte[]> getListOfHashesStartFrom(byte[] hash, int qty) {
@ -91,7 +87,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional
public void deleteBlocksSince(long number) {
sessionFactory.getCurrentSession().
@ -102,7 +97,6 @@ public class BlockStoreImpl implements BlockStore {
@Override
@Transactional
public void saveBlock(Block block, List<TransactionReceipt> receipts) {
BlockVO blockVO = new BlockVO(block.getNumber(), block.getHash(),
@ -121,7 +115,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
public BigInteger getTotalDifficultySince(long number) {
return (BigInteger) sessionFactory.getCurrentSession().
@ -132,7 +125,6 @@ public class BlockStoreImpl implements BlockStore {
@Override
@Transactional(readOnly = true)
public BigInteger getTotalDifficulty() {
return (BigInteger) sessionFactory.getCurrentSession().
@ -141,7 +133,6 @@ public class BlockStoreImpl implements BlockStore {
@Override
@Transactional(readOnly = true)
public Block getBestBlock() {
Long bestNumber = (Long)
@ -156,7 +147,6 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<Block> getAllBlocks() {
@ -172,14 +162,12 @@ public class BlockStoreImpl implements BlockStore {
}
@Override
@Transactional
public void reset() {
sessionFactory.getCurrentSession().
createQuery("delete from BlockVO").executeUpdate();
}
@Override
@Transactional(readOnly = true)
public TransactionReceipt getTransactionReceiptByHash(byte[] hash) {
List result = sessionFactory.getCurrentSession().
@ -192,5 +180,4 @@ public class BlockStoreImpl implements BlockStore {
return new TransactionReceipt(vo.rlp);
}
}
*/
}

View File

@ -1,192 +0,0 @@
package org.ethereum.db;
import org.ethereum.core.Block;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.util.ByteUtil;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
/**
* @author Roman Mandeleil
* @since 12.11.2014
*/
public class BlockStoreImpl implements BlockStore {
private SessionFactory sessionFactory;
public BlockStoreImpl(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public byte[] getBlockHashByNumber(long blockNumber) {
Block block = getBlockByNumber(blockNumber);
if (block != null) return block.getHash();
return ByteUtil.EMPTY_BYTE_ARRAY;
}
@Override
@Transactional(readOnly = true)
public Block getBlockByNumber(long blockNumber) {
List result = sessionFactory.getCurrentSession().
createQuery("from BlockVO where number = :number").
setParameter("number", blockNumber).list();
if (result.size() == 0) return null;
BlockVO vo = (BlockVO) result.get(0);
return new Block(vo.rlp);
}
@Override
@Transactional(readOnly = true)
public Block getBlockByHash(byte[] hash) {
List result = sessionFactory.getCurrentSession().
createQuery("from BlockVO where hash = :hash").
setParameter("hash", hash).list();
if (result.size() == 0) return null;
BlockVO vo = (BlockVO) result.get(0);
return new Block(vo.rlp);
}
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<byte[]> getListOfHashesStartFrom(byte[] hash, int qty) {
List<byte[]> hashes = new ArrayList<>();
// find block number of that block hash
Block block = getBlockByHash(hash);
if (block == null) return hashes;
List<byte[]> result = sessionFactory.getCurrentSession().
createQuery("select hash from BlockVO where number <= :number and number >= :limit order by number desc").
setParameter("number", block.getNumber()).
setParameter("limit", block.getNumber() - qty).
setMaxResults(qty).list();
for (byte[] h : result)
hashes.add(h);
return hashes;
}
@Override
@Transactional
public void deleteBlocksSince(long number) {
sessionFactory.getCurrentSession().
createQuery("delete from BlockVO where number > :number").
setParameter("number", number).
executeUpdate();
}
@Override
@Transactional
public void saveBlock(Block block, List<TransactionReceipt> receipts) {
BlockVO blockVO = new BlockVO(block.getNumber(), block.getHash(),
block.getEncoded(), block.getCumulativeDifficulty());
for (TransactionReceipt receipt : receipts) {
byte[] hash = receipt.getTransaction().getHash();
byte[] rlp = receipt.getEncoded();
TransactionReceiptVO transactionReceiptVO = new TransactionReceiptVO(hash, rlp);
sessionFactory.getCurrentSession().persist(transactionReceiptVO);
}
sessionFactory.getCurrentSession().persist(blockVO);
}
@Override
@Transactional(readOnly = true)
public BigInteger getTotalDifficultySince(long number) {
return (BigInteger) sessionFactory.getCurrentSession().
createQuery("select sum(cumulativeDifficulty) from BlockVO where number > :number").
setParameter("number", number).
uniqueResult();
}
@Override
@Transactional(readOnly = true)
public BigInteger getTotalDifficulty() {
return (BigInteger) sessionFactory.getCurrentSession().
createQuery("select sum(cumulativeDifficulty) from BlockVO").uniqueResult();
}
@Override
@Transactional(readOnly = true)
public Block getBestBlock() {
Long bestNumber = (Long)
sessionFactory.getCurrentSession().createQuery("select max(number) from BlockVO").uniqueResult();
List result = sessionFactory.getCurrentSession().
createQuery("from BlockVO where number = :number").setParameter("number", bestNumber).list();
if (result.isEmpty()) return null;
BlockVO vo = (BlockVO) result.get(0);
return new Block(vo.rlp);
}
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<Block> getAllBlocks() {
List<BlockVO> result = sessionFactory.getCurrentSession().
createQuery("from BlockVO").list();
ArrayList<Block> blocks = new ArrayList<>();
for (BlockVO blockVO : result) {
blocks.add(new Block(blockVO.getRlp()));
}
return blocks;
}
@Override
@Transactional
public void reset() {
sessionFactory.getCurrentSession().
createQuery("delete from BlockVO").executeUpdate();
}
@Override
public TransactionReceipt getTransactionReceiptByHash(byte[] hash) {
List result = sessionFactory.getCurrentSession().
createQuery("from TransactionReceiptVO where hash = :hash").
setParameter("hash", hash).list();
if (result.size() == 0) return null;
TransactionReceiptVO vo = (TransactionReceiptVO) result.get(0);
return new TransactionReceipt(vo.rlp);
}
}

View File

@ -1,7 +1,5 @@
package org.ethereum.di.components;
import android.content.Context;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListener;
@ -14,9 +12,6 @@ import dagger.Component;
@Component(modules = EthereumModule.class)
public interface EthereumComponent {
//void inject(EthereumManager ethereumManager);
Context context();
Ethereum ethereum();
EthereumListener listener();
}

View File

@ -5,7 +5,6 @@ import android.content.Context;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.BlockchainImpl;
import org.ethereum.core.Wallet;
import org.ethereum.datasource.AndroidLevelDbDataSource;
import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.datasource.LevelDbDataSource;
import org.ethereum.db.BlockStore;
@ -44,10 +43,8 @@ import dagger.Provides;
@Module
public class EthereumModule {
private Context context;
public EthereumModule() {
public EthereumModule(Context context) {
this.context = context;
}
@Provides
@ -81,10 +78,8 @@ public class EthereumModule {
@Provides
@Singleton
Repository provideRepository() {
AndroidLevelDbDataSource detailsDS = new AndroidLevelDbDataSource();
detailsDS.setContext(context);
AndroidLevelDbDataSource stateDS = new AndroidLevelDbDataSource();
stateDS.setContext(context);
LevelDbDataSource detailsDS = new LevelDbDataSource();
LevelDbDataSource stateDS = new LevelDbDataSource();
return new RepositoryImpl(detailsDS, stateDS);
}
@ -160,14 +155,6 @@ public class EthereumModule {
return new WorkerThread(discoveryChannelProvider);
}
@Provides
@Singleton
Context provideContext() {
return context;
}
@Provides
String provideRemoteId() {
return SystemProperties.CONFIG.activePeerNodeid();

View File

@ -6,18 +6,18 @@ import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.datasource.LevelDbDataSource;
import org.ethereum.datasource.redis.RedisConnection;
import org.ethereum.db.RepositoryImpl;
//import org.hibernate.SessionFactory;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Scope;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.jdbc.datasource.DriverManagerDataSource;
//import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.Collections;
import java.util.HashSet;
@ -26,16 +26,16 @@ import java.util.Set;
import static org.ethereum.config.SystemProperties.CONFIG;
//@Configuration
//@EnableTransactionManagement
//@ComponentScan(basePackages = "org.ethereum")
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "org.ethereum")
public class CommonConfig {
private static final Logger logger = LoggerFactory.getLogger("general");
//@Autowired
//private RedisConnection redisConnection;
/*
@Autowired
private RedisConnection redisConnection;
@Bean
Repository repository() {
return new RepositoryImpl(keyValueDataSource(), keyValueDataSource());
@ -82,7 +82,7 @@ public class CommonConfig {
return builder.buildSessionFactory();
}
*/
private Properties getHibernateProperties() {
Properties prop = new Properties();
@ -97,13 +97,11 @@ public class CommonConfig {
return prop;
}
/*
@Bean
public HibernateTransactionManager txManager() {
return new HibernateTransactionManager(sessionFactory());
}
*/
/*
@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
@ -125,6 +123,5 @@ public class CommonConfig {
return ds;
}
*/
}

View File

@ -1,32 +1,29 @@
package org.ethereum.facade;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
//import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Import;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import org.ethereum.db.BlockStoreImpl;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author: Roman Mandeleil
* Created on: 27/01/2015 01:05
*/
//@Configuration
//@Import(CommonConfig.class)
@Configuration
@Import(CommonConfig.class)
public class DefaultConfig {
@Inject CommonConfig commonConfig;
//@Bean
//@Transactional(propagation = Propagation.SUPPORTS)
/*
@Autowired CommonConfig commonConfig;
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new InMemoryBlockStore();
return new BlockStoreImpl(sessionFactory);
}
*/
}
}

View File

@ -6,18 +6,20 @@ import org.ethereum.net.shh.ShhHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Singleton;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
/**
* @author Roman Mandeleil
* @since 13.11.2014
*/
@Singleton
@Component
public class EthereumFactory {
private static final Logger logger = LoggerFactory.getLogger("general");
public static ApplicationContext context = null;
public static Ethereum createEthereum() {
return createEthereum(DefaultConfig.class);
}
@ -27,7 +29,8 @@ public class EthereumFactory {
logger.info("capability eth version: [{}]", EthHandler.VERSION);
logger.info("capability shh version: [{}]", ShhHandler.VERSION);
return null;
context = new AnnotationConfigApplicationContext(clazz);
return context.getBean(Ethereum.class);
}
}
}

View File

@ -2,34 +2,31 @@ package org.ethereum.facade;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
//import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Import;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author: Roman Mandeleil
* Created on: 27/01/2015 01:05
*/
//@Configuration
//@Import(CommonConfig.class)
@Configuration
@Import(CommonConfig.class)
public class RemoteConfig {
@Inject CommonConfig commonConfig;
@Autowired CommonConfig commonConfig;
// todo: init total difficulty
// todo: init last 1000 blocks
//@Bean
//@Transactional(propagation = Propagation.SUPPORTS)
/*
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new InMemoryBlockStore();
}
*/
}
}

View File

@ -1,8 +1,10 @@
package org.ethereum.net.p2p;
import io.netty.buffer.ByteBuf;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.MessageQueue;
import org.ethereum.net.client.Capability;
import org.ethereum.net.eth.EthHandler;
@ -13,6 +15,7 @@ import org.ethereum.net.message.ReasonCode;
import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.PeerInfo;
import org.ethereum.net.rlpx.FrameCodec;
import org.ethereum.net.server.Channel;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.shh.ShhMessageCodes;
@ -23,6 +26,12 @@ import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Scope;
//import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -51,6 +60,8 @@ import static org.ethereum.net.message.StaticMessages.*;
* <li>PONG : Confirm that they themselves are still alive</li>
* </ul>
*/
//@Component
//@Scope("prototype")
public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
public final static byte VERSION = 4;

View File

@ -1,6 +1,7 @@
package org.ethereum.net.shh;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.MessageQueue;
import io.netty.channel.ChannelHandlerContext;
@ -11,11 +12,17 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Scope;
//import org.springframework.stereotype.Component;
/**
* Process the messages between peers with 'shh' capability on the network.
*
* Peers with 'shh' capability can send/receive:
*/
//@Component
//@Scope("prototype")
public class ShhHandler extends SimpleChannelInboundHandler<ShhMessage> {
public final static byte VERSION = 1;

View File

@ -12,9 +12,9 @@ peer.discovery.ip.list = poc-7.ethdev.com:30303,\
#peer.active.nodeid = d348964fbb47d0cb9d206b926d416b2be8c1c0c68679f07d7611ef04ee797857d0ec8e7490cc3cc64094de9e7659be42baaf1fd24ca822c1bffc58ca9cf479dd
# my poc-9-test peer-1
peer.active.ip = 162.243.46.9
peer.active.port = 30303
peer.active.nodeid = e437a4836b77ad9d9ffe73ee782ef2614e6d8370fcf62191a6e488276e23717147073a7ce0b444d485fff5a0c34c4577251a7a990cf80d8542e21b95aa8c5e6c
#peer.active.ip = 162.243.46.9
#peer.active.port = 30303
#peer.active.nodeid = e437a4836b77ad9d9ffe73ee782ef2614e6d8370fcf62191a6e488276e23717147073a7ce0b444d485fff5a0c34c4577251a7a990cf80d8542e21b95aa8c5e6c
# heiko peer
#peer.active.ip = 188.106.121.253
@ -31,9 +31,9 @@ peer.active.nodeid = e437a4836b77ad9d9ffe73ee782ef2614e6d8370fcf62191a6e488276e2
#peer.active.port = 30303
#peer.active.nodeid = bf01b54b6bc7faa203286dfb8359ce11d7b1fe822968fb4991f508d6f5a36ab7d9ae8af9b0d61c0467fb08567e0fb71cfb9925a370b69f9ede97927db473d1f5
#peer.active.ip = 192.168.122.90
#peer.active.port = 30303
#peer.active.nodeid = 68cb34d6e806cd3f4e240f6eb2c5e1e8e4d2ebec2b7cf508a15c9847fc769a717da1f69f918548958fcfbe7e8cc77f1cd97f000ef39d0c28c618985e519806b4
peer.active.ip = 192.168.122.90
peer.active.port = 30303
peer.active.nodeid = 4a531abc51448e584faae944d7e244e3f1ac6a629579a937b8c16ed98efb2a7aff29f6ab8c73c60041d3b078533bca842ec61d9a85f12ea9e6c3c7657e85f062
# peer.active.ip = 52.4.40.229
# peer.active.port = 30303