Skip to content

Commit

Permalink
Fix issues with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Dec 12, 2019
1 parent c5ba44e commit e0693ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit e0693ac

Please sign in to comment.