Search in sources :

Example 1 with PollingPrivateTransactionReceiptProcessor

use of org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor in project web3j by web3j.

the class BesuPrivacyQuickstartIntegrationTest method legacyContract.

@Test
public void legacyContract() throws Exception {
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager tmAlice = new PrivateTransactionManager(nodeAlice, ALICE, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_BOB), RESTRICTED);
    PrivateTransactionManager tmBob = new PrivateTransactionManager(nodeBob, BOB, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_BOB, Collections.singletonList(ENCLAVE_KEY_ALICE), RESTRICTED);
    final HumanStandardToken tokenAlice = HumanStandardToken.deploy(nodeAlice, tmAlice, ZERO_GAS_PROVIDER, BigInteger.TEN, "eea_token", BigInteger.TEN, "EEATKN").send();
    final HumanStandardToken tokenBob = HumanStandardToken.load(tokenAlice.getContractAddress(), nodeBob, tmBob, ZERO_GAS_PROVIDER);
    tokenAlice.transfer(BOB.getAddress(), BigInteger.TEN).send();
    testBalances(tokenAlice, tokenBob, BigInteger.ZERO, BigInteger.TEN);
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Test(org.junit.jupiter.api.Test)

Example 2 with PollingPrivateTransactionReceiptProcessor

use of org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor in project web3j by web3j.

the class BesuPrivacyQuickstartIntegrationTest method privacyGroupContract.

@Test
public void privacyGroupContract() throws Exception {
    // Build new privacy group using the create API
    final Base64String aliceBobGroup = nodeAlice.privCreatePrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB), "AliceBob", "AliceBob group").send().getPrivacyGroupId();
    // Find the privacy group that was built by Alice from Bob's node
    final Base64String aliceBobGroupFromBobNode = nodeBob.privFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB)).send().getGroups().stream().filter(g -> g.getName().equals("AliceBob") && g.getDescription().equals("AliceBob group") && g.getPrivacyGroupId().equals(aliceBobGroup)).findFirst().orElseThrow(RuntimeException::new).getPrivacyGroupId();
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager tmBob = new PrivateTransactionManager(nodeBob, BOB, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_BOB, aliceBobGroupFromBobNode, RESTRICTED);
    PrivateTransactionManager tmAlice = new PrivateTransactionManager(nodeAlice, ALICE, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_ALICE, aliceBobGroupFromBobNode, RESTRICTED);
    final HumanStandardToken tokenAlice = HumanStandardToken.deploy(nodeAlice, tmAlice, ZERO_GAS_PROVIDER, BigInteger.TEN, "eea_token", BigInteger.TEN, "EEATKN").send();
    final HumanStandardToken tokenBob = HumanStandardToken.load(tokenAlice.getContractAddress(), nodeBob, tmBob, ZERO_GAS_PROVIDER);
    tokenAlice.transfer(BOB.getAddress(), BigInteger.TEN).send();
    testBalances(tokenAlice, tokenBob, BigInteger.ZERO, BigInteger.TEN);
}
Also used : PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ChainIdLong(org.web3j.tx.ChainIdLong) HttpService(org.web3j.protocol.http.HttpService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Disabled(org.junit.jupiter.api.Disabled) Credentials(org.web3j.crypto.Credentials) BeforeAll(org.junit.jupiter.api.BeforeAll) BigInteger(java.math.BigInteger) PrivateTransactionEncoder(org.web3j.protocol.eea.crypto.PrivateTransactionEncoder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) BesuPrivacyGasProvider(org.web3j.tx.gas.BesuPrivacyGasProvider) DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH(org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH) DEFAULT_POLLING_FREQUENCY(org.web3j.tx.TransactionManager.DEFAULT_POLLING_FREQUENCY) RESTRICTED(org.web3j.utils.Restriction.RESTRICTED) IOException(java.io.IOException) PrivateTransactionWithPrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivateTransactionWithPrivacyGroup) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) TransactionEncoder(org.web3j.crypto.TransactionEncoder) Sign(org.web3j.crypto.Sign) Test(org.junit.jupiter.api.Test) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) Numeric(org.web3j.utils.Numeric) RawPrivateTransaction(org.web3j.protocol.eea.crypto.RawPrivateTransaction) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) Collections(java.util.Collections) Base64String(org.web3j.utils.Base64String) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Base64String(org.web3j.utils.Base64String) Test(org.junit.jupiter.api.Test)

Example 3 with PollingPrivateTransactionReceiptProcessor

use of org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor in project web3j by web3j.

the class PrivateTransactionManagerTest method sendPrivCallRevertedTest.

@Test
public void sendPrivCallRevertedTest() throws IOException {
    when(response.isReverted()).thenReturn(true);
    when(response.getRevertReason()).thenReturn(OWNER_REVERT_MSG_STR);
    when(service.send(any(), any())).thenReturn(response);
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager besuTransactionManager = new PrivateTransactionManager(besu, credentials, transactionReceiptProcessor, ChainIdLong.NONE, PRIVATE_FROM, PRIVACY_GROUP_ID, RESTRICTED);
    ContractCallException thrown = assertThrows(ContractCallException.class, () -> besuTransactionManager.sendCall("", "", defaultBlockParameter));
    assertEquals(String.format(REVERT_ERR_STR, OWNER_REVERT_MSG_STR), thrown.getMessage());
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) ContractCallException(org.web3j.tx.exceptions.ContractCallException) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) Test(org.junit.jupiter.api.Test)

Example 4 with PollingPrivateTransactionReceiptProcessor

use of org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor in project web3j by web3j.

the class PrivateTransactionManagerTest method sendPrivCallTest.

@Test
public void sendPrivCallTest() throws IOException {
    when(response.getValue()).thenReturn("test");
    when(service.send(any(), any())).thenReturn(response);
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager besuTransactionManager = new PrivateTransactionManager(besu, credentials, transactionReceiptProcessor, ChainIdLong.NONE, PRIVATE_FROM, PRIVACY_GROUP_ID, RESTRICTED);
    String value = besuTransactionManager.sendCall("", "", defaultBlockParameter);
    assertEquals("test", value);
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) Base64String(org.web3j.utils.Base64String) Test(org.junit.jupiter.api.Test)

Example 5 with PollingPrivateTransactionReceiptProcessor

use of org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor in project web3j by web3j.

the class JsonRpc2_0Besu method privOnChainAddToPrivacyGroup.

@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);
    }
}
Also used : PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionException(org.web3j.protocol.exceptions.TransactionException) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) BigInteger(java.math.BigInteger) Base64String(org.web3j.utils.Base64String)

Aggregations

PollingPrivateTransactionReceiptProcessor (org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor)10 Test (org.junit.jupiter.api.Test)6 Base64String (org.web3j.utils.Base64String)6 BigInteger (java.math.BigInteger)5 PrivateTransactionReceipt (org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt)5 TransactionReceiptProcessor (org.web3j.tx.response.TransactionReceiptProcessor)5 BeforeAll (org.junit.jupiter.api.BeforeAll)3 RawPrivateTransaction (org.web3j.protocol.eea.crypto.RawPrivateTransaction)3 TransactionException (org.web3j.protocol.exceptions.TransactionException)3 HttpService (org.web3j.protocol.http.HttpService)3 HumanStandardToken (org.web3j.test.contract.HumanStandardToken)3 PrivateTransactionManager (org.web3j.tx.PrivateTransactionManager)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Disabled (org.junit.jupiter.api.Disabled)2 Credentials (org.web3j.crypto.Credentials)2 Sign (org.web3j.crypto.Sign)2 PrivateTransactionWithPrivacyGroup (org.web3j.protocol.besu.response.privacy.PrivateTransactionWithPrivacyGroup)2