|
|
|
@ -4,8 +4,8 @@ import Foundation |
|
|
|
|
import BigInt |
|
|
|
|
import RealmSwift |
|
|
|
|
|
|
|
|
|
public class EventActivity: Object { |
|
|
|
|
public static func generatePrimaryKey(fromContract contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, eventName: String, blockNumber: Int, transactionId: String, logIndex: Int, filter: String) -> String { |
|
|
|
|
class EventActivity: Object { |
|
|
|
|
static func generatePrimaryKey(fromContract contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, eventName: String, blockNumber: Int, transactionId: String, logIndex: Int, filter: String) -> String { |
|
|
|
|
"\(contract.eip55String)-\(tokenContract.eip55String)-\(server.chainID)-\(eventName)-\(blockNumber)-\(transactionId)-\(logIndex)-\(filter)" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -46,7 +46,7 @@ public class EventActivity: Object { |
|
|
|
|
.init(chainID: chainId) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public convenience init(contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, date: Date, eventName: String, blockNumber: Int, transactionId: String, transactionIndex: Int, logIndex: Int, filter: String, json: String) { |
|
|
|
|
convenience init(contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, date: Date, eventName: String, blockNumber: Int, transactionId: String, transactionIndex: Int, logIndex: Int, filter: String, json: String) { |
|
|
|
|
self.init() |
|
|
|
|
self.primaryKey = EventActivity.generatePrimaryKey(fromContract: contract, tokenContract: tokenContract, server: server, eventName: eventName, blockNumber: blockNumber, transactionId: transactionId, logIndex: logIndex, filter: filter) |
|
|
|
|
self.contract = contract.eip55String |
|
|
|
@ -63,7 +63,7 @@ public class EventActivity: Object { |
|
|
|
|
self._data = EventActivity.convertJsonToDictionary(json) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public convenience init(value: EventActivityInstance) { |
|
|
|
|
convenience init(value: EventActivityInstance) { |
|
|
|
|
self.init() |
|
|
|
|
self.primaryKey = value.primaryKey |
|
|
|
|
self.contract = value.contract.eip55String |
|
|
|
@ -80,15 +80,15 @@ public class EventActivity: Object { |
|
|
|
|
self._data = value.data |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override static func primaryKey() -> String? { |
|
|
|
|
override static func primaryKey() -> String? { |
|
|
|
|
return "primaryKey" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override static func ignoredProperties() -> [String] { |
|
|
|
|
override static func ignoredProperties() -> [String] { |
|
|
|
|
return ["_data", "data"] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static func convertJsonToDictionary(_ json: String) -> [String: AssetInternalValue] { |
|
|
|
|
static func convertJsonToDictionary(_ json: String) -> [String: AssetInternalValue] { |
|
|
|
|
let dict = json.data(using: .utf8).flatMap({ (try? JSONSerialization.jsonObject(with: $0, options: [])) as? [String: Any] }) ?? .init() |
|
|
|
|
return Dictionary(uniqueKeysWithValues: dict.compactMap { key, value -> (String, AssetInternalValue)? in |
|
|
|
|
switch value { |
|
|
|
@ -124,23 +124,6 @@ public struct EventActivityInstance { |
|
|
|
|
//Needed because Realm objects' properties (`json`) don't fire didSet after the object has been written to the database |
|
|
|
|
public var data: [String: AssetInternalValue] |
|
|
|
|
|
|
|
|
|
public init(event: EventActivity) { |
|
|
|
|
self.primaryKey = event.primaryKey |
|
|
|
|
|
|
|
|
|
self.contract = AlphaWallet.Address(uncheckedAgainstNullAddress: event.contract)! |
|
|
|
|
self.tokenContract = AlphaWallet.Address(uncheckedAgainstNullAddress: event.tokenContract)! |
|
|
|
|
self.server = RPCServer(chainID: event.chainId) |
|
|
|
|
self.date = event.date |
|
|
|
|
self.eventName = event.eventName |
|
|
|
|
self.blockNumber = event.blockNumber |
|
|
|
|
self.transactionId = event.transactionId |
|
|
|
|
self.transactionIndex = event.transactionIndex |
|
|
|
|
self.logIndex = event.logIndex |
|
|
|
|
self.filter = event.filter |
|
|
|
|
self.json = event.json |
|
|
|
|
self.data = event.data |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public init(contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, date: Date, eventName: String, blockNumber: Int, transactionId: String, transactionIndex: Int, logIndex: Int, filter: String, json: String) { |
|
|
|
|
self.primaryKey = EventActivity.generatePrimaryKey(fromContract: contract, tokenContract: tokenContract, server: server, eventName: eventName, blockNumber: blockNumber, transactionId: transactionId, logIndex: logIndex, filter: filter) |
|
|
|
|
self.contract = contract |
|
|
|
@ -171,3 +154,22 @@ public struct EventActivityInstance { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension EventActivityInstance { |
|
|
|
|
init(event: EventActivity) { |
|
|
|
|
self.primaryKey = event.primaryKey |
|
|
|
|
|
|
|
|
|
self.contract = AlphaWallet.Address(uncheckedAgainstNullAddress: event.contract)! |
|
|
|
|
self.tokenContract = AlphaWallet.Address(uncheckedAgainstNullAddress: event.tokenContract)! |
|
|
|
|
self.server = RPCServer(chainID: event.chainId) |
|
|
|
|
self.date = event.date |
|
|
|
|
self.eventName = event.eventName |
|
|
|
|
self.blockNumber = event.blockNumber |
|
|
|
|
self.transactionId = event.transactionId |
|
|
|
|
self.transactionIndex = event.transactionIndex |
|
|
|
|
self.logIndex = event.logIndex |
|
|
|
|
self.filter = event.filter |
|
|
|
|
self.json = event.json |
|
|
|
|
self.data = event.data |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|