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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations