mirror of https://github.com/hyperledger/besu
Inject StorageProvider into PantheonController instances (#259)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
6209269eb6
commit
4e9ad2a608
@ -0,0 +1,26 @@ |
||||
/* |
||||
* Copyright 2018 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.storage; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage; |
||||
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; |
||||
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; |
||||
|
||||
import java.io.Closeable; |
||||
|
||||
public interface StorageProvider extends Closeable { |
||||
|
||||
BlockchainStorage createBlockchainStorage(ProtocolSchedule<?> protocolSchedule); |
||||
|
||||
WorldStateStorage createWorldStateStorage(); |
||||
} |
@ -0,0 +1,47 @@ |
||||
/* |
||||
* Copyright 2018 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.storage.keyvalue; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.db.BlockchainStorage; |
||||
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; |
||||
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction; |
||||
import tech.pegasys.pantheon.ethereum.storage.StorageProvider; |
||||
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; |
||||
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public class KeyValueStorageProvider implements StorageProvider { |
||||
|
||||
private final KeyValueStorage keyValueStorage; |
||||
|
||||
public KeyValueStorageProvider(final KeyValueStorage keyValueStorage) { |
||||
this.keyValueStorage = keyValueStorage; |
||||
} |
||||
|
||||
@Override |
||||
public BlockchainStorage createBlockchainStorage(final ProtocolSchedule<?> protocolSchedule) { |
||||
return new KeyValueStoragePrefixedKeyBlockchainStorage( |
||||
keyValueStorage, ScheduleBasedBlockHashFunction.create(protocolSchedule)); |
||||
} |
||||
|
||||
@Override |
||||
public WorldStateStorage createWorldStateStorage() { |
||||
return new KeyValueStorageWorldStateStorage(keyValueStorage); |
||||
} |
||||
|
||||
@Override |
||||
public void close() throws IOException { |
||||
keyValueStorage.close(); |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
/* |
||||
* Copyright 2018 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.storage.keyvalue; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.storage.StorageProvider; |
||||
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; |
||||
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
|
||||
public class RocksDbStorageProvider { |
||||
|
||||
public static StorageProvider create(final Path databaseDir) throws IOException { |
||||
final KeyValueStorage kv = RocksDbKeyValueStorage.create(Files.createDirectories(databaseDir)); |
||||
return new KeyValueStorageProvider(kv); |
||||
} |
||||
} |
Loading…
Reference in new issue