Search in sources :

Example 11 with PrivateKey

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++;
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) KeyList(com.hedera.hashgraph.sdk.KeyList) Given(io.cucumber.java.en.Given)

Example 12 with PrivateKey

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());
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) AccountId(com.hedera.hashgraph.sdk.AccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) PublicKey(com.hedera.hashgraph.sdk.PublicKey) KeyList(com.hedera.hashgraph.sdk.KeyList) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction)

Example 13 with PrivateKey

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;
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) ScheduleId(com.hedera.hashgraph.sdk.ScheduleId) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction)

Example 14 with PrivateKey

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;
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) Client(com.hedera.hashgraph.sdk.Client)

Example 15 with PrivateKey

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();
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey)

Aggregations

PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)28 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)16 AccountId (com.hedera.hashgraph.sdk.AccountId)16 Client (com.hedera.hashgraph.sdk.Client)15 Hbar (com.hedera.hashgraph.sdk.Hbar)13 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)13 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)13 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)11 KeyList (com.hedera.hashgraph.sdk.KeyList)10 PublicKey (com.hedera.hashgraph.sdk.PublicKey)9 Var (com.google.errorprone.annotations.Var)7 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)6 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)6 ScheduleId (com.hedera.hashgraph.sdk.ScheduleId)6 ScheduleSignTransaction (com.hedera.hashgraph.sdk.ScheduleSignTransaction)6 ScheduleCreateTransaction (com.hedera.hashgraph.sdk.ScheduleCreateTransaction)5 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)5 ScheduleInfo (com.hedera.hashgraph.sdk.ScheduleInfo)4 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)4 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)4