Skip to content

Commit

Permalink
Merge 1f0bf80 into 896b905
Browse files Browse the repository at this point in the history
  • Loading branch information
Nana-EC authored Apr 14, 2021
2 parents 896b905 + 1f0bf80 commit 77b97de
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 113 deletions.
2 changes: 1 addition & 1 deletion hedera-mirror-datagenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
</dependency>
<dependency>
<groupId>com.hedera</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public ScheduleCreateTransaction get() {

// set nodeAccountId and freeze inner transaction
TransactionId transactionId = TransactionId.generate(getOperatorId());
innerTransaction.setNodeAccountIds(Collections.singletonList(getNodeId()));
innerTransaction.setTransactionId(transactionId.setScheduled(true));
innerTransaction.freeze();

String scheduleMemo = Utility.getMemo("Mirror node created test schedule");
ScheduleCreateTransaction scheduleCreateTransaction = innerTransaction
Expand All @@ -119,15 +117,20 @@ public ScheduleCreateTransaction get() {
scheduleCreateTransaction.setAdminKey(getAdminPublicKey());
}

if (payerAccount != null) {
scheduleCreateTransaction.setPayerAccountId(getPayerAccountId());
if (operatorId != null) {
scheduleCreateTransaction.setPayerAccountId(getOperatorId());
}

// add initial set of required signatures to ScheduleCreate transaction
if (totalSignatoryCount > 0) {
getSigningKeys().forEach(k -> scheduleCreateTransaction.addScheduleSignature(
k.getPublicKey(),
k.signTransaction(innerTransaction)));
scheduleCreateTransaction.setNodeAccountIds(Collections.singletonList(getNodeId()));
getSigningKeys().forEach(pk -> {
byte[] signature = pk.signTransaction(scheduleCreateTransaction);
scheduleCreateTransaction.addSignature(
pk.getPublicKey(),
signature);
});
log.debug("Added {} signatures to ScheduleCreate", totalSignatoryCount);
}

return scheduleCreateTransaction;
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.hedera.hashgraph.sdk.AccountId;
import com.hedera.hashgraph.sdk.Client;
import com.hedera.hashgraph.sdk.PrivateKey;
import com.hedera.hashgraph.sdk.Transaction;
import com.hedera.hashgraph.sdk.TransactionId;
import com.hedera.hashgraph.sdk.TransactionResponse;
import com.hedera.mirror.monitor.MonitorProperties;
Expand Down Expand Up @@ -84,11 +85,8 @@ private Mono<PublishResponse> doPublish(PublishRequest request) {
log.trace("Publishing: {}", request);
int clientIndex = counter.getAndUpdate(n -> (n + 1 < clients.get().size()) ? n + 1 : 0);
Client client = clients.get().get(clientIndex);
int nodeIndex = secureRandom.nextInt(nodeAccountIds.get().size());
List<AccountId> nodeAccountId = List.of(nodeAccountIds.get().get(nodeIndex));

return Mono
.fromFuture(() -> request.getTransaction().setNodeAccountIds(nodeAccountId).executeAsync(client))
return getTransactionResponse(request, client)
.flatMap(transactionResponse -> processTransactionResponse(client, request, transactionResponse))
.map(PublishResponse.PublishResponseBuilder::build)
.doOnNext(response -> {
Expand All @@ -99,8 +97,22 @@ private Mono<PublishResponse> doPublish(PublishRequest request) {
.timeout(request.getTimeout());
}

private Mono<TransactionResponse> getTransactionResponse(PublishRequest request, Client client) {
Transaction transaction = request.getTransaction();

// set transaction node where applicable
if (transaction.getNodeAccountIds() == null) {
int nodeIndex = secureRandom.nextInt(nodeAccountIds.get().size());
List<AccountId> nodeAccountId = List.of(nodeAccountIds.get().get(nodeIndex));
transaction.setNodeAccountIds(nodeAccountId);
}

return Mono.fromFuture(transaction.executeAsync(client));
}

private Mono<PublishResponse.PublishResponseBuilder> processTransactionResponse(Client client,
PublishRequest request, TransactionResponse transactionResponse) {
PublishRequest request,
TransactionResponse transactionResponse) {
TransactionId transactionId = transactionResponse.transactionId;
PublishResponse.PublishResponseBuilder builder = PublishResponse.builder()
.request(request)
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public TransactionId executeTransaction(Transaction transaction, KeyList keyList
for (Key k : keyList) {
transaction = transaction.sign((PrivateKey) k);
}
log.debug("{} additional signatures added to transaction", keyList.size());
}

TransactionResponse transactionResponse = (TransactionResponse) transaction.execute(client);
TransactionId transactionId = transactionResponse.transactionId;
log.debug("Executed transaction {}.", transactionId);
log.debug("Executed transaction {} w {} signatures.", transactionId, keyList == null ? 0 : keyList.size());

return transactionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
import lombok.Value;
import lombok.extern.log4j.Log4j2;

import com.hedera.hashgraph.sdk.KeyList;
import com.hedera.hashgraph.sdk.PrecheckStatusException;
import com.hedera.hashgraph.sdk.PrivateKey;
import com.hedera.hashgraph.sdk.ReceiptStatusException;
Expand All @@ -48,16 +48,12 @@ public ScheduleClient(SDKClient sdkClient) {
}

public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountId, Transaction transaction,
String memo, List<PrivateKey> innerSignatureKeyList) throws ReceiptStatusException,
String memo, KeyList innerSignatureKeyList) throws ReceiptStatusException,
PrecheckStatusException, TimeoutException {

log.debug("Create new schedule");
TransactionId transactionId = TransactionId.generate(sdkClient.getOperatorId()).setScheduled(true);

// set nodeAccountId and freeze inner transaction
transaction.setNodeAccountIds(Collections.singletonList(sdkClient.getNodeId()));
transaction.setTransactionId(transactionId);
transaction.freeze();

ScheduleCreateTransaction scheduleCreateTransaction = transaction.schedule()
.setAdminKey(payerAccountId.getPublicKey())
Expand All @@ -68,10 +64,16 @@ public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountI
.setTransactionMemo(memo);

if (innerSignatureKeyList != null) {
scheduleCreateTransaction.setNodeAccountIds(Collections.singletonList(sdkClient.getNodeId()));

// add initial set of required signatures to ScheduleCreate transaction
innerSignatureKeyList.forEach(k -> scheduleCreateTransaction.addScheduleSignature(
k.getPublicKey(),
k.signTransaction(transaction)));
innerSignatureKeyList.forEach(k -> {
PrivateKey pk = (PrivateKey) k;
byte[] signature = pk.signTransaction(scheduleCreateTransaction);
scheduleCreateTransaction.addSignature(
pk.getPublicKey(),
signature);
});
}

NetworkTransactionResponse networkTransactionResponse =
Expand All @@ -83,20 +85,16 @@ public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountI
}

public NetworkTransactionResponse signSchedule(ExpandedAccountId expandedAccountId,
Transaction scheduledTransaction,
ScheduleId scheduleId) throws ReceiptStatusException,
PrecheckStatusException, TimeoutException {

log.debug("Sign schedule {}", scheduleId);
byte[] signature = expandedAccountId.getPrivateKey().signTransaction(scheduledTransaction);

ScheduleSignTransaction scheduleSignTransaction = new ScheduleSignTransaction()
.setMaxTransactionFee(sdkClient.getMaxTransactionFee())
.setScheduleId(scheduleId)
.addScheduleSignature(expandedAccountId.getPublicKey(), signature);
.setScheduleId(scheduleId);

NetworkTransactionResponse networkTransactionResponse =
executeTransactionAndRetrieveReceipt(scheduleSignTransaction, null);
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(
scheduleSignTransaction,
KeyList.of(expandedAccountId.getPrivateKey()));
log.debug("Signed schedule {}", scheduleId);

return networkTransactionResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import lombok.Value;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ArrayUtils;

Expand All @@ -49,10 +48,10 @@
import com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse;

@Log4j2
@Value
public class TopicClient extends AbstractNetworkClient {
private static final Duration autoRenewPeriod = Duration.ofSeconds(8000000);
private final Map<Long, Instant> recordPublishInstants;
private TopicId defaultTopicId = null;

public TopicClient(SDKClient sdkClient) {
super(sdkClient);
Expand Down Expand Up @@ -151,6 +150,22 @@ public TopicMessageSubmitTransaction getTopicMessageSubmitTransaction(TopicId to
.setMessage(message);
}

public TopicId getDefaultTopicId() throws PrecheckStatusException, ReceiptStatusException, TimeoutException {
if (defaultTopicId == null) {
NetworkTransactionResponse networkTransactionResponse = createTopic(sdkClient
.getExpandedOperatorAccountId(), null);
defaultTopicId = networkTransactionResponse.getReceipt().topicId;
log.debug("Created TopicId: '{}' for use in current test session", defaultTopicId);
}

return defaultTopicId;
}

public void publishMessageToDefaultTopic() throws ReceiptStatusException, PrecheckStatusException,
TimeoutException {
publishMessagesToTopic(getDefaultTopicId(), "Background message", null, 1, false);
}

public TransactionId publishMessageToTopic(TopicId topicId, byte[] message, KeyList submitKeys) throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
TopicMessageSubmitTransaction consensusMessageSubmitTransaction = new TopicMessageSubmitTransaction()
.setTopicId(topicId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public void createNewAccount(long initialBalance) throws ReceiptStatusException,
assertNotNull(accountId);
}

@When("I send {long} tℏ to newly created account")
public void sendTinyHbars(long amount) throws TimeoutException, PrecheckStatusException,
ReceiptStatusException {
startingBalance = accountClient.getBalance(accountId);
TransactionReceipt receipt = accountClient.sendCryptoTransfer(accountId, Hbar.fromTinybars(amount));
assertNotNull(receipt);
}

@When("I send {long} tℏ to account {int}")
public void sendTinyHbars(long amount, int accountNum) throws TimeoutException, PrecheckStatusException,
ReceiptStatusException {
Expand Down
Loading

0 comments on commit 77b97de

Please sign in to comment.