Search in sources :

Example 21 with TransferTransaction

use of com.hedera.hashgraph.sdk.TransferTransaction in project hedera-mirror-node by hashgraph.

the class CryptoTransferTransactionSupplierTest method createWithMinimumData.

@Test
void createWithMinimumData() {
    CryptoTransferTransactionSupplier cryptoTransferTransactionSupplier = new CryptoTransferTransactionSupplier();
    cryptoTransferTransactionSupplier.setRecipientAccountId(ACCOUNT_ID_2.toString());
    cryptoTransferTransactionSupplier.setSenderAccountId(ACCOUNT_ID.toString());
    TransferTransaction actual = cryptoTransferTransactionSupplier.get();
    assertThat(actual).returns(MAX_TRANSACTION_FEE_HBAR, TransferTransaction::getMaxTransactionFee).returns(Collections.emptyMap(), TransferTransaction::getTokenNftTransfers).returns(Collections.emptyMap(), TransferTransaction::getTokenTransfers).extracting(TransferTransaction::getHbarTransfers, MAP).hasSize(2).containsEntry(ACCOUNT_ID, ONE_TINYBAR.negated()).containsEntry(ACCOUNT_ID_2, ONE_TINYBAR);
}
Also used : TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 22 with TransferTransaction

use of com.hedera.hashgraph.sdk.TransferTransaction in project hedera-mirror-node by hashgraph.

the class CryptoTransferTransactionSupplierTest method createWithCustomTokenTransfer.

@Test
void createWithCustomTokenTransfer() {
    CryptoTransferTransactionSupplier cryptoTransferTransactionSupplier = new CryptoTransferTransactionSupplier();
    cryptoTransferTransactionSupplier.setAmount(10);
    cryptoTransferTransactionSupplier.setMaxTransactionFee(1);
    cryptoTransferTransactionSupplier.setRecipientAccountId(ACCOUNT_ID_2.toString());
    cryptoTransferTransactionSupplier.setSenderAccountId(ACCOUNT_ID.toString());
    cryptoTransferTransactionSupplier.setTokenId(TOKEN_ID.toString());
    cryptoTransferTransactionSupplier.setTransferTypes(Set.of(TOKEN));
    TransferTransaction actual = cryptoTransferTransactionSupplier.get();
    assertThat(actual).returns(Collections.emptyMap(), TransferTransaction::getHbarTransfers).returns(ONE_TINYBAR, TransferTransaction::getMaxTransactionFee).returns(Collections.emptyMap(), TransferTransaction::getTokenNftTransfers).extracting(TransferTransaction::getTokenTransfers, MAP).hasSize(1).extractingByKey(TOKEN_ID, MAP).hasSize(2).containsEntry(ACCOUNT_ID, -10L).containsEntry(ACCOUNT_ID_2, 10L);
}
Also used : TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 23 with TransferTransaction

use of com.hedera.hashgraph.sdk.TransferTransaction in project hedera-mirror-node by hashgraph.

the class TransactionPublisher method validateNode.

boolean validateNode(NodeProperties node) {
    try {
        log.info("Validating node {}", node);
        Hbar hbar = Hbar.fromTinybars(1L);
        AccountId nodeAccountId = AccountId.fromString(node.getAccountId());
        Client client = validationClient.get();
        Status receiptStatus = new TransferTransaction().addHbarTransfer(nodeAccountId, hbar).addHbarTransfer(client.getOperatorAccountId(), hbar.negated()).setNodeAccountIds(node.getAccountIds()).execute(client).getReceipt(client).status;
        if (receiptStatus == SUCCESS) {
            log.info("Validated node {} successfully", nodeAccountId);
            nodes.addIfAbsent(node);
            return true;
        }
        log.warn("Unable to validate node {}: invalid status code {}", node, receiptStatus);
    } catch (TimeoutException e) {
        log.warn("Unable to validate node {}: Timed out", node);
    } catch (Exception e) {
        log.warn("Unable to validate node {}: ", node, e);
    }
    nodes.remove(node);
    return false;
}
Also used : Status(com.hedera.hashgraph.sdk.Status) AccountId(com.hedera.hashgraph.sdk.AccountId) Hbar(com.hedera.hashgraph.sdk.Hbar) Client(com.hedera.hashgraph.sdk.Client) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 24 with TransferTransaction

use of com.hedera.hashgraph.sdk.TransferTransaction in project hedera-mirror-node by hashgraph.

the class AccountClient method sendCryptoTransfer.

private NetworkTransactionResponse sendCryptoTransfer(ExpandedAccountId sender, AccountId recipient, Hbar hbarAmount, boolean isApproval) {
    log.debug("Send CryptoTransfer of {} tℏ from {} to {}. isApproval: {}", hbarAmount.toTinybars(), sender.getAccountId(), recipient, isApproval);
    TransferTransaction cryptoTransferTransaction = getCryptoTransferTransaction(sender.getAccountId(), recipient, hbarAmount, isApproval);
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(cryptoTransferTransaction, isApproval ? KeyList.of(sender.getPrivateKey()) : null);
    log.debug("Sent CryptoTransfer");
    return networkTransactionResponse;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction)

Example 25 with TransferTransaction

use of com.hedera.hashgraph.sdk.TransferTransaction in project hedera-sdk-java by hashgraph.

the class ScheduleCreateIntegrationTest method cannotScheduleTwoTransactions.

@Test
@DisplayName("Cannot schedule two identical transactions")
void cannotScheduleTwoTransactions() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setInitialBalance(new Hbar(10)).setKey(key).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    var transferTx = new TransferTransaction().addHbarTransfer(testEnv.operatorId, new Hbar(-10)).addHbarTransfer(accountId, new Hbar(10));
    var scheduleId1 = transferTx.schedule().execute(testEnv.client).getReceipt(testEnv.client).scheduleId;
    var info1 = new ScheduleInfoQuery().setScheduleId(scheduleId1).execute(testEnv.client);
    assertThat(info1.executedAt).isNotNull();
    var transferTxFromInfo = info1.getScheduledTransaction();
    var scheduleCreateTx1 = transferTx.schedule();
    var scheduleCreateTx2 = transferTxFromInfo.schedule();
    assertThat(scheduleCreateTx2.toString()).isEqualTo(scheduleCreateTx1.toString());
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        transferTxFromInfo.schedule().execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining("IDENTICAL_SCHEDULE_ALREADY_CREATED");
    testEnv.close(accountId, key);
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)42 Hbar (com.hedera.hashgraph.sdk.Hbar)31 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)26 Test (org.junit.jupiter.api.Test)23 DisplayName (org.junit.jupiter.api.DisplayName)18 AccountId (com.hedera.hashgraph.sdk.AccountId)15 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)14 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)13 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)13 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)13 Client (com.hedera.hashgraph.sdk.Client)12 Var (com.google.errorprone.annotations.Var)10 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)10 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)8 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)8 KeyList (com.hedera.hashgraph.sdk.KeyList)7 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)7 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)6 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)6 ScheduleSignTransaction (com.hedera.hashgraph.sdk.ScheduleSignTransaction)6