Skip to content

Commit a8b0bbe

Browse files
author
Alex Vlasov
committed
fixed batching, 70% of operations are done
1 parent 9505afc commit a8b0bbe

17 files changed

+338
-340
lines changed

Pods/Target Support Files/Alamofire-iOS/Info.plist

Lines changed: 0 additions & 26 deletions
This file was deleted.

Pods/Target Support Files/BigInt-macOS/BigInt-macOS-umbrella.h renamed to Pods/Target Support Files/PromiseKit.root-CorePromise-Foundation/PromiseKit.root-CorePromise-Foundation-prefix.pch

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Target Support Files/Result-iOS/Result-iOS-umbrella.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

web3swift.xcodeproj/project.pbxproj

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
8125F06A20499AC300A0F2FE /* BloomFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8125F06820499AC300A0F2FE /* BloomFilter.swift */; };
9393
813FFF8D1FD82EEB006379A2 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8113D2FF1FD7F30F0074282C /* String+Extension.swift */; };
9494
81531AA01FE7C07A002192CC /* EthereumKeystoreV3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81531A9F1FE7C07A002192CC /* EthereumKeystoreV3.swift */; };
95-
81531AA71FE7D8DB002192CC /* ERC20abi.json in Resources */ = {isa = PBXBuildFile; fileRef = 81531AA31FE7CD74002192CC /* ERC20abi.json */; };
9695
815630002007B48800A0EC2F /* BIP32KeystoreJSONStructure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81562FFF2007B48800A0EC2F /* BIP32KeystoreJSONStructure.swift */; };
9796
815630022007B53C00A0EC2F /* BIP32Keystore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815630012007B53C00A0EC2F /* BIP32Keystore.swift */; };
9897
815630042007BC8F00A0EC2F /* BIP39+WordLists.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815630032007BC8F00A0EC2F /* BIP39+WordLists.swift */; };
@@ -137,6 +136,15 @@
137136
81A1823520D6E1FD0016741F /* Promise+Web3+Eth+GetBlockByNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823320D6E1FD0016741F /* Promise+Web3+Eth+GetBlockByNumber.swift */; };
138137
81A1823720D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823620D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift */; };
139138
81A1823820D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823620D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift */; };
139+
81A1823A20D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823920D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift */; };
140+
81A1823C20D79C270016741F /* Promise+Web3+Eth+Call.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823B20D79C270016741F /* Promise+Web3+Eth+Call.swift */; };
141+
81A1823D20D79C290016741F /* Promise+Web3+Eth+Call.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823B20D79C270016741F /* Promise+Web3+Eth+Call.swift */; };
142+
81A1823E20D79C2C0016741F /* Promise+Web3+Eth+SendRawTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823920D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift */; };
143+
81A1824020D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1823F20D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift */; };
144+
81A1824220D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1824120D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift */; };
145+
81A1824320D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1824120D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift */; };
146+
81A1824520D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1824420D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift */; };
147+
81A1824620D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A1824420D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift */; };
140148
81BEDE1D20852F75002CD87D /* Web3+PersonalOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81BEDE1C20852F75002CD87D /* Web3+PersonalOperations.swift */; };
141149
81BEDE1E20852F75002CD87D /* Web3+PersonalOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81BEDE1C20852F75002CD87D /* Web3+PersonalOperations.swift */; };
142150
81C0FCF220440EB500D82FAF /* Web3+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C0FCF120440EB500D82FAF /* Web3+Protocols.swift */; };
@@ -266,7 +274,6 @@
266274
8125F0652047D9FF00A0F2FE /* ABIEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ABIEncoder.swift; sourceTree = "<group>"; };
267275
8125F06820499AC300A0F2FE /* BloomFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BloomFilter.swift; sourceTree = "<group>"; };
268276
81531A9F1FE7C07A002192CC /* EthereumKeystoreV3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumKeystoreV3.swift; sourceTree = "<group>"; };
269-
81531AA31FE7CD74002192CC /* ERC20abi.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ERC20abi.json; sourceTree = "<group>"; };
270277
81562FFF2007B48800A0EC2F /* BIP32KeystoreJSONStructure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BIP32KeystoreJSONStructure.swift; sourceTree = "<group>"; };
271278
815630012007B53C00A0EC2F /* BIP32Keystore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BIP32Keystore.swift; sourceTree = "<group>"; };
272279
815630032007BC8F00A0EC2F /* BIP39+WordLists.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BIP39+WordLists.swift"; sourceTree = "<group>"; };
@@ -299,6 +306,11 @@
299306
81A1823020D68A110016741F /* Promise+Batching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Batching.swift"; sourceTree = "<group>"; };
300307
81A1823320D6E1FD0016741F /* Promise+Web3+Eth+GetBlockByNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+GetBlockByNumber.swift"; sourceTree = "<group>"; };
301308
81A1823620D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+GetBlockByHash.swift"; sourceTree = "<group>"; };
309+
81A1823920D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+SendRawTransaction.swift"; sourceTree = "<group>"; };
310+
81A1823B20D79C270016741F /* Promise+Web3+Eth+Call.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+Call.swift"; sourceTree = "<group>"; };
311+
81A1823F20D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+EstimateGas.swift"; sourceTree = "<group>"; };
312+
81A1824120D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Eth+SendTransaction.swift"; sourceTree = "<group>"; };
313+
81A1824420D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Web3+Intermediate+Send.swift"; sourceTree = "<group>"; };
302314
81BEDE1C20852F75002CD87D /* Web3+PersonalOperations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+PersonalOperations.swift"; sourceTree = "<group>"; };
303315
81C0FCEF20440C3600D82FAF /* Web3+Wallet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+Wallet.swift"; sourceTree = "<group>"; };
304316
81C0FCF120440EB500D82FAF /* Web3+Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+Protocols.swift"; sourceTree = "<group>"; };
@@ -433,7 +445,6 @@
433445
children = (
434446
81A1821C20D5C6C10016741F /* web3swift_promises_Tests.swift */,
435447
81A0FA0220BFEF2700417C64 /* key.json */,
436-
81531AA31FE7CD74002192CC /* ERC20abi.json */,
437448
1CD91B311FD769A6007BFB45 /* web3swiftTests.swift */,
438449
4EFFCB6F208554EB008165FE /* web3swift_remote_Tests.swift */,
439450
4EFFCB6D208552F2008165FE /* web3swift_local_node_Tests.swift */,
@@ -617,6 +628,11 @@
617628
81A1822D20D67BC30016741F /* Promise+Web3+Eth+GetTransactionReceipt.swift */,
618629
81A1823320D6E1FD0016741F /* Promise+Web3+Eth+GetBlockByNumber.swift */,
619630
81A1823620D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift */,
631+
81A1823920D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift */,
632+
81A1823B20D79C270016741F /* Promise+Web3+Eth+Call.swift */,
633+
81A1823F20D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift */,
634+
81A1824120D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift */,
635+
81A1824420D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift */,
620636
);
621637
path = Classes;
622638
sourceTree = "<group>";
@@ -917,7 +933,6 @@
917933
isa = PBXResourcesBuildPhase;
918934
buildActionMask = 2147483647;
919935
files = (
920-
81531AA71FE7D8DB002192CC /* ERC20abi.json in Resources */,
921936
81A0FA0320BFEF2B00417C64 /* key.json in Resources */,
922937
);
923938
runOnlyForDeploymentPostprocessing = 0;
@@ -1033,12 +1048,14 @@
10331048
8125F0662047D9FF00A0F2FE /* ABIEncoder.swift in Sources */,
10341049
8113D2C61FD7E1590074282C /* LibSecp256k1Extension.swift in Sources */,
10351050
81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */,
1051+
81A1823A20D79AD40016741F /* Promise+Web3+Eth+SendRawTransaction.swift in Sources */,
10361052
81D7D97520A3240900A193EC /* EthereumFilterEncodingExtensions.swift in Sources */,
10371053
817EBB122004FE2F00E02EAA /* BIP32HDNode.swift in Sources */,
10381054
8113D2C41FD7E1590074282C /* CryptoExtensions.swift in Sources */,
10391055
8103BBB72076391F00499769 /* Web3+Concurrency.swift in Sources */,
10401056
81A1822220D678060016741F /* Promise+Web3+Eth+GetBlockNumber.swift in Sources */,
10411057
81C5DA252072E14E00424CD6 /* ABIv2Encoding.swift in Sources */,
1058+
81A1824220D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift in Sources */,
10421059
817EBB2920075D2E00E02EAA /* BIP39.swift in Sources */,
10431060
815630022007B53C00A0EC2F /* BIP32Keystore.swift in Sources */,
10441061
818ABD5B1FE95F8F002657BB /* Web3+Instance.swift in Sources */,
@@ -1058,6 +1075,7 @@
10581075
818D16CF204D42910084D2A4 /* Web3+EventParser.swift in Sources */,
10591076
8103BBC3207763B100499769 /* Web3+NativePrimitivesConversionOperations.swift in Sources */,
10601077
81C5DA16207261C800424CD6 /* ABIRecordParser.swift in Sources */,
1078+
81A1824520D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift in Sources */,
10611079
81C5DA282072E18200424CD6 /* NativeTypesEncoding+Extensions.swift in Sources */,
10621080
8123E1C7200CBAC200B6D3AB /* Dictionary+Extension.swift in Sources */,
10631081
81D7D97820A61E3800A193EC /* EventFiltering.swift in Sources */,
@@ -1096,6 +1114,7 @@
10961114
81C0FCF220440EB500D82FAF /* Web3+Protocols.swift in Sources */,
10971115
81C0FCF420440F0900D82FAF /* Web3+Options.swift in Sources */,
10981116
81A1822E20D67BC30016741F /* Promise+Web3+Eth+GetTransactionReceipt.swift in Sources */,
1117+
81A1824020D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift in Sources */,
10991118
81A1822B20D67A1B0016741F /* Promise+Web3+Eth+GetTransactionDetails.swift in Sources */,
11001119
815630042007BC8F00A0EC2F /* BIP39+WordLists.swift in Sources */,
11011120
81C5DA2B2074CA1400424CD6 /* ABIv2Decoding.swift in Sources */,
@@ -1104,6 +1123,7 @@
11041123
81A1821520D5A2700016741F /* Promise+Web3+Eth+GetBalance.swift in Sources */,
11051124
81C0FD012044A89300D82FAF /* Web3+TransactionIntermediate.swift in Sources */,
11061125
8103BBC02076800500499769 /* Web3+EthOperations.swift in Sources */,
1126+
81A1823C20D79C270016741F /* Promise+Web3+Eth+Call.swift in Sources */,
11071127
);
11081128
runOnlyForDeploymentPostprocessing = 0;
11091129
};
@@ -1148,6 +1168,8 @@
11481168
81D7D97320A31FB700A193EC /* ComparisonExtensions.swift in Sources */,
11491169
8103BBBE207654B900499769 /* Web3+ConversionOperations.swift in Sources */,
11501170
81BEDE1E20852F75002CD87D /* Web3+PersonalOperations.swift in Sources */,
1171+
81A1823E20D79C2C0016741F /* Promise+Web3+Eth+SendRawTransaction.swift in Sources */,
1172+
81A1823D20D79C290016741F /* Promise+Web3+Eth+Call.swift in Sources */,
11511173
81C5DA12207254F600424CD6 /* ABIv2.swift in Sources */,
11521174
8103BBC72077954200499769 /* Web3+TransactionOperations.swift in Sources */,
11531175
4194812D203630530065A83B /* EthereumAddress.swift in Sources */,
@@ -1171,6 +1193,7 @@
11711193
81A1822620D678590016741F /* Promise+Web3+Eth+GetGasPrice.swift in Sources */,
11721194
41948133203630530065A83B /* BIP39.swift in Sources */,
11731195
81C5DA2F2074EBF500424CD6 /* ContractABIv2.swift in Sources */,
1196+
81A1824320D7AA750016741F /* Promise+Web3+Eth+SendTransaction.swift in Sources */,
11741197
81166666204565AD008D8AD0 /* Web3+BrowserFunctions.swift in Sources */,
11751198
41948134203630530065A83B /* BIP39+WordLists.swift in Sources */,
11761199
41948135203630530065A83B /* EthereumKeystoreV3.swift in Sources */,
@@ -1199,6 +1222,7 @@
11991222
4194813D203630530065A83B /* RIPEMD160+StackOveflow.swift in Sources */,
12001223
4194813E203630530065A83B /* Data+Extension.swift in Sources */,
12011224
81A1822F20D67BC30016741F /* Promise+Web3+Eth+GetTransactionReceipt.swift in Sources */,
1225+
81A1824620D7B91B0016741F /* Promise+Web3+Intermediate+Send.swift in Sources */,
12021226
81A1822C20D67A1B0016741F /* Promise+Web3+Eth+GetTransactionDetails.swift in Sources */,
12031227
4194813F203630530065A83B /* Dictionary+Extension.swift in Sources */,
12041228
81C5DA2C2074CA1400424CD6 /* ABIv2Decoding.swift in Sources */,

web3swift/Promises/Classes/Promise+Batching.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public class JSONRPCrequestDispatcher {
3535
var queue: DispatchQueue
3636
var lockQueue : DispatchQueue
3737
var triggered : Bool = false
38-
func add(_ request: JSONRPCrequest, maxWaitTime: TimeInterval) -> Promise<JSONRPCresponse> {
38+
func add(_ request: JSONRPCrequest, maxWaitTime: TimeInterval) throws -> Promise<JSONRPCresponse> {
39+
if self.triggered {
40+
throw Web3Error.nodeError("Batch is already in flight")
41+
}
3942
let requestID = request.id
4043
let promiseToReturn = Promise<JSONRPCresponse>.pending()
4144
self.queue.async {
@@ -97,7 +100,7 @@ public class JSONRPCrequestDispatcher {
97100
throw Web3Error.inputError("Trying to batch a request when policy is not to batch")
98101
}
99102
let currentBatch = self.batches.last!
100-
if currentBatch.requests.count % batchLength == 0 {
103+
if currentBatch.requests.count % batchLength == 0 || currentBatch.triggered {
101104
let newBatch = Batch(provider: self.provider, capacity: Int(batchLength), queue: self.queue, lockQueue: self.lockQueue)
102105
self.batches.append(newBatch)
103106
return newBatch
@@ -120,7 +123,7 @@ public class JSONRPCrequestDispatcher {
120123
self.lockQueue.async {
121124
do {
122125
let batch = try self.getBatch()
123-
let internalPromise = batch.add(request, maxWaitTime: self.MAX_WAIT_TIME)
126+
let internalPromise = try batch.add(request, maxWaitTime: self.MAX_WAIT_TIME)
124127
internalPromise.done(on: self.queue) {resp in
125128
seal.fulfill(resp)
126129
}.catch(on: self.queue){err in
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Promise+Web3+Eth+Call.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Alexander Vlasov on 18.06.2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import PromiseKit
11+
12+
extension web3.Eth {
13+
14+
func callPromise(_ transaction: EthereumTransaction, options: Web3Options, onBlock: String = "latest") -> Promise<Data>{
15+
let queue = web3.requestDispatcher.queue
16+
do {
17+
guard let request = EthereumTransaction.createRequest(method: .call, transaction: transaction, onBlock: onBlock, options: options) else {
18+
throw Web3Error.processingError("Transaction is invalid")
19+
}
20+
let rp = web3.dispatch(request)
21+
return rp.map(on: queue ) { response in
22+
guard let value: Data = response.getValue() else {
23+
throw Web3Error.nodeError("Invalid value from Ethereum node")
24+
}
25+
return value
26+
}
27+
} catch {
28+
let returnPromise = Promise<Data>.pending()
29+
queue.async {
30+
returnPromise.resolver.reject(error)
31+
}
32+
return returnPromise.promise
33+
}
34+
}
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Promise+Web3+Eth+EstimateGas.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Alexander Vlasov on 18.06.2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import BigInt
11+
import PromiseKit
12+
13+
extension web3.Eth {
14+
15+
func estimateGasPromise(_ transaction: EthereumTransaction, options: Web3Options? = nil, onBlock: String = "latest") -> Promise<BigUInt>{
16+
let queue = web3.requestDispatcher.queue
17+
do {
18+
guard let request = EthereumTransaction.createRequest(method: .estimateGas, transaction: transaction, onBlock: onBlock, options: options) else {
19+
throw Web3Error.processingError("Transaction is invalid")
20+
}
21+
let rp = web3.dispatch(request)
22+
return rp.map(on: queue ) { response in
23+
guard let value: BigUInt = response.getValue() else {
24+
throw Web3Error.nodeError("Invalid value from Ethereum node")
25+
}
26+
return value
27+
}
28+
} catch {
29+
let returnPromise = Promise<BigUInt>.pending()
30+
queue.async {
31+
returnPromise.resolver.reject(error)
32+
}
33+
return returnPromise.promise
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)