-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from currybab/feature/pendingTransactions
adds txpool function and its local node test
- Loading branch information
Showing
7 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Promise+Web3+TxPool.swift | ||
// web3swift-iOS | ||
// | ||
// Created by Jun Park on 10/10/2018. | ||
// Copyright © 2018 The Matter Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import BigInt | ||
import PromiseKit | ||
|
||
|
||
extension web3.TxPool { | ||
public func getInspectPromise() -> Promise<[String:[String:[String:String]]]> { | ||
let request = JSONRPCRequestFabric.prepareRequest(.getTxPoolInspect, parameters: []) | ||
let rp = web3.dispatch(request) | ||
let queue = web3.requestDispatcher.queue | ||
return rp.map(on: queue ) { response in | ||
guard let value: [String:[String:[String:String]]] = response.getValue() else { | ||
if response.error != nil { | ||
throw Web3Error.nodeError(desc: response.error!.message) | ||
} | ||
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node") | ||
} | ||
return value | ||
} | ||
} | ||
|
||
public func getStatusPromise() -> Promise<[String: Int]> { | ||
let request = JSONRPCRequestFabric.prepareRequest(.getTxPoolStatus, parameters: []) | ||
let rp = web3.dispatch(request) | ||
let queue = web3.requestDispatcher.queue | ||
return rp.map(on: queue ) { response in | ||
guard let value: [String: String] = response.result as? [String: String] else { | ||
if response.error != nil { | ||
throw Web3Error.nodeError(desc: response.error!.message) | ||
} | ||
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node") | ||
} | ||
var result: [String: Int] = [:] | ||
for (k, v) in value { | ||
result[k] = Int.init(v.stripHexPrefix(), radix: 16) | ||
} | ||
return result | ||
} | ||
} | ||
|
||
public func getContentPromise() -> Promise<[String:[String:[String:[String:String?]]]]> { | ||
let request = JSONRPCRequestFabric.prepareRequest(.getTxPoolContent, parameters: []) | ||
let rp = web3.dispatch(request) | ||
let queue = web3.requestDispatcher.queue | ||
return rp.map(on: queue ) { response in | ||
guard let value: [String:[String:[String:[String:String?]]]] = response.getValue() else { | ||
if response.error != nil { | ||
throw Web3Error.nodeError(desc: response.error!.message) | ||
} | ||
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node") | ||
} | ||
return value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Web3+TxPool.swift | ||
// web3swift-iOS | ||
// | ||
// Created by Jun Park on 09/10/2018. | ||
// Copyright © 2018 The Matter Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Result | ||
import BigInt | ||
|
||
|
||
extension web3.TxPool { | ||
public func getInspect() -> Result<[String:[String:[String:String]]], Web3Error> { | ||
do { | ||
let result = try self.getInspectPromise().wait() | ||
return Result(result) | ||
} catch { | ||
if let err = error as? Web3Error { | ||
return Result.failure(err) | ||
} | ||
return Result.failure(Web3Error.generalError(err: error)) | ||
} | ||
} | ||
|
||
public func getStatus() -> Result<[String: Int], Web3Error> { | ||
do { | ||
let result = try self.getStatusPromise().wait() | ||
return Result(result) | ||
} catch { | ||
if let err = error as? Web3Error { | ||
return Result.failure(err) | ||
} | ||
return Result.failure(Web3Error.generalError(err: error)) | ||
} | ||
} | ||
|
||
public func getContent() -> Result<[String:[String:[String:[String:String?]]]], Web3Error> { | ||
do { | ||
let result = try self.getContentPromise().wait() | ||
return Result(result) | ||
} catch { | ||
if let err = error as? Web3Error { | ||
return Result.failure(err) | ||
} | ||
return Result.failure(Web3Error.generalError(err: error)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters