-
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
25 changed files
with
492 additions
and
298 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
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
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
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
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
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
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
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
42 changes: 0 additions & 42 deletions
42
Boka/Tests/BokaTests/chainfiles/devnet_allconfig_spec.json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
Boka/Tests/BokaTests/chainfiles/mainnet_someconfig_spec.json
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
|
||
struct KeyValuePair<Key: Codable & Hashable & Comparable, Value: Codable>: Codable { | ||
var key: Key | ||
var value: Value | ||
} | ||
|
||
public struct SortedKeyValues<Key: Codable & Hashable & Comparable, Value: Codable>: Codable, CodableAlias { | ||
public typealias Alias = [Key: Value] | ||
|
||
public var alias: Alias | ||
|
||
public init(alias: Alias) { | ||
self.alias = alias | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let array = try container.decode([KeyValuePair<Key, Value>].self) | ||
|
||
// ensure array is sorted and unique | ||
var previous: KeyValuePair<Key, Value>? | ||
for item in array { | ||
guard previous == nil || item.key > previous!.key else { | ||
throw DecodingError.dataCorrupted( | ||
DecodingError.Context( | ||
codingPath: container.codingPath, | ||
debugDescription: "Array is not sorted" | ||
) | ||
) | ||
} | ||
previous = item | ||
} | ||
|
||
alias = .init(uniqueKeysWithValues: array.map { ($0.key, $0.value) }) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
var array = alias.map { KeyValuePair(key: $0.key, value: $0.value) } | ||
array.sort { $0.key < $1.key } | ||
try container.encode(array) | ||
} | ||
} | ||
|
||
extension SortedKeyValues: Sendable where Key: Sendable, Value: Sendable, Alias: Sendable {} | ||
|
||
extension SortedKeyValues: Equatable where Key: Equatable, Value: Equatable, Alias: Equatable {} |
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
Oops, something went wrong.