Search in sources :

Example 1 with PrivateMarkerTransactionFactory

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())));
}
Also used : PrivacyController(org.hyperledger.besu.ethereum.privacy.PrivacyController) RestrictedDefaultPrivacyController(org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController) PluginPrivacyController(org.hyperledger.besu.ethereum.privacy.PluginPrivacyController) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) FlexiblePrivacyController(org.hyperledger.besu.ethereum.privacy.FlexiblePrivacyController) PrivacyController(org.hyperledger.besu.ethereum.privacy.PrivacyController) RestrictedDefaultPrivacyController(org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController) PluginPrivacyController(org.hyperledger.besu.ethereum.privacy.PluginPrivacyController) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) PrivacyQueries(org.hyperledger.besu.ethereum.api.query.PrivacyQueries) DisabledPrivacyRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.DisabledPrivacyRpcMethod) PrivacyIdProvider(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider) ChainHeadPrivateNonceProvider(org.hyperledger.besu.ethereum.privacy.ChainHeadPrivateNonceProvider) Map(java.util.Map) BigInteger(java.math.BigInteger) MultiTenancyRpcMethodDecorator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.MultiTenancyRpcMethodDecorator) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) PrivateTransactionSimulator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionSimulator) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) RandomSigningPrivateMarkerTransactionFactory(org.hyperledger.besu.ethereum.privacy.markertransaction.RandomSigningPrivateMarkerTransactionFactory) Collectors(java.util.stream.Collectors) PrivateNonceProvider(org.hyperledger.besu.ethereum.privacy.PrivateNonceProvider) GasCalculator(org.hyperledger.besu.evm.gascalculator.GasCalculator) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) FlexiblePrivacyController(org.hyperledger.besu.ethereum.privacy.FlexiblePrivacyController) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) Optional(java.util.Optional) FixedKeySigningPrivateMarkerTransactionFactory(org.hyperledger.besu.ethereum.privacy.markertransaction.FixedKeySigningPrivateMarkerTransactionFactory) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) RandomSigningPrivateMarkerTransactionFactory(org.hyperledger.besu.ethereum.privacy.markertransaction.RandomSigningPrivateMarkerTransactionFactory) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) FixedKeySigningPrivateMarkerTransactionFactory(org.hyperledger.besu.ethereum.privacy.markertransaction.FixedKeySigningPrivateMarkerTransactionFactory) PrivacyIdProvider(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider) Map(java.util.Map)

Example 2 with PrivateMarkerTransactionFactory

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;
}
Also used : PrivDebugGetStateRoot(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDebugGetStateRoot) PrivGetFilterLogs(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterLogs) PrivDeletePrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup) PrivacyController(org.hyperledger.besu.ethereum.privacy.PrivacyController) RpcApis(org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis) PrivUninstallFilter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivUninstallFilter) PrivGetTransactionReceipt(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionReceipt) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) PrivCreatePrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) PrivCall(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCall) PrivGetFilterChanges(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterChanges) PrivacyIdProvider(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider) PrivNewFilter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivNewFilter) Map(java.util.Map) PrivGetPrivateTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction) PrivDistributeRawTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDistributeRawTransaction) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) PrivGetLogs(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetLogs) PrivDebugGetStateRoot(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDebugGetStateRoot) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) PrivGetTransactionCount(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) PrivFindPrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup) PrivGetPrivacyPrecompileAddress(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivGetFilterLogs(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterLogs) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) PrivGetCode(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetCode) PrivGetTransactionCount(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount) PrivGetCode(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetCode) PrivDeletePrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup) PrivNewFilter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivNewFilter) PrivGetFilterChanges(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterChanges) PrivGetTransactionReceipt(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionReceipt) PrivGetLogs(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetLogs) PrivFindPrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivGetPrivacyPrecompileAddress(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress) PrivGetPrivateTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction) PrivDistributeRawTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDistributeRawTransaction) PrivCreatePrivacyGroup(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup) PrivCall(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCall) PrivUninstallFilter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivUninstallFilter)

Example 3 with PrivateMarkerTransactionFactory

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());
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Bytes(org.apache.tuweni.bytes.Bytes) PrivacyPluginPayloadProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyPluginPayloadProvider) Optional(java.util.Optional) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivacyPluginService(org.hyperledger.besu.plugin.services.PrivacyPluginService) Block(org.hyperledger.besu.ethereum.core.Block) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) PrivacyGroupGenesisProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) PrivacyGroupAuthProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupAuthProvider) Before(org.junit.Before)

Aggregations

PrivateMarkerTransactionFactory (org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory)3 Map (java.util.Map)2 Optional (java.util.Optional)2 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)2 PrivacyIdProvider (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 PrivacyParameters (org.hyperledger.besu.ethereum.core.PrivacyParameters)2 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)2 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)2 PrivacyController (org.hyperledger.besu.ethereum.privacy.PrivacyController)2 BigInteger (java.math.BigInteger)1 Collectors (java.util.stream.Collectors)1 Bytes (org.apache.tuweni.bytes.Bytes)1 RpcApis (org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis)1 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)1 FilterManager (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager)1 DisabledPrivacyRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.DisabledPrivacyRpcMethod)1 MultiTenancyRpcMethodDecorator (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.MultiTenancyRpcMethodDecorator)1 PrivGetFilterChanges (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterChanges)1 PrivGetFilterLogs (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivGetFilterLogs)1