Skip to content

Commit 06a1b97

Browse files
committed
Added get transaction history method
1 parent d3299ba commit 06a1b97

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0073F22620D949F7000791F1 /* BlockExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0073F22520D949F7000791F1 /* BlockExporter.swift */; };
11+
0073F22820D94A11000791F1 /* BlockExporter+GetTransactionHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0073F22720D94A11000791F1 /* BlockExporter+GetTransactionHistory.swift */; };
1012
13AE5971A972F5B55FA6FB69 /* libPods-web3swift-iOS_Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8349531F1984454E50389370 /* libPods-web3swift-iOS_Tests.a */; };
1113
1CD91B321FD769A6007BFB45 /* web3swiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD91B311FD769A6007BFB45 /* web3swiftTests.swift */; };
1214
1CD91B341FD769A6007BFB45 /* web3swift_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CD91AFC1FD76910007BFB45 /* web3swift_iOS.framework */; };
@@ -227,6 +229,8 @@
227229
/* End PBXContainerItemProxy section */
228230

229231
/* Begin PBXFileReference section */
232+
0073F22520D949F7000791F1 /* BlockExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockExporter.swift; sourceTree = "<group>"; };
233+
0073F22720D94A11000791F1 /* BlockExporter+GetTransactionHistory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlockExporter+GetTransactionHistory.swift"; sourceTree = "<group>"; };
230234
08BD06D432296DA533D07D20 /* Pods_Web3Swift_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Web3Swift_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
231235
0F133EC83594B17BA8C71784 /* Pods_web3swift_ios_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3swift_ios_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
232236
10C02100CDF7C2D5C79A52B9 /* Pods_web3Swift_Demo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3Swift_Demo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -404,6 +408,23 @@
404408
/* End PBXFrameworksBuildPhase section */
405409

406410
/* Begin PBXGroup section */
411+
0073F22320D949D7000791F1 /* BlockExporter */ = {
412+
isa = PBXGroup;
413+
children = (
414+
0073F22420D949E8000791F1 /* Classes */,
415+
);
416+
path = BlockExporter;
417+
sourceTree = "<group>";
418+
};
419+
0073F22420D949E8000791F1 /* Classes */ = {
420+
isa = PBXGroup;
421+
children = (
422+
0073F22520D949F7000791F1 /* BlockExporter.swift */,
423+
0073F22720D94A11000791F1 /* BlockExporter+GetTransactionHistory.swift */,
424+
);
425+
path = Classes;
426+
sourceTree = "<group>";
427+
};
407428
1CD91AF21FD76910007BFB45 = {
408429
isa = PBXGroup;
409430
children = (
@@ -430,6 +451,7 @@
430451
1CD91AFE1FD76910007BFB45 /* web3swift */ = {
431452
isa = PBXGroup;
432453
children = (
454+
0073F22320D949D7000791F1 /* BlockExporter */,
433455
81A1821220D5A2430016741F /* Promises */,
434456
81FB2204207BCFD9007F9A83 /* Resources */,
435457
8103BBB4207638F800499769 /* Concurrency */,
@@ -1135,6 +1157,8 @@
11351157
8113D2CE1FD7E1590074282C /* EthereumTransaction.swift in Sources */,
11361158
81A1821F20D676BC0016741F /* Promise+Web3+Eth+GetTransactionCount.swift in Sources */,
11371159
81A1821520D5A2700016741F /* Promise+Web3+Eth+GetBalance.swift in Sources */,
1160+
0073F22820D94A11000791F1 /* BlockExporter+GetTransactionHistory.swift in Sources */,
1161+
0073F22620D949F7000791F1 /* BlockExporter.swift in Sources */,
11381162
81C0FD012044A89300D82FAF /* Web3+TransactionIntermediate.swift in Sources */,
11391163
8103BBC02076800500499769 /* Web3+EthOperations.swift in Sources */,
11401164
81A1823C20D79C270016741F /* Promise+Web3+Eth+Call.swift in Sources */,
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//
2+
// BlockExporter+GetTransactionHistory.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Георгий Фесенко on 19/06/2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import PromiseKit
11+
12+
enum ListId: String {
13+
case listOfETH
14+
case listOfTokens
15+
}
16+
17+
extension Scan {
18+
public func getTransactionsHistory(address publicAddress: String, tokenName name: String = "Ether", page: Int = 1, size: Int = 50) -> Promise<[Transaction]> {
19+
20+
//Configuring http request
21+
var listId: ListId
22+
if name == "Ether" {
23+
listId = .listOfETH
24+
} else {
25+
listId = .listOfTokens
26+
}
27+
28+
let url = URL(string: urlStringList)!
29+
var request = URLRequest(url: url)
30+
request.httpMethod = "POST"
31+
let internalParams: [String: Any] = ["entityId": publicAddress, "page": page, "size": size]
32+
let parameters: [String: Any] = ["listId": listId.rawValue, "moduleId": "address", "params": internalParams]
33+
34+
35+
return Promise<[Transaction]> {seal in
36+
do {
37+
request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: [])
38+
} catch {
39+
seal.reject(error)
40+
}
41+
//Performing the request
42+
let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
43+
if let error = error { seal.reject(error); return }
44+
guard let data = data else { return }
45+
46+
do {
47+
//Parsing JSON
48+
let jsonResponce = try JSONDecoder().decode(Response.self, from: data)
49+
if listId == .listOfETH {
50+
seal.fulfill(jsonResponce.rows)
51+
} else {
52+
seal.fulfill( jsonResponce.rows.filter { $0.token.name == name } )
53+
}
54+
} catch {
55+
seal.reject(error)
56+
}
57+
})
58+
task.resume()
59+
}
60+
}
61+
}
62+
63+
public struct Response: Decodable {
64+
let rows: [Transaction]
65+
let head: Head
66+
}
67+
68+
public struct Transaction: Decodable {
69+
70+
let id: String
71+
let hash: String
72+
let block: Int
73+
let addrFrom: String
74+
let addrTo: String
75+
let isoTime: String
76+
let type: String
77+
let status: Int
78+
let error: String
79+
let isContract: Int
80+
let isInner: Int
81+
let value: String
82+
let token: Token
83+
let txFee: String
84+
let gasUsed: Double
85+
let gasCost: Double
86+
87+
88+
enum CodingKeys: String, CodingKey {
89+
case id = "_id"
90+
case hash
91+
case block
92+
case addrFrom = "addrfrom"
93+
case addrTo = "addrto"
94+
case isoTime = "isotime"
95+
case type
96+
case status
97+
case error
98+
case isContract = "iscontract"
99+
case isInner = "isinner"
100+
case value
101+
case token
102+
case txFee = "txfee"
103+
case gasUsed = "gasused"
104+
case gasCost = "gascost"
105+
}
106+
107+
}
108+
109+
public struct Token: Decodable {
110+
let addr: String
111+
let name: String
112+
let smbl: String
113+
let dcm: Int
114+
}
115+
116+
public struct Head: Decodable {
117+
let totalEntities: Int
118+
let pageNumber: Int
119+
let pageSize: Int
120+
let listId: String
121+
let moduleId: String
122+
let entityId: String
123+
let updateTime: String
124+
}
125+
126+
127+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// BlockExporter.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Георгий Фесенко on 19/06/2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class Scan {
12+
public var urlStringList = "https://scan.bankex.com/api/list"
13+
}

0 commit comments

Comments
 (0)