handle new ticket format

pull/323/head
James Sangalli 7 years ago
parent 58e65844bc
commit 023e71cdd5
  1. 2
      Trust/Foundation/AssetDefinitionXML.swift
  2. 13
      Trust/Foundation/XMLHandler.swift
  3. 3
      Trust/Market/Coordinators/UniversalLinkCoordinator.swift
  4. 4
      Trust/Tokens/Helpers/TicketAdaptor.swift

@ -11,7 +11,7 @@ import Foundation
class AssetDefinitionXML {
private static let xmlInputStream = InputStream(fileAtPath: "./contracts/AssetDefinition.xml")
// swiftlint:disable:this
public static let assetDefinition = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><asset><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\n" +
public static let assetDefinition = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><asset><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\n" +
"<ds:SignedInfo>\n" +
"<ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n" +
"<ds:SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256\"/>\n" +

@ -22,13 +22,14 @@ public class XMLHandler {
let tokenHex = MarketQueueHandler.bytesToHexa(tokenBytes32.serialize().bytes)
let location = getLocality(attribute: tokenHex.substring(to: 2), lang: lang)
let venue = getVenue(attribute: tokenHex.substring(with: Range(uncheckedBounds: (2, 4))), lang: lang)
let time = Int(tokenHex.substring(with: Range(uncheckedBounds: (4, 12))), radix: 16)!
let time = Int(tokenHex.substring(with: Range(uncheckedBounds: (4, 12))), radix: 16)
?? Int(Date.tomorrow.timeIntervalSince1970.rounded(to: 0))
//translatable to ascii
let countryA = tokenHex.substring(with: Range(uncheckedBounds: (12, 18))).hexa2Bytes
let countryB = tokenHex.substring(with: Range(uncheckedBounds: (18, 24))).hexa2Bytes
let match = Int(tokenHex.substring(with: Range(uncheckedBounds: (24, 26))), radix: 16)!
let category = Int(tokenHex.substring(with: Range(uncheckedBounds: (26, 28))), radix: 16)!
let number = Int(tokenHex.substring(with: Range(uncheckedBounds: (28, 32))), radix: 16)!
let match = Int(tokenHex.substring(with: Range(uncheckedBounds: (24, 26))), radix: 16) ?? 0
let category = Int(tokenHex.substring(with: Range(uncheckedBounds: (26, 28))), radix: 16) ?? 0
let number = Int(tokenHex.substring(with: Range(uncheckedBounds: (28, 32))), radix: 16) ?? 0
return Ticket(
id: MarketQueueHandler.bytesToHexa(tokenId.serialize().array),
@ -78,7 +79,7 @@ public class XMLHandler {
}
func getLocality(attribute: String, lang: Int) -> String {
//TODO find out why - 1
//entity keys start at 1 but xml finder starts at 0, hence -1
let locality = Int(attribute, radix: 16)! - 1
if let parsedLocality = xml["asset"]["fields"]["field"][0][0]["mapping"]["entity"][locality]["name"][lang].text {
return parsedLocality
@ -87,7 +88,7 @@ public class XMLHandler {
}
func getVenue(attribute: String, lang: Int) -> String {
let venueNumber = Int(attribute, radix: 16)!
let venueNumber = Int(attribute, radix: 16)! - 1
if let parsedVenue = xml["asset"]["fields"]["field"][1][0]["mapping"]["entity"][venueNumber]["name"][lang].text {
return parsedVenue
}

@ -221,7 +221,8 @@ class UniversalLinkCoordinator: Coordinator {
var tickets = [Ticket]()
let xmlHandler = XMLHandler()
for i in 0...bytes32Tickets.count - 1 {
if let tokenId = BigUInt(bytes32Tickets[i], radix: 16) {
let ticket = bytes32Tickets[i]
if let tokenId = BigUInt(ticket, radix: 16) {
let ticket = xmlHandler.getFifaInfoForTicket(tokenId: tokenId, index: UInt16(i))
tickets.append(ticket)
}

@ -25,7 +25,9 @@ class TicketAdaptor {
if id == "0x0000000000000000000000000000000000000000000000000000000000000000" { // if balance is 0, then skip
continue
}
let ticket = getTicket(for: BigUInt(id.substring(from: 2), radix: 16)!, index: UInt16(index), in: token)
//TODO shouldn't have to do this when parser is dynamic
let ticketData = id.substring(from: 2)
let ticket = getTicket(for: BigUInt(ticketData.substring(from: 32), radix: 16)!, index: UInt16(index), in: token)
tickets.append(ticket)
}

Loading…
Cancel
Save