@@ -15,21 +15,26 @@ public class WriteOperation: ReadOperation {
15
15
/// - Parameters:
16
16
/// - password: Password for private key.
17
17
/// - 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 {
19
19
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) " )
31
36
}
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 )
34
39
}
35
40
}
0 commit comments