use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction in project besu by hyperledger.
the class PrivGetPrivateTransactionIntegrationTest method returnsStoredPrivateTransaction.
@Test
public void returnsStoredPrivateTransaction() {
final PrivGetPrivateTransaction privGetPrivateTransaction = new PrivGetPrivateTransaction(privacyController, privacyIdProvider);
final Hash blockHash = Hash.ZERO;
final Transaction pmt = spy(privateMarkerTransaction());
when(blockchain.getTransactionByHash(eq(pmt.getHash()))).thenReturn(Optional.of(pmt));
when(blockchain.getTransactionLocation(eq(pmt.getHash()))).thenReturn(Optional.of(new TransactionLocation(blockHash, 0)));
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getHash()).thenReturn(blockHash);
when(blockchain.getBlockHeader(eq(blockHash))).thenReturn(Optional.of(blockHeader));
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput();
privateTransaction.writeTo(bvrlp);
final String payload = Base64.getEncoder().encodeToString(bvrlp.encoded().toArrayUnsafe());
final ArrayList<String> to = Lists.newArrayList("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
final SendResponse sendResponse = enclave.send(payload, ENCLAVE_PUBLIC_KEY, to);
final Bytes hexKey = Bytes.fromBase64String(sendResponse.getKey());
when(pmt.getPayload()).thenReturn(hexKey);
final Object[] params = new Object[] { pmt.getHash() };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_getPrivateTransaction", params));
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetPrivateTransaction.response(request);
final PrivateTransactionLegacyResult result = (PrivateTransactionLegacyResult) response.getResult();
assertThat(new PrivateTransactionLegacyResult(this.privateTransaction)).usingRecursiveComparison().isEqualTo(result);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction 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;
}
Aggregations