-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 12 additions & 49 deletions
61
Sources/SubVTData/Model/Substrate/RewardDestination.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} |