Search in sources :

Example 46 with Hbar

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

the class ScheduleCreateTransactionSupplier method get.

@Override
public ScheduleCreateTransaction get() {
    Hbar maxTransactionFee = Hbar.fromTinybars(getMaxTransactionFee());
    TransferTransaction innerTransaction = new TransferTransaction().setMaxTransactionFee(maxTransactionFee).addHbarTransfer(getOperatorId(), Hbar.fromTinybars(1L).negated()).addHbarTransfer(getPayerAccountId(), Hbar.fromTinybars(1L));
    ScheduleCreateTransaction scheduleCreateTransaction = new ScheduleCreateTransaction().setAdminKey(getAdminPublicKey()).setMaxTransactionFee(maxTransactionFee).setPayerAccountId(getPayerAccountId()).setScheduleMemo(Utility.getMemo("Mirror node created test schedule")).setScheduledTransaction(innerTransaction);
    return scheduleCreateTransaction;
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction)

Example 47 with Hbar

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

the class CryptoTransferTransactionSupplierTest method createWithCustomAllTransfer.

@Test
void createWithCustomAllTransfer() {
    TokenId nftTokenId = TokenId.fromString("0.0.21");
    Hbar transferAmount = Hbar.fromTinybars(2);
    CryptoTransferTransactionSupplier cryptoTransferTransactionSupplier = new CryptoTransferTransactionSupplier();
    cryptoTransferTransactionSupplier.setAmount(2);
    cryptoTransferTransactionSupplier.setMaxTransactionFee(1);
    cryptoTransferTransactionSupplier.setNftTokenId(nftTokenId.toString());
    cryptoTransferTransactionSupplier.setRecipientAccountId(ACCOUNT_ID_2.toString());
    cryptoTransferTransactionSupplier.setSenderAccountId(ACCOUNT_ID.toString());
    cryptoTransferTransactionSupplier.setSerialNumber(new AtomicLong(10));
    cryptoTransferTransactionSupplier.setTokenId(TOKEN_ID.toString());
    cryptoTransferTransactionSupplier.setTransferTypes(Set.of(CRYPTO, NFT, TOKEN));
    TransferTransaction actual = cryptoTransferTransactionSupplier.get();
    assertThat(actual).returns(ONE_TINYBAR, TransferTransaction::getMaxTransactionFee).satisfies(a -> assertThat(a.getHbarTransfers()).containsEntry(ACCOUNT_ID, transferAmount.negated()).containsEntry(ACCOUNT_ID_2, transferAmount)).satisfies(a -> assertThat(a).extracting(TransferTransaction::getTokenNftTransfers, MAP).hasSize(1).extractingByKey(nftTokenId, LIST).extracting("serial", "sender", "receiver").containsExactlyInAnyOrder(tuple(10L, ACCOUNT_ID, ACCOUNT_ID_2), tuple(11L, ACCOUNT_ID, ACCOUNT_ID_2))).extracting(TransferTransaction::getHbarTransfers, MAP).hasSize(2).containsEntry(ACCOUNT_ID, transferAmount.negated()).containsEntry(ACCOUNT_ID_2, transferAmount);
}
Also used : TokenId(com.hedera.hashgraph.sdk.TokenId) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) MAP(org.assertj.core.api.InstanceOfAssertFactories.MAP) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TOKEN(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.TOKEN) Set(java.util.Set) CRYPTO(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.CRYPTO) NFT(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.NFT) Test(org.junit.jupiter.api.Test) AtomicLong(java.util.concurrent.atomic.AtomicLong) LIST(org.assertj.core.api.InstanceOfAssertFactories.LIST) Hbar(com.hedera.hashgraph.sdk.Hbar) Collections(java.util.Collections) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest) AtomicLong(java.util.concurrent.atomic.AtomicLong) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenId(com.hedera.hashgraph.sdk.TokenId) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 48 with Hbar

use of com.hedera.hashgraph.sdk.Hbar 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 49 with Hbar

use of com.hedera.hashgraph.sdk.Hbar 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)

Example 50 with Hbar

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

the class ScheduleCreateIntegrationTest method canGetTransactionSchedule.

@Test
@Disabled
@DisplayName("Can get Transaction")
void canGetTransactionSchedule() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10));
    var response = new ScheduleCreateTransaction().setScheduledTransaction(transaction).setAdminKey(testEnv.operatorKey).setPayerAccountId(testEnv.operatorId).execute(testEnv.client);
    var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId);
    var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNotNull();
    assertThat(info.getScheduledTransaction()).isNotNull();
    testEnv.close();
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Hbar (com.hedera.hashgraph.sdk.Hbar)106 Test (org.junit.jupiter.api.Test)77 DisplayName (org.junit.jupiter.api.DisplayName)75 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)62 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)34 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)31 Client (com.hedera.hashgraph.sdk.Client)22 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)22 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)19 Var (com.google.errorprone.annotations.Var)18 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 AccountId (com.hedera.hashgraph.sdk.AccountId)15 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)13 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)13 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)12 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)11 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)11 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)9 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)9