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