use of com.hedera.hashgraph.sdk.PublicKey in project hedera-mirror-node by hashgraph.
the class AccountUpdateTransactionSupplierTest method createWithCustomData.
@Test
void createWithCustomData() {
Instant expirationTime = Instant.now().plus(1, ChronoUnit.DAYS);
PublicKey key = PrivateKey.generate().getPublicKey();
AccountUpdateTransactionSupplier accountUpdateTransactionSupplier = new AccountUpdateTransactionSupplier();
accountUpdateTransactionSupplier.setAccountId(ACCOUNT_ID.toString());
accountUpdateTransactionSupplier.setExpirationTime(expirationTime);
accountUpdateTransactionSupplier.setMaxTransactionFee(1);
accountUpdateTransactionSupplier.setProxyAccountId(ACCOUNT_ID_2.toString());
accountUpdateTransactionSupplier.setPublicKey(key.toString());
accountUpdateTransactionSupplier.setReceiverSignatureRequired(true);
AccountUpdateTransaction actual = accountUpdateTransactionSupplier.get();
assertThat(actual).returns(ACCOUNT_ID, AccountUpdateTransaction::getAccountId).returns(expirationTime, AccountUpdateTransaction::getExpirationTime).returns(key, AccountUpdateTransaction::getKey).returns(ONE_TINYBAR, AccountUpdateTransaction::getMaxTransactionFee).returns(ACCOUNT_ID_2, AccountUpdateTransaction::getProxyAccountId).returns(true, AccountUpdateTransaction::getReceiverSignatureRequired).extracting(AccountUpdateTransaction::getAccountMemo, STRING).contains("Mirror node updated test account");
}
use of com.hedera.hashgraph.sdk.PublicKey in project hedera-mirror-node by hashgraph.
the class ScheduleCreateTransactionSupplierTest method createWithCustomData.
@Test
void createWithCustomData() {
PublicKey adminKey = PrivateKey.generate().getPublicKey();
ScheduleCreateTransactionSupplier scheduleCreateTransactionSupplier = new ScheduleCreateTransactionSupplier();
scheduleCreateTransactionSupplier.setAdminKey(adminKey.toString());
scheduleCreateTransactionSupplier.setMaxTransactionFee(1);
scheduleCreateTransactionSupplier.setOperatorAccountId(ACCOUNT_ID.toString());
scheduleCreateTransactionSupplier.setPayerAccount(ACCOUNT_ID_2.toString());
ScheduleCreateTransaction actual = scheduleCreateTransactionSupplier.get();
assertThat(actual).returns(adminKey, a -> a.getAdminKey()).returns(ONE_TINYBAR, ScheduleCreateTransaction::getMaxTransactionFee).returns(ACCOUNT_ID_2, ScheduleCreateTransaction::getPayerAccountId).extracting(ScheduleCreateTransaction::getScheduleMemo, STRING).contains("Mirror node created test schedule");
}
use of com.hedera.hashgraph.sdk.PublicKey in project hedera-mirror-node by hashgraph.
the class TokenCreateTransactionSupplierTest method createWithNonFungibleData.
@Test
void createWithNonFungibleData() {
PublicKey key = PrivateKey.generate().getPublicKey();
TokenCreateTransactionSupplier tokenCreateTransactionSupplier = new TokenCreateTransactionSupplier();
tokenCreateTransactionSupplier.setTreasuryAccountId(ACCOUNT_ID.toString());
tokenCreateTransactionSupplier.setType(TokenType.NON_FUNGIBLE_UNIQUE);
TokenCreateTransaction actual = tokenCreateTransactionSupplier.get();
assertThat(actual).returns(null, TokenCreateTransaction::getAdminKey).returns(ACCOUNT_ID, TokenCreateTransaction::getAutoRenewAccountId).returns(0, TokenCreateTransaction::getDecimals).returns(null, TokenCreateTransaction::getFeeScheduleKey).returns(false, TokenCreateTransaction::getFreezeDefault).returns(null, TokenCreateTransaction::getFreezeKey).returns(0L, TokenCreateTransaction::getInitialSupply).returns(null, TokenCreateTransaction::getKycKey).returns(0L, TokenCreateTransaction::getMaxSupply).returns(MAX_TRANSACTION_FEE_HBAR, TokenCreateTransaction::getMaxTransactionFee).returns(null, TokenCreateTransaction::getSupplyKey).returns(TokenSupplyType.INFINITE, TokenCreateTransaction::getSupplyType).returns(TokenType.NON_FUNGIBLE_UNIQUE, TokenCreateTransaction::getTokenType).returns(ACCOUNT_ID, TokenCreateTransaction::getTreasuryAccountId).returns(null, TokenCreateTransaction::getWipeKey).extracting(TokenCreateTransaction::getTokenMemo, STRING).contains("Mirror node created test token");
}
use of com.hedera.hashgraph.sdk.PublicKey in project hedera-mirror-node by hashgraph.
the class ConsensusUpdateTopicTransactionSupplier method get.
@Override
public TopicUpdateTransaction get() {
TopicUpdateTransaction topicUpdateTransaction = new TopicUpdateTransaction().setMaxTransactionFee(Hbar.fromTinybars(maxTransactionFee)).setTopicId(TopicId.fromString(topicId)).setTopicMemo(Utility.getMemo("Mirror node updated test topic"));
if (adminKey != null) {
PublicKey key = PublicKey.fromString(adminKey);
topicUpdateTransaction.setAdminKey(key).setSubmitKey(key);
}
if (autoRenewAccountId != null) {
topicUpdateTransaction.setAutoRenewAccountId(AccountId.fromString(autoRenewAccountId)).setAutoRenewPeriod(autoRenewPeriod);
}
return topicUpdateTransaction;
}
use of com.hedera.hashgraph.sdk.PublicKey in project hedera-sdk-java by hashgraph.
the class ScheduledTransactionMultiSigThresholdExample method main.
// public static void main(String[] args) throws PrecheckStatusException, IOException, TimeoutException, ReceiptStatusException {
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 four new Ed25519 private, public key pairs.
PrivateKey[] privateKeys = new PrivateKey[4];
PublicKey[] publicKeys = new PublicKey[4];
for (int i = 0; i < 4; i++) {
PrivateKey key = PrivateKey.generateED25519();
privateKeys[i] = key;
publicKeys[i] = key.getPublicKey();
System.out.println("public key " + (i + 1) + ": " + publicKeys[i]);
System.out.println("private key " + (i + 1) + ": " + privateKeys[i]);
}
// require 3 of the 4 keys we generated to sign on anything modifying this account
KeyList transactionKey = KeyList.withThreshold(3);
Collections.addAll(transactionKey, publicKeys);
TransactionResponse transactionResponse = new AccountCreateTransaction().setKey(transactionKey).setInitialBalance(Hbar.fromTinybars(1)).setAccountMemo("3-of-4 multi-sig account").execute(client);
// This will wait for the receipt to become available
TransactionReceipt txAccountCreateReceipt = transactionResponse.getReceipt(client);
AccountId multiSigAccountId = Objects.requireNonNull(txAccountCreateReceipt.accountId);
System.out.println("3-of-4 multi-sig account ID: " + multiSigAccountId);
AccountBalance balance = new AccountBalanceQuery().setAccountId(multiSigAccountId).execute(client);
System.out.println("Balance of account " + multiSigAccountId + ": " + balance.hbars.toTinybars() + " tinybar.");
// schedule crypto transfer from multi-sig account to operator account
TransactionResponse transferToSchedule = new TransferTransaction().addHbarTransfer(multiSigAccountId, Hbar.fromTinybars(-1)).addHbarTransfer(Objects.requireNonNull(client.getOperatorAccountId()), Hbar.fromTinybars(1)).schedule().freezeWith(client).sign(// add 1 signature`
privateKeys[0]).execute(client);
TransactionReceipt txScheduleReceipt = transferToSchedule.getReceipt(client);
System.out.println("Schedule status: " + txScheduleReceipt.status);
ScheduleId scheduleId = Objects.requireNonNull(txScheduleReceipt.scheduleId);
System.out.println("Schedule ID: " + scheduleId);
TransactionId scheduledTxId = Objects.requireNonNull(txScheduleReceipt.scheduledTransactionId);
System.out.println("Scheduled tx ID: " + scheduledTxId);
// add 2 signature
TransactionResponse txScheduleSign1 = new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(client).sign(privateKeys[1]).execute(client);
TransactionReceipt txScheduleSign1Receipt = txScheduleSign1.getReceipt(client);
System.out.println("1. ScheduleSignTransaction status: " + txScheduleSign1Receipt.status);
// add 3 signature
TransactionResponse txScheduleSign2 = new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(client).sign(privateKeys[2]).execute(client);
TransactionReceipt txScheduleSign2Receipt = txScheduleSign2.getReceipt(client);
System.out.println("2. ScheduleSignTransaction status: " + txScheduleSign2Receipt.status);
// query schedule
ScheduleInfo scheduleInfo = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(client);
System.out.println(scheduleInfo);
// query triggered scheduled tx
TransactionRecord recordScheduledTx = new TransactionRecordQuery().setTransactionId(scheduledTxId).execute(client);
System.out.println(recordScheduledTx);
}
Aggregations