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.
Added eea_getTransactionCount Json Rpc (#1861)
Exposers a Json Rpc which allows "legacy" users to query for the nonce of a given address, in a group of private users.
- Loading branch information
Showing
10 changed files
with
380 additions
and
28 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
67 changes: 67 additions & 0 deletions
67
...egasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/eea/EeaGetTransactionCount.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.jsonrpc.internal.methods.privacy.eea; | ||
|
||
import static org.apache.logging.log4j.LogManager.getLogger; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.Quantity; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
|
||
public class EeaGetTransactionCount implements JsonRpcMethod { | ||
|
||
private static final Logger LOG = getLogger(); | ||
|
||
private final JsonRpcParameter parameters; | ||
private final EeaPrivateNonceProvider nonceProvider; | ||
|
||
public EeaGetTransactionCount( | ||
final JsonRpcParameter parameters, final EeaPrivateNonceProvider nonceProvider) { | ||
this.parameters = parameters; | ||
this.nonceProvider = nonceProvider; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.EEA_GET_TRANSACTION_COUNT.getMethodName(); | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequest request) { | ||
if (request.getParamLength() != 3) { | ||
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
|
||
final Address address = parameters.required(request.getParams(), 0, Address.class); | ||
final String privateFrom = parameters.required(request.getParams(), 1, String.class); | ||
final String[] privateFor = parameters.required(request.getParams(), 2, String[].class); | ||
|
||
try { | ||
final long nonce = nonceProvider.determineNonce(privateFrom, privateFor, address); | ||
return new JsonRpcSuccessResponse(request.getId(), Quantity.create(nonce)); | ||
} catch (final Exception e) { | ||
LOG.error(e.getMessage(), e); | ||
return new JsonRpcErrorResponse( | ||
request.getId(), JsonRpcError.GET_PRIVATE_TRANSACTION_NONCE_ERROR); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...gasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/eea/EeaPrivateNonceProvider.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,62 @@ | ||
/* | ||
* 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.jsonrpc.internal.methods.privacy.eea; | ||
|
||
import tech.pegasys.pantheon.enclave.Enclave; | ||
import tech.pegasys.pantheon.enclave.types.FindPrivacyGroupRequest; | ||
import tech.pegasys.pantheon.enclave.types.PrivacyGroup; | ||
import tech.pegasys.pantheon.enclave.types.PrivacyGroup.Type; | ||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionHandler; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
public class EeaPrivateNonceProvider { | ||
|
||
private final Enclave enclave; | ||
private final PrivateTransactionHandler privateTransactionHandler; | ||
|
||
public EeaPrivateNonceProvider( | ||
final Enclave enclave, final PrivateTransactionHandler privateTransactionHandler) { | ||
this.enclave = enclave; | ||
this.privateTransactionHandler = privateTransactionHandler; | ||
} | ||
|
||
public long determineNonce( | ||
final String privateFrom, final String[] privateFor, final Address address) { | ||
|
||
final String[] groupMembers = Arrays.append(privateFor, privateFrom); | ||
|
||
final FindPrivacyGroupRequest request = new FindPrivacyGroupRequest(groupMembers); | ||
final List<PrivacyGroup> matchingGroups = Lists.newArrayList(enclave.findPrivacyGroup(request)); | ||
|
||
final List<PrivacyGroup> legacyGroups = | ||
matchingGroups.stream() | ||
.filter(group -> group.getType() == Type.LEGACY) | ||
.collect(Collectors.toList()); | ||
|
||
if (legacyGroups.size() != 1) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Found invalid number of privacy groups (%d), expected 1.", legacyGroups.size())); | ||
} | ||
|
||
final String privacyGroupId = legacyGroups.get(0).getPrivacyGroupId(); | ||
|
||
return privateTransactionHandler.getSenderNonce(address, privacyGroupId); | ||
} | ||
} |
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.