diff --git a/Example/Podfile.lock b/Example/Podfile.lock index b049ba6..02da464 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -2,13 +2,13 @@ PODS: - BigInt (5.2.0) - CryptoSwift (1.3.2) - SwiftLint (0.39.2) - - SwiftProtobuf (1.12.0) - - TrustSDK/Client (1.4.3): + - SwiftProtobuf (1.13.0) + - TrustSDK/Client (1.4.4): - BigInt - TrustWalletCore/Types - - TrustSDK/Wallet (1.4.3): + - TrustSDK/Wallet (1.4.4): - TrustSDK/Client - - TrustWalletCore/Types (2.3.2): + - TrustWalletCore/Types (2.3.7): - SwiftProtobuf DEPENDENCIES: @@ -32,9 +32,9 @@ SPEC CHECKSUMS: BigInt: f668a80089607f521586bbe29513d708491ef2f7 CryptoSwift: 093499be1a94b0cae36e6c26b70870668cb56060 SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447 - SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699 - TrustSDK: 22058b92df9d20c9e1a9e8cfbf738f6baa67fba1 - TrustWalletCore: 296d747041462b68851f1649a0d75f04723f6a33 + SwiftProtobuf: fd4693388a96c8c2df35d3b063272b0e7c499d00 + TrustSDK: 447cc2dfacf15bd1624e1794ac728e986c283534 + TrustWalletCore: c00c4f68a16a7bce915dba327c7d5e5ef67cdf8b PODFILE CHECKSUM: 3cd8abdd82cb2787c7ceb3f28154a7ede783339d diff --git a/Example/Tests/AssetIDTests.swift b/Example/Tests/AssetIDTests.swift deleted file mode 100644 index 3d1b2a2..0000000 --- a/Example/Tests/AssetIDTests.swift +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Trust Wallet. All rights reserved. -// -// This file is part of TrustSDK. The full TrustSDK copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - - -import XCTest -import TrustSDK - -class AssetIDTests: XCTestCase { - - func testDescription() { - let btc = UniversalAssetID(coin: .bitcoin) - let eth = UniversalAssetID(coin: .ethereum) - let dai = UniversalAssetID(coin: .ethereum, token: "0x6B175474E89094C44Da98b954EedeAC495271d0F") - let trx = UniversalAssetID(coin: .tron, token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") - let busd = UniversalAssetID(coin: .binance, token: "BUSD-BD1") - - XCTAssertEqual(btc.description, "c0") - XCTAssertEqual(eth.description, "c60") - XCTAssertEqual(dai.description, "c60_t0x6B175474E89094C44Da98b954EedeAC495271d0F") - XCTAssertEqual(trx.description, "c195_tTR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") - XCTAssertEqual(busd.description, "c714_tBUSD-BD1") - } - - func testParse() throws { - for string in [ - "c0", - "c60", - "c714", - "c60_t0x6b175474e89094c44da98b954eedeac495271d0f", - "c714_tTWT-8C2" - ] { - XCTAssertNotNil(UniversalAssetID(string: string)) - } - - for string in [ - "", - "c1a", - "c60_0xasdf" - ] { - XCTAssertNil(UniversalAssetID(string: string)) - } - - } -} diff --git a/Example/Tests/CommandTests.swift b/Example/Tests/CommandTests.swift index 69dca4e..dd6bb63 100644 --- a/Example/Tests/CommandTests.swift +++ b/Example/Tests/CommandTests.swift @@ -5,6 +5,7 @@ // file LICENSE at the root of the source code distribution tree. import XCTest +import BigInt import WalletCore @testable import TrustSDK @@ -110,15 +111,15 @@ class CommandTests: XCTestCase { let app = "trust" let wallet = WalletApp(scheme: app, installURL: URL(string: "https://trustwallet.com")!) let tx = TrustSDK.Transaction( - asset: UniversalAssetID(coin: .ethereum), + asset: UniversalAssetID(coin: .ethereum, token: ""), to: "0x728B02377230b5df73Aa4E3192E89b6090DD7312", amount: "0.01", action: .transfer, confirm: .sign, from: nil, nonce: 447, - feePrice: "2112000000", - feeLimit: "21000", + feePrice: BigInt(2112000000), + feeLimit: BigInt(21000), meta: "0xasdf" ) diff --git a/Example/TrustSDK.xcodeproj/project.pbxproj b/Example/TrustSDK.xcodeproj/project.pbxproj index b474dfe..d3b8195 100644 --- a/Example/TrustSDK.xcodeproj/project.pbxproj +++ b/Example/TrustSDK.xcodeproj/project.pbxproj @@ -19,7 +19,6 @@ 7507FFE3240D774300DE2741 /* WalletRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7507FFE2240D774300DE2741 /* WalletRequestTests.swift */; }; 7598AD192414175000421EFA /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7598AD182414175000421EFA /* DictionaryTests.swift */; }; 75CD0D8324A41DC300242DA3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 75CD0D8224A41DC300242DA3 /* Main.storyboard */; }; - BB5AE6D8256276B800D1D440 /* AssetIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5AE6D7256276B800D1D440 /* AssetIDTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -54,7 +53,6 @@ 973C7B142BAB8746D0C53AF2 /* TrustSDK.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = TrustSDK.podspec; path = ../TrustSDK.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 9CE43E415D1BA0F22441C393 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; A5726054D0480EABD61CA7E8 /* Pods-TrustSDK_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustSDK_Tests.debug.xcconfig"; path = "Target Support Files/Pods-TrustSDK_Tests/Pods-TrustSDK_Tests.debug.xcconfig"; sourceTree = ""; }; - BB5AE6D7256276B800D1D440 /* AssetIDTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetIDTests.swift; sourceTree = ""; }; C5D9043738C8AAF9420A137C /* Pods_TrustSDK_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustSDK_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C9B18CC4B138BEA7D295FC63 /* Pods-TrustSDK_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustSDK_Example.debug.xcconfig"; path = "Target Support Files/Pods-TrustSDK_Example/Pods-TrustSDK_Example.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -137,7 +135,6 @@ isa = PBXGroup; children = ( 7598AD172414171700421EFA /* Extensions */, - BB5AE6D7256276B800D1D440 /* AssetIDTests.swift */, 7507FFE2240D774300DE2741 /* WalletRequestTests.swift */, 7507FFE0240D75AE00DE2741 /* WalletResponseTests.swift */, 7507FFDD240D738100DE2741 /* CommandTests.swift */, @@ -393,7 +390,6 @@ 7507FFE1240D75AE00DE2741 /* WalletResponseTests.swift in Sources */, 7507FFDF240D73BD00DE2741 /* CommandTests.swift in Sources */, 607FACEC1AFB9204008FA782 /* RequestRegistryTests.swift in Sources */, - BB5AE6D8256276B800D1D440 /* AssetIDTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/TrustSDK/ViewController.swift b/Example/TrustSDK/ViewController.swift index 42a6ab2..1ae1721 100644 --- a/Example/TrustSDK/ViewController.swift +++ b/Example/TrustSDK/ViewController.swift @@ -91,7 +91,7 @@ class ViewController: UIViewController { @IBAction func signSimpleEthTx(sender: UIButton) { let tx = TrustSDK.Transaction( - asset: UniversalAssetID(coin: .ethereum), + asset: UniversalAssetID(coin: .ethereum, token: ""), to: "0x728B02377230b5df73Aa4E3192E89b6090DD7312", amount: "0.01", action: .transfer, diff --git a/TrustSDK.podspec b/TrustSDK.podspec index 43d3161..1527c29 100644 --- a/TrustSDK.podspec +++ b/TrustSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TrustSDK' - s.version = '1.4.3' + s.version = '1.4.4' s.summary = 'Trust Wallet SDK' s.homepage = 'https://github.com/TrustWallet/TrustSDK-iOS' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/TrustSDK/Classes/Client/Types/Transaction.swift b/TrustSDK/Classes/Client/Types/Transaction.swift index a090ead..759351c 100644 --- a/TrustSDK/Classes/Client/Types/Transaction.swift +++ b/TrustSDK/Classes/Client/Types/Transaction.swift @@ -5,6 +5,8 @@ // file LICENSE at the root of the source code distribution tree. import Foundation +import BigInt +import WalletCore public extension TrustSDK { struct Transaction: Equatable { @@ -19,8 +21,8 @@ public extension TrustSDK { public let confirm: ConfirmType public let from: String? public let nonce: UInt64? - public let feeLimit: String? - public let feePrice: String? + public let feeLimit: BigInt? + public let feePrice: BigInt? public let meta: String? public init( @@ -31,8 +33,8 @@ public extension TrustSDK { confirm: ConfirmType, from: String? = nil, nonce: UInt64? = nil, - feePrice: String? = nil, - feeLimit: String? = nil, + feePrice: BigInt? = nil, + feeLimit: BigInt? = nil, meta: String? = nil ) { self.asset = asset @@ -63,9 +65,20 @@ public extension TrustSDK { self.action = action self.confirm = confirm self.from = params["from"] as? String - self.feeLimit = params["fee_limit"] as? String - self.feePrice = params["fee_price"] as? String self.meta = params["meta"] as? String + + if let limit = params["fee_limit"] as? String { + self.feeLimit = BigInt(limit) + } else { + self.feeLimit = nil + } + + if let price = params["fee_price"] as? String { + self.feePrice = BigInt(price) + } else { + self.feePrice = nil + } + if let nonceStr = params["nonce"] as? String { self.nonce = UInt64(nonceStr) } else { @@ -88,10 +101,10 @@ public extension TrustSDK { params["nonce"] = nonce } if let feePrice = feePrice { - params["fee_price"] = feePrice + params["fee_price"] = feePrice.description } if let feeLimit = feeLimit { - params["fee_limit"] = feeLimit + params["fee_limit"] = feeLimit.description } if let meta = meta { params["meta"] = meta diff --git a/TrustSDK/Classes/Client/Types/UniversalAssetID.swift b/TrustSDK/Classes/Client/Types/UniversalAssetID.swift deleted file mode 100644 index aef0f0b..0000000 --- a/TrustSDK/Classes/Client/Types/UniversalAssetID.swift +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Trust Wallet. All rights reserved. -// -// This file is part of TrustSDK. The full TrustSDK copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -import Foundation -import WalletCore - -/// https://developer.trustwallet.com/add_new_asset/universal_asset_id -public struct UniversalAssetID: CustomStringConvertible, Equatable { - - let cPrefix = "c" - let tPrefix = "t" - - public let coin: CoinType - public let token: String? - - public var description: String { - let prefix = "\(cPrefix)\(coin.rawValue)" - guard let token = token else { - return prefix - } - return "\(prefix)_\(tPrefix)\(token)" - } - - public init(coin: CoinType, token: String? = nil) { - self.coin = coin - self.token = token - } - - public init?(string: String) { - guard !string.isEmpty else { return nil } - let parts = string.split(separator: "_").map { String($0) } - guard parts[0].hasPrefix(cPrefix) else { - return nil - } - guard let int = UInt32(String(parts[0].dropFirst(cPrefix.count))), - let coin = CoinType(rawValue: int) else { - return nil - } - self.coin = coin - if parts.count == 2 { - guard parts[1].hasPrefix(tPrefix) else { - return nil - } - self.token = String(parts[1].dropFirst(tPrefix.count)) - } else { - self.token = nil - } - } -}