Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Refactor code. Update version 0.6.2 -> 0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Nov 18, 2019
1 parent 47861a8 commit b7ab480
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Erc20Kit.swift.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 3 additions & 0 deletions Erc20Kit/Erc20Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = D001D2DD2251CC7F00165546;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Erc20Kit/Erc20Kit/Core/DataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension DataProvider: IDataProvider {
}

func sendSingle(contractAddress: Data, transactionInput: Data, gasPrice: Int, gasLimit: Int) -> Single<Data> {
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)!
}
Expand Down
12 changes: 6 additions & 6 deletions Erc20Kit/Erc20Kit/Core/Erc20Kit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Erc20Kit/Erc20Kit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion EthereumKit.swift.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions EthereumKit/EthereumKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions EthereumKit/EthereumKit/Core/EthereumKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionInfo> {
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<TransactionInfo> {
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
Expand All @@ -111,7 +111,7 @@ extension EthereumKit {
.map { TransactionInfo(transaction: $0) }
}

public func sendSingle(to: String, value: String, gasPrice: Int) -> Single<TransactionInfo> {
public func sendSingle(to: String, value: String, gasPrice: Int, gasLimit: Int? = nil) -> Single<TransactionInfo> {
guard let to = Data(hex: to) else {
return Single.error(SendError.invalidAddress)
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion EthereumKit/EthereumKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
3 changes: 3 additions & 0 deletions EthereumKitDemo/EthereumKitDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 3A3B59CD216B1D81001C5E99;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion EthereumKitDemo/EthereumKitDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down

0 comments on commit b7ab480

Please sign in to comment.