Merge pull request #159 from James-Sangalli/assetDefinitionParsing

Asset definition parsing
pull/162/head
James Sangalli 7 years ago committed by GitHub
commit 5139d12a33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Podfile
  2. 10
      Podfile.lock
  3. 14
      Trust.xcodeproj/project.pbxproj
  4. 15
      Trust/Foundation/AssetDefinitionXML.swift
  5. 66
      Trust/Foundation/XMLHandler.swift
  6. 2
      Trust/Info.plist
  7. 1
      Trust/Market/UniversalLinkHandler.swift
  8. 22
      TrustTests/Foundation/XMLHandlerTest.swift

@ -24,6 +24,7 @@ target 'AlphaWallet' do
pod 'CryptoSwift', :git=>'https://github.com/krzyzanowskim/CryptoSwift', :branch=>'master'
pod 'Fabric'
pod 'Crashlytics'
pod 'SwiftyXMLParser', :git => 'https://github.com/yahoojapan/SwiftyXMLParser.git'
pod 'Kingfisher', '~> 4.0'
pod 'TrustKeystore', :git=>'https://github.com/alpha-wallet/trust-keystore-snapshot', :branch=>'master'
pod 'Branch'

@ -43,6 +43,7 @@ PODS:
- StatefulViewController (3.0)
- SwiftLint (0.24.1)
- SwiftyJSON (4.0.0)
- SwiftyXMLParser (4.1.0)
- TrezorCrypto (0.0.4)
- TrustKeystore (0.2.0):
- BigInt
@ -74,6 +75,7 @@ DEPENDENCIES:
- StatefulViewController
- SwiftLint
- SwiftyJSON
- SwiftyXMLParser (from `https://github.com/yahoojapan/SwiftyXMLParser.git`)
- TrustKeystore (from `https://github.com/alpha-wallet/trust-keystore-snapshot`, branch `master`)
EXTERNAL SOURCES:
@ -85,6 +87,8 @@ EXTERNAL SOURCES:
QRCodeReaderViewController:
:branch: master
:git: https://github.com/yannickl/QRCodeReaderViewController.git
SwiftyXMLParser:
:git: https://github.com/yahoojapan/SwiftyXMLParser.git
TrustKeystore:
:branch: master
:git: https://github.com/alpha-wallet/trust-keystore-snapshot
@ -99,6 +103,9 @@ CHECKOUT OPTIONS:
QRCodeReaderViewController:
:commit: 80bd79cbeede842949b229f81bc6328f53701c5a
:git: https://github.com/yannickl/QRCodeReaderViewController.git
SwiftyXMLParser:
:commit: 1ddcad0a09efb85f2325d994c2169cd9ba116ae3
:git: https://github.com/yahoojapan/SwiftyXMLParser.git
TrustKeystore:
:commit: 71cf8592d88c770081bd4e24ad1bbdd06bb63303
:git: https://github.com/alpha-wallet/trust-keystore-snapshot
@ -133,9 +140,10 @@ SPEC CHECKSUMS:
StatefulViewController: 4803bf900d44de26074344998e10e041113b5931
SwiftLint: 2e4b89feed5909c42c3735bbd6745f4345c4b772
SwiftyJSON: 070dabdcb1beb81b247c65ffa3a79dbbfb3b48aa
SwiftyXMLParser: b5a79fb8a730903703d0a92d30752a0b05158967
TrezorCrypto: 7f87a2296cf13872b21565c29fd9f7882dd00803
TrustKeystore: 381590c561f58fe0948abbd9cb626cbc08d75ff8
PODFILE CHECKSUM: 53f98ad2d779a0137c05fe727a9e97f20552dae3
PODFILE CHECKSUM: caca540a69e277efe6ea84cc65721152f15ab2cd
COCOAPODS: 1.3.1

@ -441,6 +441,9 @@
AA893ED5203C3E5400CDCED1 /* TokenBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */; };
AAEB8DA2204BC7B700CB0B2C /* RedeemTicketsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEB8DA1204BC7B700CB0B2C /* RedeemTicketsViewController.swift */; };
AAEF2CAB2050A68A0038BE0D /* SignatureHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */; };
B1DB1A95207DBF6D00CA2B77 /* XMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */; };
B1DB1A97207DCECF00CA2B77 /* AssetDefinitionXML.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */; };
B1DB1A99207DDF9600CA2B77 /* XMLHandlerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */; };
B1DC375D203AEAE200C9756D /* MarketQueueHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */; };
B1DC375F203AEB4800C9756D /* MarketQueueHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */; };
BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; };
@ -949,6 +952,9 @@
AAEB8DA1204BC7B700CB0B2C /* RedeemTicketsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedeemTicketsViewController.swift; sourceTree = "<group>"; };
AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureHelper.swift; sourceTree = "<group>"; };
B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = "<group>"; };
B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XMLHandler.swift; sourceTree = "<group>"; };
B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDefinitionXML.swift; sourceTree = "<group>"; };
B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XMLHandlerTest.swift; sourceTree = "<group>"; };
B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandler.swift; sourceTree = "<group>"; };
B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandlerTests.swift; sourceTree = "<group>"; };
B2CF9CDF557F98DECE6D0AF6 /* Pods_AlphaWalletUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlphaWalletUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -1699,6 +1705,7 @@
61FC5ED01FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift */,
73D2683A202E8411009777A1 /* DecimalNumberFormatterTest.swift */,
73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */,
B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */,
);
path = Foundation;
sourceTree = "<group>";
@ -1838,6 +1845,8 @@
298542F81FBE9A0100CB5081 /* CryptoAddressValidator.swift */,
61FC5ECE1FCFBAE500CCB12A /* EtherNumberFormatter.swift */,
73ED85A420349BE400593BF3 /* StringFormatter.swift */,
B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */,
B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */,
);
path = Foundation;
sourceTree = "<group>";
@ -3068,6 +3077,7 @@
"${BUILT_PRODUCTS_DIR}/SipHash/SipHash.framework",
"${BUILT_PRODUCTS_DIR}/StatefulViewController/StatefulViewController.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyXMLParser/SwiftyXMLParser.framework",
"${BUILT_PRODUCTS_DIR}/TrezorCrypto/TrezorCrypto.framework",
"${BUILT_PRODUCTS_DIR}/TrustKeystore/TrustKeystore.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1_ios/secp256k1_ios.framework",
@ -3097,6 +3107,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SipHash.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/StatefulViewController.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyXMLParser.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrezorCrypto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrustKeystore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_ios.framework",
@ -3156,6 +3167,7 @@
77872D232023F43B0032D687 /* TransactionsTracker.swift in Sources */,
29FA00CE201CA64E002F7DC5 /* DappCommand.swift in Sources */,
29FF12F61F74799D00AFD326 /* NSAttributedString.swift in Sources */,
B1DB1A97207DCECF00CA2B77 /* AssetDefinitionXML.swift in Sources */,
AA26C62320412A4100318B9B /* UIViewInspectableEnhancements.swift in Sources */,
290B2B651F91A4880053C83E /* TransactionsFooterView.swift in Sources */,
293B8B431F70815900356286 /* BalanceTitleView.swift in Sources */,
@ -3383,6 +3395,7 @@
29F1C83E1FEB5C91003780D8 /* EditTokensViewController.swift in Sources */,
296AF9A31F733AB30058AF78 /* WalletCoordinator.swift in Sources */,
442FCBBFCC5926B4D416E6D3 /* GetNameCoordinator.swift in Sources */,
B1DB1A95207DBF6D00CA2B77 /* XMLHandler.swift in Sources */,
442FCB9850FC6F2D28978199 /* GetERC20Symbol.swift in Sources */,
442FC5F70AF003F331F7C841 /* GetSymbolCoordinator.swift in Sources */,
442FCB2B0DD39EB2D9233A2F /* GetStormBirdBalance.swift in Sources */,
@ -3556,6 +3569,7 @@
29BDF19D1FEE50E90023A45F /* GasPriceConfigurationTests.swift in Sources */,
295996141FAB09A200DB66A8 /* DepositCoordinatorTests.swift in Sources */,
778EAF7D1FF10AF400C8E2AB /* SettingsCoordinatorTests.swift in Sources */,
B1DB1A99207DDF9600CA2B77 /* XMLHandlerTest.swift in Sources */,
732E0F502022716700B39C1F /* LockEnterPasscodeCoordinatorTest.swift in Sources */,
29F114E91FA3EC9E00114A29 /* InCoordinatorTests.swift in Sources */,
2981F4731F8303E600CA6590 /* TransactionCoordinatorTests.swift in Sources */,

File diff suppressed because one or more lines are too long

@ -0,0 +1,66 @@
//
// XMLHandler.swift
// AlphaWallet
//
// Created by James Sangalli on 11/4/18.
//
import Foundation
import SwiftyXMLParser
struct FIFAInfo {
let locale: String
let venue: String
let time: Int
let countryA: String
let countryB: String
let match: Int
let category: Int
let number: Int
}
/**
langs:
0 = ru
1 = en
2 = zh
3 = es
*/
public class XMLHandler {
private let xml = try! XML.parse(AssetDefinitionXML.assetDefinition)
func getFifaInfoForToken(tokenId: String, lang: Int) -> FIFAInfo {
let locale = getLocale(attribute: tokenId.substring(to: 2), lang: lang)
let venue = getVenue(attribute: tokenId.substring(with: Range(uncheckedBounds: (2, 4))), lang: lang)
let time = Int(tokenId.substring(with: Range(uncheckedBounds: (5, 12))), radix: 16)!
//translatable to ascii
let countryA = tokenId.substring(with: Range(uncheckedBounds: (12, 18))).hexa2Bytes
let countryB = tokenId.substring(with: Range(uncheckedBounds: (18, 24))).hexa2Bytes
let match = Int(tokenId.substring(with: Range(uncheckedBounds: (24, 26))), radix: 16)!
let category = Int(tokenId.substring(with: Range(uncheckedBounds: (26, 28))), radix: 16)!
let number = Int(tokenId.substring(from: 28), radix: 16)!
return FIFAInfo(
locale: locale,
venue: venue,
time: time,
countryA: String(data: Data(bytes: countryA), encoding: .utf8)!,
countryB: String(data: Data(bytes:countryB), encoding: .utf8)!,
match: match,
category: category,
number: number
)
}
func getLocale(attribute: String, lang: Int) -> String {
let localeNumber = Int(attribute, radix: 16)!
return xml["asset"]["fields"]["field"][0][0]["mapping"]["entity"][localeNumber]["name"][lang].text!
}
func getVenue(attribute: String, lang: Int) -> String {
let venueNumber = Int(attribute, radix: 16)!
return xml["asset"]["fields"]["field"][1][0]["mapping"]["entity"][venueNumber]["name"][lang].text!
}
}

@ -28,7 +28,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>161</string>
<string>162</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>

@ -32,6 +32,7 @@ public class UniversalLinkHandler {
public let urlPrefix = "https://app.awallet.io/"
public static let paymentServer = "http://feemaster.eastasia.cloudapp.azure.com:8080/api/claimToken"
//message is with 32 bytes each of price and expiry and is shortened for link
func createUniversalLink(signedOrder: SignedOrder) -> String {
let message = formatMessageForLink(signedOrder: signedOrder)

@ -0,0 +1,22 @@
//
// XMLHandlerTest.swift
// AlphaWalletTests
//
// Created by James Sangalli on 11/4/18.
//
import Foundation
import XCTest
@testable import Trust
class XMLHandlerTest: XCTestCase {
func testParser() {
let fifaDetails = XMLHandler().getFifaInfoForToken(
tokenId: "0x0a015af6d74042544e43484e01010001".substring(from: 2),
lang: 1
)
XCTAssertNotNil(fifaDetails)
}
}
Loading…
Cancel
Save