Skip to content

Commit d42c851

Browse files
committed
fix: adjust to failing bigint initializer in new version, that does not default to 0 when initializing from empty string
1 parent 0659da3 commit d42c851

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

web3swift/src/Extensions/HexExtensions.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88

99
public extension BigUInt {
1010
init?(hex: String) {
11-
self.init(hex.web3.noHexPrefix.lowercased(), radix: 16)
11+
self.init(hex.web3.noHexPrefix.web3.orZero.lowercased(), radix: 16)
1212
}
1313
}
1414

@@ -24,7 +24,7 @@ public extension Web3Extensions where Base == BigUInt {
2424

2525
public extension BigInt {
2626
init?(hex: String) {
27-
self.init(hex.web3.noHexPrefix.lowercased(), radix: 16)
27+
self.init(hex.web3.noHexPrefix.web3.orZero.lowercased(), radix: 16)
2828
}
2929
}
3030

@@ -79,6 +79,11 @@ public extension Web3Extensions where Base == String {
7979
return base
8080
}
8181

82+
var orZero: String {
83+
if base.isEmpty { return "0" }
84+
return base
85+
}
86+
8287
var stringValue: String {
8388
if let byteArray = try? HexUtil.byteArray(fromHex: base.web3.noHexPrefix), let str = String(bytes: byteArray, encoding: .utf8) {
8489
return str

0 commit comments

Comments
 (0)