blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
// Copyright SIX DAY LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
import RealmSwift
|
|
import TrustKeystore
|
|
|
|
class MigrationInitializer: Initializer {
|
|
|
|
let account: Wallet
|
|
let chainID: Int
|
|
lazy var config: Realm.Configuration = {
|
|
return RealmConfiguration.configuration(for: account, chainID: chainID)
|
|
}()
|
|
|
|
init(
|
|
account: Wallet, chainID: Int
|
|
) {
|
|
self.account = account
|
|
self.chainID = chainID
|
|
}
|
|
|
|
func perform() {
|
|
config.schemaVersion = 41
|
|
config.migrationBlock = { migration, oldSchemaVersion in
|
|
switch oldSchemaVersion {
|
|
case 0...32:
|
|
migration.enumerateObjects(ofType: TokenObject.className()) { oldObject, newObject in
|
|
|
|
guard let oldObject = oldObject else { return }
|
|
guard let newObject = newObject else { return }
|
|
guard let value = oldObject["contract"] as? String else { return }
|
|
guard let address = Address(string: value) else { return }
|
|
|
|
newObject["contract"] = address.description
|
|
}
|
|
default: break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|