Search in sources :

Example 1 with AccountId

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

the class AccountBalanceFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    accountBalance = view.findViewById(R.id.accountBalance);
    accountId = view.findViewById(R.id.accountId);
    view.findViewById(R.id.button).setOnClickListener(v -> {
        try {
            final AccountId operatorId = AccountId.fromString(view.getResources().getString(R.string.operator_id));
            final Ed25519PrivateKey operatorKey = Ed25519PrivateKey.fromString(view.getResources().getString(R.string.operator_key));
            Client client = Client.forTestnet().setOperator(operatorId, operatorKey);
            final AccountId id = AccountId.fromString(accountId.getText().toString());
            new AccountBalanceAsyncTask(id).execute(client);
        } catch (IllegalArgumentException e) {
            accountBalance.setText("Error: " + e.getMessage());
        }
    });
}
Also used : Ed25519PrivateKey(com.hedera.hashgraph.sdk.crypto.ed25519.Ed25519PrivateKey) AccountId(com.hedera.hashgraph.sdk.account.AccountId) Client(com.hedera.hashgraph.sdk.Client)

Example 2 with AccountId

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

the class CryptoTransferFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    recipientAccountId = view.findViewById(R.id.recipientAccountId);
    amountToSend = view.findViewById(R.id.amountToSend);
    resultText = view.findViewById(R.id.transferResult);
    view.findViewById(R.id.sendHbar).setOnClickListener(v -> {
        try {
            final AccountId operatorId = AccountId.fromString(view.getResources().getString(R.string.operator_id));
            final Ed25519PrivateKey operatorKey = Ed25519PrivateKey.fromString(view.getResources().getString(R.string.operator_key));
            Client client = Client.forTestnet().setOperator(operatorId, operatorKey);
            final AccountId recipientId = AccountId.fromString(recipientAccountId.getText().toString());
            final Hbar amount = new Hbar(new BigDecimal(amountToSend.getText().toString()).longValueExact());
            new TransferAsyncTask(operatorId, recipientId, amount).execute(client);
        } catch (Throwable e) {
            resultText.setText("Error: " + e.getMessage());
        }
    });
}
Also used : Ed25519PrivateKey(com.hedera.hashgraph.sdk.crypto.ed25519.Ed25519PrivateKey) AccountId(com.hedera.hashgraph.sdk.account.AccountId) Hbar(com.hedera.hashgraph.sdk.Hbar) Client(com.hedera.hashgraph.sdk.Client) BigDecimal(java.math.BigDecimal)

Aggregations

Client (com.hedera.hashgraph.sdk.Client)2 AccountId (com.hedera.hashgraph.sdk.account.AccountId)2 Ed25519PrivateKey (com.hedera.hashgraph.sdk.crypto.ed25519.Ed25519PrivateKey)2 Hbar (com.hedera.hashgraph.sdk.Hbar)1 BigDecimal (java.math.BigDecimal)1