File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Sources/web3swift/Utils/ERC Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // ERCBasePropertiesProvider.swift
3
+ //
4
+ //
5
+ // Created by Jann Driessen on 21.11.22.
6
+ //
7
+
8
+ import BigInt
9
+ import Foundation
10
+
11
+ public final class ERCBasePropertiesProvider {
12
+ var name : String ?
13
+ var symbol : String ?
14
+ var decimals : UInt8 ?
15
+
16
+ private let contract : Web3 . Contract
17
+ private ( set) var hasReadProperties : Bool = false
18
+ init ( contract: Web3 . Contract ) {
19
+ self . contract = contract
20
+ }
21
+
22
+ public func readProperties( ) async throws {
23
+ guard !hasReadProperties else { return }
24
+ guard contract. contract. address != nil else { return }
25
+ name = try await contract
26
+ . createReadOperation ( " name " ) ?
27
+ . callContractMethod ( ) [ " 0 " ] as? String
28
+
29
+ symbol = try await contract
30
+ . createReadOperation ( " symbol " ) ?
31
+ . callContractMethod ( ) [ " 0 " ] as? String
32
+
33
+ let decimals = try await contract
34
+ . createReadOperation ( " decimals " ) ?
35
+ . callContractMethod ( ) [ " 0 " ] as? BigUInt
36
+ self . decimals = decimals != nil ? UInt8 ( decimals!) : nil
37
+ hasReadProperties = true
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments