Skip to content

Commit eea9749

Browse files
pharms-ethJeneaVranceanu
authored andcommitted
fix bugs
1 parent 57fb16b commit eea9749

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Sources/Core/EthereumABI/ABIElements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ extension ABI.Element.Function {
202202

203203
/// Encode parameters of a given contract method
204204
/// - Parameter parameters: Parameters to pass to Ethereum contract
205-
/// - Returns: Encoded data
205+
/// - Returns: Encoded data
206206
public func encodeParameters(_ parameters: [AnyObject]) -> Data? {
207207
guard parameters.count == inputs.count,
208208
let data = ABIEncoder.encode(types: inputs, values: parameters) else { return nil }
@@ -325,7 +325,7 @@ extension ABI.Element.Function {
325325
// set a flag to detect the request succeeded
326326
}
327327

328-
if returnArray.isEmpty {
328+
if returnArray.isEmpty && !outputs.isEmpty {
329329
return nil
330330
}
331331

Sources/web3swift/Operations/WriteOperation.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,26 @@ public class WriteOperation: ReadOperation {
1515
/// - Parameters:
1616
/// - password: Password for private key.
1717
/// - policies: Custom policies for how to resolve (optional). Default is auto.
18-
public func writeToChain(password: String, policies: Policies = .auto) async throws -> TransactionSendingResult {
18+
public func writeToChain(password: String, policies: Policies = .auto, sendRaw: Bool = false) async throws -> TransactionSendingResult {
1919
try await policyResolver.resolveAll(for: &transaction, with: policies)
20-
if let attachedKeystoreManager = self.web3.provider.attachedKeystoreManager {
21-
do {
22-
try Web3Signer.signTX(transaction: &transaction,
23-
keystore: attachedKeystoreManager,
24-
account: transaction.from ?? transaction.sender ?? EthereumAddress.contractDeploymentAddress(),
25-
password: password)
26-
} catch {
27-
throw Web3Error.inputError(desc: "Failed to locally sign a transaction")
28-
}
29-
guard let transactionData = transaction.encode(for: .transaction) else { throw Web3Error.dataError }
30-
return try await web3.eth.send(raw: transactionData)
20+
21+
guard sendRaw else {
22+
return try await web3.eth.send(transaction)
23+
}
24+
25+
guard let attachedKeystoreManager = web3.provider.attachedKeystoreManager else {
26+
throw Web3Error.inputError(desc: "Failed to locally sign a transaction. Web3 provider doesn't have keystore attached.")
27+
}
28+
29+
do {
30+
try Web3Signer.signTX(transaction: &transaction,
31+
keystore: attachedKeystoreManager,
32+
account: transaction.from ?? transaction.sender ?? EthereumAddress.contractDeploymentAddress(),
33+
password: password)
34+
} catch {
35+
throw Web3Error.inputError(desc: "Failed to locally sign a transaction. \(error.localizedDescription)")
3136
}
32-
// MARK: Sending Data flow
33-
return try await web3.eth.send(transaction)
37+
guard let transactionData = transaction.encode(for: .transaction) else { throw Web3Error.dataError }
38+
return try await web3.eth.send(raw: transactionData)
3439
}
3540
}

0 commit comments

Comments
 (0)