Skip to content

Commit

Permalink
[FIX] Cache number representation in EthereumAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthMike committed Mar 3, 2023
1 parent 855c8d1 commit 7e620cf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions web3swift/src/Client/Models/EthereumAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ public struct EthereumAddress: Codable, Hashable {
}

private let raw: String
private let numberRepresentation: BigUInt?
public static let zero: Self = "0x0000000000000000000000000000000000000000"

public init(_ value: String) {
self.raw = value.lowercased()
self.numberRepresentation = BigUInt(hex: raw)
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.raw = try container.decode(String.self).lowercased()
let raw = try container.decode(String.self).lowercased()
self.raw = raw
self.numberRepresentation = BigUInt(hex: raw)
}

public func encode(to encoder: Encoder) throws {
Expand Down Expand Up @@ -51,7 +55,7 @@ public extension EthereumAddress {
}

func asNumber() -> BigUInt? {
.init(hex: raw)
numberRepresentation
}

func asData() -> Data? {
Expand Down

0 comments on commit 7e620cf

Please sign in to comment.