-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap SOME of Radix Engine Toolkit types, first of MANY PRs. #3
Merged
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
eedf6a2
Arithmetic operations for Decimal
Sajjon d4a019a
Decimal compare methods and UniFFI exported funtions
Sajjon ed6e18e
add Swift bindgen tests for decimal
Sajjon 2e95bfb
Merge branch 'develop' into wrap_radix_engine_toolkit
Sajjon 30f134d
Sargon: Add method to read Mnemonic, UniFFI exported, Improve iOS exa…
Sajjon 2c447c5
Merge
Sajjon 944795e
WIP Decimal192 + Swifitfied
Sajjon a9b96d0
Make Decimal192 conform to Comparable
Sajjon 5ec79b6
Add clamped
Sajjon ff8a4a4
Decimal rounding
Sajjon ac0e057
rename file decimal -> decimal192.rs, add from f32.
Sajjon 3dc5907
Add from_formatted_string
Sajjon b2c90d9
Swiftify Decimal192 from formatted string
Sajjon 47f6da9
Add tests
Sajjon 7592b04
more tests
Sajjon 9437497
Start stubbing out Signatures and other types required by RET, which …
Sajjon 5f5cc20
Declare Ed25519Signature and use it with Ed25519PrivateKey and Public…
Sajjon fe86e8c
drop Ord/PartialOrd for types where it did not really make sense. Rem…
CyonAlexRDX 9aad4ff
Add HasPlaceholder conformance to Ed25519PublicKey
Sajjon b31d4fa
Add HasPlaceholder conformance to Secp256k1Signature
Sajjon 1731692
tests of Ed25519Signature and Secp256k1Signature
CyonAlexRDX 3d286fc
Unit tests for Signature
CyonAlexRDX 6a7efd4
Merge branch 'develop' into wrap_radix_engine_toolkit
CyonAlexRDX 95931b9
Add step to precommit ensuring that local development is set to false…
CyonAlexRDX 32e15fb
fail fast in precommit
CyonAlexRDX edd3748
build, here is the updated Swift bindgen
CyonAlexRDX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
[all] | ||
exclude-files = [ | ||
"tests/*", | ||
"src/wrapped_radix_engine_toolkit/*", | ||
"example/*", | ||
"target/*", | ||
"apple/*", | ||
".swiftpm/*", | ||
"scripts/*", | ||
".build/*", | ||
"Package.swift", | ||
] | ||
verbose = false | ||
all-features = true | ||
timeout = "1800s" | ||
timeout = "5m" | ||
skip-clean = true | ||
out = ["Xml"] | ||
force-clean = false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/AppearanceID+Wrap+Functions.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/BagOfBytes+Wrap+Functions.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension BagOfBytes { | ||
public init(data: Data) { | ||
self = newBagOfBytesFrom(bytes: data) | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
apple/Sources/Sargon/Extensions/Methods/Decimal192+Methods.swift
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
apple/Sources/Sargon/Extensions/Methods/Decimal192+Wrap+Functions.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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
extension Decimal192 { | ||
public init(_ string: String) throws { | ||
self = try newDecimalFromString(string: string) | ||
} | ||
} | ||
|
||
extension Decimal192: CustomStringConvertible { | ||
public var description: String { | ||
decimalToString(decimal: self) | ||
} | ||
} | ||
|
||
extension Decimal192 { | ||
public static let maxDivisibility: UInt8 = 18 | ||
} | ||
|
||
extension Decimal192 { | ||
/// Parse a local respecting string | ||
public init( | ||
formattedString: String, | ||
locale: Locale = .autoupdatingCurrent | ||
) throws { | ||
let localConfig: LocaleConfig = LocaleConfig(locale: locale) | ||
self = try newDecimalFromFormattedString( | ||
formattedString: formattedString, | ||
locale: localConfig | ||
) | ||
} | ||
} | ||
|
||
// MARK: Truncation and rounding | ||
|
||
extension Decimal192 { | ||
|
||
private func rounded(decimalPlaces: UInt8, roundingMode: RoundingMode) -> Self { | ||
precondition( | ||
decimalPlaces <= Decimal192.maxDivisibility, | ||
"Decimal places MUST be 0...18, was: \(decimalPlaces)" | ||
) | ||
do { | ||
return try decimalRound( | ||
decimal: self, | ||
decimalPlaces: Int32(decimalPlaces), | ||
roundingMode: roundingMode | ||
) | ||
} catch { | ||
fatalError("Failed to round, error: \(error)") | ||
} | ||
} | ||
|
||
|
||
/// Rounds to `decimalPlaces` decimals | ||
public func rounded(decimalPlaces: UInt8 = 0) -> Self { | ||
rounded( | ||
decimalPlaces: decimalPlaces, | ||
roundingMode: .toNearestMidpointAwayFromZero | ||
) | ||
} | ||
|
||
/// Rounds to `decimalPlaces` decimals, in the direction of 0 | ||
public func floor(decimalPlaces: UInt8) -> Self { | ||
rounded(decimalPlaces: decimalPlaces, roundingMode: .toZero) | ||
} | ||
|
||
/// Rounds to `decimalPlaces` decimals, in the direction away from zero | ||
public func ceil(decimalPlaces: UInt8) -> Self { | ||
rounded(decimalPlaces: decimalPlaces, roundingMode: .awayFromZero) | ||
} | ||
|
||
} | ||
|
||
extension Decimal192 { | ||
public var clamped: Self { | ||
decimalClampedToZero(decimal: self) | ||
} | ||
|
||
public func isNegative() -> Bool { | ||
decimalIsNegative(decimal: self) | ||
} | ||
} | ||
|
||
extension Decimal192: Comparable { | ||
public static func > (lhs: Self, rhs: Self) -> Bool { | ||
lhs.greaterThan(other: rhs) | ||
} | ||
public static func < (lhs: Self, rhs: Self) -> Bool { | ||
lhs.lessThan(other: rhs) | ||
} | ||
public static func >= (lhs: Self, rhs: Self) -> Bool { | ||
lhs.greaterThanOrEqual(other: rhs) | ||
} | ||
public static func <= (lhs: Self, rhs: Self) -> Bool { | ||
lhs.lessThanOrEqual(other: rhs) | ||
} | ||
} | ||
extension Decimal192 { | ||
|
||
public func lessThan(other: Self) -> Bool { | ||
decimalLessThan(lhs: self, rhs: other) | ||
} | ||
|
||
public func lessThanOrEqual(other: Self) -> Bool { | ||
decimalLessThanOrEqual(lhs: self, rhs: other) | ||
} | ||
|
||
public func greaterThan(other: Self) -> Bool { | ||
decimalGreaterThan(lhs: self, rhs: other) | ||
} | ||
|
||
public func greaterThanOrEqual(other: Self) -> Bool { | ||
decimalGreaterThanOrEqual(lhs: self, rhs: other) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/DisplayName+Wrap+Functions.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension DisplayName { | ||
public init(validating name: String) throws { | ||
self = try newDisplayName(name: name) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/Mnemonic+Wrap+Functions.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension Mnemonic { | ||
public var phrase: String { | ||
mnemonicPhrase(from: self) | ||
} | ||
} |
File renamed without changes.
12 changes: 9 additions & 3 deletions
12
apple/Sources/Sargon/Extensions/Swiftified/AppearanceID+Swiftified.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,8 +1,14 @@ | ||
public typealias AppearanceID = AppearanceId | ||
|
||
extension AppearanceID: Sendable {} | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
extension AppearanceID: Identifiable { | ||
public typealias ID = UInt8 | ||
public var id: ID { | ||
value | ||
} | ||
} | ||
extension AppearanceID: CustomStringConvertible { | ||
public var description: String { | ||
value.description | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
apple/Sources/Sargon/Extensions/Swiftified/BagOfBytes+Random.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
64 changes: 54 additions & 10 deletions
64
apple/Sources/Sargon/Extensions/Swiftified/Decimal192+Swiftified.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,11 +1,55 @@ | ||
extension Decimal192: Sendable {} | ||
//extension Decimal192: ExpressibleByStringLiteral { | ||
// | ||
//} | ||
//extension Decimal192: ExpressibleByFloatLiteral { | ||
// | ||
//} | ||
//extension Decimal192: SignedNumeric /* Numeric, ExpressibleByIntegerLiteral AdditiveArithmetic */ | ||
//{ | ||
// | ||
//} | ||
|
||
extension Decimal192: ExpressibleByStringLiteral { | ||
public init(stringLiteral string: String) { | ||
try! self.init(string) | ||
} | ||
} | ||
extension Decimal192: ExpressibleByIntegerLiteral { | ||
public init(integerLiteral i64: Int64) { | ||
self = newDecimalFromI64(value: i64) | ||
} | ||
} | ||
|
||
|
||
extension Decimal192: AdditiveArithmetic { | ||
public static var zero: Self { | ||
newDecimalFromU64(value: 0) | ||
} | ||
public static func + (lhs: Self, rhs: Self) -> Self { | ||
decimalAdd(lhs: lhs, rhs: rhs) | ||
} | ||
public static func - (lhs: Self, rhs: Self) -> Self { | ||
decimalSub(lhs: lhs, rhs: rhs) | ||
} | ||
} | ||
extension Decimal192: SignedNumeric { | ||
public prefix static func - (operand: Self) -> Self { | ||
decimalNeg(decimal: operand) | ||
} | ||
} | ||
extension Decimal192: Numeric { | ||
public typealias Magnitude = Self | ||
|
||
public var magnitude: Magnitude { | ||
decimalAbs(decimal: self) | ||
} | ||
|
||
public static func * (lhs: Self, rhs: Self) -> Self { | ||
decimalMul(lhs: lhs, rhs: rhs) | ||
} | ||
|
||
public static func *= (lhs: inout Self, rhs: Self) { | ||
lhs = lhs * rhs | ||
} | ||
|
||
public init?<T>(exactly source: T) where T: BinaryInteger { | ||
if let i64 = Int64(exactly: source) { | ||
self = newDecimalFromI64(value: i64) | ||
} else if let u64 = UInt64(exactly: source) { | ||
self = newDecimalFromU64(value: u64) | ||
} else { | ||
return nil | ||
} | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
apple/Sources/Sargon/Extensions/Swiftified/DisplayName+Swiftified.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
9 changes: 9 additions & 0 deletions
9
apple/Sources/Sargon/Extensions/Swiftified/LocaleConfig+Swiftified.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extension LocaleConfig: Sendable {} | ||
extension LocaleConfig { | ||
public init(locale: Locale) { | ||
self.init( | ||
decimalSeparator: locale.decimalSeparator, | ||
groupingSeparator: locale.groupingSeparator | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apple/Sources/Sargon/Extensions/Swiftified/Mnemonic+Swiftified.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
extension Mnemonic: Sendable {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@micbakos-rdx please re-install the precommit hook