-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for private log subscriptions (Pub-Sub API) (#858)
* Created priv_subscribe and priv_unsubscribe methods Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
- Loading branch information
1 parent
f2244ee
commit 06ca344
Showing
29 changed files
with
1,159 additions
and
53 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
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
43 changes: 43 additions & 0 deletions
43
...ledger/besu/ethereum/api/jsonrpc/websocket/methods/AbstractPrivateSubscriptionMethod.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 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods; | ||
|
||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.EnclavePublicKeyProvider; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscriptionRequestMapper; | ||
import org.hyperledger.besu.ethereum.privacy.PrivacyController; | ||
|
||
abstract class AbstractPrivateSubscriptionMethod extends AbstractSubscriptionMethod { | ||
|
||
private final PrivacyController privacyController; | ||
private final EnclavePublicKeyProvider enclavePublicKeyProvider; | ||
|
||
AbstractPrivateSubscriptionMethod( | ||
final SubscriptionManager subscriptionManager, | ||
final SubscriptionRequestMapper mapper, | ||
final PrivacyController privacyController, | ||
final EnclavePublicKeyProvider enclavePublicKeyProvider) { | ||
super(subscriptionManager, mapper); | ||
this.privacyController = privacyController; | ||
this.enclavePublicKeyProvider = enclavePublicKeyProvider; | ||
} | ||
|
||
void checkIfPrivacyGroupMatchesAuthenticatedEnclaveKey( | ||
final JsonRpcRequestContext request, final String privacyGroupId) { | ||
final String enclavePublicKey = enclavePublicKeyProvider.getEnclaveKey(request.getUser()); | ||
privacyController.verifyPrivacyGroupContainsEnclavePublicKey(privacyGroupId, enclavePublicKey); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/methods/PrivSubscribe.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,64 @@ | ||
/* | ||
* Copyright 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods; | ||
|
||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.EnclavePublicKeyProvider; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscriptionRequestMapper; | ||
import org.hyperledger.besu.ethereum.privacy.PrivacyController; | ||
|
||
public class PrivSubscribe extends AbstractPrivateSubscriptionMethod { | ||
|
||
public PrivSubscribe( | ||
final SubscriptionManager subscriptionManager, | ||
final SubscriptionRequestMapper mapper, | ||
final PrivacyController privacyController, | ||
final EnclavePublicKeyProvider enclavePublicKeyProvider) { | ||
super(subscriptionManager, mapper, privacyController, enclavePublicKeyProvider); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.PRIV_SUBSCRIBE.getMethodName(); | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | ||
try { | ||
final PrivateSubscribeRequest subscribeRequest = | ||
getMapper().mapPrivateSubscribeRequest(requestContext); | ||
|
||
checkIfPrivacyGroupMatchesAuthenticatedEnclaveKey( | ||
requestContext, subscribeRequest.getPrivacyGroupId()); | ||
|
||
final Long subscriptionId = subscriptionManager().subscribe(subscribeRequest); | ||
|
||
return new JsonRpcSuccessResponse( | ||
requestContext.getRequest().getId(), Quantity.create(subscriptionId)); | ||
} catch (final InvalidSubscriptionRequestException isEx) { | ||
return new JsonRpcErrorResponse( | ||
requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST); | ||
} | ||
} | ||
} |
Oops, something went wrong.