From e0693ac6e75bc16c0c37ed235ffa457b2e050e48 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Thu, 12 Dec 2019 10:55:46 -0800 Subject: [PATCH] Fix issues with examples --- .../sdk/examples/advanced/CreateAccountThresholdKey.java | 2 ++ .../hashgraph/sdk/examples/advanced/CreateFile.java | 5 ++--- .../sdk/examples/advanced/MultiAppTransfer.java | 2 ++ .../com/hedera/hashgraph/sdk/TransactionBuilder.java | 9 +++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateAccountThresholdKey.java b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateAccountThresholdKey.java index 518565757..f4f755888 100644 --- a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateAccountThresholdKey.java +++ b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateAccountThresholdKey.java @@ -68,6 +68,8 @@ public static void main(String[] args) throws HederaException { TransactionId tsfrTxnId = new CryptoTransferTransaction() .addSender(newAccountId, 50_000) .addRecipient(AccountId.fromString(Objects.requireNonNull(Dotenv.load().get("NODE_ID"))), 50_000) + // To manually sign, you must explicitly build the Transaction + .build(client) // we sign with 2 of the 3 keys .sign(keys.get(0)) .sign(keys.get(1)) diff --git a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateFile.java b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateFile.java index a743dea7b..42489ab95 100644 --- a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateFile.java +++ b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/CreateFile.java @@ -37,12 +37,11 @@ public static void main(String[] args) throws HederaException { byte[] fileContents = "Hedera hashgraph is great!".getBytes(); TransactionId txId = new FileCreateTransaction() - .setExpirationTime( - Instant.now() - .plus(Duration.ofSeconds(2592000))) // Use the same key as the operator to "own" this file .addKey(OPERATOR_KEY.getPublicKey()) .setContents(fileContents) + // The default max fee of 1 HBAR is not enough to make a file ( starts around 1.1 HBAR ) + .setMaxTransactionFee(200_000_000) // 2 HBAR .execute(client); TransactionReceipt receipt = txId.getReceipt(client); diff --git a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/MultiAppTransfer.java b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/MultiAppTransfer.java index 32ce5a915..f1d74c219 100644 --- a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/MultiAppTransfer.java +++ b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/advanced/MultiAppTransfer.java @@ -53,6 +53,7 @@ public static void main(String[] args) throws HederaException, InvalidProtocolBu .setKey(exchangeKey.getPublicKey()) // The owner key has to sign this transaction // when setReceiverSignatureRequired is true + .build(client) .sign(exchangeKey) .execute(client); @@ -63,6 +64,7 @@ public static void main(String[] args) throws HederaException, InvalidProtocolBu .addRecipient(exchangeAccountId, transferAmount) // the exchange-provided memo required to validate the transaction .setMemo("https://some-exchange.com/user1/account1") + // To manually sign, you must explicitly build the Transaction .build(client) .sign(userKey); diff --git a/src/main/java/com/hedera/hashgraph/sdk/TransactionBuilder.java b/src/main/java/com/hedera/hashgraph/sdk/TransactionBuilder.java index e04f94d1f..a6a4cbfa3 100644 --- a/src/main/java/com/hedera/hashgraph/sdk/TransactionBuilder.java +++ b/src/main/java/com/hedera/hashgraph/sdk/TransactionBuilder.java @@ -177,13 +177,14 @@ public final Transaction build(@Nullable Client client) { localValidate(); - inner.setBodyBytes( - bodyBuilder.build() - .toByteString()); + inner.setBodyBytes(bodyBuilder.build().toByteString()); Transaction tx = new Transaction(null, inner, bodyBuilder, getMethod()); - if (client != null && client.getOperatorKey() != null) { + // Sign with the operator if there is a client; the client has an operator; and, the transaction + // has a transaction ID that matches that operator ( which it would unless overridden ). + if (client != null && client.getOperatorKey() != null && client.getOperatorId() != null && + client.getOperatorId().equals(new AccountId(bodyBuilder.getTransactionID().getAccountID()))) { tx.sign(client.getOperatorKey()); }