use of org.web3j.protocol.besu.response.privacy.PrivateTransactionWithPrivacyGroup in project web3j by web3j.
the class ResponseTest method testPrivGetPrivateTransactionPrivacyGroup.
@Test
public void testPrivGetPrivateTransactionPrivacyGroup() {
buildResponse("{\n" + " \"id\":1,\n" + " \"jsonrpc\":\"2.0\",\n" + " \"result\": {\n" + " \"hash\":\"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b\",\n" + " \"nonce\":\"0x0\",\n" + " \"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\n" + " \"to\":\"0x85h43d8a49eeb85d32cf465507dd71d507100c1\",\n" + " \"value\":\"0x7f110\",\n" + " \"gas\": \"0x7f110\",\n" + " \"gasPrice\":\"0x9184e72a000\",\n" + " \"input\":\"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360\",\n" + " \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n" + " \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n" + " \"v\":\"0x0\",\n" + " \"privateFrom\":\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n" + " \"privateFor\":\"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n" + " \"restriction\":\"restricted\"" + " }\n" + "}");
PrivateTransactionWithPrivacyGroup privateTransaction = new PrivateTransactionWithPrivacyGroup("0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0", "0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x85h43d8a49eeb85d32cf465507dd71d507100c1", "0x7f110", "0x7f110", "0x9184e72a000", "0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360", "0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc", "0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62", "0x0", Base64String.wrap("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="), Base64String.wrap("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="), "restricted");
PrivGetPrivateTransaction privPrivateTransaction = deserialiseResponse(PrivGetPrivateTransaction.class);
assertEquals(privPrivateTransaction.getPrivateTransaction().get(), (privateTransaction));
}
use of org.web3j.protocol.besu.response.privacy.PrivateTransactionWithPrivacyGroup in project web3j by web3j.
the class BesuPrivacyQuickstartIntegrationTest method simplePrivateTransactions.
@Test
public void simplePrivateTransactions() throws Exception {
// Build new privacy group using the create API
final Base64String privacyGroupId = nodeBob.privCreatePrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB, ENCLAVE_KEY_CHARLIE), "AliceBobCharlie", "AliceBobCharlie group").send().getPrivacyGroupId();
final BigInteger nonce = nodeCharlie.privGetTransactionCount(ALICE.getAddress(), privacyGroupId).send().getTransactionCount();
final RawPrivateTransaction rawPrivateTransaction = RawPrivateTransaction.createContractTransaction(nonce, ZERO_GAS_PROVIDER.getGasPrice(), ZERO_GAS_PROVIDER.getGasLimit(), HUMAN_STANDARD_TOKEN_BINARY, ENCLAVE_KEY_ALICE, privacyGroupId, RESTRICTED);
final String signedTransactionData = Numeric.toHexString(PrivateTransactionEncoder.signMessage(rawPrivateTransaction, 2018, ALICE));
final String transactionHash = nodeAlice.eeaSendRawTransaction(signedTransactionData).send().getTransactionHash();
final PollingPrivateTransactionReceiptProcessor receiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, 1 * 1000, 120);
final PrivateTransactionReceipt receipt = receiptProcessor.waitForTransactionReceipt(transactionHash);
assertEquals(receipt.getFrom(), (ALICE.getAddress()));
assertEquals(receipt.getLogs().size(), (0));
assertNull(receipt.getTo());
assertNotNull(receipt.getContractAddress());
assertNotNull(receipt.getStatus());
assertNull(receipt.getRevertReason());
final PrivateTransactionWithPrivacyGroup privateTransaction = (PrivateTransactionWithPrivacyGroup) nodeAlice.privGetPrivateTransaction(transactionHash).send().getPrivateTransaction().get();
assertEquals(privateTransaction.getFrom(), (ALICE.getAddress()));
assertEquals(privateTransaction.getGas(), (ZERO_GAS_PROVIDER.getGasLimit()));
assertEquals(privateTransaction.getGasPrice(), (ZERO_GAS_PROVIDER.getGasPrice()));
assertEquals(privateTransaction.getNonce(), (nonce));
final byte[] encodedTransaction = PrivateTransactionEncoder.encode(rawPrivateTransaction, 2018);
final Sign.SignatureData signatureData = Sign.signMessage(encodedTransaction, ALICE.getEcKeyPair());
final Sign.SignatureData eip155SignatureData = TransactionEncoder.createEip155SignatureData(signatureData, 2018);
assertEquals(Numeric.toBytesPadded(BigInteger.valueOf(privateTransaction.getV()), 2), (eip155SignatureData.getV()));
assertEquals(Numeric.hexStringToByteArray(privateTransaction.getR()), (eip155SignatureData.getR()));
assertEquals(Numeric.hexStringToByteArray(privateTransaction.getS()), (eip155SignatureData.getS()));
assertEquals(privateTransaction.getPrivateFrom(), (ENCLAVE_KEY_ALICE));
assertEquals(privateTransaction.getPrivacyGroupId(), (privacyGroupId));
assertEquals(privateTransaction.getRestriction(), (RESTRICTED));
assertNull(privateTransaction.getTo());
}
Aggregations