This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store Private State Root Hash in DB.
- Loading branch information
1 parent
45dc009
commit b18d5a5
Showing
13 changed files
with
227 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ore/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateStateKeyValueStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2019 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.privacy; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; | ||
import tech.pegasys.pantheon.util.bytes.Bytes32; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.util.Optional; | ||
|
||
public class PrivateStateKeyValueStorage implements PrivateStateStorage { | ||
|
||
private final KeyValueStorage keyValueStorage; | ||
|
||
public PrivateStateKeyValueStorage(final KeyValueStorage keyValueStorage) { | ||
this.keyValueStorage = keyValueStorage; | ||
} | ||
|
||
@Override | ||
public Optional<Hash> getPrivateAccountState(final BytesValue privacyId) { | ||
if (keyValueStorage.get(privacyId).isPresent()) | ||
return Optional.of( | ||
Hash.wrap(Bytes32.wrap(keyValueStorage.get(privacyId).get().extractArray()))); | ||
else return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean isWorldStateAvailable(final Bytes32 rootHash) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public PrivateStateStorage.Updater updater() { | ||
return new PrivateStateKeyValueStorage.Updater(keyValueStorage.startTransaction()); | ||
} | ||
|
||
public static class Updater implements PrivateStateStorage.Updater { | ||
private final KeyValueStorage.Transaction transaction; | ||
|
||
private Updater(final KeyValueStorage.Transaction transaction) { | ||
this.transaction = transaction; | ||
} | ||
|
||
@Override | ||
public PrivateStateStorage.Updater putPrivateAccountState( | ||
final BytesValue privacyId, final Hash privateStateHash) { | ||
transaction.put(privacyId, BytesValue.wrap(privateStateHash.extractArray())); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void commit() { | ||
transaction.commit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2019 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.privacy; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Log; | ||
import tech.pegasys.pantheon.ethereum.core.LogSeries; | ||
import tech.pegasys.pantheon.util.bytes.Bytes32; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface PrivateTransactionStorage { | ||
|
||
Optional<List<Log>> getEvents(Bytes32 transactionHash); | ||
|
||
Optional<BytesValue> getOutput(Bytes32 transactionHash); | ||
|
||
boolean isPrivateStateAvailable(Bytes32 transactionHash); | ||
|
||
Updater updater(); | ||
|
||
interface Updater { | ||
|
||
Updater putTransactionLogs(Bytes32 transactionHash, LogSeries logs); | ||
|
||
Updater putTransactionResult(Bytes32 transactionHash, BytesValue events); | ||
|
||
void commit(); | ||
|
||
void rollback(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.