Skip to content

Commit

Permalink
Fix prev. exposed enums and structs
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Dec 18, 2024
1 parent a8cb352 commit 034c2fe
Show file tree
Hide file tree
Showing 12 changed files with 2,146 additions and 286 deletions.
16 changes: 16 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
freezed_annotation:
dependency: transitive
description:
name: freezed_annotation
sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2
url: "https://pub.dev"
source: hosted
version: "2.4.4"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand All @@ -122,6 +130,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
url: "https://pub.dev"
source: hosted
version: "4.9.0"
leak_tracker:
dependency: transitive
description:
Expand Down
54 changes: 51 additions & 3 deletions lib/src/rust/api/client/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,68 @@
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../../frb_generated.dart';
import '../relay/options.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These types are ignored because they are not used by any `pub` functions: `_ConnectionTarget`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `deref`, `deref`, `from`, `from`
// These functions have error during generation (see debug logs or enable `stop_on_error: true` for more details): `addr`, `autoconnect`, `automatic_authentication`, `connection`, `embedded_tor_with_path`, `embedded_tor`, `gossip`, `min_pow`, `mode`, `target`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `deref`, `from`, `from`

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_ClientOptions>>
abstract class ClientOptions implements RustOpaqueInterface {
/// Automatically start connection with relays (default: false)
///
/// When set to `true`, there isn't the need of calling the connect methods.
ClientOptions autoconnect({required bool val});

/// Auto authenticate to relays (default: true)
///
/// <https://github.com/nostr-protocol/nips/blob/master/42.md>
ClientOptions automaticAuthentication({required bool enabled});

/// Connection
ClientOptions connection({required Connection connection});

/// Enable gossip model (default: false)
ClientOptions gossip({required bool enabled});

/// Minimum POW difficulty for received events
ClientOptions minPow({required int difficulty});

factory ClientOptions() =>
NostrSdk.instance.api.crateApiClientOptionsClientOptionsNew();
}

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_Connection>>
abstract class Connection implements RustOpaqueInterface {
/// Set proxy (ex. `127.0.0.1:9050`)
Connection addr({required String addr});

/// Use embedded tor client
///
/// This not work on `android` and/or `ios` targets.
/// Use [`Connection::embedded_tor_with_path`] instead.
Connection embeddedTor();

/// Use embedded tor client
///
/// Specify a path where to store data
Connection embeddedTorWithPath({required String dataPath});

/// Set connection mode (default: direct)
Connection mode({required ConnectionMode mode});

factory Connection() =>
NostrSdk.instance.api.crateApiClientOptionsConnectionNew();

/// Set connection target (default: all)
Connection target({required ConnectionTarget target});
}

/// Connection target
enum ConnectionTarget {
/// Use proxy for all relays
all,

/// Use proxy only for `.onion` relays
onion,
;
}
46 changes: 23 additions & 23 deletions lib/src/rust/api/relay/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
part 'options.freezed.dart';

// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`, `try_from`



@freezed
sealed class _ConnectionMode with _$_ConnectionMode {
const _ConnectionMode._();

/// Direct connection
const factory _ConnectionMode.direct() = _ConnectionMode_Direct;
/// Connect through proxy
const factory _ConnectionMode.proxy({ /// Socket addr (i.e. 127.0.0.1:9050)
required String addr , }) = _ConnectionMode_Proxy;
/// Connect through tor network
const factory _ConnectionMode.tor({ /// Path where to store data
///
/// This is required for `android` and `ios` targets!
String? customPath , }) = _ConnectionMode_Tor;

}
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`, `try_from`

@freezed
sealed class ConnectionMode with _$ConnectionMode {
const ConnectionMode._();

/// Direct connection
const factory ConnectionMode.direct() = ConnectionMode_Direct;

/// Connect through proxy
const factory ConnectionMode.proxy({
/// Socket addr (i.e. 127.0.0.1:9050)
required String addr,
}) = ConnectionMode_Proxy;

/// Connect through tor network
const factory ConnectionMode.tor({
/// Path where to store data
///
/// This is required for `android` and `ios` targets!
String? customPath,
}) = ConnectionMode_Tor;
}
Loading

0 comments on commit 034c2fe

Please sign in to comment.