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

Rust: SargonOS &Drivers more Profile Logic | Swift: Shared State (working example app)! #131

Merged
merged 141 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 137 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
c0cc997
BROKEN WIP
Sajjon May 2, 2024
d23e2c8
BROKEN WIP
Sajjon May 2, 2024
5493e93
WIP
Sajjon May 2, 2024
b9296b5
WIP
Sajjon May 2, 2024
dbf0988
WIP
Sajjon May 2, 2024
b6c60f9
WIP
Sajjon May 3, 2024
8302776
WIP
Sajjon May 3, 2024
d53e213
wip
Sajjon May 3, 2024
e7d6872
nicer boot
CyonAlexRDX May 3, 2024
c17200e
logging driver
CyonAlexRDX May 3, 2024
013d8e8
WIP
Sajjon May 3, 2024
45c216e
WIP
CyonAlexRDX May 3, 2024
0145b86
WIP
Sajjon May 3, 2024
14d9f0a
WIP
Sajjon May 3, 2024
7a6ff10
WIP
Sajjon May 3, 2024
f59d687
WIP
Sajjon May 3, 2024
4dcc68a
WIP
Sajjon May 3, 2024
56b8a7c
WIP
Sajjon May 4, 2024
5d572c0
Merge branch 'main' into ac/system_with_drivers
Sajjon May 4, 2024
a503380
WIP
Sajjon May 4, 2024
7ab28f7
WIP
Sajjon May 4, 2024
4bd1635
WIP
Sajjon May 4, 2024
09c3faf
WIP
Sajjon May 4, 2024
ee7fc6e
WIP
Sajjon May 5, 2024
7f6bf0f
WIP
Sajjon May 5, 2024
eeace21
WIP
Sajjon May 5, 2024
c7138a9
WIP
Sajjon May 5, 2024
ca1a045
WIP
Sajjon May 5, 2024
a5c058f
WIP
Sajjon May 5, 2024
71f982a
WIP
Sajjon May 5, 2024
6a36962
WIP
Sajjon May 5, 2024
836e9ca
WIP
Sajjon May 5, 2024
202edf4
WIP
Sajjon May 5, 2024
a363d0b
WIP
Sajjon May 6, 2024
b7ce86a
WIP
Sajjon May 6, 2024
68548f9
WIP
Sajjon May 6, 2024
a41b65d
WIP
Sajjon May 6, 2024
3a4e390
WIP
Sajjon May 6, 2024
c7b728c
merge and fixes
CyonAlexRDX May 9, 2024
adc4f90
Merge branch 'main' into ac/system_with_drivers
Sajjon May 9, 2024
c202bca
bump version to 1.1.0
Sajjon May 9, 2024
5e7da97
wip rust drivers
CyonAlexRDX May 9, 2024
855fc3a
BROKEN WIP
CyonAlexRDX May 9, 2024
b356ae1
WIP
Sajjon May 9, 2024
8ff484f
WIP
Sajjon May 9, 2024
4c519ff
WIP
Sajjon May 9, 2024
06fa870
WIP
Sajjon May 9, 2024
5e69f2c
sargon os tests
Sajjon May 9, 2024
301ec9a
merge
Sajjon May 9, 2024
f3cede3
fix failing swift test
Sajjon May 9, 2024
f272fba
restructure
Sajjon May 10, 2024
8a66b30
async test util
Sajjon May 10, 2024
5f637f4
make it possible to inject mnemonic into SargonOS. for tests.
Sajjon May 10, 2024
99dc187
more tests
Sajjon May 11, 2024
0d8cc9b
merge
Sajjon May 11, 2024
0277010
more tests
Sajjon May 11, 2024
a59ef1d
more tests
Sajjon May 11, 2024
da3548c
more tests
Sajjon May 11, 2024
8c04c18
make sure timestamp is stable post JSON roundtrip
Sajjon May 12, 2024
e773211
logging
Sajjon May 12, 2024
084d6e3
log
Sajjon May 12, 2024
abb73c1
test rust file system.
Sajjon May 12, 2024
8300417
update account tests
Sajjon May 12, 2024
13b582c
more tests
Sajjon May 12, 2024
9c79f89
more tests
Sajjon May 12, 2024
5701232
WIP more tests
Sajjon May 13, 2024
ee7366f
merge
Sajjon May 13, 2024
017638d
swift tests
Sajjon May 13, 2024
4c75954
cleanup
Sajjon May 13, 2024
14800a1
events
Sajjon May 13, 2024
62dc6a8
Merge branch 'main' into ac/system_with_drivers
Sajjon May 13, 2024
062eac3
more tests
Sajjon May 13, 2024
eef6c72
more tests (factors)
Sajjon May 13, 2024
895ec12
fix swift tests
Sajjon May 13, 2024
a10cb29
more tests
Sajjon May 14, 2024
d70c1a7
claim profile
Sajjon May 14, 2024
130964b
use device_info from host
Sajjon May 14, 2024
ea14243
bump tarpaulin to 0.30.0 in CI (also done locally)
Sajjon May 14, 2024
1dd3bcd
kotlin
Sajjon May 14, 2024
a1219de
error code
CyonAlexRDX May 14, 2024
181b97e
kotlin
CyonAlexRDX May 14, 2024
161b7c6
Merge branch 'main' into ac/system_with_drivers
CyonAlexRDX May 14, 2024
f584c9c
fix kotlin? fix build issue with cast (discriminant of CommonError).
Sajjon May 14, 2024
3c80613
UniFFI export drivers
Sajjon May 14, 2024
0bf4987
remove test
Sajjon May 14, 2024
7c36650
more tests
Sajjon May 14, 2024
80957c9
more tests
Sajjon May 14, 2024
b523b05
more tests
Sajjon May 14, 2024
0ab29d1
remove shared state
Sajjon May 15, 2024
6c6f116
more tests
Sajjon May 15, 2024
9581a7e
WIP
Sajjon May 15, 2024
7d186ba
WIP
Sajjon May 15, 2024
4118bfe
WIP
Sajjon May 15, 2024
d381b93
merge
Sajjon May 15, 2024
b197e2a
wip
Sajjon May 16, 2024
419f143
IMPORTANT Fix broken Rust security-framework bug see https://github.c…
Sajjon May 16, 2024
9e269c7
WIP
Sajjon May 16, 2024
2625153
WIP
Sajjon May 16, 2024
2b4c346
WIP changeGW
CyonAlexRDX May 16, 2024
30f8a85
merge
Sajjon May 16, 2024
6afaf58
fix
Sajjon May 16, 2024
07ec7ed
fixes
Sajjon May 16, 2024
60ae29a
Profile is now created with empty mainnet network
CyonAlexRDX May 16, 2024
129cf57
more tests
Sajjon May 16, 2024
f90c571
tests
Sajjon May 16, 2024
e67c6d2
Add Vendor to DeviceInfo and HostInfoDriver
Sajjon May 16, 2024
b7c1ca5
more tests
Sajjon May 16, 2024
0fd46ef
fix kotlin test
Sajjon May 16, 2024
170677b
emit event when account is updated
Sajjon May 16, 2024
dda3a50
fixes
Sajjon May 17, 2024
48934a5
Ensure SharedReader in swift is created once per value kind, and then…
Sajjon May 17, 2024
4d890d5
add host_vendor to DeviceFactorSourceHitn
CyonAlexRDX May 17, 2024
f8701e4
more tests
CyonAlexRDX May 17, 2024
7aee200
add attention
CyonAlexRDX May 17, 2024
a8dff03
Change designated init of Profile to accept a Mnemonic and DeviceInfo…
Sajjon May 18, 2024
2055fe2
fix device_info_description for old Swift format. Still need to add A…
Sajjon May 20, 2024
c45b015
address some PR comments.
Sajjon May 23, 2024
54eda11
merge
Sajjon May 24, 2024
ec50125
bump to 1.1.0
Sajjon May 24, 2024
526e052
WIP event kind query methods shared between iOS and Android to check …
Sajjon May 24, 2024
274ae2d
merge
CyonAlexRDX May 24, 2024
9789e8c
Add methods to check if a certain EventKind affects certain state, e.…
Sajjon May 25, 2024
4da9c46
Swift: Changing singleton instance creation of BIOS and SargonOS and …
Sajjon May 25, 2024
4cfd24a
fixes
Sajjon May 25, 2024
9bdc364
Clients no longer hold reference to Drivers, since each client respec…
Sajjon May 26, 2024
751f073
cleanup
Sajjon May 26, 2024
50701c6
fixes
Sajjon May 26, 2024
78e1017
documentation
Sajjon May 26, 2024
1847ba9
fix kotlin
Sajjon May 26, 2024
75e7c7a
fixes
Sajjon May 26, 2024
2bfa430
fixes
Sajjon May 26, 2024
d91b83e
documentation and cleanup of SharedState
Sajjon May 26, 2024
40792b5
more tests
Sajjon May 27, 2024
d79e565
add missing asserts to test
CyonAlexRDX May 27, 2024
436c2bc
fixes
CyonAlexRDX May 27, 2024
f47dc2c
rename events
CyonAlexRDX May 27, 2024
ddbc911
fix swift
CyonAlexRDX May 27, 2024
b3d19c7
merge main
Sajjon Jun 28, 2024
dd5514a
fix swift, try fix kotlin tests
CyonAlexRDX Jun 28, 2024
9297cb7
try fix kotlin
CyonAlexRDX Jun 28, 2024
2ce371b
fix kotlin
CyonAlexRDX Jun 28, 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
5 changes: 5 additions & 0 deletions .github/attention.md
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! 🙏
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rustup target add aarch64-apple-darwin
sh ./scripts/ios/test.sh --codecov ${{ env.SWIFT_CODE_COV_REPORT_PATH }}
sh ./scripts/ios/test.sh --build --codecov ${{ env.SWIFT_CODE_COV_REPORT_PATH }}
Copy link
Contributor

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.

- name: Upload to CodeCov.io
uses: RDXWorks-actions/codecov-action@main
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
uses: RDXWorks-actions/cargo-install@main
with:
crate: cargo-tarpaulin
tag: 0.27.3
tag: 0.30.0
CyonAlexRDX marked this conversation as resolved.
Show resolved Hide resolved
locked: true

- name: Code Coverage - Generate
Expand Down
20 changes: 10 additions & 10 deletions Cargo.lock

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

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sargon"
version = "1.0.2"
version = "1.1.0"
edition = "2021"
build = "build.rs"

Expand Down Expand Up @@ -172,17 +172,18 @@ aes-gcm = { git = "https://github.com/RustCrypto/AEADs", rev = "7e82b01cd4901f6a
# hkdf = "0.12.4"
hkdf = { git = "https://github.com/RustCrypto/KDFs/", rev = "1ac16e8b9d4ee7a67613c9396c6cc1327652eaba" }

# reqwest = "0.12.3"
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "0720159f6369f54e045a1fd315e0f24b7a0b4a39", default-features = false, features = [
"native-tls-vendored",
] }


[dev-dependencies]
# uniffi = "0.27.1"
uniffi = { git = "https://github.com/mozilla/uniffi-rs/", rev = "6f33088e8100a2ea9586c8c3ecf98ab51d5aba62", features = [
"bindgen-tests",
] }

# reqwest = "0.12.3"
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "0720159f6369f54e045a1fd315e0f24b7a0b4a39", default-features = false, features = [
"native-tls-vendored",
] }

# actix-rt = "3.3.0"
actix-rt = { git = "https://github.com/actix/actix-net", rev = "57fd6ea8098d1f2d281c305fc331216c4fe1992e" }

Expand Down
22 changes: 20 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"pins" : [
{
"identity" : "asyncextensions",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sideeffect-io/AsyncExtensions",
"state" : {
"revision" : "1f0729e4f1f6c7166acfac3cec43b3cbe83be0e6",
"version" : "0.5.2"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
Expand All @@ -23,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
"revision" : "6f30bdba373bbd7fbfe241dddd732651f2fbd1e2",
"version" : "1.1.2"
}
}
],
Expand Down
19 changes: 16 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var swiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("StrictConcurrency")
]


let sargonBinaryTargetName = "SargonCoreRS"
let binaryTarget: Target
let useLocalFramework = true
Expand Down Expand Up @@ -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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncExtensions used for Multicast / Shared consumers, beacuse Swifts AsyncStream does not support multiple consumers, and we need to have multiple consumers of EventBus notification in our multiple @SharedReaders.

],
targets: [
binaryTarget,
Expand All @@ -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
Expand All @@ -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"
),
]
)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice for testing to pick up RUST_LOG=info environment variable so that when you run cargo test you will see logs.


### `nextest`

[Nextest](https://nexte.st/index.html) is a nice test runner for Rust!
Expand Down
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()
}
}
67 changes: 67 additions & 0 deletions apple/Sources/Sargon/Drivers/EventBus/EventBus.swift
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
}
}
Loading
Loading