Search in sources :

Example 1 with TransactionRecordQuery

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

the class ReceiptQueryIntegrationTest method getCostTransactionRecord.

@Test
@DisplayName("Can get Record cost")
@SuppressWarnings("UnusedVariable")
void getCostTransactionRecord() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    new TransactionReceiptQuery().setTransactionId(response.transactionId).execute(testEnv.client);
    var recordQuery = new TransactionRecordQuery().setTransactionId(response.transactionId);
    var cost = recordQuery.getCost(testEnv.client);
    var record = recordQuery.execute(testEnv.client);
    testEnv.close(record.receipt.accountId, key);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TransactionRecordQuery

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

the class ReceiptQueryIntegrationTest method getCostBigMaxTransactionRecord.

@Test
@DisplayName("Can get Record cost with big max set")
@SuppressWarnings("UnusedVariable")
void getCostBigMaxTransactionRecord() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    new TransactionReceiptQuery().setTransactionId(response.transactionId).execute(testEnv.client);
    var recordQuery = new TransactionRecordQuery().setTransactionId(response.transactionId).setMaxQueryPayment(new Hbar(1000));
    var cost = recordQuery.getCost(testEnv.client);
    var record = recordQuery.execute(testEnv.client);
    testEnv.close(record.receipt.accountId, key);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TransactionRecordQuery

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

the class ReceiptQueryIntegrationTest method getCostInsufficientTxFeeTransactionRecord.

@Test
@DisplayName("Insufficient transaction fee error for transaction record query")
void getCostInsufficientTxFeeTransactionRecord() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    var receipt = new TransactionReceiptQuery().setTransactionId(response.transactionId).execute(testEnv.client);
    var recordQuery = new TransactionRecordQuery().setTransactionId(response.transactionId);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        recordQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    testEnv.close(receipt.accountId, key);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TransactionRecordQuery

use of com.hedera.hashgraph.sdk.TransactionRecordQuery in project hedera-mirror-node by hashgraph.

the class TransactionPublisher method processTransactionResponse.

private Mono<PublishResponse.PublishResponseBuilder> processTransactionResponse(Client client, PublishRequest request, TransactionResponse transactionResponse) {
    TransactionId transactionId = transactionResponse.transactionId;
    PublishResponse.PublishResponseBuilder builder = PublishResponse.builder().request(request).timestamp(Instant.now()).transactionId(transactionId);
    if (request.isRecord()) {
        // TransactionId.getRecord() is inefficient doing a get receipt, a cost query, then the get record
        TransactionRecordQuery transactionRecordQuery = new TransactionRecordQuery().setQueryPayment(Hbar.from(1, HbarUnit.HBAR)).setTransactionId(transactionId);
        return execute(client, transactionRecordQuery).map(r -> builder.record(r).receipt(r.receipt));
    } else if (request.isReceipt()) {
        var receiptQuery = new TransactionReceiptQuery().setTransactionId(transactionId);
        return execute(client, receiptQuery).map(builder::receipt);
    }
    return Mono.just(builder);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) TransactionId(com.hedera.hashgraph.sdk.TransactionId)

Example 5 with TransactionRecordQuery

use of com.hedera.hashgraph.sdk.TransactionRecordQuery 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);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) AccountId(com.hedera.hashgraph.sdk.AccountId) PublicKey(com.hedera.hashgraph.sdk.PublicKey) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) KeyList(com.hedera.hashgraph.sdk.KeyList) AccountBalanceQuery(com.hedera.hashgraph.sdk.AccountBalanceQuery) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) ScheduleId(com.hedera.hashgraph.sdk.ScheduleId) ScheduleInfo(com.hedera.hashgraph.sdk.ScheduleInfo) TransactionId(com.hedera.hashgraph.sdk.TransactionId) TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) AccountBalance(com.hedera.hashgraph.sdk.AccountBalance) Client(com.hedera.hashgraph.sdk.Client) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) TransactionRecord(com.hedera.hashgraph.sdk.TransactionRecord)

Aggregations

TransactionRecordQuery (com.hedera.hashgraph.sdk.TransactionRecordQuery)5 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)4 TransactionReceiptQuery (com.hedera.hashgraph.sdk.TransactionReceiptQuery)4 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 TransactionId (com.hedera.hashgraph.sdk.TransactionId)2 AccountBalance (com.hedera.hashgraph.sdk.AccountBalance)1 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)1 AccountId (com.hedera.hashgraph.sdk.AccountId)1 Client (com.hedera.hashgraph.sdk.Client)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 KeyList (com.hedera.hashgraph.sdk.KeyList)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 PublicKey (com.hedera.hashgraph.sdk.PublicKey)1 ScheduleId (com.hedera.hashgraph.sdk.ScheduleId)1 ScheduleInfo (com.hedera.hashgraph.sdk.ScheduleInfo)1 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)1 ScheduleSignTransaction (com.hedera.hashgraph.sdk.ScheduleSignTransaction)1 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)1 TransactionRecord (com.hedera.hashgraph.sdk.TransactionRecord)1