Skip to content

Commit 7bd664e

Browse files
Merge pull request #605 from JeneaVranceanu/fix/warnings
2 parents b8d54f6 + 8f21f33 commit 7bd664e

File tree

5 files changed

+10
-46
lines changed

5 files changed

+10
-46
lines changed

Sources/Core/Transaction/EthereumTransaction.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public struct EthereumTransaction: CustomStringConvertible {
178178
public func encodeAsDictionary(from: EthereumAddress? = nil) -> TransactionParameters? { self.envelope.encodeAsDictionary(from: from) }
179179

180180
/// - Returns: a raw bytestream of the transaction, encoded according to the transactionType
181-
func encode(for type: EncodeType = .transaction) -> Data? {
181+
public func encode(for type: EncodeType = .transaction) -> Data? {
182182
return self.envelope.encode(for: type)
183183
}
184184
}
@@ -399,8 +399,7 @@ extension EthereumTransaction {
399399

400400
@available(*, deprecated, message: "use encode() instead")
401401
public func encode(forSignature: Bool = false, chainID: BigUInt? = nil) -> Data? {
402-
if forSignature == true { return self.envelope.encode(for: .signature) }
403-
return self.envelope.encode(for: .transaction)
402+
envelope.encode(for: forSignature ? .signature : .transaction)
404403
}
405404

406405
@available(*, deprecated, message: "use Decodable instead")

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendRawTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension web3.Eth {
1717
}
1818

1919
public func send(raw transaction: EthereumTransaction) async throws -> TransactionSendingResult {
20-
guard let transactionHexData = transaction.encode()?.toHexString().addHexPrefix() else { throw Web3Error.dataError }
20+
guard let transactionHexData = transaction.encode(for: .transaction)?.toHexString().addHexPrefix() else { throw Web3Error.dataError }
2121
let request: APIRequest = .sendRawTransaction(transactionHexData)
2222
let response: APIResponse<Hash> = try await APIRequest.sendRequest(with: self.provider, for: request)
2323

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ extension web3.BrowserFunctions {
207207
guard let keystore = keystoreManager.walletForAddress(from) else {return nil}
208208
try Web3Signer.signTX(transaction: &transaction, keystore: keystore, account: from, password: password)
209209
print(transaction)
210-
let signedData = transaction.encode()?.toHexString().addHexPrefix()
210+
let signedData = transaction.encode(for: .transaction)?.toHexString().addHexPrefix()
211211
return signedData
212212
} catch {
213213
return nil

Tests/web3swiftTests/localTests/LocalTests.xctestplan

Lines changed: 0 additions & 35 deletions
This file was deleted.

Tests/web3swiftTests/localTests/TransactionsTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class TransactionsTests: XCTestCase {
235235

236236
// now sign the transaction with the private key
237237
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
238-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
238+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
239239

240240
// check the hash, if they match everything was parsed, and re-encoded correctly
241241
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
@@ -304,7 +304,7 @@ class TransactionsTests: XCTestCase {
304304

305305
// now sign the transaction with the private key
306306
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
307-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
307+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
308308

309309
// check the hash, if they match everything was parsed, and re-encoded correctly
310310
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
@@ -373,7 +373,7 @@ class TransactionsTests: XCTestCase {
373373

374374
// now sign the transaction with the private key
375375
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
376-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
376+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
377377

378378
// check the hash, if they match everything was parsed, and re-encoded correctly
379379
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
@@ -442,7 +442,7 @@ class TransactionsTests: XCTestCase {
442442

443443
// now sign the transaction with the private key
444444
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
445-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
445+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
446446

447447
// check the hash, if they match everything was parsed, and re-encoded correctly
448448
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
@@ -511,7 +511,7 @@ class TransactionsTests: XCTestCase {
511511

512512
// now sign the transaction with the private key
513513
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
514-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
514+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
515515

516516
// check the hash, if they match everything was parsed, and re-encoded correctly
517517
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
@@ -580,7 +580,7 @@ class TransactionsTests: XCTestCase {
580580

581581
// now sign the transaction with the private key
582582
try jsonTxn.sign(privateKey: privateKeyData, useExtraEntropy: false)
583-
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
583+
let rawTxn = jsonTxn.encode(for: .transaction)!.toHexString().addHexPrefix()
584584

585585
// check the hash, if they match everything was parsed, and re-encoded correctly
586586
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")

0 commit comments

Comments
 (0)