Search in sources :

Example 6 with TransactionId

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

the class TopicClient method publishMessageToTopicAndVerify.

public TransactionReceipt publishMessageToTopicAndVerify(TopicId topicId, byte[] message, KeyList submitKeys) {
    TransactionId transactionId = publishMessageToTopic(topicId, message, submitKeys);
    TransactionReceipt transactionReceipt = null;
    try {
        transactionReceipt = getTransactionReceipt(transactionId);
        // note time stamp
        recordPublishInstants.put(transactionReceipt.topicSequenceNumber, getTransactionRecord(transactionId).consensusTimestamp);
    } catch (Exception e) {
        log.error("Error retrieving transaction receipt", e);
    }
    log.trace("Verified message published : '{}' to topicId : {} with sequence number : {}", message, topicId, transactionReceipt.topicSequenceNumber);
    return transactionReceipt;
}
Also used : TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) TransactionId(com.hedera.hashgraph.sdk.TransactionId)

Example 7 with TransactionId

use of com.hedera.hashgraph.sdk.TransactionId 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 8 with TransactionId

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

the class AbstractNetworkClient method executeTransaction.

public TransactionId executeTransaction(Transaction transaction, KeyList keyList, ExpandedAccountId payer) {
    int numSignatures = 0;
    // set max retries on sdk
    transaction.setMaxAttempts(sdkClient.getAcceptanceTestProperties().getSdkProperties().getMaxAttempts());
    if (payer != null) {
        transaction.setTransactionId(TransactionId.generate(payer.getAccountId()));
        transaction.freezeWith(client);
        transaction.sign(payer.getPrivateKey());
        numSignatures++;
    }
    if (keyList != null) {
        // Signing requires transaction to be frozen
        transaction.freezeWith(client);
        for (Key k : keyList) {
            transaction.sign((PrivateKey) k);
        }
        log.debug("{} additional signatures added to transaction", keyList.size());
        numSignatures += keyList.size();
    }
    TransactionResponse transactionResponse = retryTemplate.execute(x -> executeTransaction(transaction));
    TransactionId transactionId = transactionResponse.transactionId;
    log.debug("Executed transaction {} with {} signatures.", transactionId, numSignatures);
    return transactionId;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) Key(com.hedera.hashgraph.sdk.Key) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) TransactionId(com.hedera.hashgraph.sdk.TransactionId)

Example 9 with TransactionId

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

the class PublishMetricsTest method onErrorPrecheckStatusException.

@Test
void onErrorPrecheckStatusException() throws Exception {
    TransactionId transactionId = TransactionId.withValidStart(AccountId.fromString("0.0.3"), Instant.now());
    com.hedera.hashgraph.sdk.Status status = com.hedera.hashgraph.sdk.Status.SUCCESS;
    Constructor<PrecheckStatusException> constructor = getDeclaredConstructor(PrecheckStatusException.class);
    constructor.setAccessible(true);
    PrecheckStatusException precheckStatusException = constructor.newInstance(status, transactionId);
    onError(precheckStatusException, status.toString());
}
Also used : PrecheckStatusException(com.hedera.hashgraph.sdk.PrecheckStatusException) TransactionId(com.hedera.hashgraph.sdk.TransactionId) Test(org.junit.jupiter.api.Test)

Example 10 with TransactionId

use of com.hedera.hashgraph.sdk.TransactionId 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();
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) AccountId(com.hedera.hashgraph.sdk.AccountId) Var(com.google.errorprone.annotations.Var) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) KeyList(com.hedera.hashgraph.sdk.KeyList) AccountDeleteTransaction(com.hedera.hashgraph.sdk.AccountDeleteTransaction) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) ScheduleId(com.hedera.hashgraph.sdk.ScheduleId) ScheduleInfo(com.hedera.hashgraph.sdk.ScheduleInfo) TransactionId(com.hedera.hashgraph.sdk.TransactionId) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TransactionId (com.hedera.hashgraph.sdk.TransactionId)11 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)6 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)4 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)4 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)3 AccountId (com.hedera.hashgraph.sdk.AccountId)3 KeyList (com.hedera.hashgraph.sdk.KeyList)3 ScheduleId (com.hedera.hashgraph.sdk.ScheduleId)3 ScheduleInfo (com.hedera.hashgraph.sdk.ScheduleInfo)3 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)3 ScheduleSignTransaction (com.hedera.hashgraph.sdk.ScheduleSignTransaction)3 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)3 Test (org.junit.jupiter.api.Test)3 Var (com.google.errorprone.annotations.Var)2 Client (com.hedera.hashgraph.sdk.Client)2 Hbar (com.hedera.hashgraph.sdk.Hbar)2 ScheduleCreateTransaction (com.hedera.hashgraph.sdk.ScheduleCreateTransaction)2 TransactionRecord (com.hedera.hashgraph.sdk.TransactionRecord)2 TransactionRecordQuery (com.hedera.hashgraph.sdk.TransactionRecordQuery)2 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)2