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;
}
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);
}
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;
}
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());
}
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();
}
Aggregations