From b6835ee814484b05c21fcaf6d0aab417be4b6e2b Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 16:04:04 +0200 Subject: [PATCH 1/7] Read logs in dart, make log level adjustable --- .../p2panda/lib/src/bridge_generated.dart | 104 ++++++++++++++-- packages/p2panda/native/src/api.rs | 112 ++++++++++++++++-- .../p2panda/native/src/bridge_generated.rs | 63 ++++++++++ 3 files changed, 257 insertions(+), 22 deletions(-) diff --git a/packages/p2panda/lib/src/bridge_generated.dart b/packages/p2panda/lib/src/bridge_generated.dart index b47b1360..e236ef53 100644 --- a/packages/p2panda/lib/src/bridge_generated.dart +++ b/packages/p2panda/lib/src/bridge_generated.dart @@ -14,6 +14,10 @@ import 'dart:ffi' as ffi; part 'bridge_generated.freezed.dart'; abstract class P2Panda { + Stream subscribeLogStream({dynamic hint}); + + FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta; + /// Create, sign and encode a p2panda entry. /// /// Takes large u64 integers for log id and seq num as strings. If we would declare them as u64 @@ -60,7 +64,8 @@ abstract class P2Panda { /// /// Supports Android logging for logs coming from the node. Future startNode( - {required KeyPair keyPair, + {required String logLevel, + required KeyPair keyPair, required String databaseUrl, required String blobsBasePath, required List relayAddresses, @@ -149,6 +154,28 @@ class KeyPair { ); } +class LogEntry { + final int timestamp; + final LogLevel level; + final String tag; + final String msg; + + const LogEntry({ + required this.timestamp, + required this.level, + required this.tag, + required this.msg, + }); +} + +enum LogLevel { + Trace, + Debug, + Info, + Warn, + Error, +} + /// Operations are categorised by their action type. /// /// An action defines the operation format and if this operation creates, updates or deletes a data @@ -225,6 +252,23 @@ class P2PandaImpl implements P2Panda { factory P2PandaImpl.wasm(FutureOr module) => P2PandaImpl(module as ExternalLibrary); P2PandaImpl.raw(this._platform); + Stream subscribeLogStream({dynamic hint}) { + return _platform.executeStream(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_subscribe_log_stream(port_), + parseSuccessData: _wire2api_log_entry, + parseErrorData: null, + constMeta: kSubscribeLogStreamConstMeta, + argValues: [], + hint: hint, + )); + } + + FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "subscribe_log_stream", + argNames: [], + ); + Future signAndEncodeEntry( {required String logId, required String seqNum, @@ -331,24 +375,27 @@ class P2PandaImpl implements P2Panda { ); Future startNode( - {required KeyPair keyPair, + {required String logLevel, + required KeyPair keyPair, required String databaseUrl, required String blobsBasePath, required List relayAddresses, required List allowSchemaIds, dynamic hint}) { - var arg0 = _platform.api2wire_box_autoadd_key_pair(keyPair); - var arg1 = _platform.api2wire_String(databaseUrl); - var arg2 = _platform.api2wire_String(blobsBasePath); - var arg3 = _platform.api2wire_StringList(relayAddresses); - var arg4 = _platform.api2wire_StringList(allowSchemaIds); + var arg0 = _platform.api2wire_String(logLevel); + var arg1 = _platform.api2wire_box_autoadd_key_pair(keyPair); + var arg2 = _platform.api2wire_String(databaseUrl); + var arg3 = _platform.api2wire_String(blobsBasePath); + var arg4 = _platform.api2wire_StringList(relayAddresses); + var arg5 = _platform.api2wire_StringList(allowSchemaIds); return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - _platform.inner.wire_start_node(port_, arg0, arg1, arg2, arg3, arg4), + callFfi: (port_) => _platform.inner + .wire_start_node(port_, arg0, arg1, arg2, arg3, arg4, arg5), parseSuccessData: _wire2api_unit, parseErrorData: _wire2api_FrbAnyhowException, constMeta: kStartNodeConstMeta, argValues: [ + logLevel, keyPair, databaseUrl, blobsBasePath, @@ -363,6 +410,7 @@ class P2PandaImpl implements P2Panda { const FlutterRustBridgeTaskConstMeta( debugName: "start_node", argNames: [ + "logLevel", "keyPair", "databaseUrl", "blobsBasePath", @@ -533,6 +581,22 @@ class P2PandaImpl implements P2Panda { ); } + LogEntry _wire2api_log_entry(dynamic raw) { + final arr = raw as List; + if (arr.length != 4) + throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); + return LogEntry( + timestamp: _wire2api_u64(arr[0]), + level: _wire2api_log_level(arr[1]), + tag: _wire2api_String(arr[2]), + msg: _wire2api_String(arr[3]), + ); + } + + LogLevel _wire2api_log_level(dynamic raw) { + return LogLevel.values[raw as int]; + } + OperationAction _wire2api_operation_action(dynamic raw) { return OperationAction.values[raw as int]; } @@ -541,6 +605,10 @@ class P2PandaImpl implements P2Panda { return raw == null ? null : _wire2api_String(raw); } + int _wire2api_u64(dynamic raw) { + return castInt(raw); + } + int _wire2api_u8(dynamic raw) { return raw as int; } @@ -845,6 +913,20 @@ class P2PandaWire implements FlutterRustBridgeWireBase { late final _init_frb_dart_api_dl = _init_frb_dart_api_dlPtr .asFunction)>(); + void wire_subscribe_log_stream( + int port_, + ) { + return _wire_subscribe_log_stream( + port_, + ); + } + + late final _wire_subscribe_log_streamPtr = + _lookup>( + 'wire_subscribe_log_stream'); + late final _wire_subscribe_log_stream = + _wire_subscribe_log_streamPtr.asFunction(); + void wire_sign_and_encode_entry( int port_, ffi.Pointer log_id, @@ -955,6 +1037,7 @@ class P2PandaWire implements FlutterRustBridgeWireBase { void wire_start_node( int port_, + ffi.Pointer log_level, ffi.Pointer key_pair, ffi.Pointer database_url, ffi.Pointer blobs_base_path, @@ -963,6 +1046,7 @@ class P2PandaWire implements FlutterRustBridgeWireBase { ) { return _wire_start_node( port_, + log_level, key_pair, database_url, blobs_base_path, @@ -975,6 +1059,7 @@ class P2PandaWire implements FlutterRustBridgeWireBase { ffi.NativeFunction< ffi.Void Function( ffi.Int64, + ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer, @@ -983,6 +1068,7 @@ class P2PandaWire implements FlutterRustBridgeWireBase { late final _wire_start_node = _wire_start_nodePtr.asFunction< void Function( int, + ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer, diff --git a/packages/p2panda/native/src/api.rs b/packages/p2panda/native/src/api.rs index 15532331..957e9804 100644 --- a/packages/p2panda/native/src/api.rs +++ b/packages/p2panda/native/src/api.rs @@ -1,11 +1,14 @@ // SPDX-License-Identifier: AGPL-3.0-or-later -use android_logger::{Config, FilterBuilder}; +use std::str::FromStr; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use android_logger::{AndroidLogger, Config, FilterBuilder}; use anyhow::{anyhow, Result}; use aquadoggo::{AllowList, Configuration}; use ed25519_dalek::SecretKey; -use flutter_rust_bridge::RustOpaque; -use log::LevelFilter; +use flutter_rust_bridge::{RustOpaque, StreamSink}; +use log::{Level, LevelFilter, Log, Record}; use p2panda_rs::document::DocumentViewId; use p2panda_rs::entry; use p2panda_rs::entry::traits::{AsEncodedEntry, AsEntry}; @@ -21,6 +24,95 @@ use crate::node::Manager; static NODE_INSTANCE: OnceCell = OnceCell::const_new(); +static STREAM_SINK: OnceCell> = OnceCell::const_new(); + +static LOGGER: OnceCell = OnceCell::const_new(); + +struct Logger { + android_logger: AndroidLogger, + max_level: LevelFilter, +} + +impl Logger { + fn new(max_level: LevelFilter) -> Logger { + let android_config = Config::default().with_max_level(max_level).with_filter( + FilterBuilder::new() + .filter(Some("aquadoggo"), LevelFilter::Debug) + .build(), + ); + let android_logger = AndroidLogger::new(android_config); + + Logger { + android_logger, + max_level, + } + } + + fn record_to_entry(record: &Record) -> LogEntry { + let timestamp = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_else(|_| Duration::from_secs(0)) + .as_millis() as u64; + + let level = match record.level() { + Level::Trace => LogLevel::Trace, + Level::Debug => LogLevel::Debug, + Level::Info => LogLevel::Info, + Level::Warn => LogLevel::Warn, + Level::Error => LogLevel::Error, + }; + + let tag = record.file().unwrap_or_else(|| record.target()).to_owned(); + + let msg = format!("{}", record.args()); + + LogEntry { + timestamp, + level, + tag, + msg, + } + } +} + +impl Log for Logger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() <= self.max_level + } + + fn log(&self, record: &log::Record) { + match STREAM_SINK.get() { + Some(sink) => { + sink.add(Logger::record_to_entry(record)); + } + None => (), + } + + self.android_logger.log(record); + } + + fn flush(&self) {} +} + +pub fn subscribe_log_stream(sink: StreamSink) { + let _ = STREAM_SINK.set(sink); +} + +pub enum LogLevel { + Trace, + Debug, + Info, + Warn, + Error, +} + +pub struct LogEntry { + pub timestamp: u64, + pub level: LogLevel, + pub tag: String, + pub msg: String, +} + pub type HexString = String; /// Ed25519 key pair for authors to sign p2panda entries with. @@ -211,22 +303,16 @@ pub fn decode_operation(operation: Vec) -> Result<(OperationAction, String)> /// /// Supports Android logging for logs coming from the node. pub fn start_node( + log_level: String, key_pair: KeyPair, database_url: String, blobs_base_path: String, relay_addresses: Vec, allow_schema_ids: Vec, ) -> Result<()> { - // Initialise logging for Android developer console - android_logger::init_once( - Config::default() - .with_max_level(LevelFilter::Trace) - .with_filter( - FilterBuilder::new() - .filter(Some("aquadoggo"), LevelFilter::Debug) - .build(), - ), - ); + let _ = LOGGER.set(Logger::new( + LevelFilter::from_str(&log_level).expect("unknown log level"), + )); // Set node configuration let mut config = Configuration::default(); diff --git a/packages/p2panda/native/src/bridge_generated.rs b/packages/p2panda/native/src/bridge_generated.rs index 611a700e..516bc409 100644 --- a/packages/p2panda/native/src/bridge_generated.rs +++ b/packages/p2panda/native/src/bridge_generated.rs @@ -22,6 +22,22 @@ use std::sync::Arc; // Section: wire functions +fn wire_subscribe_log_stream_impl(port_: MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>( + WrapInfo { + debug_name: "subscribe_log_stream", + port: Some(port_), + mode: FfiCallMode::Stream, + }, + move || { + move |task_callback| { + Result::<_, ()>::Ok(subscribe_log_stream( + task_callback.stream_sink::<_, LogEntry>(), + )) + } + }, + ) +} fn wire_sign_and_encode_entry_impl( port_: MessagePort, log_id: impl Wire2Api + UnwindSafe, @@ -110,6 +126,7 @@ fn wire_decode_operation_impl(port_: MessagePort, operation: impl Wire2Api + UnwindSafe, key_pair: impl Wire2Api + UnwindSafe, database_url: impl Wire2Api + UnwindSafe, blobs_base_path: impl Wire2Api + UnwindSafe, @@ -123,6 +140,7 @@ fn wire_start_node_impl( mode: FfiCallMode::Normal, }, move || { + let api_log_level = log_level.wire2api(); let api_key_pair = key_pair.wire2api(); let api_database_url = database_url.wire2api(); let api_blobs_base_path = blobs_base_path.wire2api(); @@ -130,6 +148,7 @@ fn wire_start_node_impl( let api_allow_schema_ids = allow_schema_ids.wire2api(); move |task_callback| { start_node( + api_log_level, api_key_pair, api_database_url, api_blobs_base_path, @@ -284,6 +303,43 @@ impl rust2dart::IntoIntoDart for KeyPair { } } +impl support::IntoDart for LogEntry { + fn into_dart(self) -> support::DartAbi { + vec![ + self.timestamp.into_into_dart().into_dart(), + self.level.into_into_dart().into_dart(), + self.tag.into_into_dart().into_dart(), + self.msg.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl support::IntoDartExceptPrimitive for LogEntry {} +impl rust2dart::IntoIntoDart for LogEntry { + fn into_into_dart(self) -> Self { + self + } +} + +impl support::IntoDart for LogLevel { + fn into_dart(self) -> support::DartAbi { + match self { + Self::Trace => 0, + Self::Debug => 1, + Self::Info => 2, + Self::Warn => 3, + Self::Error => 4, + } + .into_dart() + } +} +impl support::IntoDartExceptPrimitive for LogLevel {} +impl rust2dart::IntoIntoDart for LogLevel { + fn into_into_dart(self) -> Self { + self + } +} + impl support::IntoDart for OperationAction { fn into_dart(self) -> support::DartAbi { match self { @@ -312,6 +368,11 @@ mod io { use super::*; // Section: wire functions + #[no_mangle] + pub extern "C" fn wire_subscribe_log_stream(port_: i64) { + wire_subscribe_log_stream_impl(port_) + } + #[no_mangle] pub extern "C" fn wire_sign_and_encode_entry( port_: i64, @@ -357,6 +418,7 @@ mod io { #[no_mangle] pub extern "C" fn wire_start_node( port_: i64, + log_level: *mut wire_uint_8_list, key_pair: *mut wire_KeyPair, database_url: *mut wire_uint_8_list, blobs_base_path: *mut wire_uint_8_list, @@ -365,6 +427,7 @@ mod io { ) { wire_start_node_impl( port_, + log_level, key_pair, database_url, blobs_base_path, From c51606bfa09678428ca63fad045fb99c3e0ccd5e Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 16:40:23 +0200 Subject: [PATCH 2/7] Don't forget to hook into logger --- .../p2panda/lib/src/bridge_generated.dart | 1385 ++++++++--------- packages/p2panda/native/Cargo.toml | 2 +- packages/p2panda/native/src/api.rs | 9 +- 3 files changed, 682 insertions(+), 714 deletions(-) diff --git a/packages/p2panda/lib/src/bridge_generated.dart b/packages/p2panda/lib/src/bridge_generated.dart index e236ef53..9e31e9be 100644 --- a/packages/p2panda/lib/src/bridge_generated.dart +++ b/packages/p2panda/lib/src/bridge_generated.dart @@ -1,820 +1,781 @@ // AUTO GENERATED FILE, DO NOT EDIT. // Generated by `flutter_rust_bridge`@ 1.82.6. -// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const - + // ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const + import 'dart:convert'; -import 'dart:async'; -import 'package:meta/meta.dart'; -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; + import 'dart:async'; + import 'package:meta/meta.dart'; + import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; import 'package:uuid/uuid.dart'; import 'package:freezed_annotation/freezed_annotation.dart' hide protected; import 'dart:ffi' as ffi; + part 'bridge_generated.freezed.dart'; -abstract class P2Panda { - Stream subscribeLogStream({dynamic hint}); - FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta; - /// Create, sign and encode a p2panda entry. - /// - /// Takes large u64 integers for log id and seq num as strings. If we would declare them as u64 - /// here they will get converted to int which is not a real native u64 integer in Dart! We pass - /// them over as strings and then safely convert them to u64 internally. - Future signAndEncodeEntry( - {required String logId, - required String seqNum, - String? skiplinkHash, - String? backlinkHash, - required Uint8List payload, - required KeyPair keyPair, - dynamic hint}); - FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta; - /// Decodes a p2panda entry. - /// - /// Returns large u64 integers for log id and seq num as strings. If we would declare them as u64 - /// here they will get converted to int which is not a real native u64 integer in Dart! We pass - /// them over as strings and then safely convert them to `BigInt` in the Dart world. - Future<(String, String, String, String?, String?)> decodeEntry( - {required Uint8List entry, dynamic hint}); - FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta; - /// Encode a p2panda operation parsed from JSON input. - Future encodeOperation( - {required OperationAction action, - required String schemaId, - String? previous, - List<(String, OperationValue)>? fields, - dynamic hint}); - FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta; - /// Decodes an p2panda operation, returning it's action and schema id. - Future<(OperationAction, String)> decodeOperation( - {required Uint8List operation, dynamic hint}); - FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta; - /// Runs a p2panda node in a separate thread in the background. - /// - /// Supports Android logging for logs coming from the node. - Future startNode( - {required String logLevel, - required KeyPair keyPair, - required String databaseUrl, - required String blobsBasePath, - required List relayAddresses, - required List allowSchemaIds, - dynamic hint}); - FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta; + abstract class P2Panda { + Stream subscribeLogStream({ dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta; + +/// Create, sign and encode a p2panda entry. +/// +/// Takes large u64 integers for log id and seq num as strings. If we would declare them as u64 +/// here they will get converted to int which is not a real native u64 integer in Dart! We pass +/// them over as strings and then safely convert them to u64 internally. +Future signAndEncodeEntry({ required String logId ,required String seqNum ,String? skiplinkHash ,String? backlinkHash ,required Uint8List payload ,required KeyPair keyPair ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta; + +/// Decodes a p2panda entry. +/// +/// Returns large u64 integers for log id and seq num as strings. If we would declare them as u64 +/// here they will get converted to int which is not a real native u64 integer in Dart! We pass +/// them over as strings and then safely convert them to `BigInt` in the Dart world. +Future<(String,String,String,String?,String?)> decodeEntry({ required Uint8List entry ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta; + +/// Encode a p2panda operation parsed from JSON input. +Future encodeOperation({ required OperationAction action ,required String schemaId ,String? previous ,List<(String,OperationValue)>? fields ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta; + +/// Decodes an p2panda operation, returning it's action and schema id. +Future<(OperationAction,String)> decodeOperation({ required Uint8List operation ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta; + +/// Runs a p2panda node in a separate thread in the background. +/// +/// Supports Android logging for logs coming from the node. +Future startNode({ required String logLevel ,required KeyPair keyPair ,required String databaseUrl ,required String blobsBasePath ,required List relayAddresses ,required List allowSchemaIds ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta; + +/// Turns off running node. +Future shutdownNode({ dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta; + +/// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. +Future newStaticMethodKeyPair({ dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta; + +/// Derives a key pair from a private key. +Future fromPrivateKeyStaticMethodKeyPair({ required Uint8List bytes ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kFromPrivateKeyStaticMethodKeyPairConstMeta; + +/// Returns the private half of the key pair. +Future privateKeyMethodKeyPair({ required KeyPair that ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta; + +/// Returns the public half of the key pair. +Future publicKeyMethodKeyPair({ required KeyPair that ,dynamic hint }); + +FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta; + + + DropFnType get dropOpaquePandaKeyPair; + ShareFnType get shareOpaquePandaKeyPair; + OpaqueTypeFinalizer get PandaKeyPairFinalizer; + + + + } + + + +@sealed class PandaKeyPair extends FrbOpaque { + final P2Panda bridge; + PandaKeyPair.fromRaw(int ptr, int size, this.bridge) : super.unsafe(ptr, size); + @override + DropFnType get dropFn => bridge.dropOpaquePandaKeyPair; + + @override + ShareFnType get shareFn => bridge.shareOpaquePandaKeyPair; + + @override + OpaqueTypeFinalizer get staticFinalizer => bridge.PandaKeyPairFinalizer; + } + + + + + + - /// Turns off running node. - Future shutdownNode({dynamic hint}); - FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta; - /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. - Future newStaticMethodKeyPair({dynamic hint}); - FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta; - /// Derives a key pair from a private key. - Future fromPrivateKeyStaticMethodKeyPair( - {required Uint8List bytes, dynamic hint}); - FlutterRustBridgeTaskConstMeta - get kFromPrivateKeyStaticMethodKeyPairConstMeta; - /// Returns the private half of the key pair. - Future privateKeyMethodKeyPair( - {required KeyPair that, dynamic hint}); - FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta; - /// Returns the public half of the key pair. - Future publicKeyMethodKeyPair( - {required KeyPair that, dynamic hint}); - FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta; - DropFnType get dropOpaquePandaKeyPair; - ShareFnType get shareOpaquePandaKeyPair; - OpaqueTypeFinalizer get PandaKeyPairFinalizer; -} -@sealed -class PandaKeyPair extends FrbOpaque { - final P2Panda bridge; - PandaKeyPair.fromRaw(int ptr, int size, this.bridge) - : super.unsafe(ptr, size); - @override - DropFnType get dropFn => bridge.dropOpaquePandaKeyPair; - @override - ShareFnType get shareFn => bridge.shareOpaquePandaKeyPair; - @override - OpaqueTypeFinalizer get staticFinalizer => bridge.PandaKeyPairFinalizer; -} /// Ed25519 key pair for authors to sign p2panda entries with. -class KeyPair { - final P2Panda bridge; - final PandaKeyPair field0; - - const KeyPair({ - required this.bridge, - required this.field0, - }); - - /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. - static Future newKeyPair({required P2Panda bridge, dynamic hint}) => - bridge.newStaticMethodKeyPair(hint: hint); - - /// Derives a key pair from a private key. - static Future fromPrivateKey( - {required P2Panda bridge, required Uint8List bytes, dynamic hint}) => - bridge.fromPrivateKeyStaticMethodKeyPair(bytes: bytes, hint: hint); - - /// Returns the private half of the key pair. - Future privateKey({dynamic hint}) => - bridge.privateKeyMethodKeyPair( - that: this, - ); - - /// Returns the public half of the key pair. - Future publicKey({dynamic hint}) => bridge.publicKeyMethodKeyPair( - that: this, - ); -} +class KeyPair { + final P2Panda bridge; +final PandaKeyPair field0; -class LogEntry { - final int timestamp; - final LogLevel level; - final String tag; - final String msg; - - const LogEntry({ - required this.timestamp, - required this.level, - required this.tag, - required this.msg, - }); -} + const KeyPair({required this.bridge,required this.field0 ,}); + + /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. +static Future newKeyPair({ required P2Panda bridge,dynamic hint })=>bridge.newStaticMethodKeyPair(hint: hint); + +/// Derives a key pair from a private key. +static Future fromPrivateKey({ required P2Panda bridge,required Uint8List bytes ,dynamic hint })=>bridge.fromPrivateKeyStaticMethodKeyPair(bytes:bytes,hint: hint); + +/// Returns the private half of the key pair. + Future privateKey({ dynamic hint })=>bridge.privateKeyMethodKeyPair(that: this, ); + +/// Returns the public half of the key pair. + Future publicKey({ dynamic hint })=>bridge.publicKeyMethodKeyPair(that: this, ); + + + } + + + +class LogEntry { + final int timestamp; +final LogLevel level; +final String tag; +final String msg; + + const LogEntry({required this.timestamp ,required this.level ,required this.tag ,required this.msg ,}); + + + } enum LogLevel { - Trace, - Debug, - Info, - Warn, - Error, -} + Trace, +Debug, +Info, +Warn, +Error, + } /// Operations are categorised by their action type. /// /// An action defines the operation format and if this operation creates, updates or deletes a data /// document. enum OperationAction { - /// Operation creates a new document. - Create, + /// Operation creates a new document. +Create, +/// Operation updates an existing document. +Update, +/// Operation deletes an existing document. +Delete, + } - /// Operation updates an existing document. - Update, +@freezed + sealed class OperationValue with _$OperationValue { + /// Boolean value. +const factory OperationValue.boolean( bool field0,) = OperationValue_Boolean; + /// Floating point value. +const factory OperationValue.float( double field0,) = OperationValue_Float; + /// Signed integer value. +const factory OperationValue.integer( int field0,) = OperationValue_Integer; + /// String value. +const factory OperationValue.string( String field0,) = OperationValue_String; + /// Bytes value. +const factory OperationValue.bytes( Uint8List field0,) = OperationValue_Bytes; + /// Reference to a document. +const factory OperationValue.relation( String field0,) = OperationValue_Relation; + /// Reference to a list of documents. +const factory OperationValue.relationList( List field0,) = OperationValue_RelationList; + /// Reference to a document view. +/// +/// Multiple operation ids are separated by an understore ('_'). +const factory OperationValue.pinnedRelation( String field0,) = OperationValue_PinnedRelation; + /// Reference to a list of document views. +/// +/// Multiple operation ids are separated by an understore ('_'). +const factory OperationValue.pinnedRelationList( List field0,) = OperationValue_PinnedRelationList; + } - /// Operation deletes an existing document. - Delete, -} -@freezed -sealed class OperationValue with _$OperationValue { - /// Boolean value. - const factory OperationValue.boolean( - bool field0, - ) = OperationValue_Boolean; - - /// Floating point value. - const factory OperationValue.float( - double field0, - ) = OperationValue_Float; - - /// Signed integer value. - const factory OperationValue.integer( - int field0, - ) = OperationValue_Integer; - - /// String value. - const factory OperationValue.string( - String field0, - ) = OperationValue_String; - - /// Bytes value. - const factory OperationValue.bytes( - Uint8List field0, - ) = OperationValue_Bytes; - - /// Reference to a document. - const factory OperationValue.relation( - String field0, - ) = OperationValue_Relation; - - /// Reference to a list of documents. - const factory OperationValue.relationList( - List field0, - ) = OperationValue_RelationList; - - /// Reference to a document view. - /// - /// Multiple operation ids are separated by an understore ('_'). - const factory OperationValue.pinnedRelation( - String field0, - ) = OperationValue_PinnedRelation; - - /// Reference to a list of document views. - /// - /// Multiple operation ids are separated by an understore ('_'). - const factory OperationValue.pinnedRelationList( - List field0, - ) = OperationValue_PinnedRelationList; -} -class P2PandaImpl implements P2Panda { - final P2PandaPlatform _platform; - factory P2PandaImpl(ExternalLibrary dylib) => - P2PandaImpl.raw(P2PandaPlatform(dylib)); - - /// Only valid on web/WASM platforms. - factory P2PandaImpl.wasm(FutureOr module) => - P2PandaImpl(module as ExternalLibrary); - P2PandaImpl.raw(this._platform); - Stream subscribeLogStream({dynamic hint}) { - return _platform.executeStream(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_subscribe_log_stream(port_), - parseSuccessData: _wire2api_log_entry, - parseErrorData: null, - constMeta: kSubscribeLogStreamConstMeta, - argValues: [], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "subscribe_log_stream", - argNames: [], - ); - - Future signAndEncodeEntry( - {required String logId, - required String seqNum, - String? skiplinkHash, - String? backlinkHash, - required Uint8List payload, - required KeyPair keyPair, - dynamic hint}) { - var arg0 = _platform.api2wire_String(logId); - var arg1 = _platform.api2wire_String(seqNum); - var arg2 = _platform.api2wire_opt_String(skiplinkHash); - var arg3 = _platform.api2wire_opt_String(backlinkHash); - var arg4 = _platform.api2wire_uint_8_list(payload); - var arg5 = _platform.api2wire_box_autoadd_key_pair(keyPair); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_sign_and_encode_entry( - port_, arg0, arg1, arg2, arg3, arg4, arg5), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kSignAndEncodeEntryConstMeta, - argValues: [logId, seqNum, skiplinkHash, backlinkHash, payload, keyPair], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "sign_and_encode_entry", - argNames: [ - "logId", - "seqNum", - "skiplinkHash", - "backlinkHash", - "payload", - "keyPair" - ], - ); - - Future<(String, String, String, String?, String?)> decodeEntry( - {required Uint8List entry, dynamic hint}) { - var arg0 = _platform.api2wire_uint_8_list(entry); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_decode_entry(port_, arg0), - parseSuccessData: - _wire2api___record__String_String_String_opt_String_opt_String, - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kDecodeEntryConstMeta, - argValues: [entry], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "decode_entry", - argNames: ["entry"], - ); - - Future encodeOperation( - {required OperationAction action, - required String schemaId, - String? previous, - List<(String, OperationValue)>? fields, - dynamic hint}) { - var arg0 = api2wire_operation_action(action); - var arg1 = _platform.api2wire_String(schemaId); - var arg2 = _platform.api2wire_opt_String(previous); - var arg3 = - _platform.api2wire_opt_list___record__String_operation_value(fields); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - _platform.inner.wire_encode_operation(port_, arg0, arg1, arg2, arg3), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kEncodeOperationConstMeta, - argValues: [action, schemaId, previous, fields], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "encode_operation", - argNames: ["action", "schemaId", "previous", "fields"], - ); - - Future<(OperationAction, String)> decodeOperation( - {required Uint8List operation, dynamic hint}) { - var arg0 = _platform.api2wire_uint_8_list(operation); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_decode_operation(port_, arg0), - parseSuccessData: _wire2api___record__operation_action_String, - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kDecodeOperationConstMeta, - argValues: [operation], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "decode_operation", - argNames: ["operation"], - ); - - Future startNode( - {required String logLevel, - required KeyPair keyPair, - required String databaseUrl, - required String blobsBasePath, - required List relayAddresses, - required List allowSchemaIds, - dynamic hint}) { - var arg0 = _platform.api2wire_String(logLevel); - var arg1 = _platform.api2wire_box_autoadd_key_pair(keyPair); - var arg2 = _platform.api2wire_String(databaseUrl); - var arg3 = _platform.api2wire_String(blobsBasePath); - var arg4 = _platform.api2wire_StringList(relayAddresses); - var arg5 = _platform.api2wire_StringList(allowSchemaIds); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner - .wire_start_node(port_, arg0, arg1, arg2, arg3, arg4, arg5), - parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kStartNodeConstMeta, - argValues: [ - logLevel, - keyPair, - databaseUrl, - blobsBasePath, - relayAddresses, - allowSchemaIds - ], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "start_node", - argNames: [ - "logLevel", - "keyPair", - "databaseUrl", - "blobsBasePath", - "relayAddresses", - "allowSchemaIds" - ], - ); - - Future shutdownNode({dynamic hint}) { - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_shutdown_node(port_), - parseSuccessData: _wire2api_unit, - parseErrorData: null, - constMeta: kShutdownNodeConstMeta, - argValues: [], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "shutdown_node", - argNames: [], - ); - - Future newStaticMethodKeyPair({dynamic hint}) { - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - _platform.inner.wire_new__static_method__KeyPair(port_), - parseSuccessData: (d) => _wire2api_key_pair(d), - parseErrorData: null, - constMeta: kNewStaticMethodKeyPairConstMeta, - argValues: [], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "new__static_method__KeyPair", - argNames: [], - ); - - Future fromPrivateKeyStaticMethodKeyPair( - {required Uint8List bytes, dynamic hint}) { - var arg0 = _platform.api2wire_uint_8_list(bytes); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner - .wire_from_private_key__static_method__KeyPair(port_, arg0), - parseSuccessData: (d) => _wire2api_key_pair(d), - parseErrorData: _wire2api_FrbAnyhowException, - constMeta: kFromPrivateKeyStaticMethodKeyPairConstMeta, - argValues: [bytes], - hint: hint, - )); - } - FlutterRustBridgeTaskConstMeta - get kFromPrivateKeyStaticMethodKeyPairConstMeta => - const FlutterRustBridgeTaskConstMeta( + + +class P2PandaImpl implements P2Panda { + final P2PandaPlatform _platform; + factory P2PandaImpl(ExternalLibrary dylib) => P2PandaImpl.raw(P2PandaPlatform(dylib)); + + /// Only valid on web/WASM platforms. + factory P2PandaImpl.wasm(FutureOr module) => + P2PandaImpl(module as ExternalLibrary); + P2PandaImpl.raw(this._platform); +Stream subscribeLogStream({ dynamic hint }) { + + return _platform.executeStream(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_subscribe_log_stream(port_), + parseSuccessData: _wire2api_log_entry, + parseErrorData: null, + + constMeta: kSubscribeLogStreamConstMeta, + argValues: [], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "subscribe_log_stream", + argNames: [], + ); + +Future signAndEncodeEntry({ required String logId ,required String seqNum ,String? skiplinkHash ,String? backlinkHash ,required Uint8List payload ,required KeyPair keyPair ,dynamic hint }) { + var arg0 = _platform.api2wire_String(logId); +var arg1 = _platform.api2wire_String(seqNum); +var arg2 = _platform.api2wire_opt_String(skiplinkHash); +var arg3 = _platform.api2wire_opt_String(backlinkHash); +var arg4 = _platform.api2wire_uint_8_list(payload); +var arg5 = _platform.api2wire_box_autoadd_key_pair(keyPair); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_sign_and_encode_entry(port_, arg0, arg1, arg2, arg3, arg4, arg5), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kSignAndEncodeEntryConstMeta, + argValues: [logId, seqNum, skiplinkHash, backlinkHash, payload, keyPair], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "sign_and_encode_entry", + argNames: ["logId", "seqNum", "skiplinkHash", "backlinkHash", "payload", "keyPair"], + ); + +Future<(String,String,String,String?,String?)> decodeEntry({ required Uint8List entry ,dynamic hint }) { + var arg0 = _platform.api2wire_uint_8_list(entry); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_decode_entry(port_, arg0), + parseSuccessData: _wire2api___record__String_String_String_opt_String_opt_String, + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kDecodeEntryConstMeta, + argValues: [entry], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "decode_entry", + argNames: ["entry"], + ); + +Future encodeOperation({ required OperationAction action ,required String schemaId ,String? previous ,List<(String,OperationValue)>? fields ,dynamic hint }) { + var arg0 = api2wire_operation_action(action); +var arg1 = _platform.api2wire_String(schemaId); +var arg2 = _platform.api2wire_opt_String(previous); +var arg3 = _platform.api2wire_opt_list___record__String_operation_value(fields); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_encode_operation(port_, arg0, arg1, arg2, arg3), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kEncodeOperationConstMeta, + argValues: [action, schemaId, previous, fields], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "encode_operation", + argNames: ["action", "schemaId", "previous", "fields"], + ); + +Future<(OperationAction,String)> decodeOperation({ required Uint8List operation ,dynamic hint }) { + var arg0 = _platform.api2wire_uint_8_list(operation); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_decode_operation(port_, arg0), + parseSuccessData: _wire2api___record__operation_action_String, + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kDecodeOperationConstMeta, + argValues: [operation], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "decode_operation", + argNames: ["operation"], + ); + +Future startNode({ required String logLevel ,required KeyPair keyPair ,required String databaseUrl ,required String blobsBasePath ,required List relayAddresses ,required List allowSchemaIds ,dynamic hint }) { + var arg0 = _platform.api2wire_String(logLevel); +var arg1 = _platform.api2wire_box_autoadd_key_pair(keyPair); +var arg2 = _platform.api2wire_String(databaseUrl); +var arg3 = _platform.api2wire_String(blobsBasePath); +var arg4 = _platform.api2wire_StringList(relayAddresses); +var arg5 = _platform.api2wire_StringList(allowSchemaIds); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_start_node(port_, arg0, arg1, arg2, arg3, arg4, arg5), + parseSuccessData: _wire2api_unit, + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kStartNodeConstMeta, + argValues: [logLevel, keyPair, databaseUrl, blobsBasePath, relayAddresses, allowSchemaIds], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "start_node", + argNames: ["logLevel", "keyPair", "databaseUrl", "blobsBasePath", "relayAddresses", "allowSchemaIds"], + ); + +Future shutdownNode({ dynamic hint }) { + + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_shutdown_node(port_), + parseSuccessData: _wire2api_unit, + parseErrorData: null, + + constMeta: kShutdownNodeConstMeta, + argValues: [], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "shutdown_node", + argNames: [], + ); + +Future newStaticMethodKeyPair({ dynamic hint }) { + + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_new__static_method__KeyPair(port_), + parseSuccessData: (d) => _wire2api_key_pair(d), + parseErrorData: null, + + constMeta: kNewStaticMethodKeyPairConstMeta, + argValues: [], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "new__static_method__KeyPair", + argNames: [], + ); + +Future fromPrivateKeyStaticMethodKeyPair({ required Uint8List bytes ,dynamic hint }) { + var arg0 = _platform.api2wire_uint_8_list(bytes); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_from_private_key__static_method__KeyPair(port_, arg0), + parseSuccessData: (d) => _wire2api_key_pair(d), + parseErrorData: _wire2api_FrbAnyhowException, + + constMeta: kFromPrivateKeyStaticMethodKeyPairConstMeta, + argValues: [bytes], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kFromPrivateKeyStaticMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( debugName: "from_private_key__static_method__KeyPair", argNames: ["bytes"], - ); - - Future privateKeyMethodKeyPair( - {required KeyPair that, dynamic hint}) { - var arg0 = _platform.api2wire_box_autoadd_key_pair(that); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - _platform.inner.wire_private_key__method__KeyPair(port_, arg0), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: null, - constMeta: kPrivateKeyMethodKeyPairConstMeta, - argValues: [that], - hint: hint, - )); - } + ); + +Future privateKeyMethodKeyPair({ required KeyPair that ,dynamic hint }) { + var arg0 = _platform.api2wire_box_autoadd_key_pair(that); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_private_key__method__KeyPair(port_, arg0), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: null, + + constMeta: kPrivateKeyMethodKeyPairConstMeta, + argValues: [that], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "private_key__method__KeyPair", + argNames: ["that"], + ); + +Future publicKeyMethodKeyPair({ required KeyPair that ,dynamic hint }) { + var arg0 = _platform.api2wire_box_autoadd_key_pair(that); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_public_key__method__KeyPair(port_, arg0), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: null, + + constMeta: kPublicKeyMethodKeyPairConstMeta, + argValues: [that], + hint: hint, + + ));} + + + FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "public_key__method__KeyPair", + argNames: ["that"], + ); + + + DropFnType get dropOpaquePandaKeyPair => _platform.inner.drop_opaque_PandaKeyPair; + ShareFnType get shareOpaquePandaKeyPair => _platform.inner.share_opaque_PandaKeyPair; + OpaqueTypeFinalizer get PandaKeyPairFinalizer => _platform.PandaKeyPairFinalizer; + + + +void dispose() {_platform.dispose();} +// Section: wire2api - FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "private_key__method__KeyPair", - argNames: ["that"], - ); - - Future publicKeyMethodKeyPair( - {required KeyPair that, dynamic hint}) { - var arg0 = _platform.api2wire_box_autoadd_key_pair(that); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - _platform.inner.wire_public_key__method__KeyPair(port_, arg0), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: null, - constMeta: kPublicKeyMethodKeyPairConstMeta, - argValues: [that], - hint: hint, - )); - } +FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) { + return FrbAnyhowException(raw as String); + } + + +PandaKeyPair _wire2api_PandaKeyPair(dynamic raw) { + return PandaKeyPair.fromRaw(raw[0], raw[1], this); + } + + +String _wire2api_String(dynamic raw) { + return raw as String; + } + + +(String,String,String,String?,String?) _wire2api___record__String_String_String_opt_String_opt_String(dynamic raw) { + final arr = raw as List; + if (arr.length != 5) { + throw Exception('Expected 5 elements, got ${arr.length}'); + } + return (_wire2api_String(arr[0]),_wire2api_String(arr[1]),_wire2api_String(arr[2]),_wire2api_opt_String(arr[3]),_wire2api_opt_String(arr[4]),); + } + + +(OperationAction,String) _wire2api___record__operation_action_String(dynamic raw) { + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return (_wire2api_operation_action(arr[0]),_wire2api_String(arr[1]),); + } + + +int _wire2api_i32(dynamic raw) { + return raw as int; + } + + +KeyPair _wire2api_key_pair(dynamic raw) { + final arr = raw as List; + if (arr.length != 1) throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); + return KeyPair(bridge: this, +field0: _wire2api_PandaKeyPair(arr[0]),); + } + + +LogEntry _wire2api_log_entry(dynamic raw) { + final arr = raw as List; + if (arr.length != 4) throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); + return LogEntry(timestamp: _wire2api_u64(arr[0]), +level: _wire2api_log_level(arr[1]), +tag: _wire2api_String(arr[2]), +msg: _wire2api_String(arr[3]),); + } + + +LogLevel _wire2api_log_level(dynamic raw) { + return LogLevel.values[raw as int]; + } + + +OperationAction _wire2api_operation_action(dynamic raw) { + return OperationAction.values[raw as int]; + } + + +String? _wire2api_opt_String(dynamic raw) { + return raw == null ? null : _wire2api_String(raw); + } + + +int _wire2api_u64(dynamic raw) { + return castInt(raw); + } + + +int _wire2api_u8(dynamic raw) { + return raw as int; + } + + +Uint8List _wire2api_uint_8_list(dynamic raw) { + return raw as Uint8List; + } + + +void _wire2api_unit(dynamic raw) { + return; + } + +} - FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta => - const FlutterRustBridgeTaskConstMeta( - debugName: "public_key__method__KeyPair", - argNames: ["that"], - ); - - DropFnType get dropOpaquePandaKeyPair => - _platform.inner.drop_opaque_PandaKeyPair; - ShareFnType get shareOpaquePandaKeyPair => - _platform.inner.share_opaque_PandaKeyPair; - OpaqueTypeFinalizer get PandaKeyPairFinalizer => - _platform.PandaKeyPairFinalizer; - - void dispose() { - _platform.dispose(); - } -// Section: wire2api +// Section: api2wire - FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) { - return FrbAnyhowException(raw as String); - } - PandaKeyPair _wire2api_PandaKeyPair(dynamic raw) { - return PandaKeyPair.fromRaw(raw[0], raw[1], this); - } - String _wire2api_String(dynamic raw) { - return raw as String; - } - (String, String, String, String?, String?) - _wire2api___record__String_String_String_opt_String_opt_String( - dynamic raw) { - final arr = raw as List; - if (arr.length != 5) { - throw Exception('Expected 5 elements, got ${arr.length}'); - } - return ( - _wire2api_String(arr[0]), - _wire2api_String(arr[1]), - _wire2api_String(arr[2]), - _wire2api_opt_String(arr[3]), - _wire2api_opt_String(arr[4]), - ); - } - (OperationAction, String) _wire2api___record__operation_action_String( - dynamic raw) { - final arr = raw as List; - if (arr.length != 2) { - throw Exception('Expected 2 elements, got ${arr.length}'); - } - return ( - _wire2api_operation_action(arr[0]), - _wire2api_String(arr[1]), - ); - } +@protected + bool api2wire_bool(bool raw) { + return raw; + } - int _wire2api_i32(dynamic raw) { - return raw as int; - } +@protected + double api2wire_f64(double raw) { + return raw; + } +@protected + int api2wire_i32(int raw) { + return raw; + } - KeyPair _wire2api_key_pair(dynamic raw) { - final arr = raw as List; - if (arr.length != 1) - throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); - return KeyPair( - bridge: this, - field0: _wire2api_PandaKeyPair(arr[0]), - ); - } - LogEntry _wire2api_log_entry(dynamic raw) { - final arr = raw as List; - if (arr.length != 4) - throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); - return LogEntry( - timestamp: _wire2api_u64(arr[0]), - level: _wire2api_log_level(arr[1]), - tag: _wire2api_String(arr[2]), - msg: _wire2api_String(arr[3]), - ); - } - LogLevel _wire2api_log_level(dynamic raw) { - return LogLevel.values[raw as int]; - } +@protected + int api2wire_operation_action(OperationAction raw) { + return api2wire_i32(raw.index); + } - OperationAction _wire2api_operation_action(dynamic raw) { - return OperationAction.values[raw as int]; - } - String? _wire2api_opt_String(dynamic raw) { - return raw == null ? null : _wire2api_String(raw); - } - int _wire2api_u64(dynamic raw) { - return castInt(raw); - } +@protected + int api2wire_u8(int raw) { + return raw; + } - int _wire2api_u8(dynamic raw) { - return raw as int; - } +// Section: finalizer - Uint8List _wire2api_uint_8_list(dynamic raw) { - return raw as Uint8List; - } - void _wire2api_unit(dynamic raw) { - return; - } -} + + +class P2PandaPlatform extends FlutterRustBridgeBase { + P2PandaPlatform(ffi.DynamicLibrary dylib) : super(P2PandaWire(dylib)); // Section: api2wire @protected -bool api2wire_bool(bool raw) { - return raw; -} + wire_PandaKeyPair api2wire_PandaKeyPair(PandaKeyPair raw) { + final ptr = inner.new_PandaKeyPair(); + _api_fill_to_wire_PandaKeyPair(raw, ptr); + return ptr; + } +@protected + ffi.Pointer api2wire_String(String raw) { + return api2wire_uint_8_list(utf8.encoder.convert(raw)); + } +@protected + ffi.Pointer api2wire_StringList(List raw) { + final ans = inner.new_StringList_0(raw.length); + for (var i = 0; i < raw.length; i++){ + ans.ref.ptr[i] = api2wire_String(raw[i]); + } + return ans; + } + @protected -double api2wire_f64(double raw) { - return raw; -} + ffi.Pointer api2wire_box_autoadd_key_pair(KeyPair raw) { + final ptr = inner.new_box_autoadd_key_pair_0(); + _api_fill_to_wire_key_pair(raw, ptr.ref); + return ptr; + } + @protected -int api2wire_i32(int raw) { - return raw; -} + int api2wire_i64(int raw) { + return raw; + } @protected -int api2wire_operation_action(OperationAction raw) { - return api2wire_i32(raw.index); -} + ffi.Pointer api2wire_list___record__String_operation_value(List<(String,OperationValue)> raw) { + final ans = inner.new_list___record__String_operation_value_0(raw.length); + for (var i = 0; i < raw.length; ++i) { + _api_fill_to_wire___record__String_operation_value(raw[i], ans.ref.ptr[i]); + } + return ans; + + } + @protected -int api2wire_u8(int raw) { - return raw; -} + ffi.Pointer api2wire_opt_String(String? raw) { + return raw == null ? ffi.nullptr : api2wire_String(raw); + } +@protected + ffi.Pointer api2wire_opt_list___record__String_operation_value(List<(String,OperationValue)>? raw) { + return raw == null ? ffi.nullptr : api2wire_list___record__String_operation_value(raw); + } +@protected + ffi.Pointer api2wire_uint_8_list(Uint8List raw) { + final ans = inner.new_uint_8_list_0(raw.length); + ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); + return ans; + } // Section: finalizer -class P2PandaPlatform extends FlutterRustBridgeBase { - P2PandaPlatform(ffi.DynamicLibrary dylib) : super(P2PandaWire(dylib)); +late final OpaqueTypeFinalizer _PandaKeyPairFinalizer = OpaqueTypeFinalizer(inner._drop_opaque_PandaKeyPairPtr); + OpaqueTypeFinalizer get PandaKeyPairFinalizer => _PandaKeyPairFinalizer; +// Section: api_fill_to_wire -// Section: api2wire +void _api_fill_to_wire_PandaKeyPair(PandaKeyPair apiObj, wire_PandaKeyPair wireObj) { + wireObj.ptr = apiObj.shareOrMove(); + } - @protected - wire_PandaKeyPair api2wire_PandaKeyPair(PandaKeyPair raw) { - final ptr = inner.new_PandaKeyPair(); - _api_fill_to_wire_PandaKeyPair(raw, ptr); - return ptr; - } - @protected - ffi.Pointer api2wire_String(String raw) { - return api2wire_uint_8_list(utf8.encoder.convert(raw)); - } - @protected - ffi.Pointer api2wire_StringList(List raw) { - final ans = inner.new_StringList_0(raw.length); - for (var i = 0; i < raw.length; i++) { - ans.ref.ptr[i] = api2wire_String(raw[i]); - } - return ans; - } - @protected - ffi.Pointer api2wire_box_autoadd_key_pair(KeyPair raw) { - final ptr = inner.new_box_autoadd_key_pair_0(); - _api_fill_to_wire_key_pair(raw, ptr.ref); - return ptr; - } - @protected - int api2wire_i64(int raw) { - return raw; - } +void _api_fill_to_wire___record__String_operation_value((String,OperationValue) apiObj, wire___record__String_operation_value wireObj) { + wireObj.field0 = api2wire_String(apiObj.$1); +_api_fill_to_wire_operation_value(apiObj.$2, wireObj.field1); + } - @protected - ffi.Pointer - api2wire_list___record__String_operation_value( - List<(String, OperationValue)> raw) { - final ans = inner.new_list___record__String_operation_value_0(raw.length); - for (var i = 0; i < raw.length; ++i) { - _api_fill_to_wire___record__String_operation_value( - raw[i], ans.ref.ptr[i]); - } - return ans; - } - @protected - ffi.Pointer api2wire_opt_String(String? raw) { - return raw == null ? ffi.nullptr : api2wire_String(raw); - } - @protected - ffi.Pointer - api2wire_opt_list___record__String_operation_value( - List<(String, OperationValue)>? raw) { - return raw == null - ? ffi.nullptr - : api2wire_list___record__String_operation_value(raw); - } +void _api_fill_to_wire_box_autoadd_key_pair(KeyPair apiObj, ffi.Pointer wireObj) { + _api_fill_to_wire_key_pair(apiObj, wireObj.ref); + } + + + + + + + +void _api_fill_to_wire_key_pair(KeyPair apiObj, wire_KeyPair wireObj) { + wireObj.field0 = api2wire_PandaKeyPair(apiObj.field0); + } + + + + + +void _api_fill_to_wire_operation_value(OperationValue apiObj, wire_OperationValue wireObj) { + if (apiObj is OperationValue_Boolean) { + var pre_field0 = api2wire_bool(apiObj.field0); + wireObj.tag = 0; + wireObj.kind = inner.inflate_OperationValue_Boolean(); + wireObj.kind.ref.Boolean.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_Float) { + var pre_field0 = api2wire_f64(apiObj.field0); + wireObj.tag = 1; + wireObj.kind = inner.inflate_OperationValue_Float(); + wireObj.kind.ref.Float.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_Integer) { + var pre_field0 = api2wire_i64(apiObj.field0); + wireObj.tag = 2; + wireObj.kind = inner.inflate_OperationValue_Integer(); + wireObj.kind.ref.Integer.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_String) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 3; + wireObj.kind = inner.inflate_OperationValue_String(); + wireObj.kind.ref.String.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_Bytes) { + var pre_field0 = api2wire_uint_8_list(apiObj.field0); + wireObj.tag = 4; + wireObj.kind = inner.inflate_OperationValue_Bytes(); + wireObj.kind.ref.Bytes.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_Relation) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 5; + wireObj.kind = inner.inflate_OperationValue_Relation(); + wireObj.kind.ref.Relation.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_RelationList) { + var pre_field0 = api2wire_StringList(apiObj.field0); + wireObj.tag = 6; + wireObj.kind = inner.inflate_OperationValue_RelationList(); + wireObj.kind.ref.RelationList.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_PinnedRelation) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 7; + wireObj.kind = inner.inflate_OperationValue_PinnedRelation(); + wireObj.kind.ref.PinnedRelation.ref.field0 = pre_field0; + return; + } +if (apiObj is OperationValue_PinnedRelationList) { + var pre_field0 = api2wire_StringList(apiObj.field0); + wireObj.tag = 8; + wireObj.kind = inner.inflate_OperationValue_PinnedRelationList(); + wireObj.kind.ref.PinnedRelationList.ref.field0 = pre_field0; + return; + } + } + - @protected - ffi.Pointer api2wire_uint_8_list(Uint8List raw) { - final ans = inner.new_uint_8_list_0(raw.length); - ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); - return ans; - } -// Section: finalizer - late final OpaqueTypeFinalizer _PandaKeyPairFinalizer = - OpaqueTypeFinalizer(inner._drop_opaque_PandaKeyPairPtr); - OpaqueTypeFinalizer get PandaKeyPairFinalizer => _PandaKeyPairFinalizer; -// Section: api_fill_to_wire - void _api_fill_to_wire_PandaKeyPair( - PandaKeyPair apiObj, wire_PandaKeyPair wireObj) { - wireObj.ptr = apiObj.shareOrMove(); - } - void _api_fill_to_wire___record__String_operation_value( - (String, OperationValue) apiObj, - wire___record__String_operation_value wireObj) { - wireObj.field0 = api2wire_String(apiObj.$1); - _api_fill_to_wire_operation_value(apiObj.$2, wireObj.field1); - } - void _api_fill_to_wire_box_autoadd_key_pair( - KeyPair apiObj, ffi.Pointer wireObj) { - _api_fill_to_wire_key_pair(apiObj, wireObj.ref); - } - void _api_fill_to_wire_key_pair(KeyPair apiObj, wire_KeyPair wireObj) { - wireObj.field0 = api2wire_PandaKeyPair(apiObj.field0); - } - void _api_fill_to_wire_operation_value( - OperationValue apiObj, wire_OperationValue wireObj) { - if (apiObj is OperationValue_Boolean) { - var pre_field0 = api2wire_bool(apiObj.field0); - wireObj.tag = 0; - wireObj.kind = inner.inflate_OperationValue_Boolean(); - wireObj.kind.ref.Boolean.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_Float) { - var pre_field0 = api2wire_f64(apiObj.field0); - wireObj.tag = 1; - wireObj.kind = inner.inflate_OperationValue_Float(); - wireObj.kind.ref.Float.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_Integer) { - var pre_field0 = api2wire_i64(apiObj.field0); - wireObj.tag = 2; - wireObj.kind = inner.inflate_OperationValue_Integer(); - wireObj.kind.ref.Integer.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_String) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 3; - wireObj.kind = inner.inflate_OperationValue_String(); - wireObj.kind.ref.String.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_Bytes) { - var pre_field0 = api2wire_uint_8_list(apiObj.field0); - wireObj.tag = 4; - wireObj.kind = inner.inflate_OperationValue_Bytes(); - wireObj.kind.ref.Bytes.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_Relation) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 5; - wireObj.kind = inner.inflate_OperationValue_Relation(); - wireObj.kind.ref.Relation.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_RelationList) { - var pre_field0 = api2wire_StringList(apiObj.field0); - wireObj.tag = 6; - wireObj.kind = inner.inflate_OperationValue_RelationList(); - wireObj.kind.ref.RelationList.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_PinnedRelation) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 7; - wireObj.kind = inner.inflate_OperationValue_PinnedRelation(); - wireObj.kind.ref.PinnedRelation.ref.field0 = pre_field0; - return; - } - if (apiObj is OperationValue_PinnedRelationList) { - var pre_field0 = api2wire_StringList(apiObj.field0); - wireObj.tag = 8; - wireObj.kind = inner.inflate_OperationValue_PinnedRelationList(); - wireObj.kind.ref.PinnedRelationList.ref.field0 = pre_field0; - return; - } - } } // ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names @@ -826,9 +787,8 @@ class P2PandaPlatform extends FlutterRustBridgeBase { /// generated by flutter_rust_bridge class P2PandaWire implements FlutterRustBridgeWireBase { - @internal - late final dartApi = DartApiDl(init_frb_dart_api_dl); - + @internal + late final dartApi = DartApiDl(init_frb_dart_api_dl); /// Holds the symbol lookup function. final ffi.Pointer Function(String symbolName) _lookup; @@ -1366,6 +1326,8 @@ class P2PandaWire implements FlutterRustBridgeWireBase { final class _Dart_Handle extends ffi.Opaque {} + + final class wire_uint_8_list extends ffi.Struct { external ffi.Pointer ptr; @@ -1472,3 +1434,4 @@ typedef DartPostCObjectFnType = ffi.Pointer< ffi.NativeFunction< ffi.Bool Function(DartPort port_id, ffi.Pointer message)>>; typedef DartPort = ffi.Int64; + diff --git a/packages/p2panda/native/Cargo.toml b/packages/p2panda/native/Cargo.toml index 0b2f434b..8f1d89b8 100644 --- a/packages/p2panda/native/Cargo.toml +++ b/packages/p2panda/native/Cargo.toml @@ -17,4 +17,4 @@ ed25519-dalek = "1.0.1" flutter_rust_bridge = "1.82.6" log = "0.4.19" p2panda-rs = "0.8.1" -tokio = { version = "1.28.2", features = ["rt", "rt-multi-thread", "sync", "parking_lot"] } +tokio = { version = "1.28.2", features = ["rt"] } diff --git a/packages/p2panda/native/src/api.rs b/packages/p2panda/native/src/api.rs index 957e9804..efeffe76 100644 --- a/packages/p2panda/native/src/api.rs +++ b/packages/p2panda/native/src/api.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use std::str::FromStr; +use std::sync::OnceLock; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use android_logger::{AndroidLogger, Config, FilterBuilder}; @@ -26,7 +27,7 @@ static NODE_INSTANCE: OnceCell = OnceCell::const_new(); static STREAM_SINK: OnceCell> = OnceCell::const_new(); -static LOGGER: OnceCell = OnceCell::const_new(); +static LOGGER: OnceLock = OnceLock::new(); struct Logger { android_logger: AndroidLogger, @@ -310,10 +311,14 @@ pub fn start_node( relay_addresses: Vec, allow_schema_ids: Vec, ) -> Result<()> { - let _ = LOGGER.set(Logger::new( + let logger = LOGGER.get_or_init(|| Logger::new( LevelFilter::from_str(&log_level).expect("unknown log level"), )); + if let Err(err) = log::set_logger(logger) { + panic!("logger setup failed: {err}"); + } + // Set node configuration let mut config = Configuration::default(); config.database_url = database_url; From 4a44117fcb82be6143d72496ac4f75cecda4964b Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 16:40:33 +0200 Subject: [PATCH 3/7] New build --- .../p2panda/lib/src/bridge_generated.dart | 1385 +++++++++-------- 1 file changed, 711 insertions(+), 674 deletions(-) diff --git a/packages/p2panda/lib/src/bridge_generated.dart b/packages/p2panda/lib/src/bridge_generated.dart index 9e31e9be..e236ef53 100644 --- a/packages/p2panda/lib/src/bridge_generated.dart +++ b/packages/p2panda/lib/src/bridge_generated.dart @@ -1,781 +1,820 @@ // AUTO GENERATED FILE, DO NOT EDIT. // Generated by `flutter_rust_bridge`@ 1.82.6. - // ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const - +// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const + import 'dart:convert'; - import 'dart:async'; - import 'package:meta/meta.dart'; - import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; +import 'dart:async'; +import 'package:meta/meta.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; import 'package:uuid/uuid.dart'; import 'package:freezed_annotation/freezed_annotation.dart' hide protected; import 'dart:ffi' as ffi; - part 'bridge_generated.freezed.dart'; +abstract class P2Panda { + Stream subscribeLogStream({dynamic hint}); + FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta; + /// Create, sign and encode a p2panda entry. + /// + /// Takes large u64 integers for log id and seq num as strings. If we would declare them as u64 + /// here they will get converted to int which is not a real native u64 integer in Dart! We pass + /// them over as strings and then safely convert them to u64 internally. + Future signAndEncodeEntry( + {required String logId, + required String seqNum, + String? skiplinkHash, + String? backlinkHash, + required Uint8List payload, + required KeyPair keyPair, + dynamic hint}); + FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta; + /// Decodes a p2panda entry. + /// + /// Returns large u64 integers for log id and seq num as strings. If we would declare them as u64 + /// here they will get converted to int which is not a real native u64 integer in Dart! We pass + /// them over as strings and then safely convert them to `BigInt` in the Dart world. + Future<(String, String, String, String?, String?)> decodeEntry( + {required Uint8List entry, dynamic hint}); + FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta; + /// Encode a p2panda operation parsed from JSON input. + Future encodeOperation( + {required OperationAction action, + required String schemaId, + String? previous, + List<(String, OperationValue)>? fields, + dynamic hint}); + FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta; + /// Decodes an p2panda operation, returning it's action and schema id. + Future<(OperationAction, String)> decodeOperation( + {required Uint8List operation, dynamic hint}); + FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta; + /// Runs a p2panda node in a separate thread in the background. + /// + /// Supports Android logging for logs coming from the node. + Future startNode( + {required String logLevel, + required KeyPair keyPair, + required String databaseUrl, + required String blobsBasePath, + required List relayAddresses, + required List allowSchemaIds, + dynamic hint}); - abstract class P2Panda { - Stream subscribeLogStream({ dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta; - -/// Create, sign and encode a p2panda entry. -/// -/// Takes large u64 integers for log id and seq num as strings. If we would declare them as u64 -/// here they will get converted to int which is not a real native u64 integer in Dart! We pass -/// them over as strings and then safely convert them to u64 internally. -Future signAndEncodeEntry({ required String logId ,required String seqNum ,String? skiplinkHash ,String? backlinkHash ,required Uint8List payload ,required KeyPair keyPair ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta; - -/// Decodes a p2panda entry. -/// -/// Returns large u64 integers for log id and seq num as strings. If we would declare them as u64 -/// here they will get converted to int which is not a real native u64 integer in Dart! We pass -/// them over as strings and then safely convert them to `BigInt` in the Dart world. -Future<(String,String,String,String?,String?)> decodeEntry({ required Uint8List entry ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta; - -/// Encode a p2panda operation parsed from JSON input. -Future encodeOperation({ required OperationAction action ,required String schemaId ,String? previous ,List<(String,OperationValue)>? fields ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta; - -/// Decodes an p2panda operation, returning it's action and schema id. -Future<(OperationAction,String)> decodeOperation({ required Uint8List operation ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta; - -/// Runs a p2panda node in a separate thread in the background. -/// -/// Supports Android logging for logs coming from the node. -Future startNode({ required String logLevel ,required KeyPair keyPair ,required String databaseUrl ,required String blobsBasePath ,required List relayAddresses ,required List allowSchemaIds ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta; - -/// Turns off running node. -Future shutdownNode({ dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta; - -/// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. -Future newStaticMethodKeyPair({ dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta; - -/// Derives a key pair from a private key. -Future fromPrivateKeyStaticMethodKeyPair({ required Uint8List bytes ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kFromPrivateKeyStaticMethodKeyPairConstMeta; - -/// Returns the private half of the key pair. -Future privateKeyMethodKeyPair({ required KeyPair that ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta; - -/// Returns the public half of the key pair. -Future publicKeyMethodKeyPair({ required KeyPair that ,dynamic hint }); - -FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta; - - - DropFnType get dropOpaquePandaKeyPair; - ShareFnType get shareOpaquePandaKeyPair; - OpaqueTypeFinalizer get PandaKeyPairFinalizer; - - - - } - - - -@sealed class PandaKeyPair extends FrbOpaque { - final P2Panda bridge; - PandaKeyPair.fromRaw(int ptr, int size, this.bridge) : super.unsafe(ptr, size); - @override - DropFnType get dropFn => bridge.dropOpaquePandaKeyPair; - - @override - ShareFnType get shareFn => bridge.shareOpaquePandaKeyPair; - - @override - OpaqueTypeFinalizer get staticFinalizer => bridge.PandaKeyPairFinalizer; - } - - - - - - + FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta; + /// Turns off running node. + Future shutdownNode({dynamic hint}); + FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta; + /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. + Future newStaticMethodKeyPair({dynamic hint}); + FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta; + /// Derives a key pair from a private key. + Future fromPrivateKeyStaticMethodKeyPair( + {required Uint8List bytes, dynamic hint}); + FlutterRustBridgeTaskConstMeta + get kFromPrivateKeyStaticMethodKeyPairConstMeta; + /// Returns the private half of the key pair. + Future privateKeyMethodKeyPair( + {required KeyPair that, dynamic hint}); + FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta; + /// Returns the public half of the key pair. + Future publicKeyMethodKeyPair( + {required KeyPair that, dynamic hint}); + FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta; + DropFnType get dropOpaquePandaKeyPair; + ShareFnType get shareOpaquePandaKeyPair; + OpaqueTypeFinalizer get PandaKeyPairFinalizer; +} +@sealed +class PandaKeyPair extends FrbOpaque { + final P2Panda bridge; + PandaKeyPair.fromRaw(int ptr, int size, this.bridge) + : super.unsafe(ptr, size); + @override + DropFnType get dropFn => bridge.dropOpaquePandaKeyPair; + @override + ShareFnType get shareFn => bridge.shareOpaquePandaKeyPair; + @override + OpaqueTypeFinalizer get staticFinalizer => bridge.PandaKeyPairFinalizer; +} /// Ed25519 key pair for authors to sign p2panda entries with. -class KeyPair { - final P2Panda bridge; -final PandaKeyPair field0; - - const KeyPair({required this.bridge,required this.field0 ,}); - - /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. -static Future newKeyPair({ required P2Panda bridge,dynamic hint })=>bridge.newStaticMethodKeyPair(hint: hint); - -/// Derives a key pair from a private key. -static Future fromPrivateKey({ required P2Panda bridge,required Uint8List bytes ,dynamic hint })=>bridge.fromPrivateKeyStaticMethodKeyPair(bytes:bytes,hint: hint); - -/// Returns the private half of the key pair. - Future privateKey({ dynamic hint })=>bridge.privateKeyMethodKeyPair(that: this, ); - -/// Returns the public half of the key pair. - Future publicKey({ dynamic hint })=>bridge.publicKeyMethodKeyPair(that: this, ); - - - } - - - -class LogEntry { - final int timestamp; -final LogLevel level; -final String tag; -final String msg; - - const LogEntry({required this.timestamp ,required this.level ,required this.tag ,required this.msg ,}); +class KeyPair { + final P2Panda bridge; + final PandaKeyPair field0; + + const KeyPair({ + required this.bridge, + required this.field0, + }); + + /// Generates a new key pair using the systems random number generator (CSPRNG) as a seed. + static Future newKeyPair({required P2Panda bridge, dynamic hint}) => + bridge.newStaticMethodKeyPair(hint: hint); + + /// Derives a key pair from a private key. + static Future fromPrivateKey( + {required P2Panda bridge, required Uint8List bytes, dynamic hint}) => + bridge.fromPrivateKeyStaticMethodKeyPair(bytes: bytes, hint: hint); + + /// Returns the private half of the key pair. + Future privateKey({dynamic hint}) => + bridge.privateKeyMethodKeyPair( + that: this, + ); + + /// Returns the public half of the key pair. + Future publicKey({dynamic hint}) => bridge.publicKeyMethodKeyPair( + that: this, + ); +} - - } +class LogEntry { + final int timestamp; + final LogLevel level; + final String tag; + final String msg; + + const LogEntry({ + required this.timestamp, + required this.level, + required this.tag, + required this.msg, + }); +} enum LogLevel { - Trace, -Debug, -Info, -Warn, -Error, - } + Trace, + Debug, + Info, + Warn, + Error, +} /// Operations are categorised by their action type. /// /// An action defines the operation format and if this operation creates, updates or deletes a data /// document. enum OperationAction { - /// Operation creates a new document. -Create, -/// Operation updates an existing document. -Update, -/// Operation deletes an existing document. -Delete, - } - -@freezed - sealed class OperationValue with _$OperationValue { - /// Boolean value. -const factory OperationValue.boolean( bool field0,) = OperationValue_Boolean; - /// Floating point value. -const factory OperationValue.float( double field0,) = OperationValue_Float; - /// Signed integer value. -const factory OperationValue.integer( int field0,) = OperationValue_Integer; - /// String value. -const factory OperationValue.string( String field0,) = OperationValue_String; - /// Bytes value. -const factory OperationValue.bytes( Uint8List field0,) = OperationValue_Bytes; - /// Reference to a document. -const factory OperationValue.relation( String field0,) = OperationValue_Relation; - /// Reference to a list of documents. -const factory OperationValue.relationList( List field0,) = OperationValue_RelationList; - /// Reference to a document view. -/// -/// Multiple operation ids are separated by an understore ('_'). -const factory OperationValue.pinnedRelation( String field0,) = OperationValue_PinnedRelation; - /// Reference to a list of document views. -/// -/// Multiple operation ids are separated by an understore ('_'). -const factory OperationValue.pinnedRelationList( List field0,) = OperationValue_PinnedRelationList; - } + /// Operation creates a new document. + Create, + /// Operation updates an existing document. + Update, + /// Operation deletes an existing document. + Delete, +} +@freezed +sealed class OperationValue with _$OperationValue { + /// Boolean value. + const factory OperationValue.boolean( + bool field0, + ) = OperationValue_Boolean; + + /// Floating point value. + const factory OperationValue.float( + double field0, + ) = OperationValue_Float; + + /// Signed integer value. + const factory OperationValue.integer( + int field0, + ) = OperationValue_Integer; + + /// String value. + const factory OperationValue.string( + String field0, + ) = OperationValue_String; + + /// Bytes value. + const factory OperationValue.bytes( + Uint8List field0, + ) = OperationValue_Bytes; + + /// Reference to a document. + const factory OperationValue.relation( + String field0, + ) = OperationValue_Relation; + + /// Reference to a list of documents. + const factory OperationValue.relationList( + List field0, + ) = OperationValue_RelationList; + + /// Reference to a document view. + /// + /// Multiple operation ids are separated by an understore ('_'). + const factory OperationValue.pinnedRelation( + String field0, + ) = OperationValue_PinnedRelation; + + /// Reference to a list of document views. + /// + /// Multiple operation ids are separated by an understore ('_'). + const factory OperationValue.pinnedRelationList( + List field0, + ) = OperationValue_PinnedRelationList; +} +class P2PandaImpl implements P2Panda { + final P2PandaPlatform _platform; + factory P2PandaImpl(ExternalLibrary dylib) => + P2PandaImpl.raw(P2PandaPlatform(dylib)); + + /// Only valid on web/WASM platforms. + factory P2PandaImpl.wasm(FutureOr module) => + P2PandaImpl(module as ExternalLibrary); + P2PandaImpl.raw(this._platform); + Stream subscribeLogStream({dynamic hint}) { + return _platform.executeStream(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_subscribe_log_stream(port_), + parseSuccessData: _wire2api_log_entry, + parseErrorData: null, + constMeta: kSubscribeLogStreamConstMeta, + argValues: [], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "subscribe_log_stream", + argNames: [], + ); + + Future signAndEncodeEntry( + {required String logId, + required String seqNum, + String? skiplinkHash, + String? backlinkHash, + required Uint8List payload, + required KeyPair keyPair, + dynamic hint}) { + var arg0 = _platform.api2wire_String(logId); + var arg1 = _platform.api2wire_String(seqNum); + var arg2 = _platform.api2wire_opt_String(skiplinkHash); + var arg3 = _platform.api2wire_opt_String(backlinkHash); + var arg4 = _platform.api2wire_uint_8_list(payload); + var arg5 = _platform.api2wire_box_autoadd_key_pair(keyPair); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_sign_and_encode_entry( + port_, arg0, arg1, arg2, arg3, arg4, arg5), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kSignAndEncodeEntryConstMeta, + argValues: [logId, seqNum, skiplinkHash, backlinkHash, payload, keyPair], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "sign_and_encode_entry", + argNames: [ + "logId", + "seqNum", + "skiplinkHash", + "backlinkHash", + "payload", + "keyPair" + ], + ); + + Future<(String, String, String, String?, String?)> decodeEntry( + {required Uint8List entry, dynamic hint}) { + var arg0 = _platform.api2wire_uint_8_list(entry); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_decode_entry(port_, arg0), + parseSuccessData: + _wire2api___record__String_String_String_opt_String_opt_String, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kDecodeEntryConstMeta, + argValues: [entry], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "decode_entry", + argNames: ["entry"], + ); + + Future encodeOperation( + {required OperationAction action, + required String schemaId, + String? previous, + List<(String, OperationValue)>? fields, + dynamic hint}) { + var arg0 = api2wire_operation_action(action); + var arg1 = _platform.api2wire_String(schemaId); + var arg2 = _platform.api2wire_opt_String(previous); + var arg3 = + _platform.api2wire_opt_list___record__String_operation_value(fields); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => + _platform.inner.wire_encode_operation(port_, arg0, arg1, arg2, arg3), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kEncodeOperationConstMeta, + argValues: [action, schemaId, previous, fields], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "encode_operation", + argNames: ["action", "schemaId", "previous", "fields"], + ); + + Future<(OperationAction, String)> decodeOperation( + {required Uint8List operation, dynamic hint}) { + var arg0 = _platform.api2wire_uint_8_list(operation); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_decode_operation(port_, arg0), + parseSuccessData: _wire2api___record__operation_action_String, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kDecodeOperationConstMeta, + argValues: [operation], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "decode_operation", + argNames: ["operation"], + ); + + Future startNode( + {required String logLevel, + required KeyPair keyPair, + required String databaseUrl, + required String blobsBasePath, + required List relayAddresses, + required List allowSchemaIds, + dynamic hint}) { + var arg0 = _platform.api2wire_String(logLevel); + var arg1 = _platform.api2wire_box_autoadd_key_pair(keyPair); + var arg2 = _platform.api2wire_String(databaseUrl); + var arg3 = _platform.api2wire_String(blobsBasePath); + var arg4 = _platform.api2wire_StringList(relayAddresses); + var arg5 = _platform.api2wire_StringList(allowSchemaIds); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner + .wire_start_node(port_, arg0, arg1, arg2, arg3, arg4, arg5), + parseSuccessData: _wire2api_unit, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kStartNodeConstMeta, + argValues: [ + logLevel, + keyPair, + databaseUrl, + blobsBasePath, + relayAddresses, + allowSchemaIds + ], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "start_node", + argNames: [ + "logLevel", + "keyPair", + "databaseUrl", + "blobsBasePath", + "relayAddresses", + "allowSchemaIds" + ], + ); + + Future shutdownNode({dynamic hint}) { + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_shutdown_node(port_), + parseSuccessData: _wire2api_unit, + parseErrorData: null, + constMeta: kShutdownNodeConstMeta, + argValues: [], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "shutdown_node", + argNames: [], + ); + + Future newStaticMethodKeyPair({dynamic hint}) { + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => + _platform.inner.wire_new__static_method__KeyPair(port_), + parseSuccessData: (d) => _wire2api_key_pair(d), + parseErrorData: null, + constMeta: kNewStaticMethodKeyPairConstMeta, + argValues: [], + hint: hint, + )); + } - + FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "new__static_method__KeyPair", + argNames: [], + ); + + Future fromPrivateKeyStaticMethodKeyPair( + {required Uint8List bytes, dynamic hint}) { + var arg0 = _platform.api2wire_uint_8_list(bytes); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner + .wire_from_private_key__static_method__KeyPair(port_, arg0), + parseSuccessData: (d) => _wire2api_key_pair(d), + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kFromPrivateKeyStaticMethodKeyPairConstMeta, + argValues: [bytes], + hint: hint, + )); + } -class P2PandaImpl implements P2Panda { - final P2PandaPlatform _platform; - factory P2PandaImpl(ExternalLibrary dylib) => P2PandaImpl.raw(P2PandaPlatform(dylib)); - - /// Only valid on web/WASM platforms. - factory P2PandaImpl.wasm(FutureOr module) => - P2PandaImpl(module as ExternalLibrary); - P2PandaImpl.raw(this._platform); -Stream subscribeLogStream({ dynamic hint }) { - - return _platform.executeStream(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_subscribe_log_stream(port_), - parseSuccessData: _wire2api_log_entry, - parseErrorData: null, - - constMeta: kSubscribeLogStreamConstMeta, - argValues: [], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kSubscribeLogStreamConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "subscribe_log_stream", - argNames: [], - ); - -Future signAndEncodeEntry({ required String logId ,required String seqNum ,String? skiplinkHash ,String? backlinkHash ,required Uint8List payload ,required KeyPair keyPair ,dynamic hint }) { - var arg0 = _platform.api2wire_String(logId); -var arg1 = _platform.api2wire_String(seqNum); -var arg2 = _platform.api2wire_opt_String(skiplinkHash); -var arg3 = _platform.api2wire_opt_String(backlinkHash); -var arg4 = _platform.api2wire_uint_8_list(payload); -var arg5 = _platform.api2wire_box_autoadd_key_pair(keyPair); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_sign_and_encode_entry(port_, arg0, arg1, arg2, arg3, arg4, arg5), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kSignAndEncodeEntryConstMeta, - argValues: [logId, seqNum, skiplinkHash, backlinkHash, payload, keyPair], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kSignAndEncodeEntryConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "sign_and_encode_entry", - argNames: ["logId", "seqNum", "skiplinkHash", "backlinkHash", "payload", "keyPair"], - ); - -Future<(String,String,String,String?,String?)> decodeEntry({ required Uint8List entry ,dynamic hint }) { - var arg0 = _platform.api2wire_uint_8_list(entry); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_decode_entry(port_, arg0), - parseSuccessData: _wire2api___record__String_String_String_opt_String_opt_String, - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kDecodeEntryConstMeta, - argValues: [entry], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kDecodeEntryConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "decode_entry", - argNames: ["entry"], - ); - -Future encodeOperation({ required OperationAction action ,required String schemaId ,String? previous ,List<(String,OperationValue)>? fields ,dynamic hint }) { - var arg0 = api2wire_operation_action(action); -var arg1 = _platform.api2wire_String(schemaId); -var arg2 = _platform.api2wire_opt_String(previous); -var arg3 = _platform.api2wire_opt_list___record__String_operation_value(fields); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_encode_operation(port_, arg0, arg1, arg2, arg3), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kEncodeOperationConstMeta, - argValues: [action, schemaId, previous, fields], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kEncodeOperationConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "encode_operation", - argNames: ["action", "schemaId", "previous", "fields"], - ); - -Future<(OperationAction,String)> decodeOperation({ required Uint8List operation ,dynamic hint }) { - var arg0 = _platform.api2wire_uint_8_list(operation); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_decode_operation(port_, arg0), - parseSuccessData: _wire2api___record__operation_action_String, - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kDecodeOperationConstMeta, - argValues: [operation], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kDecodeOperationConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "decode_operation", - argNames: ["operation"], - ); - -Future startNode({ required String logLevel ,required KeyPair keyPair ,required String databaseUrl ,required String blobsBasePath ,required List relayAddresses ,required List allowSchemaIds ,dynamic hint }) { - var arg0 = _platform.api2wire_String(logLevel); -var arg1 = _platform.api2wire_box_autoadd_key_pair(keyPair); -var arg2 = _platform.api2wire_String(databaseUrl); -var arg3 = _platform.api2wire_String(blobsBasePath); -var arg4 = _platform.api2wire_StringList(relayAddresses); -var arg5 = _platform.api2wire_StringList(allowSchemaIds); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_start_node(port_, arg0, arg1, arg2, arg3, arg4, arg5), - parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kStartNodeConstMeta, - argValues: [logLevel, keyPair, databaseUrl, blobsBasePath, relayAddresses, allowSchemaIds], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kStartNodeConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "start_node", - argNames: ["logLevel", "keyPair", "databaseUrl", "blobsBasePath", "relayAddresses", "allowSchemaIds"], - ); - -Future shutdownNode({ dynamic hint }) { - - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_shutdown_node(port_), - parseSuccessData: _wire2api_unit, - parseErrorData: null, - - constMeta: kShutdownNodeConstMeta, - argValues: [], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kShutdownNodeConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "shutdown_node", - argNames: [], - ); - -Future newStaticMethodKeyPair({ dynamic hint }) { - - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_new__static_method__KeyPair(port_), - parseSuccessData: (d) => _wire2api_key_pair(d), - parseErrorData: null, - - constMeta: kNewStaticMethodKeyPairConstMeta, - argValues: [], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kNewStaticMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "new__static_method__KeyPair", - argNames: [], - ); - -Future fromPrivateKeyStaticMethodKeyPair({ required Uint8List bytes ,dynamic hint }) { - var arg0 = _platform.api2wire_uint_8_list(bytes); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_from_private_key__static_method__KeyPair(port_, arg0), - parseSuccessData: (d) => _wire2api_key_pair(d), - parseErrorData: _wire2api_FrbAnyhowException, - - constMeta: kFromPrivateKeyStaticMethodKeyPairConstMeta, - argValues: [bytes], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kFromPrivateKeyStaticMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( + FlutterRustBridgeTaskConstMeta + get kFromPrivateKeyStaticMethodKeyPairConstMeta => + const FlutterRustBridgeTaskConstMeta( debugName: "from_private_key__static_method__KeyPair", argNames: ["bytes"], - ); - -Future privateKeyMethodKeyPair({ required KeyPair that ,dynamic hint }) { - var arg0 = _platform.api2wire_box_autoadd_key_pair(that); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_private_key__method__KeyPair(port_, arg0), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: null, - - constMeta: kPrivateKeyMethodKeyPairConstMeta, - argValues: [that], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "private_key__method__KeyPair", - argNames: ["that"], - ); - -Future publicKeyMethodKeyPair({ required KeyPair that ,dynamic hint }) { - var arg0 = _platform.api2wire_box_autoadd_key_pair(that); - return _platform.executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => _platform.inner.wire_public_key__method__KeyPair(port_, arg0), - parseSuccessData: _wire2api_uint_8_list, - parseErrorData: null, - - constMeta: kPublicKeyMethodKeyPairConstMeta, - argValues: [that], - hint: hint, - - ));} - - - FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta => const FlutterRustBridgeTaskConstMeta( - debugName: "public_key__method__KeyPair", - argNames: ["that"], - ); - - - DropFnType get dropOpaquePandaKeyPair => _platform.inner.drop_opaque_PandaKeyPair; - ShareFnType get shareOpaquePandaKeyPair => _platform.inner.share_opaque_PandaKeyPair; - OpaqueTypeFinalizer get PandaKeyPairFinalizer => _platform.PandaKeyPairFinalizer; - - - -void dispose() {_platform.dispose();} -// Section: wire2api - -FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) { - return FrbAnyhowException(raw as String); - } - - -PandaKeyPair _wire2api_PandaKeyPair(dynamic raw) { - return PandaKeyPair.fromRaw(raw[0], raw[1], this); - } - - -String _wire2api_String(dynamic raw) { - return raw as String; - } - - -(String,String,String,String?,String?) _wire2api___record__String_String_String_opt_String_opt_String(dynamic raw) { - final arr = raw as List; - if (arr.length != 5) { - throw Exception('Expected 5 elements, got ${arr.length}'); - } - return (_wire2api_String(arr[0]),_wire2api_String(arr[1]),_wire2api_String(arr[2]),_wire2api_opt_String(arr[3]),_wire2api_opt_String(arr[4]),); - } - - -(OperationAction,String) _wire2api___record__operation_action_String(dynamic raw) { - final arr = raw as List; - if (arr.length != 2) { - throw Exception('Expected 2 elements, got ${arr.length}'); - } - return (_wire2api_operation_action(arr[0]),_wire2api_String(arr[1]),); - } - - -int _wire2api_i32(dynamic raw) { - return raw as int; - } - - -KeyPair _wire2api_key_pair(dynamic raw) { - final arr = raw as List; - if (arr.length != 1) throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); - return KeyPair(bridge: this, -field0: _wire2api_PandaKeyPair(arr[0]),); - } - - -LogEntry _wire2api_log_entry(dynamic raw) { - final arr = raw as List; - if (arr.length != 4) throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); - return LogEntry(timestamp: _wire2api_u64(arr[0]), -level: _wire2api_log_level(arr[1]), -tag: _wire2api_String(arr[2]), -msg: _wire2api_String(arr[3]),); - } - - -LogLevel _wire2api_log_level(dynamic raw) { - return LogLevel.values[raw as int]; - } - - -OperationAction _wire2api_operation_action(dynamic raw) { - return OperationAction.values[raw as int]; - } - - -String? _wire2api_opt_String(dynamic raw) { - return raw == null ? null : _wire2api_String(raw); - } - - -int _wire2api_u64(dynamic raw) { - return castInt(raw); - } - - -int _wire2api_u8(dynamic raw) { - return raw as int; - } - - -Uint8List _wire2api_uint_8_list(dynamic raw) { - return raw as Uint8List; - } - - -void _wire2api_unit(dynamic raw) { - return; - } - -} - -// Section: api2wire + ); + + Future privateKeyMethodKeyPair( + {required KeyPair that, dynamic hint}) { + var arg0 = _platform.api2wire_box_autoadd_key_pair(that); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => + _platform.inner.wire_private_key__method__KeyPair(port_, arg0), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: null, + constMeta: kPrivateKeyMethodKeyPairConstMeta, + argValues: [that], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kPrivateKeyMethodKeyPairConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "private_key__method__KeyPair", + argNames: ["that"], + ); + + Future publicKeyMethodKeyPair( + {required KeyPair that, dynamic hint}) { + var arg0 = _platform.api2wire_box_autoadd_key_pair(that); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => + _platform.inner.wire_public_key__method__KeyPair(port_, arg0), + parseSuccessData: _wire2api_uint_8_list, + parseErrorData: null, + constMeta: kPublicKeyMethodKeyPairConstMeta, + argValues: [that], + hint: hint, + )); + } + FlutterRustBridgeTaskConstMeta get kPublicKeyMethodKeyPairConstMeta => + const FlutterRustBridgeTaskConstMeta( + debugName: "public_key__method__KeyPair", + argNames: ["that"], + ); + + DropFnType get dropOpaquePandaKeyPair => + _platform.inner.drop_opaque_PandaKeyPair; + ShareFnType get shareOpaquePandaKeyPair => + _platform.inner.share_opaque_PandaKeyPair; + OpaqueTypeFinalizer get PandaKeyPairFinalizer => + _platform.PandaKeyPairFinalizer; + + void dispose() { + _platform.dispose(); + } +// Section: wire2api + FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) { + return FrbAnyhowException(raw as String); + } + PandaKeyPair _wire2api_PandaKeyPair(dynamic raw) { + return PandaKeyPair.fromRaw(raw[0], raw[1], this); + } -@protected - bool api2wire_bool(bool raw) { - return raw; - } + String _wire2api_String(dynamic raw) { + return raw as String; + } -@protected - double api2wire_f64(double raw) { - return raw; - } -@protected - int api2wire_i32(int raw) { - return raw; - } + (String, String, String, String?, String?) + _wire2api___record__String_String_String_opt_String_opt_String( + dynamic raw) { + final arr = raw as List; + if (arr.length != 5) { + throw Exception('Expected 5 elements, got ${arr.length}'); + } + return ( + _wire2api_String(arr[0]), + _wire2api_String(arr[1]), + _wire2api_String(arr[2]), + _wire2api_opt_String(arr[3]), + _wire2api_opt_String(arr[4]), + ); + } + (OperationAction, String) _wire2api___record__operation_action_String( + dynamic raw) { + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + _wire2api_operation_action(arr[0]), + _wire2api_String(arr[1]), + ); + } + int _wire2api_i32(dynamic raw) { + return raw as int; + } -@protected - int api2wire_operation_action(OperationAction raw) { - return api2wire_i32(raw.index); - } + KeyPair _wire2api_key_pair(dynamic raw) { + final arr = raw as List; + if (arr.length != 1) + throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); + return KeyPair( + bridge: this, + field0: _wire2api_PandaKeyPair(arr[0]), + ); + } + LogEntry _wire2api_log_entry(dynamic raw) { + final arr = raw as List; + if (arr.length != 4) + throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); + return LogEntry( + timestamp: _wire2api_u64(arr[0]), + level: _wire2api_log_level(arr[1]), + tag: _wire2api_String(arr[2]), + msg: _wire2api_String(arr[3]), + ); + } + LogLevel _wire2api_log_level(dynamic raw) { + return LogLevel.values[raw as int]; + } -@protected - int api2wire_u8(int raw) { - return raw; - } + OperationAction _wire2api_operation_action(dynamic raw) { + return OperationAction.values[raw as int]; + } -// Section: finalizer + String? _wire2api_opt_String(dynamic raw) { + return raw == null ? null : _wire2api_String(raw); + } + int _wire2api_u64(dynamic raw) { + return castInt(raw); + } + int _wire2api_u8(dynamic raw) { + return raw as int; + } + Uint8List _wire2api_uint_8_list(dynamic raw) { + return raw as Uint8List; + } -class P2PandaPlatform extends FlutterRustBridgeBase { - P2PandaPlatform(ffi.DynamicLibrary dylib) : super(P2PandaWire(dylib)); + void _wire2api_unit(dynamic raw) { + return; + } +} // Section: api2wire @protected - wire_PandaKeyPair api2wire_PandaKeyPair(PandaKeyPair raw) { - final ptr = inner.new_PandaKeyPair(); - _api_fill_to_wire_PandaKeyPair(raw, ptr); - return ptr; - } -@protected - ffi.Pointer api2wire_String(String raw) { - return api2wire_uint_8_list(utf8.encoder.convert(raw)); - } -@protected - ffi.Pointer api2wire_StringList(List raw) { - final ans = inner.new_StringList_0(raw.length); - for (var i = 0; i < raw.length; i++){ - ans.ref.ptr[i] = api2wire_String(raw[i]); - } - return ans; - } - +bool api2wire_bool(bool raw) { + return raw; +} @protected - ffi.Pointer api2wire_box_autoadd_key_pair(KeyPair raw) { - final ptr = inner.new_box_autoadd_key_pair_0(); - _api_fill_to_wire_key_pair(raw, ptr.ref); - return ptr; - } - +double api2wire_f64(double raw) { + return raw; +} @protected - int api2wire_i64(int raw) { - return raw; - } +int api2wire_i32(int raw) { + return raw; +} @protected - ffi.Pointer api2wire_list___record__String_operation_value(List<(String,OperationValue)> raw) { - final ans = inner.new_list___record__String_operation_value_0(raw.length); - for (var i = 0; i < raw.length; ++i) { - _api_fill_to_wire___record__String_operation_value(raw[i], ans.ref.ptr[i]); - } - return ans; - - } - +int api2wire_operation_action(OperationAction raw) { + return api2wire_i32(raw.index); +} @protected - ffi.Pointer api2wire_opt_String(String? raw) { - return raw == null ? ffi.nullptr : api2wire_String(raw); - } -@protected - ffi.Pointer api2wire_opt_list___record__String_operation_value(List<(String,OperationValue)>? raw) { - return raw == null ? ffi.nullptr : api2wire_list___record__String_operation_value(raw); - } +int api2wire_u8(int raw) { + return raw; +} -@protected - ffi.Pointer api2wire_uint_8_list(Uint8List raw) { - final ans = inner.new_uint_8_list_0(raw.length); - ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); - return ans; - } // Section: finalizer -late final OpaqueTypeFinalizer _PandaKeyPairFinalizer = OpaqueTypeFinalizer(inner._drop_opaque_PandaKeyPairPtr); - OpaqueTypeFinalizer get PandaKeyPairFinalizer => _PandaKeyPairFinalizer; -// Section: api_fill_to_wire - -void _api_fill_to_wire_PandaKeyPair(PandaKeyPair apiObj, wire_PandaKeyPair wireObj) { - wireObj.ptr = apiObj.shareOrMove(); - } - - - - - -void _api_fill_to_wire___record__String_operation_value((String,OperationValue) apiObj, wire___record__String_operation_value wireObj) { - wireObj.field0 = api2wire_String(apiObj.$1); -_api_fill_to_wire_operation_value(apiObj.$2, wireObj.field1); - } - - - -void _api_fill_to_wire_box_autoadd_key_pair(KeyPair apiObj, ffi.Pointer wireObj) { - _api_fill_to_wire_key_pair(apiObj, wireObj.ref); - } - - - - +class P2PandaPlatform extends FlutterRustBridgeBase { + P2PandaPlatform(ffi.DynamicLibrary dylib) : super(P2PandaWire(dylib)); +// Section: api2wire + @protected + wire_PandaKeyPair api2wire_PandaKeyPair(PandaKeyPair raw) { + final ptr = inner.new_PandaKeyPair(); + _api_fill_to_wire_PandaKeyPair(raw, ptr); + return ptr; + } -void _api_fill_to_wire_key_pair(KeyPair apiObj, wire_KeyPair wireObj) { - wireObj.field0 = api2wire_PandaKeyPair(apiObj.field0); - } + @protected + ffi.Pointer api2wire_String(String raw) { + return api2wire_uint_8_list(utf8.encoder.convert(raw)); + } + @protected + ffi.Pointer api2wire_StringList(List raw) { + final ans = inner.new_StringList_0(raw.length); + for (var i = 0; i < raw.length; i++) { + ans.ref.ptr[i] = api2wire_String(raw[i]); + } + return ans; + } + @protected + ffi.Pointer api2wire_box_autoadd_key_pair(KeyPair raw) { + final ptr = inner.new_box_autoadd_key_pair_0(); + _api_fill_to_wire_key_pair(raw, ptr.ref); + return ptr; + } + @protected + int api2wire_i64(int raw) { + return raw; + } + @protected + ffi.Pointer + api2wire_list___record__String_operation_value( + List<(String, OperationValue)> raw) { + final ans = inner.new_list___record__String_operation_value_0(raw.length); + for (var i = 0; i < raw.length; ++i) { + _api_fill_to_wire___record__String_operation_value( + raw[i], ans.ref.ptr[i]); + } + return ans; + } -void _api_fill_to_wire_operation_value(OperationValue apiObj, wire_OperationValue wireObj) { - if (apiObj is OperationValue_Boolean) { - var pre_field0 = api2wire_bool(apiObj.field0); - wireObj.tag = 0; - wireObj.kind = inner.inflate_OperationValue_Boolean(); - wireObj.kind.ref.Boolean.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_Float) { - var pre_field0 = api2wire_f64(apiObj.field0); - wireObj.tag = 1; - wireObj.kind = inner.inflate_OperationValue_Float(); - wireObj.kind.ref.Float.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_Integer) { - var pre_field0 = api2wire_i64(apiObj.field0); - wireObj.tag = 2; - wireObj.kind = inner.inflate_OperationValue_Integer(); - wireObj.kind.ref.Integer.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_String) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 3; - wireObj.kind = inner.inflate_OperationValue_String(); - wireObj.kind.ref.String.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_Bytes) { - var pre_field0 = api2wire_uint_8_list(apiObj.field0); - wireObj.tag = 4; - wireObj.kind = inner.inflate_OperationValue_Bytes(); - wireObj.kind.ref.Bytes.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_Relation) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 5; - wireObj.kind = inner.inflate_OperationValue_Relation(); - wireObj.kind.ref.Relation.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_RelationList) { - var pre_field0 = api2wire_StringList(apiObj.field0); - wireObj.tag = 6; - wireObj.kind = inner.inflate_OperationValue_RelationList(); - wireObj.kind.ref.RelationList.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_PinnedRelation) { - var pre_field0 = api2wire_String(apiObj.field0); - wireObj.tag = 7; - wireObj.kind = inner.inflate_OperationValue_PinnedRelation(); - wireObj.kind.ref.PinnedRelation.ref.field0 = pre_field0; - return; - } -if (apiObj is OperationValue_PinnedRelationList) { - var pre_field0 = api2wire_StringList(apiObj.field0); - wireObj.tag = 8; - wireObj.kind = inner.inflate_OperationValue_PinnedRelationList(); - wireObj.kind.ref.PinnedRelationList.ref.field0 = pre_field0; - return; - } - } + @protected + ffi.Pointer api2wire_opt_String(String? raw) { + return raw == null ? ffi.nullptr : api2wire_String(raw); + } + @protected + ffi.Pointer + api2wire_opt_list___record__String_operation_value( + List<(String, OperationValue)>? raw) { + return raw == null + ? ffi.nullptr + : api2wire_list___record__String_operation_value(raw); + } + @protected + ffi.Pointer api2wire_uint_8_list(Uint8List raw) { + final ans = inner.new_uint_8_list_0(raw.length); + ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); + return ans; + } +// Section: finalizer + late final OpaqueTypeFinalizer _PandaKeyPairFinalizer = + OpaqueTypeFinalizer(inner._drop_opaque_PandaKeyPairPtr); + OpaqueTypeFinalizer get PandaKeyPairFinalizer => _PandaKeyPairFinalizer; +// Section: api_fill_to_wire + void _api_fill_to_wire_PandaKeyPair( + PandaKeyPair apiObj, wire_PandaKeyPair wireObj) { + wireObj.ptr = apiObj.shareOrMove(); + } + void _api_fill_to_wire___record__String_operation_value( + (String, OperationValue) apiObj, + wire___record__String_operation_value wireObj) { + wireObj.field0 = api2wire_String(apiObj.$1); + _api_fill_to_wire_operation_value(apiObj.$2, wireObj.field1); + } + void _api_fill_to_wire_box_autoadd_key_pair( + KeyPair apiObj, ffi.Pointer wireObj) { + _api_fill_to_wire_key_pair(apiObj, wireObj.ref); + } + void _api_fill_to_wire_key_pair(KeyPair apiObj, wire_KeyPair wireObj) { + wireObj.field0 = api2wire_PandaKeyPair(apiObj.field0); + } + void _api_fill_to_wire_operation_value( + OperationValue apiObj, wire_OperationValue wireObj) { + if (apiObj is OperationValue_Boolean) { + var pre_field0 = api2wire_bool(apiObj.field0); + wireObj.tag = 0; + wireObj.kind = inner.inflate_OperationValue_Boolean(); + wireObj.kind.ref.Boolean.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_Float) { + var pre_field0 = api2wire_f64(apiObj.field0); + wireObj.tag = 1; + wireObj.kind = inner.inflate_OperationValue_Float(); + wireObj.kind.ref.Float.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_Integer) { + var pre_field0 = api2wire_i64(apiObj.field0); + wireObj.tag = 2; + wireObj.kind = inner.inflate_OperationValue_Integer(); + wireObj.kind.ref.Integer.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_String) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 3; + wireObj.kind = inner.inflate_OperationValue_String(); + wireObj.kind.ref.String.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_Bytes) { + var pre_field0 = api2wire_uint_8_list(apiObj.field0); + wireObj.tag = 4; + wireObj.kind = inner.inflate_OperationValue_Bytes(); + wireObj.kind.ref.Bytes.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_Relation) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 5; + wireObj.kind = inner.inflate_OperationValue_Relation(); + wireObj.kind.ref.Relation.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_RelationList) { + var pre_field0 = api2wire_StringList(apiObj.field0); + wireObj.tag = 6; + wireObj.kind = inner.inflate_OperationValue_RelationList(); + wireObj.kind.ref.RelationList.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_PinnedRelation) { + var pre_field0 = api2wire_String(apiObj.field0); + wireObj.tag = 7; + wireObj.kind = inner.inflate_OperationValue_PinnedRelation(); + wireObj.kind.ref.PinnedRelation.ref.field0 = pre_field0; + return; + } + if (apiObj is OperationValue_PinnedRelationList) { + var pre_field0 = api2wire_StringList(apiObj.field0); + wireObj.tag = 8; + wireObj.kind = inner.inflate_OperationValue_PinnedRelationList(); + wireObj.kind.ref.PinnedRelationList.ref.field0 = pre_field0; + return; + } + } } // ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names @@ -787,8 +826,9 @@ if (apiObj is OperationValue_PinnedRelationList) { /// generated by flutter_rust_bridge class P2PandaWire implements FlutterRustBridgeWireBase { - @internal - late final dartApi = DartApiDl(init_frb_dart_api_dl); + @internal + late final dartApi = DartApiDl(init_frb_dart_api_dl); + /// Holds the symbol lookup function. final ffi.Pointer Function(String symbolName) _lookup; @@ -1326,8 +1366,6 @@ class P2PandaWire implements FlutterRustBridgeWireBase { final class _Dart_Handle extends ffi.Opaque {} - - final class wire_uint_8_list extends ffi.Struct { external ffi.Pointer ptr; @@ -1434,4 +1472,3 @@ typedef DartPostCObjectFnType = ffi.Pointer< ffi.NativeFunction< ffi.Bool Function(DartPort port_id, ffi.Pointer message)>>; typedef DartPort = ffi.Int64; - From 583bbdf0f1b4aeec0e926e8d040479e0a5f0cc49 Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 16:40:50 +0200 Subject: [PATCH 4/7] Get log level from ENV vars in Flutter --- packages/app/lib/io/p2panda/node.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/app/lib/io/p2panda/node.dart b/packages/app/lib/io/p2panda/node.dart index d2cbcd1a..c774ab02 100644 --- a/packages/app/lib/io/p2panda/node.dart +++ b/packages/app/lib/io/p2panda/node.dart @@ -12,6 +12,9 @@ const List relayAddresses = (bool.hasEnvironment("RELAY_ADDRESS") && ? [String.fromEnvironment("RELAY_ADDRESS")] : []; +const String logLevel = + String.fromEnvironment("LOG_LEVEL", defaultValue: "ERROR"); + /// Start a p2panda node in the background. Future startNode() async { // Determine folder where we can persist data @@ -26,6 +29,7 @@ Future startNode() async { // Start node in background thread p2panda.startNode( + logLevel: logLevel, keyPair: key, databaseUrl: databaseUrl, blobsBasePath: basePath, @@ -33,6 +37,10 @@ Future startNode() async { allowSchemaIds: ALL_SCHEMA_IDS, ); + p2panda.subscribeLogStream().listen((logEntry) { + print(logEntry.msg); + }); + // .. since we can't `await` the FFI binding method from Rust we need to // poll here to find out until the node is ready await _untilReady(); From 387d70e143e1826d858e04edc07c5c70be865bc9 Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 18:11:16 +0200 Subject: [PATCH 5/7] Dont forget to set max_level --- packages/p2panda/native/src/api.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/p2panda/native/src/api.rs b/packages/p2panda/native/src/api.rs index efeffe76..35f50a3e 100644 --- a/packages/p2panda/native/src/api.rs +++ b/packages/p2panda/native/src/api.rs @@ -9,7 +9,7 @@ use anyhow::{anyhow, Result}; use aquadoggo::{AllowList, Configuration}; use ed25519_dalek::SecretKey; use flutter_rust_bridge::{RustOpaque, StreamSink}; -use log::{Level, LevelFilter, Log, Record}; +use log::{warn, Level, LevelFilter, Log, Record}; use p2panda_rs::document::DocumentViewId; use p2panda_rs::entry; use p2panda_rs::entry::traits::{AsEncodedEntry, AsEntry}; @@ -300,6 +300,15 @@ pub fn decode_operation(operation: Vec) -> Result<(OperationAction, String)> )) } +fn init_logging(level: LevelFilter) { + let logger = LOGGER.get_or_init(|| Logger::new(level)); + if let Err(err) = log::set_logger(logger) { + warn!("logger setup failed: {err}"); + } else { + log::set_max_level(level); + } +} + /// Runs a p2panda node in a separate thread in the background. /// /// Supports Android logging for logs coming from the node. @@ -311,13 +320,7 @@ pub fn start_node( relay_addresses: Vec, allow_schema_ids: Vec, ) -> Result<()> { - let logger = LOGGER.get_or_init(|| Logger::new( - LevelFilter::from_str(&log_level).expect("unknown log level"), - )); - - if let Err(err) = log::set_logger(logger) { - panic!("logger setup failed: {err}"); - } + init_logging(LevelFilter::from_str(&log_level).expect("unknown log level")); // Set node configuration let mut config = Configuration::default(); From 1d40fafa6159968a500ab0e686490d094e6fc39a Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 18:30:29 +0200 Subject: [PATCH 6/7] Only handle logs coming from aquadoggo --- packages/p2panda/native/src/api.rs | 53 +++++++++++++++++------------ packages/p2panda/native/src/node.rs | 13 +++++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/packages/p2panda/native/src/api.rs b/packages/p2panda/native/src/api.rs index 35f50a3e..4f49b212 100644 --- a/packages/p2panda/native/src/api.rs +++ b/packages/p2panda/native/src/api.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use std::sync::OnceLock; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use android_logger::{AndroidLogger, Config, FilterBuilder}; +use android_logger::{AndroidLogger, Config, Filter, FilterBuilder}; use anyhow::{anyhow, Result}; use aquadoggo::{AllowList, Configuration}; use ed25519_dalek::SecretKey; @@ -29,23 +29,39 @@ static STREAM_SINK: OnceCell> = OnceCell::const_new(); static LOGGER: OnceLock = OnceLock::new(); +pub enum LogLevel { + Trace, + Debug, + Info, + Warn, + Error, +} + +pub struct LogEntry { + pub timestamp: u64, + pub level: LogLevel, + pub tag: String, + pub msg: String, +} + struct Logger { android_logger: AndroidLogger, max_level: LevelFilter, + filter: Filter, } impl Logger { fn new(max_level: LevelFilter) -> Logger { - let android_config = Config::default().with_max_level(max_level).with_filter( - FilterBuilder::new() - .filter(Some("aquadoggo"), LevelFilter::Debug) - .build(), - ); - let android_logger = AndroidLogger::new(android_config); + let filter = FilterBuilder::new() + .filter(Some("aquadoggo"), max_level) + .build(); + let android_logger = + AndroidLogger::new(Config::default().with_max_level(LevelFilter::Trace)); Logger { android_logger, max_level, + filter, } } @@ -82,6 +98,14 @@ impl Log for Logger { } fn log(&self, record: &log::Record) { + if !self.enabled(record.metadata()) { + return; + } + + if !self.filter.matches(record) { + return; + } + match STREAM_SINK.get() { Some(sink) => { sink.add(Logger::record_to_entry(record)); @@ -99,21 +123,6 @@ pub fn subscribe_log_stream(sink: StreamSink) { let _ = STREAM_SINK.set(sink); } -pub enum LogLevel { - Trace, - Debug, - Info, - Warn, - Error, -} - -pub struct LogEntry { - pub timestamp: u64, - pub level: LogLevel, - pub tag: String, - pub msg: String, -} - pub type HexString = String; /// Ed25519 key pair for authors to sign p2panda entries with. diff --git a/packages/p2panda/native/src/node.rs b/packages/p2panda/native/src/node.rs index ec2ccaa8..aedda023 100644 --- a/packages/p2panda/native/src/node.rs +++ b/packages/p2panda/native/src/node.rs @@ -8,6 +8,16 @@ use p2panda_rs::identity::KeyPair; use tokio::runtime; use tokio::sync::mpsc::{channel, Sender}; +struct PanicDetector {} + +impl Drop for PanicDetector { + fn drop(&mut self) { + if std::thread::panicking() { + panic!("OUUUCH"); + } + } +} + pub struct Manager { shutdown_signal: Sender, } @@ -17,6 +27,8 @@ impl Manager { let (shutdown_signal, mut on_shutdown) = channel(4); thread::spawn(move || { + let _ = PanicDetector {}; + let rt = runtime::Builder::new_current_thread() .enable_all() .build() @@ -32,6 +44,7 @@ impl Manager { node.shutdown().await; }); + }); Ok(Manager { shutdown_signal }) From d919582a902b19a70095091b256d640370a13d1f Mon Sep 17 00:00:00 2001 From: adz Date: Mon, 24 Jun 2024 18:33:41 +0200 Subject: [PATCH 7/7] Introduce Logger class --- packages/app/lib/io/p2panda/logs.dart | 11 +++++++++++ packages/app/lib/io/p2panda/node.dart | 4 ---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 packages/app/lib/io/p2panda/logs.dart diff --git a/packages/app/lib/io/p2panda/logs.dart b/packages/app/lib/io/p2panda/logs.dart new file mode 100644 index 00000000..a9f32c45 --- /dev/null +++ b/packages/app/lib/io/p2panda/logs.dart @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import 'package:app/io/p2panda/p2panda.dart'; + +class Logger { + Logger() { + p2panda.subscribeLogStream().listen((logEntry) { + print(logEntry.msg); + }); + } +} diff --git a/packages/app/lib/io/p2panda/node.dart b/packages/app/lib/io/p2panda/node.dart index c774ab02..44c307c3 100644 --- a/packages/app/lib/io/p2panda/node.dart +++ b/packages/app/lib/io/p2panda/node.dart @@ -37,10 +37,6 @@ Future startNode() async { allowSchemaIds: ALL_SCHEMA_IDS, ); - p2panda.subscribeLogStream().listen((logEntry) { - print(logEntry.msg); - }); - // .. since we can't `await` the FFI binding method from Rust we need to // poll here to find out until the node is ready await _untilReady();