Skip to content

Commit

Permalink
Update reward destination model.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Jul 28, 2022
1 parent 4a0a6fb commit e41f506
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Sources/SubVTData/Model/App/ValidatorDetails.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
61 changes: 12 additions & 49 deletions Sources/SubVTData/Model/Substrate/RewardDestination.swift
Original file line number Diff line number Diff line change
@@ -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?
}

0 comments on commit e41f506

Please sign in to comment.