use of com.hedera.hashgraph.sdk.AccountBalanceQuery in project hedera-sdk-java by hashgraph.
the class AccountBalanceIntegrationTest method cannotConnectToPreviewnetWhenNetworkNameIsNullAndCertificateVerificationIsEnabled.
@Test
@DisplayName("can connect to previewnet with certificate verification off")
void cannotConnectToPreviewnetWhenNetworkNameIsNullAndCertificateVerificationIsEnabled() throws Exception {
var client = Client.forPreviewnet().setTransportSecurity(true).setVerifyCertificates(true).setNetworkName(null);
assertThat(client.getNetwork().isEmpty()).isFalse();
for (var entry : client.getNetwork().entrySet()) {
assertThat(entry.getKey().endsWith(":50212")).isTrue();
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
new AccountBalanceQuery().setNodeAccountIds(Collections.singletonList(entry.getValue())).setAccountId(entry.getValue()).execute(client);
});
}
client.close();
}
use of com.hedera.hashgraph.sdk.AccountBalanceQuery in project hedera-sdk-java by hashgraph.
the class AccountBalanceIntegrationTest method getCostBalanceForClientOperator.
@Test
@DisplayName("Can fetch cost for the query")
void getCostBalanceForClientOperator() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var balance = new AccountBalanceQuery().setAccountId(testEnv.operatorId).setMaxQueryPayment(new Hbar(1));
var cost = balance.getCost(testEnv.client);
var accBalance = balance.setQueryPayment(cost).execute(testEnv.client);
assertThat(accBalance.hbars.toTinybars() > 0).isTrue();
assertThat(cost.toTinybars()).isEqualTo(0);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.AccountBalanceQuery in project hedera-sdk-java by hashgraph.
the class AccountBalanceIntegrationTest method canNotFetchBalanceForInvalidAccountId.
@Test
@DisplayName("Cannot fetch balance for invalid account ID")
void canNotFetchBalanceForInvalidAccountId() throws Exception {
var testEnv = new IntegrationTestEnv(1);
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
new AccountBalanceQuery().setAccountId(AccountId.fromString("1.0.3")).execute(testEnv.client);
}).withMessageContaining(Status.INVALID_ACCOUNT_ID.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.AccountBalanceQuery in project hedera-sdk-java by hashgraph.
the class AccountBalanceIntegrationTest method getCostBigMaxBalanceForClientOperator.
@Test
@DisplayName("Can fetch cost for the query, big max set")
void getCostBigMaxBalanceForClientOperator() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var balance = new AccountBalanceQuery().setAccountId(testEnv.operatorId).setMaxQueryPayment(new Hbar(1000000));
var cost = balance.getCost(testEnv.client);
var accBalance = balance.setQueryPayment(cost).execute(testEnv.client);
assertThat(accBalance.hbars.toTinybars() > 0).isTrue();
testEnv.close();
}
use of com.hedera.hashgraph.sdk.AccountBalanceQuery in project hedera-sdk-java by hashgraph.
the class CreateAccountThresholdKeyExample method main.
public static void main(String[] args) throws PrecheckStatusException, TimeoutException, ReceiptStatusException {
Client client = Client.forName(HEDERA_NETWORK);
// Defaults the operator account ID and key such that all generated transactions will be paid for
// by this account and be signed by this key
client.setOperator(OPERATOR_ID, OPERATOR_KEY);
// Generate three new Ed25519 private, public key pairs.
// You do not need the private keys to create the Threshold Key List,
// you only need the public keys, and if you're doing things correctly,
// you probably shouldn't have these private keys.
PrivateKey[] privateKeys = new PrivateKey[3];
PublicKey[] publicKeys = new PublicKey[3];
for (int i = 0; i < 3; i++) {
PrivateKey key = PrivateKey.generateED25519();
privateKeys[i] = key;
publicKeys[i] = key.getPublicKey();
}
System.out.println("public keys: ");
for (Key key : publicKeys) {
System.out.println(key);
}
// require 2 of the 3 keys we generated to sign on anything modifying this account
KeyList transactionKey = KeyList.withThreshold(2);
Collections.addAll(transactionKey, publicKeys);
TransactionResponse transactionResponse = new AccountCreateTransaction().setKey(transactionKey).setInitialBalance(new Hbar(10)).execute(client);
// This will wait for the receipt to become available
TransactionReceipt receipt = transactionResponse.getReceipt(client);
AccountId newAccountId = Objects.requireNonNull(receipt.accountId);
System.out.println("account = " + newAccountId);
TransactionResponse transferTransactionResponse = new TransferTransaction().addHbarTransfer(newAccountId, new Hbar(10).negated()).addHbarTransfer(new AccountId(3), new Hbar(10)).freezeWith(client).sign(privateKeys[0]).sign(privateKeys[1]).execute(client);
// (important!) wait for the transfer to go to consensus
transferTransactionResponse.getReceipt(client);
Hbar balanceAfter = new AccountBalanceQuery().setAccountId(newAccountId).execute(client).hbars;
System.out.println("account balance after transfer: " + balanceAfter);
}
Aggregations