-
Notifications
You must be signed in to change notification settings - Fork 130
Added eea_getTransactionCount Json Rpc #1861
Added eea_getTransactionCount Json Rpc #1861
Conversation
Exposers a Json Rpc which allows "legacy" users to query for the nonce of a given address, in a group of private users.
|
||
public static class EeaGetTransactionCountJsonBody { | ||
|
||
final String privateFrom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't these be final
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private? yes.
|
||
public class EeaGetTransactionCount implements JsonRpcMethod { | ||
|
||
public static class EeaGetTransactionCountJsonBody { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern used in the JsonRpc package has the Json POJO split out into their classes and suffixed with Parameters
e.g. tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters
, something worth considering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
import org.junit.Test; | ||
|
||
public class EeaGetTransactionCountTest { | ||
final Address address = Address.fromHexString("55"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
modifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
new EeaGetTransactionCount(new JsonRpcParameter(), enclave, privateTransactionHandler); | ||
|
||
final JsonRpcResponse response = method.response(request); | ||
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you expecting a specific error message here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
new EeaGetTransactionCount(new JsonRpcParameter(), enclave, privateTransactionHandler); | ||
|
||
final JsonRpcResponse response = method.response(request); | ||
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, is any JsonRpcErrorResponse acceptable? or do you expecting a specific message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
import org.apache.logging.log4j.Logger; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
public class EeaGetTransactionCount implements JsonRpcMethod { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this class should be name PrivGetLegacyTransactionCount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to Madeline last night - given this capability is really required of Legacy Privacy - it belongs in the Eea namespace, and thus, the spec will need updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More to the point - priv_ namespace is geared toward the new Privacy Group - so having "priv" and "legacy" in a name is not a valid combination.
private long determineNonce(final EeaGetTransactionCountJsonBody getTransactionCount) | ||
throws Exception { | ||
|
||
final String[] groupMembers = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there should be a method on the PrivateTransactionHandler to get the legacy privacy group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't decide if this is something a PrivateTransactionHandler should know about ...
import org.apache.logging.log4j.Logger; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
public class LegacyNonceProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have the Legacy
prefix, rather than Eea
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because "Legacy" is the default terminology for things which work with EEA privacy ... (i.e. internally the Privacy is deemed LEGACY or PANTHEON.
this.privateTransactionHandler = privateTransactionHandler; | ||
} | ||
|
||
public long determineNonce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more narrow exception to throw instead of Exception
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alas - this is an effect of Encalve throwing Exception ... this behaviour is mimic'd from other Priv Json RPC ...
final long nonce = nonceProvider.determineNonce(privateFrom, privateFor, address); | ||
return new JsonRpcSuccessResponse(request.getId(), Quantity.create(nonce)); | ||
} catch (final Exception e) { | ||
LOG.error("Failed to fetch group from Enclave with error " + e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think there is any need for two log statements here. Could just do LOG.error("Failed to fetch group from Enclave", e) and let log4j log the exception nicely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
body = RequestBody.create(mediaType, objectMapper.writeValueAsString(content)); | ||
} catch (final JsonProcessingException e) { | ||
final String errorMessage = "Failed to serialise request to json body."; | ||
LOG.error(errorMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need log and throw the exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -107,7 +107,7 @@ private PrivateTransactionProcessor mockPrivateTxProcessor() { | |||
|
|||
private Enclave brokenMockEnclave() throws Exception { | |||
Enclave mockEnclave = mock(Enclave.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throws Exception shouldn't be needed now it's throwing the runtime EnclaveException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
|
||
public long determineNonce( | ||
final String privateFrom, final String[] privateFor, final Address address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Think it would have been nice if the Enclave provided a findEeaPrivacyGroup(privateFor, privateFrom) method. Probably not part of this PR though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup - this should probably be Orion.
return new JsonRpcSuccessResponse(request.getId(), Quantity.create(nonce)); | ||
} catch (final Exception e) { | ||
LOG.error(e.getMessage(), e); | ||
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.FIND_PRIVACY_GROUP_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like the wrong error type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
final String errorMessage = | ||
String.format( | ||
"Found invalid number of privacy groups (%d), expected 1.", legacyGroups.size()); | ||
LOG.error(errorMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to log and throw, perhaps just throw with the error message. Will be logged in rpc layer
Exposers a Json Rpc which allows "legacy" users to query for the nonce of a given address, in a group of private users.
Exposers a Json Rpc which allows "legacy" users to query for the
nonce of a given address, in a group of private users.