From b7ab4803564f8fc9394a56b220d85c47903549e7 Mon Sep 17 00:00:00 2001 From: Anton Stavnichiy Date: Mon, 18 Nov 2019 12:13:46 +0600 Subject: [PATCH] Refactor code. Update version 0.6.2 -> 0.7.2 --- Erc20Kit.swift.podspec | 2 +- Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj | 3 +++ Erc20Kit/Erc20Kit/Core/DataProvider.swift | 2 +- Erc20Kit/Erc20Kit/Core/Erc20Kit.swift | 12 ++++++------ Erc20Kit/Erc20Kit/Info.plist | 2 +- EthereumKit.swift.podspec | 2 +- EthereumKit/EthereumKit.xcodeproj/project.pbxproj | 2 ++ EthereumKit/EthereumKit/Core/EthereumKit.swift | 8 ++++---- EthereumKit/EthereumKit/Info.plist | 2 +- .../EthereumKitDemo.xcodeproj/project.pbxproj | 3 +++ EthereumKitDemo/EthereumKitDemo/Info.plist | 2 +- 11 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Erc20Kit.swift.podspec b/Erc20Kit.swift.podspec index ab5f7f50..bf7d04a0 100644 --- a/Erc20Kit.swift.podspec +++ b/Erc20Kit.swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| spec.name = 'Erc20Kit.swift' spec.module_name = 'Erc20Kit' - spec.version = '0.6.2' + spec.version = '0.7.2' spec.summary = 'Erc20 token library for Swift' spec.homepage = 'https://github.com/horizontalsystems/ethereum-kit-ios' diff --git a/Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj b/Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj index d47f3a40..dc321947 100644 --- a/Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj +++ b/Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj @@ -260,6 +260,7 @@ developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( + en, Base, ); mainGroup = D001D2DD2251CC7F00165546; @@ -535,6 +536,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.Erc20Kit; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -561,6 +563,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.Erc20Kit; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/Erc20Kit/Erc20Kit/Core/DataProvider.swift b/Erc20Kit/Erc20Kit/Core/DataProvider.swift index b7175b9f..aff3e7ca 100644 --- a/Erc20Kit/Erc20Kit/Core/DataProvider.swift +++ b/Erc20Kit/Erc20Kit/Core/DataProvider.swift @@ -56,7 +56,7 @@ extension DataProvider: IDataProvider { } func sendSingle(contractAddress: Data, transactionInput: Data, gasPrice: Int, gasLimit: Int) -> Single { - ethereumKit.sendSingle(to: contractAddress, value: 0, transactionInput: transactionInput, gasPrice: gasPrice, gasLimit: gasLimit) + ethereumKit.sendSingle(address: contractAddress, value: 0, transactionInput: transactionInput, gasPrice: gasPrice, gasLimit: gasLimit) .map { transactionInfo in Data(hex: transactionInfo.hash)! } diff --git a/Erc20Kit/Erc20Kit/Core/Erc20Kit.swift b/Erc20Kit/Erc20Kit/Core/Erc20Kit.swift index 7de7d83b..e3c1654c 100644 --- a/Erc20Kit/Erc20Kit/Core/Erc20Kit.swift +++ b/Erc20Kit/Erc20Kit/Core/Erc20Kit.swift @@ -4,7 +4,7 @@ import HSCryptoKit import BigInt public class Erc20Kit { - private let gasLimit = 1_000_000 + private let gasLimit: Int private let disposeBag = DisposeBag() private let ethereumKit: EthereumKit @@ -13,10 +13,11 @@ public class Erc20Kit { private let state: KitState - init(ethereumKit: EthereumKit, transactionManager: ITransactionManager, balanceManager: IBalanceManager, state: KitState = KitState()) { + init(ethereumKit: EthereumKit, transactionManager: ITransactionManager, balanceManager: IBalanceManager, gasLimit: Int = 1_000_000, state: KitState = KitState()) { self.ethereumKit = ethereumKit self.transactionManager = transactionManager self.balanceManager = balanceManager + self.gasLimit = gasLimit self.state = state onUpdateSyncState(syncState: ethereumKit.syncState) @@ -104,15 +105,14 @@ extension Erc20Kit { return Single.error(ValidationError.invalidValue) } - var data: Data? do { let toAddress = try convert(address: to) - data = transactionManager.transactionContractData(to: toAddress, value: amountValue) + let data = transactionManager.transactionContractData(to: toAddress, value: amountValue) + + return ethereumKit.estimateGas(contractAddress: contractAddress, amount: nil, gasLimit: gasLimit, data: data) } catch { return Single.error(ValidationError.invalidAddress) } - - return ethereumKit.estimateGas(contractAddress: contractAddress, amount: nil, gasLimit: gasLimit, data: data) } } diff --git a/Erc20Kit/Erc20Kit/Info.plist b/Erc20Kit/Erc20Kit/Info.plist index e1fe4cfb..82790df0 100644 --- a/Erc20Kit/Erc20Kit/Info.plist +++ b/Erc20Kit/Erc20Kit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion $(CURRENT_PROJECT_VERSION) diff --git a/EthereumKit.swift.podspec b/EthereumKit.swift.podspec index 7e8c0664..51451d8d 100644 --- a/EthereumKit.swift.podspec +++ b/EthereumKit.swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| spec.name = 'EthereumKit.swift' spec.module_name = 'EthereumKit' - spec.version = '0.6.4' + spec.version = '0.7.2' spec.summary = 'Ethereum wallet library for Swift' spec.description = <<-DESC EthereumKit.swift implements Ethereum protocol in Swift. diff --git a/EthereumKit/EthereumKit.xcodeproj/project.pbxproj b/EthereumKit/EthereumKit.xcodeproj/project.pbxproj index a2473b69..c72935f9 100644 --- a/EthereumKit/EthereumKit.xcodeproj/project.pbxproj +++ b/EthereumKit/EthereumKit.xcodeproj/project.pbxproj @@ -1384,6 +1384,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.EthereumKit; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -1414,6 +1415,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.EthereumKit; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/EthereumKit/EthereumKit/Core/EthereumKit.swift b/EthereumKit/EthereumKit/Core/EthereumKit.swift index 8362a7a5..ee19e0b7 100644 --- a/EthereumKit/EthereumKit/Core/EthereumKit.swift +++ b/EthereumKit/EthereumKit/Core/EthereumKit.swift @@ -101,8 +101,8 @@ extension EthereumKit { .map { $0.map { TransactionInfo(transaction: $0) } } } - public func sendSingle(to: Data, value: BigUInt, transactionInput: Data = Data(), gasPrice: Int, gasLimit: Int) -> Single { - let rawTransaction = transactionBuilder.rawTransaction(gasPrice: gasPrice, gasLimit: gasLimit, to: to, value: value, data: transactionInput) + public func sendSingle(address: Data, value: BigUInt, transactionInput: Data = Data(), gasPrice: Int, gasLimit: Int) -> Single { + let rawTransaction = transactionBuilder.rawTransaction(gasPrice: gasPrice, gasLimit: gasLimit, to: address, value: value, data: transactionInput) return blockchain.sendSingle(rawTransaction: rawTransaction) .do(onSuccess: { [weak self] transaction in @@ -111,7 +111,7 @@ extension EthereumKit { .map { TransactionInfo(transaction: $0) } } - public func sendSingle(to: String, value: String, gasPrice: Int) -> Single { + public func sendSingle(to: String, value: String, gasPrice: Int, gasLimit: Int? = nil) -> Single { guard let to = Data(hex: to) else { return Single.error(SendError.invalidAddress) } @@ -120,7 +120,7 @@ extension EthereumKit { return Single.error(SendError.invalidValue) } - return sendSingle(to: to, value: value, gasPrice: gasPrice, gasLimit: gasLimit) + return sendSingle(address: to, value: value, gasPrice: gasPrice, gasLimit: gasLimit ?? self.gasLimit) } public var debugInfo: String { diff --git a/EthereumKit/EthereumKit/Info.plist b/EthereumKit/EthereumKit/Info.plist index e1fe4cfb..82790df0 100644 --- a/EthereumKit/EthereumKit/Info.plist +++ b/EthereumKit/EthereumKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion $(CURRENT_PROJECT_VERSION) diff --git a/EthereumKitDemo/EthereumKitDemo.xcodeproj/project.pbxproj b/EthereumKitDemo/EthereumKitDemo.xcodeproj/project.pbxproj index 5728a7f7..62e1cb62 100644 --- a/EthereumKitDemo/EthereumKitDemo.xcodeproj/project.pbxproj +++ b/EthereumKitDemo/EthereumKitDemo.xcodeproj/project.pbxproj @@ -242,6 +242,7 @@ developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( + en, Base, ); mainGroup = 3A3B59CD216B1D81001C5E99; @@ -470,6 +471,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.EthereumKitDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -489,6 +491,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + MARKETING_VERSION = 0.7.2; PRODUCT_BUNDLE_IDENTIFIER = io.horizontalsystems.EthereumKitDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/EthereumKitDemo/EthereumKitDemo/Info.plist b/EthereumKitDemo/EthereumKitDemo/Info.plist index c8e855e6..a2232bd0 100644 --- a/EthereumKitDemo/EthereumKitDemo/Info.plist +++ b/EthereumKitDemo/EthereumKitDemo/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion 1 LSRequiresIPhoneOS