Skip to content

Commit

Permalink
Add helper methods to TransactionBuilder and move operator sign step …
Browse files Browse the repository at this point in the history
…to TransactionBuilder.build
  • Loading branch information
qtbeee committed Nov 7, 2019
1 parent 9a8dc3f commit 0724401
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion Examples/CreateAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let receipt = try! AccountCreateTransaction(client: client)
.setInitialBalance(0)
.setKey(newAccountKey.publicKey)
.setMemo("Create Account Example - Swift SDK")
.build()
.executeForReceipt()

print("Account created: \(receipt.accountId!)")
1 change: 0 additions & 1 deletion Examples/CreateFile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let receipt = try! FileCreateTransaction(client: client)
.setContents("This is a test")
.setMemo("File Create Example - Swift SDK")
.setMaxTransactionFee(1_000_000_000)
.build()
.executeForReceipt()

print("File created: \(receipt.fileId!)")
1 change: 0 additions & 1 deletion Examples/TransferCrypto/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let receipt = try! CryptoTransferTransaction(client: client)
.add(sender: AccountId("0.0.3")!, amount: 10000)
.add(recipient: AccountId("0.0.2")!, amount: 10000)
.setMemo("Transfer Crypto Example - Swift SDK")
.build()
.executeForReceipt()

print("Crypto transferred successfully")
7 changes: 0 additions & 7 deletions Sources/Hedera/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ public class Transaction {
public func execute() throws -> TransactionId {
guard let client = client else { throw HederaError(message: "client must not be nil") }

if inner.sigMap.sigPair.isEmpty {
guard let clientOperator = client.`operator` else {
throw HederaError(message: "Client must have an operator set to execute")
}
addSigPair(publicKey: clientOperator.publicKey, signer: clientOperator.signer)
}

// TODO: actually handle error
do {
let response = try methodForTransaction(client.grpcClient(for: client.pickNode()))(inner)
Expand Down
17 changes: 16 additions & 1 deletion Sources/Hedera/TransactionBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ public class TransactionBuilder {
tx.body = body
// swiftlint:disable:next force_try
tx.bodyBytes = try! body.serializedData()

let transaction = Transaction(client, tx, body.transactionID)

// Sign with the operator, if present
if let client = client, let clientOperator = client.operator {
transaction.addSigPair(publicKey: clientOperator.publicKey, signer: clientOperator.signer)
}

return Transaction(client, tx, body.transactionID)
return transaction
}

public func execute() throws -> TransactionId {
try build().execute()
}

public func executeForReceipt() throws -> TransactionReceipt {
try build().executeForReceipt()
}
}

0 comments on commit 0724401

Please sign in to comment.