org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt Java Examples
The following examples show how to use
org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PollingPrivateTransactionReceiptProcessor.java From web3j with Apache License 2.0 | 6 votes |
private PrivateTransactionReceipt getTransactionReceipt( String transactionHash, long sleepDuration, int attempts) throws IOException, TransactionException { Optional<PrivateTransactionReceipt> receiptOptional = sendTransactionReceiptRequest(transactionHash); for (int i = 0; i < attempts; i++) { if (!receiptOptional.isPresent()) { try { Thread.sleep(sleepDuration); } catch (InterruptedException e) { throw new TransactionException(e); } receiptOptional = sendTransactionReceiptRequest(transactionHash); } else { return receiptOptional.get(); } } throw new TransactionException( "Transaction receipt was not generated after " + ((sleepDuration * attempts) / 1000 + " seconds for transaction: " + transactionHash), transactionHash); }
Example #2
Source File: OnChainPrivacyAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
private PrivateTransactionReceipt setEventEmitterValue( final List<PrivacyNode> nodes, final String privacyGroupId, final EventEmitter eventEmitter, final int value) { final PrivacyNode firstNode = nodes.get(0); final String txHash = firstNode.execute( privateContractTransactions.callOnChainPermissioningSmartContract( eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.valueOf(value)).encodeFunctionCall(), firstNode.getTransactionSigningKey(), POW_CHAIN_ID, firstNode.getEnclaveKey(), privacyGroupId)); PrivateTransactionReceipt receipt = null; for (final PrivacyNode node : nodes) { receipt = node.execute(privacyTransactions.getPrivateTransactionReceipt(txHash)); assertThat(receipt.getStatus()).isEqualTo("0x1"); } return receipt; }
Example #3
Source File: EthSignerAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test @Ignore public void privateSmartContractMustDeployNoNonce() throws IOException { final String transactionHash = ethSignerClient.eeaSendTransaction( null, BigInteger.valueOf(23176), BigInteger.valueOf(1000), EventEmitter.BINARY, minerNode.getEnclaveKey(), Collections.emptyList(), "restricted"); final PrivateTransactionReceipt receipt = minerNode.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); minerNode.verify( privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, receipt)); }
Example #4
Source File: EthSignerAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test public void privateSmartContractMustDeploy() throws IOException { final String transactionHash = ethSignerClient.eeaSendTransaction( null, BigInteger.valueOf(23176), BigInteger.valueOf(1000), EventEmitter.BINARY, BigInteger.valueOf(0), minerNode.getEnclaveKey(), Collections.emptyList(), "restricted"); final PrivateTransactionReceipt receipt = minerNode.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); minerNode.verify( privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, receipt)); }
Example #5
Source File: PrivGetLogsAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test public void getLogsUsingBlockHashFilter() { final String privacyGroupId = createPrivacyGroup(); final EventEmitter eventEmitterContract = deployEventEmitterContract(privacyGroupId); /* Updating the contract value 1 times */ final PrivateTransactionReceipt updateValueReceipt = updateContractValue(privacyGroupId, eventEmitterContract, 1); final String blockHash = updateValueReceipt.getBlockHash(); final LogFilterJsonParameter filter = blockHashLogFilter(blockHash, eventEmitterContract.getContractAddress()); final List<LogResult> logs = node.execute(privacyTransactions.privGetLogs(privacyGroupId, filter)); assertThat(logs).hasSize(1); }
Example #6
Source File: PrivateContractPublicStateAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() throws Exception { final CrossContractReader privateReader = transactionNode.execute( privateContractTransactions.createSmartContract( CrossContractReader.class, transactionNode.getTransactionSigningKey(), POW_CHAIN_ID, transactionNode.getEnclaveKey())); final CrossContractReader publicReader = transactionNode.execute( contractTransactions.createSmartContract(CrossContractReader.class)); final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.incrementRemote(publicReader.getContractAddress()).send(); assertThat(transactionReceipt.getOutput()).isEqualTo("0x"); }
Example #7
Source File: PrivateContractPublicStateAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() throws Exception { final CrossContractReader privateReader = transactionNode.execute( privateContractTransactions.createSmartContract( CrossContractReader.class, transactionNode.getTransactionSigningKey(), POW_CHAIN_ID, transactionNode.getEnclaveKey())); final CrossContractReader publicReader = transactionNode.execute( contractTransactions.createSmartContract(CrossContractReader.class)); final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.deployRemote(publicReader.getContractAddress()).send(); assertThat(transactionReceipt.getLogs().size()).isEqualTo(0); }
Example #8
Source File: PrivateContractPublicStateAcceptanceTest.java From besu with Apache License 2.0 | 6 votes |
@Test public void privateContractMustNotBeAbleToCallSelfDestructOnPublicContract() throws Exception { final CrossContractReader privateReader = transactionNode.execute( privateContractTransactions.createSmartContract( CrossContractReader.class, transactionNode.getTransactionSigningKey(), POW_CHAIN_ID, transactionNode.getEnclaveKey())); final CrossContractReader publicReader = transactionNode .getBesu() .execute(contractTransactions.createSmartContract(CrossContractReader.class)); final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.remoteDestroy(publicReader.getContractAddress()).send(); assertThat(transactionReceipt.getOutput()).isEqualTo("0x"); }
Example #9
Source File: PrivateTransactionManager.java From web3j with Apache License 2.0 | 6 votes |
@Override public String sendCall( final String to, final String data, final DefaultBlockParameter defaultBlockParameter) throws IOException { try { EthSendTransaction est = sendTransaction( gasProvider.getGasPrice(), gasProvider.getGasLimit(), to, data, BigInteger.ZERO); final TransactionReceipt ptr = processResponse(est); if (!ptr.isStatusOK()) { throw new ContractCallException( String.format(REVERT_ERR_STR, extractRevertReason(ptr, data, besu, false))); } return ((PrivateTransactionReceipt) ptr).getOutput(); } catch (TransactionException e) { log.error("Failed to execute call", e); return null; } }
Example #10
Source File: Ibft2PrivacyClusterAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void onlyAliceAndBobCanExecuteContract() { // Contract address is generated from sender address and transaction nonce final String contractAddress = "0xebf56429e6500e84442467292183d4d621359838"; final EventEmitter eventEmitter = alice.execute( privateContractTransactions.createSmartContract( EventEmitter.class, alice.getTransactionSigningKey(), IBFT2_CHAIN_ID, alice.getEnclaveKey(), bob.getEnclaveKey())); privateContractVerifier .validPrivateContractDeployed(contractAddress, alice.getAddress().toString()) .verify(eventEmitter); final String transactionHash = alice.execute( privateContractTransactions.callSmartContract( eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.ONE).encodeFunctionCall(), alice.getTransactionSigningKey(), IBFT2_CHAIN_ID, alice.getEnclaveKey(), bob.getEnclaveKey())); final PrivateTransactionReceipt expectedReceipt = alice.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); bob.verify( privateTransactionVerifier.validPrivateTransactionReceipt( transactionHash, expectedReceipt)); charlie.verify(privateTransactionVerifier.noPrivateTransactionReceipt(transactionHash)); }
Example #11
Source File: PrivateLogFilterAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
private PrivateTransactionReceipt updateContractValue( final String privacyGroupId, final EventEmitter eventEmitterContract, final int value) { final String transactionHash = node.execute( privateContractTransactions.callSmartContractWithPrivacyGroupId( eventEmitterContract.getContractAddress(), eventEmitterContract.store(BigInteger.valueOf(value)).encodeFunctionCall(), node.getTransactionSigningKey(), POW_CHAIN_ID, node.getEnclaveKey(), privacyGroupId)); return node.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); }
Example #12
Source File: PrivateTransactionReceiptProcessor.java From web3j with Apache License 2.0 | 5 votes |
@Override Optional<PrivateTransactionReceipt> sendTransactionReceiptRequest(String transactionHash) throws IOException, TransactionException { PrivGetTransactionReceipt transactionReceipt = besu.privGetTransactionReceipt(transactionHash).send(); if (transactionReceipt.hasError()) { throw new TransactionException( "Error processing request: " + transactionReceipt.getError().getMessage()); } return transactionReceipt.getTransactionReceipt(); }
Example #13
Source File: EnclaveErrorAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void whenEnclaveIsDisconnectedGetReceiptReturnsInternalError() { final EventEmitter eventEmitter = alice.execute( privateContractTransactions.createSmartContract( EventEmitter.class, alice.getTransactionSigningKey(), IBFT2_CHAIN_ID, alice.getEnclaveKey(), bob.getEnclaveKey())); privateContractVerifier .validPrivateContractDeployed( eventEmitter.getContractAddress(), alice.getAddress().toString()) .verify(eventEmitter); final String transactionHash = alice.execute( privateContractTransactions.callSmartContract( eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.ONE).encodeFunctionCall(), alice.getTransactionSigningKey(), IBFT2_CHAIN_ID, alice.getEnclaveKey(), bob.getEnclaveKey())); final PrivateTransactionReceipt receiptBeforeEnclaveLosesConnection = alice.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); alice.verify( privateTransactionVerifier.validPrivateTransactionReceipt( transactionHash, receiptBeforeEnclaveLosesConnection)); alice.getOrion().stop(); alice.verify( privateTransactionVerifier.internalErrorPrivateTransactionReceipt(transactionHash)); }
Example #14
Source File: OnChainPrivacyAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
private String getContractDeploymentCommitmentHash(final Contract contract) { final Optional<TransactionReceipt> transactionReceipt = contract.getTransactionReceipt(); assertThat(transactionReceipt).isPresent(); final PrivateTransactionReceipt privateTransactionReceipt = (PrivateTransactionReceipt) transactionReceipt.get(); return privateTransactionReceipt.getcommitmentHash(); }
Example #15
Source File: OnChainPrivacyAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
private PrivateTransactionReceipt buildExpectedAddMemberTransactionReceipt( final String privacyGroupId, final PrivacyNode groupCreator, final PrivacyNode[] members) { final StringBuilder output = new StringBuilder(); // hex prefix output.append("0x"); // Dynamic array offset output.append("0000000000000000000000000000000000000000000000000000000000000020"); // Length of the array (with padded zeros to the left) output.append(Quantity.longToPaddedHex(members.length, 32).substring(2)); // Each member enclave key converted from Base64 to bytes for (final PrivacyNode member : members) { output.append(Bytes.fromBase64String(member.getEnclaveKey()).toUnprefixedHexString()); } return new PrivateTransactionReceipt( null, groupCreator.getAddress().toHexString(), Address.ONCHAIN_PRIVACY_PROXY.toHexString(), output.toString(), Collections.emptyList(), null, null, groupCreator.getEnclaveKey(), null, privacyGroupId, "0x1", null); }
Example #16
Source File: PrivGetTransactionReceiptTransaction.java From besu with Apache License 2.0 | 5 votes |
@Override public PrivateTransactionReceipt execute(final NodeRequests node) { try { final PrivacyRequestFactory.GetTransactionReceiptResponse result = node.privacy().privGetTransactionReceipt(transaction).send(); assertThat(result).isNotNull(); return result.getResult(); } catch (final IOException e) { throw new RuntimeException(e); } }
Example #17
Source File: OnChainPrivacyAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
PrivateTransactionReceipt setEventEmitterValueAndCheck( final List<PrivacyNode> nodes, final String privacyGroupId, final EventEmitter eventEmitter, final int valueSetWhileBobWasMember) { final PrivateTransactionReceipt receiptWhileBobMember = setEventEmitterValue(nodes, privacyGroupId, eventEmitter, valueSetWhileBobWasMember); checkEmitterValue(nodes, privacyGroupId, eventEmitter, valueSetWhileBobWasMember); return receiptWhileBobMember; }
Example #18
Source File: EthSignerAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void privateSmartContractMustDeployWithPrivacyGroupNoNonce() throws IOException { final String privacyGroupId = minerNode.execute(privacyTransactions.createPrivacyGroup(null, null, minerNode)); minerNode.verify( privateTransactionVerifier.validPrivacyGroupCreated( new PrivacyGroup( privacyGroupId, PrivacyGroup.Type.PANTHEON, "", "", Base64String.wrapList(minerNode.getEnclaveKey())))); final String transactionHash = ethSignerClient.eeaSendTransaction( null, BigInteger.valueOf(23176), BigInteger.valueOf(1000), EventEmitter.BINARY, minerNode.getEnclaveKey(), privacyGroupId, "restricted"); final PrivateTransactionReceipt receipt = minerNode.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); minerNode.verify( privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, receipt)); }
Example #19
Source File: EthSignerAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void privateSmartContractMustDeployWithPrivacyGroup() throws IOException { final String privacyGroupId = minerNode.execute(privacyTransactions.createPrivacyGroup(null, null, minerNode)); minerNode.verify( privateTransactionVerifier.validPrivacyGroupCreated( new PrivacyGroup( privacyGroupId, PrivacyGroup.Type.PANTHEON, "", "", Base64String.wrapList(minerNode.getEnclaveKey())))); final String transactionHash = ethSignerClient.eeaSendTransaction( null, BigInteger.valueOf(23176), BigInteger.valueOf(1000), EventEmitter.BINARY, BigInteger.valueOf(0), minerNode.getEnclaveKey(), privacyGroupId, "restricted"); final PrivateTransactionReceipt receipt = minerNode.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); minerNode.verify( privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, receipt)); }
Example #20
Source File: PrivGetLogsAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
private PrivateTransactionReceipt updateContractValue( final String privacyGroupId, final EventEmitter eventEmitterContract, final int value) { final String transactionHash = node.execute( privateContractTransactions.callSmartContractWithPrivacyGroupId( eventEmitterContract.getContractAddress(), eventEmitterContract.store(BigInteger.valueOf(value)).encodeFunctionCall(), node.getTransactionSigningKey(), POW_CHAIN_ID, node.getEnclaveKey(), privacyGroupId)); return node.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash)); }
Example #21
Source File: ExpectValidPrivateTransactionReceipt.java From besu with Apache License 2.0 | 5 votes |
@Override public void verify(final PrivacyNode node) { final PrivateTransactionReceipt actualReceipt = node.execute(transactions.getPrivateTransactionReceipt(transactionHash)); assertThat(actualReceipt) .usingRecursiveComparison() .ignoringFields( "commitmentHash", "logs", "blockHash", "blockNumber", "logsBloom", "transactionIndex") // TODO: The fields blockHash, blockNumber, logsBloom and // transactionIndex have to be ignored as the class // org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt does not contain these // fields. Once web3j has been updated these ignores can be removed. .isEqualTo(expectedReceipt); assertThat(actualReceipt.getLogs().size()).isEqualTo(expectedReceipt.getLogs().size()); for (int i = 0; i < expectedReceipt.getLogs().size(); i++) { assertThat(actualReceipt.getLogs().get(i)) .usingRecursiveComparison() .ignoringFields("blockHash", "blockNumber") .isEqualTo(expectedReceipt.getLogs().get(i)); } }
Example #22
Source File: ExpectValidPrivateTransactionReceipt.java From besu with Apache License 2.0 | 5 votes |
public ExpectValidPrivateTransactionReceipt( final PrivacyTransactions transactions, final String transactionHash, final PrivateTransactionReceipt expectedReceipt) { this.transactions = transactions; this.transactionHash = transactionHash; this.expectedReceipt = expectedReceipt; }
Example #23
Source File: PrivacyRequestFactory.java From besu with Apache License 2.0 | 5 votes |
public String privxLockPrivacyGroup(final PrivacyNode locker, final Base64String privacyGroupId) throws IOException, TransactionException { final BigInteger nonce = besuClient .privGetTransactionCount(locker.getAddress().toHexString(), privacyGroupId) .send() .getTransactionCount(); final RawPrivateTransaction privateTransaction = RawPrivateTransaction.createTransaction( nonce, BigInteger.valueOf(1000), BigInteger.valueOf(3000000), Address.ONCHAIN_PRIVACY_PROXY.toHexString(), OnChainGroupManagement.LOCK_GROUP_METHOD_SIGNATURE.toHexString(), Base64String.wrap(locker.getEnclaveKey()), privacyGroupId, org.web3j.utils.Restriction.RESTRICTED); final String transactionHash = besuClient .eeaSendRawTransaction( Numeric.toHexString( PrivateTransactionEncoder.signMessage( privateTransaction, Credentials.create(locker.getTransactionSigningKey())))) .send() .getTransactionHash(); final PrivateTransactionReceipt privateTransactionReceipt = new PollingPrivateTransactionReceiptProcessor(besuClient, 3000, 10) .waitForTransactionReceipt(transactionHash); assertThat(privateTransactionReceipt.getStatus()).isEqualTo("0x1"); return privateTransactionReceipt.getcommitmentHash(); }
Example #24
Source File: PrivGetTransactionReceiptTransaction.java From besu with Apache License 2.0 | 5 votes |
@Override public PrivateTransactionReceipt execute(final NodeRequests node) { final Besu besu = node.privacy().getBesuClient(); final PollingPrivateTransactionReceiptProcessor receiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, 1000, 15); try { final PrivateTransactionReceipt result = receiptProcessor.waitForTransactionReceipt(transactionHash); assertThat(result).isNotNull(); return result; } catch (final IOException | TransactionException e) { throw new RuntimeException(e); } }
Example #25
Source File: ExpectExistingPrivateTransactionReceipt.java From besu with Apache License 2.0 | 4 votes |
@Override public void verify(final PrivacyNode node) { final PrivateTransactionReceipt privateTransactionReceipt = node.execute(transactions.getPrivateTransactionReceipt(transactionHash)); assertThat(privateTransactionReceipt).isNotNull(); }
Example #26
Source File: ResponseTest.java From web3j with Apache License 2.0 | 4 votes |
@Test public void testPrivGetTransactionReceipt() { buildResponse( "{\n" + " \"id\":1,\n" + " \"jsonrpc\":\"2.0\",\n" + " \"result\": {\n" + " \"contractAddress\": \"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\n" + " \"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\n" + " \"to\":\"0x85h43d8a49eeb85d32cf465507dd71d507100c1\",\n" + " \"output\":\"myRlpEncodedOutputFromPrivateContract\",\n" + " \"status\":\"0x1\",\n" + " \"privacyGroupId\":\"Qlv2Jhn3C3/2KrPU7Jeu/9F6rElio9LNBSieb0Xk/Ro=\",\n" + " \"commitmentHash\": \"0x75aaac4be865057a576872587c9672197f1bab25e64b588c81f483c5869e0fa7\",\n" + " \"transactionHash\": \"0x5504d87dc6c6ab8ea4f5c988bcf1c41d40e6b594b80849d4444c432099ee6c34\",\n" + " \"privateFrom\": \"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=\",\n" + " \"logs\": [{\n" + " \"removed\": false,\n" + " \"logIndex\": \"0x1\",\n" + " \"transactionIndex\": \"0x0\",\n" + " \"transactionHash\": \"0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf\",\n" + " \"blockHash\": \"0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d\",\n" + " \"blockNumber\":\"0x1b4\",\n" + " \"address\": \"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d\",\n" + " \"data\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\n" + " \"type\":\"mined\",\n" + " \"topics\": [\"0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5\"]" + " }]\n" + " }\n" + "}"); PrivateTransactionReceipt transactionReceipt = new PrivateTransactionReceipt( "0xb60e8dd61c5d32be8058bb8eb970870f07233155", "0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x85h43d8a49eeb85d32cf465507dd71d507100c1", "myRlpEncodedOutputFromPrivateContract", Collections.singletonList( new Log( false, "0x1", "0x0", "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", "0x1b4", "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", "0x0000000000000000000000000000000000000000000000000000000000000000", "mined", Arrays.asList( "0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"))), "0x75aaac4be865057a576872587c9672197f1bab25e64b588c81f483c5869e0fa7", "0x5504d87dc6c6ab8ea4f5c988bcf1c41d40e6b594b80849d4444c432099ee6c34", "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=", null, "Qlv2Jhn3C3/2KrPU7Jeu/9F6rElio9LNBSieb0Xk/Ro=", "0x1", null); PrivGetTransactionReceipt privGetTransactionReceipt = deserialiseResponse(PrivGetTransactionReceipt.class); assertEquals(privGetTransactionReceipt.getTransactionReceipt().get(), (transactionReceipt)); }
Example #27
Source File: JsonRpc2_0Besu.java From web3j with Apache License 2.0 | 4 votes |
@Override public Request<?, EthSendTransaction> privOnChainAddToPrivacyGroup( Base64String privacyGroupId, Credentials credentials, Base64String enclaveKey, List<Base64String> participants) throws IOException, TransactionException { BigInteger transactionCount = privGetTransactionCount(credentials.getAddress(), privacyGroupId) .send() .getTransactionCount(); String lockContractCall = OnChainPrivacyTransactionBuilder.getEncodedSingleParamFunction("lock"); String lockPrivacyGroupTransactionPayload = OnChainPrivacyTransactionBuilder.buildOnChainPrivateTransaction( privacyGroupId, credentials, enclaveKey, transactionCount, lockContractCall); String lockTransactionHash = eeaSendRawTransaction(lockPrivacyGroupTransactionPayload) .send() .getTransactionHash(); PollingPrivateTransactionReceiptProcessor processor = new PollingPrivateTransactionReceiptProcessor(this, 1000, 15); PrivateTransactionReceipt receipt = processor.waitForTransactionReceipt(lockTransactionHash); if (receipt.isStatusOK()) { return privOnChainCreatePrivacyGroup( privacyGroupId, credentials, enclaveKey, participants); } else { throw new TransactionException( "Lock transaction failed - the group may already be locked", receipt); } }
Example #28
Source File: Besu.java From ethsigner with Apache License 2.0 | 4 votes |
public Optional<PrivateTransactionReceipt> getTransactionReceipt(final String hash) throws IOException { return besu.privGetTransactionReceipt(hash).send().getTransactionReceipt(); }
Example #29
Source File: PollingPrivateTransactionReceiptProcessor.java From web3j with Apache License 2.0 | 4 votes |
@Override public PrivateTransactionReceipt waitForTransactionReceipt(String transactionHash) throws IOException, TransactionException { return getTransactionReceipt(transactionHash, sleepDuration, attempts); }
Example #30
Source File: BesuPrivacyQuickstartIntegrationTest.java From web3j with Apache License 2.0 | 4 votes |
@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()); }