-
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
Rust: SargonOS
&Drivers
more Profile Logic | Swift: Shared State (working example app)!
#131
Changes from 137 commits
c0cc997
d23e2c8
5493e93
b9296b5
dbf0988
b6c60f9
8302776
d53e213
e7d6872
c17200e
013d8e8
45c216e
0145b86
14d9f0a
7a6ff10
f59d687
4dcc68a
56b8a7c
5d572c0
a503380
7ab28f7
4bd1635
09c3faf
ee7fc6e
7f6bf0f
eeace21
c7138a9
ca1a045
a5c058f
71f982a
6a36962
836e9ca
202edf4
a363d0b
b7ce86a
68548f9
a41b65d
3a4e390
c7b728c
adc4f90
c202bca
5e7da97
855fc3a
b356ae1
8ff484f
4c519ff
06fa870
5e69f2c
301ec9a
f3cede3
f272fba
8a66b30
5f637f4
99dc187
0d8cc9b
0277010
a59ef1d
da3548c
8c04c18
e773211
084d6e3
abb73c1
8300417
13b582c
9c79f89
5701232
ee7366f
017638d
4c75954
14800a1
62dc6a8
062eac3
eef6c72
895ec12
a10cb29
d70c1a7
130964b
ea14243
1dd3bcd
a1219de
181b97e
161b7c6
f584c9c
3c80613
0bf4987
7c36650
80957c9
b523b05
0ab29d1
6c6f116
9581a7e
7d186ba
4118bfe
d381b93
b197e2a
419f143
9e269c7
2625153
2b4c346
30f8a85
6afaf58
07ec7ed
60ae29a
129cf57
f90c571
e67c6d2
b7c1ca5
0fd46ef
170677b
dda3a50
48934a5
4d890d5
f8701e4
7aee200
a8dff03
2055fe2
c45b015
54eda11
ec50125
526e052
274ae2d
9789e8c
4da9c46
4cfd24a
9bdc364
751f073
50701c6
78e1017
1847ba9
75e7c7a
2bfa430
d91b83e
40792b5
d79e565
436c2bc
f47dc2c
ddbc911
b3d19c7
dd5514a
9297cb7
2ce371b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hey 👋 You DID in fact read my fancy PR description BEFORE you started reviewing the code, right? Else switch back to description now and read it in full: | ||
|
||
https://github.com/radixdlt/sargon/pull/131 | ||
|
||
Thank you! Happy review! 🙏 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ var swiftSettings: [SwiftSetting] = [ | |
.enableExperimentalFeature("StrictConcurrency") | ||
] | ||
|
||
|
||
let sargonBinaryTargetName = "SargonCoreRS" | ||
let binaryTarget: Target | ||
let useLocalFramework = true | ||
|
@@ -42,8 +41,21 @@ let package = Package( | |
) | ||
], | ||
dependencies: [ | ||
// We use XCTestDynamicOverlay to have different `description` of e.g. Decimal192 | ||
// for tests vs not tests (we use a .test `Locale`) | ||
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.1.2"), | ||
|
||
// `XCTAssertNoDifference` used in test | ||
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.0"), | ||
|
||
// Hopefully only temporary! We use `SwiftJSON` to be able to mark some Sargon models | ||
// as `Swift.Codable`. See the SargonObjectCodable protocol for details. | ||
// In the future hopefully no JSON coding happens in wallets, | ||
// i.e. Sargon does ALL JSON coding, then we can remove this. | ||
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON", from: "5.0.2"), | ||
|
||
// Multicast / Share of notifications in EventBus | ||
.package(url: "https://github.com/sideeffect-io/AsyncExtensions", exact: "0.5.2"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
], | ||
targets: [ | ||
binaryTarget, | ||
|
@@ -57,6 +69,8 @@ let package = Package( | |
dependencies: [ | ||
.target(name: "SargonUniFFI"), | ||
"SwiftyJSON", | ||
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"), | ||
"AsyncExtensions" | ||
], | ||
path: "apple/Sources/Sargon", | ||
swiftSettings: swiftSettings | ||
|
@@ -67,8 +81,7 @@ let package = Package( | |
.target(name: "Sargon"), | ||
.product(name: "CustomDump", package: "swift-custom-dump"), | ||
], | ||
path: "apple/Tests", | ||
swiftSettings: swiftSettings | ||
path: "apple/Tests" | ||
), | ||
] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,10 @@ This repo contains a [`.pre-commit-config.yaml`](./.pre-commit-config.yaml) whic | |
pre-commit install | ||
``` | ||
|
||
## `direnv` | ||
|
||
Install [`direnv`](https://direnv.net) to automatically load env variables when you change directory to Sargon dir. This repo contains an `.envrc` which exports `RUST_LOG=info` so that logs are shown when running unit tests. When you run `cargo test` those logs will show up. Prefer using `nextest` below if you dont wanna see logs, and want prettier test result output. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice for testing to pick up |
||
|
||
### `nextest` | ||
|
||
[Nextest](https://nexte.st/index.html) is a nice test runner for Rust! | ||
|
CyonAlexRDX marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Alexander Cyon on 2024-05-03. | ||
// | ||
|
||
import Foundation | ||
import SargonUniFFI | ||
|
||
// Makes it possible to type `.shared` on an initalizer/func taking | ||
// `some EntropyProviderDriver` as parameter. | ||
extension EntropyProviderDriver where Self == EntropyProvider { | ||
/// Singleton `EntropyProviderDriver` of type `EntropyProvider`, | ||
/// being an `actor` that uses CSRNG `SystemRandomNumberGenerator` | ||
public static var shared: Self { Self.shared } | ||
} | ||
|
||
/// An `EntropyProviderDriver` actor which uses CSRNG `SystemRandomNumberGenerator` | ||
/// to generate 32 bytes. | ||
public final actor EntropyProvider { | ||
internal init() {} | ||
|
||
/// Singleton `EntropyProviderDriver` of type `EntropyProvider`, | ||
/// being an `actor` that uses CSRNG `SystemRandomNumberGenerator` | ||
public static let shared = EntropyProvider() | ||
} | ||
|
||
extension EntropyProvider: EntropyProviderDriver { | ||
/// Generates 32 bytes using CSRNG `SystemRandomNumberGenerator` | ||
nonisolated public func generateSecureRandomBytes() -> Entropy32Bytes { | ||
Entropy32Bytes.generate() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Alexander Cyon on 2024-05-05. | ||
// | ||
|
||
import Foundation | ||
import SargonUniFFI | ||
import AsyncExtensions | ||
|
||
// Makes it possible to type `.shared` on an initalizer/func taking | ||
// `some EventBusDriver` as parameter. | ||
extension EventBusDriver where Self == EventBus { | ||
|
||
/// Singleton `EventBusDriver` of type `EventBus` being an `actor` which forwards `EventNotification`s | ||
/// originally emitted by `SargonOS` (Rust side). | ||
public static var shared: Self { Self.shared } | ||
} | ||
|
||
/// An `EventBusDriver` actor which handles incoming | ||
/// `EventNotifications` and forwards them to any | ||
/// subscriber of `notifications()`, being a multicasted | ||
/// async sequence. | ||
public final actor EventBus { | ||
/// A stream we multicast on. | ||
private let stream = AsyncThrowingPassthroughSubject<Element, any Error>() | ||
private let subject: Subject | ||
#if DEBUG | ||
public init() { | ||
subject = .init() | ||
} | ||
CyonAlexRDX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#else | ||
private init() { | ||
subject = .init() | ||
} | ||
#endif | ||
} | ||
|
||
extension EventBus { | ||
|
||
public typealias Element = EventNotification | ||
public typealias Subject = AsyncPassthroughSubject<Element> | ||
|
||
/// Singleton `EventBusDriver` of type `EventBus` being an `actor` which forwards `EventNotification`s | ||
/// originally emitted by `SargonOS` (Rust side). | ||
public static let shared = EventBus() | ||
|
||
/// A multicasted async sequence of `EventNotification` values | ||
/// over time, originally emitted by `SargonOS` (Rust side). | ||
public func notifications() -> AsyncMulticastSequence<EventBus.Subject, AsyncThrowingPassthroughSubject<EventBus.Element, any Error>> { | ||
subject | ||
.multicast(stream) | ||
.autoconnect() | ||
} | ||
} | ||
|
||
extension EventBus: EventBusDriver { | ||
/// This method is called by `SargonOS` (Rust side) and we should | ||
/// "forward" the events to subscribers (Swift swide), i.e. `@SharedReader`s of profile values, | ||
/// which uses `notifications()` to subscribe to these | ||
/// values. | ||
public func handleEventNotification(eventNotification: EventNotification) async { | ||
log.debug("Handle event: \(String(describing: eventNotification.event))") | ||
subject.send(eventNotification) | ||
GhenadieVP marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
I've changed
scripts/ios/test.sh
so that it does not (clean) build, but can be used to swift test with code coverage and see missed lines. If we pass--build
it builds (Rust Sargon) before.