use of org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory in project besu by hyperledger.
the class PrivacyApiGroupJsonRpcMethods method create.
@Override
protected Map<String, JsonRpcMethod> create() {
final PrivateMarkerTransactionFactory markerTransactionFactory = createPrivateMarkerTransactionFactory();
final PrivacyIdProvider enclavePublicProvider = PrivacyIdProvider.build(privacyParameters);
final PrivacyController privacyController = createPrivacyController();
return create(privacyController, enclavePublicProvider, markerTransactionFactory).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> createPrivacyMethod(privacyParameters, entry.getValue())));
}
use of org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory in project besu by hyperledger.
the class PrivJsonRpcMethods method create.
@Override
protected Map<String, JsonRpcMethod> create(final PrivacyController privacyController, final PrivacyIdProvider privacyIdProvider, final PrivateMarkerTransactionFactory privateMarkerTransactionFactory) {
final Map<String, JsonRpcMethod> RPC_METHODS = mapOf(new PrivCall(getBlockchainQueries(), privacyController, privacyIdProvider), new PrivDebugGetStateRoot(getBlockchainQueries(), privacyIdProvider, privacyController), new PrivDistributeRawTransaction(privacyController, privacyIdProvider, getPrivacyParameters().isFlexiblePrivacyGroupsEnabled()), new PrivGetCode(getBlockchainQueries(), privacyController, privacyIdProvider), new PrivGetLogs(getBlockchainQueries(), getPrivacyQueries(), privacyController, privacyIdProvider), new PrivGetPrivateTransaction(privacyController, privacyIdProvider), new PrivGetPrivacyPrecompileAddress(getPrivacyParameters()), new PrivGetTransactionCount(privacyController, privacyIdProvider), new PrivGetTransactionReceipt(getPrivacyParameters().getPrivateStateStorage(), privacyController, privacyIdProvider), new PrivGetFilterLogs(filterManager, privacyController, privacyIdProvider), new PrivGetFilterChanges(filterManager, privacyController, privacyIdProvider), new PrivNewFilter(filterManager, privacyController, privacyIdProvider), new PrivUninstallFilter(filterManager, privacyController, privacyIdProvider));
if (!getPrivacyParameters().isFlexiblePrivacyGroupsEnabled()) {
final Map<String, JsonRpcMethod> OFFCHAIN_METHODS = mapOf(new PrivCreatePrivacyGroup(privacyController, privacyIdProvider), new PrivDeletePrivacyGroup(privacyController, privacyIdProvider), new PrivFindPrivacyGroup(privacyController, privacyIdProvider));
OFFCHAIN_METHODS.forEach((key, jsonRpcMethod) -> RPC_METHODS.merge(key, jsonRpcMethod, (oldVal, newVal) -> newVal));
}
return RPC_METHODS;
}
use of org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory in project besu by hyperledger.
the class PrivacyPluginPrecompiledContractTest method setup.
@Before
public void setup() {
final PrivateStateStorage privateStateStorage = mock(PrivateStateStorage.class);
messageFrame = mock(MessageFrame.class);
final BlockDataGenerator blockGenerator = new BlockDataGenerator();
final Block genesis = blockGenerator.genesisBlock();
final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(mock(PrivateMetadataUpdater.class));
when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(PrivacyGroupHeadBlockMap.empty());
contract = new PrivacyPluginPrecompiledContract(new SpuriousDragonGasCalculator(), new PrivacyParameters.Builder().setEnabled(true).setPrivacyPluginEnabled(true).setStorageProvider(new InMemoryPrivacyStorageProvider()).setPrivacyService(new PrivacyPluginService() {
@Override
public void setPayloadProvider(final PrivacyPluginPayloadProvider provider) {
}
@Override
public PrivacyPluginPayloadProvider getPayloadProvider() {
return new PrivacyPluginPayloadProvider() {
@Override
public Bytes generateMarkerPayload(final org.hyperledger.besu.plugin.data.PrivateTransaction privateTransaction, final String privacyUserId) {
return serialize(privateTransaction).encoded();
}
@Override
public Optional<org.hyperledger.besu.plugin.data.PrivateTransaction> getPrivateTransactionFromPayload(final org.hyperledger.besu.plugin.data.Transaction transaction) {
final BytesValueRLPInput bytesValueRLPInput = new BytesValueRLPInput(transaction.getPayload(), false);
return Optional.of(readFrom(bytesValueRLPInput));
}
};
}
@Override
public void setPrivacyGroupAuthProvider(final PrivacyGroupAuthProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupAuthProvider getPrivacyGroupAuthProvider() {
return (privacyGroupId, privacyUserId, blockNumber) -> true;
}
@Override
public void setPrivacyGroupGenesisProvider(final PrivacyGroupGenesisProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupGenesisProvider getPrivacyGroupGenesisProvider() {
return (privacyGroupId, blockNumber) -> (PrivacyGenesis) Collections::emptyList;
}
@Override
public PrivateMarkerTransactionFactory getPrivateMarkerTransactionFactory() {
return null;
}
@Override
public void setPrivateMarkerTransactionFactory(final PrivateMarkerTransactionFactory privateMarkerTransactionFactory) {
}
}).setEnclaveFactory(mock(EnclaveFactory.class)).build());
}
Aggregations