From 118618606877a745791212d91769395cf0d3621c Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Wed, 29 Aug 2018 13:19:49 +0800 Subject: [PATCH 1/2] migrates realm correctly to prevent ether being marked as erc20 --- .../Core/Initializers/MigrationInitializer.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AlphaWallet/Core/Initializers/MigrationInitializer.swift b/AlphaWallet/Core/Initializers/MigrationInitializer.swift index b11db413f..837ce121d 100644 --- a/AlphaWallet/Core/Initializers/MigrationInitializer.swift +++ b/AlphaWallet/Core/Initializers/MigrationInitializer.swift @@ -13,14 +13,14 @@ class MigrationInitializer: Initializer { }() init( - account: Wallet, chainID: Int + account: Wallet, chainID: Int ) { self.account = account self.chainID = chainID } func perform() { - config.schemaVersion = 47 + config.schemaVersion = 48 config.migrationBlock = { migration, oldSchemaVersion in switch oldSchemaVersion { case 0...32: @@ -44,6 +44,15 @@ class MigrationInitializer: Initializer { } } } + if oldSchemaVersion < 48 { + migration.enumerateObjects(ofType: TokenObject.className()) { oldObject, newObject in + guard let oldObject = oldObject else { return } + guard let newObject = newObject else { return } + if let contract = oldObject["contract"] as? String, contract == "0x0000000000000000000000000000000000000000" { + newObject["rawType"] = TokenType.ether.rawValue + } + } + } } } } From 7af6add545eeb8305ef9bfd3fb8775df34864612 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Wed, 29 Aug 2018 13:23:12 +0800 Subject: [PATCH 2/2] use constants for null address --- AlphaWallet/Core/Initializers/MigrationInitializer.swift | 2 +- AlphaWallet/Settings/Types/Constants.swift | 1 + AlphaWallet/Tokens/Types/TokensDataStore.swift | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AlphaWallet/Core/Initializers/MigrationInitializer.swift b/AlphaWallet/Core/Initializers/MigrationInitializer.swift index 837ce121d..3f513811f 100644 --- a/AlphaWallet/Core/Initializers/MigrationInitializer.swift +++ b/AlphaWallet/Core/Initializers/MigrationInitializer.swift @@ -48,7 +48,7 @@ class MigrationInitializer: Initializer { migration.enumerateObjects(ofType: TokenObject.className()) { oldObject, newObject in guard let oldObject = oldObject else { return } guard let newObject = newObject else { return } - if let contract = oldObject["contract"] as? String, contract == "0x0000000000000000000000000000000000000000" { + if let contract = oldObject["contract"] as? String, contract == Constants.nullAddress { newObject["rawType"] = TokenType.ether.rawValue } } diff --git a/AlphaWallet/Settings/Types/Constants.swift b/AlphaWallet/Settings/Types/Constants.swift index ca818af75..e9ef879ed 100644 --- a/AlphaWallet/Settings/Types/Constants.swift +++ b/AlphaWallet/Settings/Types/Constants.swift @@ -35,6 +35,7 @@ public struct Constants { public static let nullTicket = "0x0000000000000000000000000000000000000000000000000000000000000000" public static let nullTicketBigUInt = BigUInt(0) public static let burnAddressString = "0x000000000000000000000000000000000000dEaD" + public static let nullAddress = "0x0000000000000000000000000000000000000000" // FIFA hardcoded FIFA token address public static let ticketContractAddress = "0xA66A3F08068174e8F005112A8b2c7A507a822335" diff --git a/AlphaWallet/Tokens/Types/TokensDataStore.swift b/AlphaWallet/Tokens/Types/TokensDataStore.swift index 05b92d92c..6c114c534 100644 --- a/AlphaWallet/Tokens/Types/TokensDataStore.swift +++ b/AlphaWallet/Tokens/Types/TokensDataStore.swift @@ -75,7 +75,7 @@ class TokensDataStore { static func etherToken(for config: Config) -> TokenObject { return TokenObject( - contract: "0x0000000000000000000000000000000000000000", + contract: Constants.nullAddress, name: config.server.name, symbol: config.server.symbol, decimals: config.server.decimals,