diff --git a/Sources/SubVTData/Model/App/ValidatorDetails.swift b/Sources/SubVTData/Model/App/ValidatorDetails.swift index 02fb918..96291e3 100644 --- a/Sources/SubVTData/Model/App/ValidatorDetails.swift +++ b/Sources/SubVTData/Model/App/ValidatorDetails.swift @@ -1,5 +1,5 @@ /** - Returned by the validatod details service right after the initial subscription. + Returned by the validator details service right after the initial subscription. */ public struct ValidatorDetails: Hashable { public private(set) var account: Account diff --git a/Sources/SubVTData/Model/Substrate/RewardDestination.swift b/Sources/SubVTData/Model/Substrate/RewardDestination.swift index a5e771f..f02b7f7 100644 --- a/Sources/SubVTData/Model/Substrate/RewardDestination.swift +++ b/Sources/SubVTData/Model/Substrate/RewardDestination.swift @@ -1,52 +1,15 @@ -public enum RewardDestination: Hashable { - case account(accountId: AccountId) - case controller - case none - case staked - case stash +public enum RewardDestinationType: String, Hashable, Codable { + case account = "Account" + case controller = "Controller" + case none = "None" + case staked = "Staked" + case stash = "Stash" } -extension RewardDestination: Codable { - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let value = try container.decode(String.self) - switch value { - case "Controller": - self = .controller - case "None": - self = .none - case "Staked": - self = .staked - case "Stash": - self = .stash - default: // account - let hex = value.replacingOccurrences( - of: "Account(", - with: "" - ).replacingOccurrences( - of: ")", - with: "" - ) - self = .account( - accountId: AccountId(hex: hex) - ) - } - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - switch self { - case .account(let accountId): - let hex = accountId.toHex() - try container.encode("Account(\(hex))") - case .controller: - try container.encode("Controller") - case .none: - try container.encode("None") - case .staked: - try container.encode("Staked") - case .stash: - try container.encode("Stash") - } - } +/** + Reward destination preference of a validator. + */ +public struct RewardDestination: Hashable, Codable { + public let destinationType: RewardDestinationType + public let destination: AccountId? }