use of com.hedera.hashgraph.sdk.PrivateKey in project hedera-mirror-node by hashgraph.
the class ScheduleFeature method createNewCryptoAccountSchedule.
@Given("I schedule a crypto transfer with {int} initial signatures but require an additional signature from " + "{string}")
public void createNewCryptoAccountSchedule(int initSignatureCount, String accountName) {
// new account, accountName and initSignatureCount
expectedSignersCount = 2 + initSignatureCount;
currentSignersCount = initSignatureCount + signatoryCountOffset;
ExpandedAccountId finalSignatory = accountClient.getAccount(AccountClient.AccountNameEnum.valueOf(accountName));
KeyList privateKeyList = new KeyList();
KeyList publicKeyList = new KeyList();
for (int i = 0; i < initSignatureCount; i++) {
PrivateKey accountKey = PrivateKey.generate();
privateKeyList.add(accountKey);
publicKeyList.add(accountKey.getPublicKey());
}
// additional signatory not provided up front to prevent schedule from executing
publicKeyList.add(finalSignatory.getPublicKey());
ExpandedAccountId newAccountId = accountClient.createCryptoAccount(Hbar.fromTinybars(DEFAULT_TINY_HBAR), false, publicKeyList, "scheduled transfer");
scheduledTransaction = accountClient.getCryptoTransferTransaction(newAccountId.getAccountId(), accountClient.getSdkClient().getExpandedOperatorAccountId().getAccountId(), Hbar.fromTinybars(DEFAULT_TINY_HBAR));
// add sender private key to ensure only Alice's signature is the only signature left that is required
privateKeyList.add(newAccountId.getPrivateKey());
createNewSchedule(scheduledTransaction, privateKeyList);
currentSignersCount++;
}
use of com.hedera.hashgraph.sdk.PrivateKey in project hedera-mirror-node by hashgraph.
the class AccountClient method createCryptoAccount.
public ExpandedAccountId createCryptoAccount(Hbar initialBalance, boolean receiverSigRequired, KeyList keyList, String memo) {
// 1. Generate a Ed25519 private, public key pair
PrivateKey privateKey = PrivateKey.generate();
PublicKey publicKey = privateKey.getPublicKey();
log.trace("Private key = {}", privateKey);
log.trace("Public key = {}", publicKey);
KeyList publicKeyList = KeyList.of(privateKey.getPublicKey());
if (keyList != null) {
publicKeyList.addAll(keyList);
}
AccountCreateTransaction accountCreateTransaction = getAccountCreateTransaction(initialBalance, publicKeyList, receiverSigRequired, memo == null ? "" : memo);
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(accountCreateTransaction, receiverSigRequired ? KeyList.of(privateKey) : null);
TransactionReceipt receipt = networkTransactionResponse.getReceipt();
AccountId newAccountId = receipt.accountId;
// verify accountId
if (receipt.accountId == null) {
throw new NetworkException(String.format("Receipt for %s returned no accountId, receipt: %s", networkTransactionResponse.getTransactionId(), receipt));
}
log.debug("Created new account {}, receiverSigRequired: {}", newAccountId, receiverSigRequired);
return new ExpandedAccountId(newAccountId, privateKey, privateKey.getPublicKey());
}
use of com.hedera.hashgraph.sdk.PrivateKey in project hedera-mirror-node by hashgraph.
the class ScheduleClient method createSchedule.
public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountId, Transaction transaction, KeyList signatureKeyList) {
String memo = getMemo("Create schedule");
ScheduleCreateTransaction scheduleCreateTransaction = new ScheduleCreateTransaction().setAdminKey(payerAccountId.getPublicKey()).setMaxTransactionFee(sdkClient.getMaxTransactionFee()).setPayerAccountId(payerAccountId.getAccountId()).setScheduleMemo(memo).setScheduledTransaction(transaction).setTransactionMemo(memo);
if (signatureKeyList != null) {
scheduleCreateTransaction.setNodeAccountIds(List.of(sdkClient.getRandomNodeAccountId())).freezeWith(client);
// add initial set of required signatures to ScheduleCreate transaction
signatureKeyList.forEach(k -> {
PrivateKey pk = (PrivateKey) k;
byte[] signature = pk.signTransaction(scheduleCreateTransaction);
scheduleCreateTransaction.addSignature(pk.getPublicKey(), signature);
});
}
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(scheduleCreateTransaction);
ScheduleId scheduleId = networkTransactionResponse.getReceipt().scheduleId;
log.debug("Created new schedule {}", scheduleId);
return networkTransactionResponse;
}
use of com.hedera.hashgraph.sdk.PrivateKey in project hedera-mirror-node by hashgraph.
the class TransactionPublisher method toClient.
private Client toClient(Map<String, AccountId> nodes) {
AccountId operatorId = AccountId.fromString(monitorProperties.getOperator().getAccountId());
PrivateKey operatorPrivateKey = PrivateKey.fromString(monitorProperties.getOperator().getPrivateKey());
Client client = Client.forNetwork(nodes);
client.setNodeMaxBackoff(publishProperties.getNodeMaxBackoff());
client.setOperator(operatorId, operatorPrivateKey);
return client;
}
use of com.hedera.hashgraph.sdk.PrivateKey in project hedera-mirror-node by hashgraph.
the class AccountCreateTransactionSupplier method generateKeys.
private PublicKey generateKeys() {
PrivateKey privateKey = PrivateKey.generate();
// provide an option to print them
if (logKeys) {
log.info("privateKey: {}", privateKey);
log.info("publicKey: {}", privateKey.getPublicKey());
}
return privateKey.getPublicKey();
}
Aggregations