use of com.hedera.hashgraph.sdk.TransactionReceipt in project hedera-mirror-node by hashgraph.
the class TopicFeature method updateTopic.
@When("I successfully update an existing topic")
public void updateTopic() {
TransactionReceipt receipt = topicClient.updateTopic(consensusTopicId).getReceipt();
assertNotNull(receipt);
}
use of com.hedera.hashgraph.sdk.TransactionReceipt in project hedera-sdk-java by hashgraph.
the class ScheduleCreateIntegrationTest method canSignSchedule2.
@Test
@DisplayName("Can sign schedule")
void canSignSchedule2() throws Exception {
var testEnv = new IntegrationTestEnv(1);
PrivateKey key1 = PrivateKey.generateED25519();
PrivateKey key2 = PrivateKey.generateED25519();
PrivateKey key3 = PrivateKey.generateED25519();
KeyList keyList = new KeyList();
keyList.add(key1.getPublicKey());
keyList.add(key2.getPublicKey());
keyList.add(key3.getPublicKey());
// Creat the account with the `KeyList`
TransactionResponse response = new AccountCreateTransaction().setKey(keyList).setInitialBalance(new Hbar(10)).execute(testEnv.client);
// This will wait for the receipt to become available
@Var TransactionReceipt receipt = response.getReceipt(testEnv.client);
AccountId accountId = Objects.requireNonNull(receipt.accountId);
// Generate a `TransactionId`. This id is used to query the inner scheduled transaction
// after we expect it to have been executed
TransactionId transactionId = TransactionId.generate(testEnv.operatorId);
// Create a transfer transaction with 2/3 signatures.
TransferTransaction transfer = new TransferTransaction().setTransactionId(transactionId).addHbarTransfer(accountId, new Hbar(1).negated()).addHbarTransfer(testEnv.operatorId, new Hbar(1));
// Schedule the transactoin
ScheduleCreateTransaction scheduled = transfer.schedule();
receipt = scheduled.execute(testEnv.client).getReceipt(testEnv.client);
// Get the schedule ID from the receipt
ScheduleId scheduleId = Objects.requireNonNull(receipt.scheduleId);
// Get the schedule info to see if `signatories` is populated with 2/3 signatures
@Var ScheduleInfo info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
assertThat(info.executedAt).isNull();
// Finally send this last signature to Hedera. This last signature _should_ mean the transaction executes
// since all 3 signatures have been provided.
ScheduleSignTransaction signTransaction = new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client);
signTransaction.sign(key1).sign(key2).sign(key3).execute(testEnv.client).getReceipt(testEnv.client);
info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
assertThat(info.executedAt).isNotNull();
new AccountDeleteTransaction().setAccountId(accountId).setTransferAccountId(testEnv.operatorId).freezeWith(testEnv.client).sign(key1).sign(key2).sign(key3).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TransactionReceipt 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);
}
use of com.hedera.hashgraph.sdk.TransactionReceipt in project hedera-sdk-java by hashgraph.
the class CreateAccountExample method main.
public static void main(String[] args) throws TimeoutException, PrecheckStatusException, 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 a Ed25519 private, public key pair
PrivateKey newKey = PrivateKey.generateED25519();
PublicKey newPublicKey = newKey.getPublicKey();
System.out.println("private key = " + newKey);
System.out.println("public key = " + newPublicKey);
TransactionResponse transactionResponse = new AccountCreateTransaction().setKey(newPublicKey).setInitialBalance(Hbar.fromTinybars(1000)).execute(client);
// This will wait for the receipt to become available
TransactionReceipt receipt = transactionResponse.getReceipt(client);
AccountId newAccountId = receipt.accountId;
System.out.println("account = " + newAccountId);
}
use of com.hedera.hashgraph.sdk.TransactionReceipt 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