Skip to content

Commit

Permalink
[PRIV-54] Use default enclave public key to generate eea_getTransacti…
Browse files Browse the repository at this point in the history
…onReceipt (PegaSysEng#1280)

* Use default enclave public key to generate eea_getTransactionReceipt

* Update the docs to reflect the changes
  • Loading branch information
Puneetha17 authored and notlesh committed Apr 24, 2019
1 parent af8345e commit 41fce79
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public Eea(final EeaTransactions transactions) {
this.transactions = transactions;
}

public Condition expectSuccessfulTransactionReceipt(
final String transactionHash, final String publicKey) {
public Condition expectSuccessfulTransactionReceipt(final String transactionHash) {
return new ExpectSuccessfulEeaGetTransactionReceipt(
transactions.getTransactionReceipt(transactionHash, publicKey));
transactions.getTransactionReceipt(transactionHash));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public ExpectNoPrivateContractDeployedReceipt(final Eea eea, final Transactions
super(eea, transactions);
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);

assertNull(privateTxReceipt.getContractAddress());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public ExpectNoValidPrivateContractValuesReturned(
super(eea, transactions);
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);

assertEquals("0x", privateTxReceipt.getOutput());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public ExpectValidPrivateContractDeployedReceipt(
this.contractAddress = contractAddress;
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);

assertEquals(contractAddress, privateTxReceipt.getContractAddress());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public ExpectValidPrivateContractEventsEmitted(
this.eventValue = eventValue;
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);

String event = privateTxReceipt.getLogs().get(0).getData().substring(66, 130);
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ public ExpectValidPrivateContractValuesReturned(
this.returnValue = returnValue;
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);

BytesValue output = BytesValue.fromHexString(privateTxReceipt.getOutput());
assertEquals(new BigInteger(returnValue), Numeric.decodeQuantity(output.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public ExpectValidPrivateTransactionReceipt(final Eea eea, final Transactions tr
super(eea, transactions);
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
public void verify(final PantheonNode node, final String transactionHash) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);
getPrivateTransactionReceipt(node, transactionHash);
assertNotNull(privateTxReceipt);
assertThat(privateTxReceipt.getFrom()).isNotBlank();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public abstract class GetValidPrivateTransactionReceipt {
}

ResponseTypes.PrivateTransactionReceipt getPrivateTransactionReceipt(
final PantheonNode node, final String transactionHash, final String publicKey) {
final PantheonNode node, final String transactionHash) {

waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash, publicKey)));
waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash)));
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
node.execute(transactions.getPrivateTransactionReceipt(transactionHash, publicKey));
node.execute(transactions.getPrivateTransactionReceipt(transactionHash));
return privateTxReceipt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public EeaJsonRpcRequestFactory(final Web3jService web3jService) {
}

public Request<?, PrivateTransactionReceiptResponse> eeaGetTransactionReceipt(
final String txHash, final String publicKey) {
final String txHash) {
return new Request<>(
"eea_getTransactionReceipt",
Lists.newArrayList(txHash, publicKey),
Lists.newArrayList(txHash),
web3jService,
PrivateTransactionReceiptResponse.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public EthGetTransactionReceiptTransaction getTransactionReceipt(final String tr
}

public EeaGetTransactionReceiptTransaction getPrivateTransactionReceipt(
final String transactionHash, final String publicKey) {
return new EeaGetTransactionReceiptTransaction(transactionHash, publicKey);
final String transactionHash) {
return new EeaGetTransactionReceiptTransaction(transactionHash);
}

public PermAddNodeTransaction addNodesToWhitelist(final List<URI> enodeList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@
public class EeaGetTransactionReceiptTransaction implements Transaction<PrivateTransactionReceipt> {

private final String txHash;
private final String publicKey;

public EeaGetTransactionReceiptTransaction(final String txHash, final String publicKey) {
public EeaGetTransactionReceiptTransaction(final String txHash) {
this.txHash = txHash;
this.publicKey = publicKey;
}

@Override
public PrivateTransactionReceipt execute(final JsonRequestFactories node) {
try {
final PrivateTransactionReceiptResponse result =
node.eea().eeaGetTransactionReceipt(txHash, publicKey).send();
node.eea().eeaGetTransactionReceipt(txHash).send();
assertThat(result).isNotNull();
assertThat(result.hasError()).isFalse();
return result.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

public class EeaTransactions {

public EeaGetTransactionReceiptTransaction getTransactionReceipt(
final String transactionHash, final String pubKey) {
return new EeaGetTransactionReceiptTransaction(transactionHash, pubKey);
public EeaGetTransactionReceiptTransaction getTransactionReceipt(final String transactionHash) {
return new EeaGetTransactionReceiptTransaction(transactionHash);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void deployingMustGiveValidReceipt() {

privateTransactionVerifier
.validPrivateContractDeployed(CONTRACT_ADDRESS.toString())
.verify(minerNode, transactionHash, PUBLIC_KEY);
.verify(minerNode, transactionHash);
}

@Test
Expand All @@ -101,9 +101,7 @@ public void privateSmartContractMustEmitEvents() {
final String transactionHash =
minerNode.execute(transactions.createPrivateRawTransaction(storeValue));

privateTransactionVerifier
.validEventReturned("1000")
.verify(minerNode, transactionHash, PUBLIC_KEY);
privateTransactionVerifier.validEventReturned("1000").verify(minerNode, transactionHash);
}

@Test
Expand All @@ -116,9 +114,7 @@ public void privateSmartContractMustReturnValues() {
final String transactionHash =
minerNode.execute(transactions.createPrivateRawTransaction(getValue));

privateTransactionVerifier
.validOutputReturned("1000")
.verify(minerNode, transactionHash, PUBLIC_KEY);
privateTransactionVerifier.validOutputReturned("1000").verify(minerNode, transactionHash);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void node2CanSeeContract() {

privateTransactionVerifier
.validPrivateContractDeployed(CONTRACT_ADDRESS.toString())
.verify(node2, transactionHash, PUBLIC_KEY_2);
.verify(node2, transactionHash);
}

@Test
Expand All @@ -156,13 +156,11 @@ public void node2CanExecuteContract() {

privateTransactionVerifier
.validPrivateContractDeployed(CONTRACT_ADDRESS.toString())
.verify(node2, transactionHash, PUBLIC_KEY_2);
.verify(node2, transactionHash);

transactionHash = node2.execute(transactions.createPrivateRawTransaction(storeValueFromNode2));

privateTransactionVerifier
.validEventReturned("1000")
.verify(node1, transactionHash, PUBLIC_KEY_1);
privateTransactionVerifier.validEventReturned("1000").verify(node1, transactionHash);
}

@Test
Expand All @@ -172,33 +170,25 @@ public void node2CanSeePrivateTransactionReceipt() {

privateTransactionVerifier
.validPrivateContractDeployed(CONTRACT_ADDRESS.toString())
.verify(node2, transactionHash, PUBLIC_KEY_2);
.verify(node2, transactionHash);

transactionHash = node2.execute(transactions.createPrivateRawTransaction(storeValueFromNode2));

privateTransactionVerifier
.validEventReturned("1000")
.verify(node1, transactionHash, PUBLIC_KEY_1);
privateTransactionVerifier.validEventReturned("1000").verify(node1, transactionHash);

transactionHash = node2.execute(transactions.createPrivateRawTransaction(getValueFromNode2));

privateTransactionVerifier
.validOutputReturned("1000")
.verify(node2, transactionHash, PUBLIC_KEY_2);
privateTransactionVerifier.validOutputReturned("1000").verify(node2, transactionHash);

privateTransactionVerifier
.validOutputReturned("1000")
.verify(node1, transactionHash, PUBLIC_KEY_1);
privateTransactionVerifier.validOutputReturned("1000").verify(node1, transactionHash);
}

@Test
public void node3CannotSeeContract() {
final String transactionHash =
node1.execute(transactions.deployPrivateSmartContract(deployContractFromNode1));

privateTransactionVerifier
.noPrivateContractDeployed()
.verify(node3, transactionHash, PUBLIC_KEY_3);
privateTransactionVerifier.noPrivateContractDeployed().verify(node3, transactionHash);
}

@Test
Expand All @@ -208,7 +198,7 @@ public void node3CannotExecuteContract() {
final String transactionHash =
node3.execute(transactions.createPrivateRawTransaction(getValueFromNode3));

privateTransactionVerifier.noValidOutputReturned().verify(node3, transactionHash, PUBLIC_KEY_3);
privateTransactionVerifier.noValidOutputReturned().verify(node3, transactionHash);
}

@Test(expected = RuntimeException.class)
Expand Down
6 changes: 2 additions & 4 deletions docs/Reference/JSON-RPC-API-Methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2648,19 +2648,17 @@ are not available.

`data` - 32-byte hash of a transaction.

`data` - Orion node public key

**Returns**

`Object` - [Private Transaction receipt object](JSON-RPC-API-Objects.md#private-transaction-receipt-object), or `null` if no receipt found.

!!! example
```bash tab="curl HTTP request"
curl -X POST --data '{"jsonrpc":"2.0","method":"eea_getTransactionReceipt","params":["0xf3ab9693ad92e277bf785e1772f29fb1864904bbbe87b0470455ddb082caab9d", "g59BmTeJIn7HIcnq8VQWgyh/pDbvbt2eyP0Ii60aDDw="],"id":1}' http://127.0.0.1:8545
curl -X POST --data '{"jsonrpc":"2.0","method":"eea_getTransactionReceipt","params":["0xf3ab9693ad92e277bf785e1772f29fb1864904bbbe87b0470455ddb082caab9d"],"id":1}' http://127.0.0.1:8545
```

```bash tab="wscat WS request"
{"jsonrpc":"2.0","method":"eea_getTransactionReceipt","params":["0xf3ab9693ad92e277bf785e1772f29fb1864904bbbe87b0470455ddb082caab9d", "g59BmTeJIn7HIcnq8VQWgyh/pDbvbt2eyP0Ii60aDDw="],"id":1}
{"jsonrpc":"2.0","method":"eea_getTransactionReceipt","params":["0xf3ab9693ad92e277bf785e1772f29fb1864904bbbe87b0470455ddb082caab9d"],"id":1}
```

```json tab="JSON result"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public String getName() {
public JsonRpcResponse response(final JsonRpcRequest request) {
LOG.trace("Executing eea_getTransactionReceipt");
final Hash transactionHash = parameters.required(request.getParams(), 0, Hash.class);
final String publicKey = parameters.required(request.getParams(), 1, String.class);
final Optional<TransactionLocation> maybeLocation =
blockchain.getBlockchain().getTransactionLocation(transactionHash);
if (!maybeLocation.isPresent()) {
Expand All @@ -91,6 +90,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
final Hash blockhash = location.getBlockHash();
final long blockNumber = blockchain.getBlockchain().getBlockHeader(blockhash).get().getNumber();

final String publicKey = privacyParameters.getEnclavePublicKey();
PrivateTransaction privateTransaction;
String privacyGroupId;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void createsPrivateTransactionReceipt() throws IOException {

final EeaGetTransactionReceipt eeaGetTransactionReceipt =
new EeaGetTransactionReceipt(blockchainQueries, enclave, parameters, privacyParameters);
final Object[] params = new Object[] {transaction.hash(), "EnclavePublicKey"};
final Object[] params = new Object[] {transaction.hash()};
final JsonRpcRequest request = new JsonRpcRequest("1", "eea_getTransactionReceipt", params);

when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
Expand Down

0 comments on commit 41fce79

Please sign in to comment.