Skip to content
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 26 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
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 Feb 13, 2024
d4a019a
Decimal compare methods and UniFFI exported funtions
Sajjon Feb 13, 2024
ed6e18e
add Swift bindgen tests for decimal
Sajjon Feb 14, 2024
2e95bfb
Merge branch 'develop' into wrap_radix_engine_toolkit
Sajjon Feb 14, 2024
30f134d
Sargon: Add method to read Mnemonic, UniFFI exported, Improve iOS exa…
Sajjon Feb 16, 2024
2c447c5
Merge
Sajjon Feb 17, 2024
944795e
WIP Decimal192 + Swifitfied
Sajjon Feb 17, 2024
a9b96d0
Make Decimal192 conform to Comparable
Sajjon Feb 17, 2024
5ec79b6
Add clamped
Sajjon Feb 17, 2024
ff8a4a4
Decimal rounding
Sajjon Feb 17, 2024
ac0e057
rename file decimal -> decimal192.rs, add from f32.
Sajjon Feb 17, 2024
3dc5907
Add from_formatted_string
Sajjon Feb 18, 2024
b2c90d9
Swiftify Decimal192 from formatted string
Sajjon Feb 18, 2024
47f6da9
Add tests
Sajjon Feb 18, 2024
7592b04
more tests
Sajjon Feb 18, 2024
9437497
Start stubbing out Signatures and other types required by RET, which …
Sajjon Feb 19, 2024
5f5cc20
Declare Ed25519Signature and use it with Ed25519PrivateKey and Public…
Sajjon Feb 19, 2024
fe86e8c
drop Ord/PartialOrd for types where it did not really make sense. Rem…
CyonAlexRDX Feb 19, 2024
9aad4ff
Add HasPlaceholder conformance to Ed25519PublicKey
Sajjon Feb 19, 2024
b31d4fa
Add HasPlaceholder conformance to Secp256k1Signature
Sajjon Feb 19, 2024
1731692
tests of Ed25519Signature and Secp256k1Signature
CyonAlexRDX Feb 19, 2024
3d286fc
Unit tests for Signature
CyonAlexRDX Feb 19, 2024
6a7efd4
Merge branch 'develop' into wrap_radix_engine_toolkit
CyonAlexRDX Feb 19, 2024
95931b9
Add step to precommit ensuring that local development is set to false…
CyonAlexRDX Feb 19, 2024
32e15fb
fail fast in precommit
CyonAlexRDX Feb 19, 2024
edd3748
build, here is the updated Swift bindgen
CyonAlexRDX Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Copy link
Contributor Author

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

Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
fail_fast: true

repos:
- repo: https://github.com/crate-ci/typos
rev: v1.17.2
hooks:
- id: typos
- repo: local
hooks:
- id: ensure Swift not changed to local development
name: ensure Swift not changed to local development
language: system
types: [file, swift]
entry: ./scripts/ios/ensure-not-local.sh
pass_filenames: false

- id: fmt
name: fmt
language: system
Expand Down
12 changes: 10 additions & 2 deletions .tarpaulin.toml
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
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ path = "src/bin.rs"
[dependencies]
log = "0.4.20"
pretty_env_logger = "0.5.0"
derive_more = { version = "1.0.0-beta.6", features = ["debug", "display"] }
derive_more = { version = "1.0.0-beta.6", features = [
"debug",
"display",
"from_str",
] }
serde = { version = "1.0.193", features = ["derive", "rc", "std"] }
serde_json = { version = "1.0.108", features = ["preserve_order"] }
serde_with = { version = "3.4.0" }
Expand All @@ -46,7 +50,7 @@ radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto",
radix-engine-toolkit-json = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "9dc3deeb3299b4f4c255f36bb3d504681379ad5a" }
radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "9dc3deeb3299b4f4c255f36bb3d504681379ad5a" }
enum-iterator = "1.4.1"
bip32 = "0.5.1" # only need Secp256k1, to do validation of PublicKey
bip32 = "0.5.1" # only need Secp256k1, to do validation of PublicKey
ed25519-dalek = "1.0.1"
rand = "0.8.5"
hex = "0.4.3"
Expand All @@ -64,6 +68,7 @@ bip39 = { version = "2.0.0", features = ["serde"] }
time-util = { version = "0.3.4", features = ["chrono"] }
assert-json-diff = "2.0.2"
url = { version = "2.5.0", features = ["serde"] }
num-format = "0.4.4"

[build-dependencies]
uniffi = { version = "0.26.0", features = ["build"] }
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let sargonBinaryTargetName = "SargonCoreRS"
let binaryTarget: Target
let useLocalFramework = true
let useLocalFramework = false

if useLocalFramework {
binaryTarget = .binaryTarget(
Expand Down
7 changes: 7 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ extend-exclude = [
"tarpaulin-report.html",
"tests/vectors/fixtures/*.json",
]


[default.extend-identifiers]
inout = "inout"

[default.extend-words]
inout = "inout"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension AppearanceID: CaseIterable {
public static var allCases: [Self] {
appearanceIdsAll()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension BagOfBytes {
public init(data: Data) {
self = newBagOfBytesFrom(bytes: data)
}
}

This file was deleted.

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)
}
}
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension Mnemonic {
public var phrase: String {
mnemonicPhrase(from: self)
}
}
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
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
extension BagOfBytes {
public init(data: Data) {
self = newBagOfBytesFrom(bytes: data)
}
public static func random(byteCount: Int) -> Self {
var data = Data(repeating: 0, count: byteCount)
data.withUnsafeMutableBytes {
Expand Down
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
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
extension DisplayName: Sendable {}
extension DisplayName {
public init(validating name: String) throws {
self = try newDisplayName(name: name)
}
}

#if DEBUG
extension DisplayName: ExpressibleByStringLiteral {
Expand Down
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
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension Mnemonic: Sendable {}
Loading
Loading