Fix: Must only return the last modified date for a file if it's for the current schema version otherwise, a file using the old schema might have a more recent timestamp (because it was recently downloaded) than a newer version on the server (which was not yet made available by the time the user downloaded the version with the old schema)

pull/1528/head
Hwee-Boon Yar 5 years ago
parent db219524f2
commit 96ae96a87a
  1. 2
      AlphaWallet/TokenScriptClient/Models/AssetDefinitionDiskBackingStore.swift
  2. 13
      AlphaWallet/TokenScriptClient/Models/XMLHandler.swift

@ -176,10 +176,12 @@ class AssetDefinitionDiskBackingStore: AssetDefinitionBackingStore {
tokenScriptFileIndices.write(toUrl: indicesFileUrl)
}
//Must only return the last modified date for a file if it's for the current schema version otherwise, a file using the old schema might have a more recent timestamp (because it was recently downloaded) than a newer version on the server (which was not yet made available by the time the user downloaded the version with the old schema)
func lastModifiedDateOfCachedAssetDefinitionFile(forContract contract: AlphaWallet.Address) -> Date? {
assert(isOfficial)
let path = localURLOfXML(for: contract)
guard let lastModified = try? path.resourceValues(forKeys: [.contentModificationDateKey]) else { return nil }
guard XMLHandler.isTokenScriptSupportedSchemaVersion(path) else { return nil }
return lastModified.contentModificationDate
}

@ -718,6 +718,19 @@ public class XMLHandler {
}
}
static func isTokenScriptSupportedSchemaVersion(_ url: URL) -> Bool {
switch XMLHandler.checkTokenScriptSchema(forPath: url) {
case .supportedTokenScriptVersion:
return true
case .unsupportedTokenScriptVersion:
return false
case .unknownXml:
return false
case .others:
return false
}
}
static func checkTokenScriptSchema(_ contents: String) -> TokenScriptSchema {
//It's fine to have a file that is empty. A CSS file for example. But we should expect the input to be XML
if let xml = try? Kanna.XML(xml: contents, encoding: .utf8) {

Loading…
Cancel
Save