Skip to content

Commit 7c9ca5f

Browse files
committed
replaced throwOnError with throwOnWarning
1 parent 5088e51 commit 7c9ca5f

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Sources/Web3Core/KeystoreManager/BIP44.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import Foundation
77

88
public protocol BIP44 {
99
/**
10-
Derive an ``HDNode`` based on the provided path. The function will throw ``BIP44Error.warning`` if it was invoked with throwOnError equal to`true` and the root key doesn't have a previous child with at least one transaction. If it is invoked with throwOnError equal to `false` the child node will be derived directly using the derive function of ``HDNode``. This function needs to query the blockchain history when throwOnError is `true`, so it can throw network errors.
10+
Derive an ``HDNode`` based on the provided path. The function will throw ``BIP44Error.warning`` if it was invoked with throwOnWarning equal to`true` and the root key doesn't have a previous child with at least one transaction. If it is invoked with throwOnError equal to `false` the child node will be derived directly using the derive function of ``HDNode``. This function needs to query the blockchain history when throwOnWarning is `true`, so it can throw network errors.
1111
- Parameter path: valid BIP44 path.
12-
- Parameter throwOnError: `true` to use [Account Discovery](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery) standard, otherwise it will dervive the key using the derive function of ``HDNode``.
12+
- Parameter throwOnWarning: `true` to use [Account Discovery](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery) standard, otherwise it will dervive the key using the derive function of ``HDNode``.
1313
- Throws: ``BIP44Error.warning`` if the child key shouldn't be used according to [Account Discovery](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery) standard.
1414
- Returns: an ``HDNode`` child key for the provided `path` if it can be created, otherwise `nil`
1515
*/
16-
func derive(path: String, throwOnError: Bool, transactionChecker: TransactionChecker) async throws -> HDNode?
16+
func derive(path: String, throwOnWarning: Bool, transactionChecker: TransactionChecker) async throws -> HDNode?
1717
}
1818

1919
public enum BIP44Error: LocalizedError, Equatable {
@@ -39,8 +39,8 @@ public protocol TransactionChecker {
3939
}
4040

4141
extension HDNode: BIP44 {
42-
public func derive(path: String, throwOnError: Bool = true, transactionChecker: TransactionChecker) async throws -> HDNode? {
43-
guard throwOnError else {
42+
public func derive(path: String, throwOnWarning: Bool = true, transactionChecker: TransactionChecker) async throws -> HDNode? {
43+
guard throwOnWarning else {
4444
return derive(path: path, derivePrivateKey: true)
4545
}
4646
guard let account = path.accountFromPath else {

Tests/web3swiftTests/localTests/BIP44Tests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ final class BIP44Tests: XCTestCase {
5757
}
5858
private var mockTransactionChecker: MockTransactionChecker = .init()
5959

60-
func testDeriveWithoutThrowOnError() async throws {
60+
func testDeriveWithoutThrowOnWarning() async throws {
6161
let rootNode = try rootNode()
6262

63-
let childNode = try await rootNode.derive(path: "m/44'/60'/8096'/0/1", throwOnError: false, transactionChecker: mockTransactionChecker)
63+
let childNode = try await rootNode.derive(path: "m/44'/60'/8096'/0/1", throwOnWarning: false, transactionChecker: mockTransactionChecker)
6464

6565
XCTAssertEqual(try XCTUnwrap(childNode).publicKey.toHexString(), "035785d4918449c87892371c0f9ccf6e4eda40a7fb0f773f1254c064d3bba64026")
6666
XCTAssertEqual(mockTransactionChecker.addresses.count, 0)
@@ -69,7 +69,7 @@ final class BIP44Tests: XCTestCase {
6969
func testDeriveInvalidPath() async throws {
7070
let rootNode = try rootNode()
7171

72-
let childNode = try? await rootNode.derive(path: "", throwOnError: true, transactionChecker: mockTransactionChecker)
72+
let childNode = try? await rootNode.derive(path: "", throwOnWarning: true, transactionChecker: mockTransactionChecker)
7373

7474
XCTAssertNil(childNode)
7575
XCTAssertEqual(mockTransactionChecker.addresses.count, 0)
@@ -80,7 +80,7 @@ final class BIP44Tests: XCTestCase {
8080
func testZeroAccountNeverThrow() async throws {
8181
let rootNode = try rootNode()
8282

83-
let childNode = try await rootNode.derive(path: "m/44'/60'/0'/0/255", throwOnError: true, transactionChecker: mockTransactionChecker)
83+
let childNode = try await rootNode.derive(path: "m/44'/60'/0'/0/255", throwOnWarning: true, transactionChecker: mockTransactionChecker)
8484

8585
XCTAssertEqual(try XCTUnwrap(childNode).publicKey.toHexString(), "0262fba1af8f149258123265318114066decf50d16c1222a9d657b7de2296c2734")
8686
XCTAssertEqual(mockTransactionChecker.addresses.count, 0)
@@ -94,9 +94,9 @@ final class BIP44Tests: XCTestCase {
9494
results.append(true)
9595
mockTransactionChecker.results = results
9696

97-
_ = try await rootNode.derive(path: path, throwOnError: true, transactionChecker: mockTransactionChecker)
97+
_ = try await rootNode.derive(path: path, throwOnWarning: true, transactionChecker: mockTransactionChecker)
9898

99-
XCTFail("Child must not be created using warns true for the path: \(path)")
99+
XCTFail("Child must not be created using throwOnWarning true for the path: \(path)")
100100
} catch BIP44Error.warning {
101101
XCTAssertEqual(mockTransactionChecker.addresses, accountZeroScannedAddresses)
102102
}
@@ -110,7 +110,7 @@ final class BIP44Tests: XCTestCase {
110110
results.append(true)
111111
mockTransactionChecker.results = results
112112

113-
let childNode = try await rootNode.derive(path: path, throwOnError: true, transactionChecker: mockTransactionChecker)
113+
let childNode = try await rootNode.derive(path: path, throwOnWarning: true, transactionChecker: mockTransactionChecker)
114114

115115
XCTAssertEqual(try XCTUnwrap(childNode).publicKey.toHexString(), "036cd8f1bad46fa7caf7a80d48528b90db2a3b7a5c9a18d74d61b286e03850abf4")
116116
XCTAssertEqual(mockTransactionChecker.addresses, accountZeroScannedAddresses)
@@ -128,9 +128,9 @@ final class BIP44Tests: XCTestCase {
128128
results.append(contentsOf: false.times(n: 20))
129129
mockTransactionChecker.results = results
130130

131-
_ = try await rootNode.derive(path: path, throwOnError: true, transactionChecker: mockTransactionChecker)
131+
_ = try await rootNode.derive(path: path, throwOnWarning: true, transactionChecker: mockTransactionChecker)
132132

133-
XCTFail("Child must not be created using warns true for the path: \(path)")
133+
XCTFail("Child must not be created using throwOnWarning true for the path: \(path)")
134134
} catch BIP44Error.warning {
135135
XCTAssertEqual(mockTransactionChecker.addresses, accountZeroAndOneScannedAddresses)
136136
XCTAssertEqual(mockTransactionChecker.addresses.count, 21)
@@ -147,7 +147,7 @@ final class BIP44Tests: XCTestCase {
147147
results.append(true)
148148
mockTransactionChecker.results = results
149149

150-
let childNode = try await rootNode.derive(path: path, throwOnError: true, transactionChecker: mockTransactionChecker)
150+
let childNode = try await rootNode.derive(path: path, throwOnWarning: true, transactionChecker: mockTransactionChecker)
151151

152152
XCTAssertEqual(try XCTUnwrap(childNode).publicKey.toHexString(), "0282134e44d4c040a4b4c1a780d8302955096cf1d5e738b161c83f0ce1b863c14e")
153153
XCTAssertEqual(mockTransactionChecker.addresses, accountZeroScannedAddresses)

0 commit comments

Comments
 (0)