File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Sources/web3swift/Promises Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // Promise+Web3+Eth+GetCode.swift
3+ // web3swift
4+ //
5+ // Created by Ndriqim Haxhaj on 8/25/21.
6+ //
7+
8+ import Foundation
9+ import PromiseKit
10+ import BigInt
11+
12+ extension web3 . Eth {
13+ public func getCodePromise( address: EthereumAddress , onBlock: String = " latest " ) -> Promise < String > {
14+ let addr = address. address
15+ return getCodePromise ( address: addr, onBlock: onBlock)
16+ }
17+ public func getCodePromise( address: String , onBlock: String = " latest " ) -> Promise < String > {
18+ let request = JSONRPCRequestFabric . prepareRequest ( . getCode, parameters: [ address. lowercased ( ) , onBlock] )
19+ let rp = web3. dispatch ( request)
20+ let queue = web3. requestDispatcher. queue
21+ return rp. map ( on: queue ) { response in
22+ guard let value: String = response. getValue ( ) else {
23+ if response. error != nil {
24+ throw Web3Error . nodeError ( desc: response. error!. message)
25+ }
26+ throw Web3Error . nodeError ( desc: " Invalid value from Ethereum node " )
27+ }
28+ return value
29+ }
30+ }
31+ }
32+
33+
You can’t perform that action at this time.
0 commit comments