Search in sources :

Example 16 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class DefaultConfig method blockStore.

@Bean
public BlockStore blockStore(RskSystemProperties config) {
    String database = config.databaseDir();
    File blockIndexDirectory = new File(database + "/blocks/");
    File dbFile = new File(blockIndexDirectory, "index");
    if (!blockIndexDirectory.exists()) {
        boolean mkdirsSuccess = blockIndexDirectory.mkdirs();
        if (!mkdirsSuccess) {
            logger.error("Unable to create blocks directory: {}", blockIndexDirectory);
        }
    }
    DB indexDB = DBMaker.fileDB(dbFile).closeOnJvmShutdown().make();
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index").keySerializer(Serializer.LONG).valueSerializer(BLOCK_INFO_SERIALIZER).counterEnable().makeOrGet();
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
    return indexedBlockStore;
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) List(java.util.List) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) File(java.io.File) DB(org.mapdb.DB) Bean(org.springframework.context.annotation.Bean)

Example 17 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class DataSourcePoolTest method openUseAndCloseDataSource.

@Test
public void openUseAndCloseDataSource() {
    KeyValueDataSource dataSource = DataSourcePool.levelDbByName(config, "test2");
    dataSource.put(new byte[] { 0x01 }, new byte[] { 0x02 });
    dataSource.close();
    KeyValueDataSource dataSource2 = DataSourcePool.levelDbByName(config, "test2");
    byte[] result = dataSource2.get(new byte[] { 0x01 });
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.length);
    Assert.assertEquals(0x02, result[0]);
    dataSource2.close();
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Test(org.junit.Test)

Example 18 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class DataSourcePoolTest method openAndCloseDataSource.

@Test
public void openAndCloseDataSource() {
    KeyValueDataSource dataSource = DataSourcePool.levelDbByName(config, "test1");
    dataSource.close();
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Test(org.junit.Test)

Example 19 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class HashMapDBTest method getUnknownKeyValue.

@Test
public void getUnknownKeyValue() {
    KeyValueDataSource ds = new HashMapDB();
    byte[] key = new byte[] { 0x01, 0x02 };
    byte[] result = ds.get(key);
    Assert.assertNull(result);
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 20 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class HashMapDBTest method putAndGetKeyValue.

@Test
public void putAndGetKeyValue() {
    KeyValueDataSource ds = new HashMapDB();
    byte[] key = new byte[] { 0x01, 0x02 };
    byte[] value = new byte[] { 0x03, 0x03 };
    ds.put(key, value);
    byte[] result = ds.get(key);
    Assert.assertNotNull(result);
    Assert.assertArrayEquals(value, result);
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)26 HashMapDB (org.ethereum.datasource.HashMapDB)13 Test (org.junit.Test)13 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)10 BlockDifficulty (co.rsk.core.BlockDifficulty)6 Block (org.ethereum.core.Block)6 DB (org.mapdb.DB)6 BigInteger (java.math.BigInteger)5 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 Bean (org.springframework.context.annotation.Bean)4 RskAddress (co.rsk.core.RskAddress)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 EthereumListener (org.ethereum.listener.EthereumListener)3 AdminInfo (org.ethereum.manager.AdminInfo)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2