From 19e614db145d9e8190999bc9fc9aada39a6a4a4d Mon Sep 17 00:00:00 2001 From: yse <70684173+hydra-yse@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:38:07 +0100 Subject: [PATCH] adding dart bindings for metadata --- libs/sdk-core/src/binding.rs | 11 +++++ libs/sdk-core/src/bridge_generated.io.rs | 9 ++++ libs/sdk-core/src/bridge_generated.rs | 18 ++++++++ .../ios/Classes/bridge_generated.h | 5 +++ libs/sdk-flutter/lib/bridge_generated.dart | 42 +++++++++++++++++++ 5 files changed, 85 insertions(+) diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index 16f6e0ce3..7d80d79c6 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -261,6 +261,17 @@ pub fn payment_by_hash(hash: String) -> Result> { .map_err(anyhow::Error::new::) } +/// See [BreezServices::set_payment_metadata] +pub fn set_payment_metadata(hash: String, metadata: String) -> Result<()> { + block_on(async { + get_breez_services() + .await? + .set_payment_metadata(hash, metadata) + .await + }) + .map_err(anyhow::Error::new::) +} + /* Lightning Payment API's */ /// See [BreezServices::send_payment] diff --git a/libs/sdk-core/src/bridge_generated.io.rs b/libs/sdk-core/src/bridge_generated.io.rs index 84b00685a..a58227ad4 100644 --- a/libs/sdk-core/src/bridge_generated.io.rs +++ b/libs/sdk-core/src/bridge_generated.io.rs @@ -136,6 +136,15 @@ pub extern "C" fn wire_payment_by_hash(port_: i64, hash: *mut wire_uint_8_list) wire_payment_by_hash_impl(port_, hash) } +#[no_mangle] +pub extern "C" fn wire_set_payment_metadata( + port_: i64, + hash: *mut wire_uint_8_list, + metadata: *mut wire_uint_8_list, +) { + wire_set_payment_metadata_impl(port_, hash, metadata) +} + #[no_mangle] pub extern "C" fn wire_send_payment(port_: i64, req: *mut wire_SendPaymentRequest) { wire_send_payment_impl(port_, req) diff --git a/libs/sdk-core/src/bridge_generated.rs b/libs/sdk-core/src/bridge_generated.rs index 092d1bb11..5007cc73c 100644 --- a/libs/sdk-core/src/bridge_generated.rs +++ b/libs/sdk-core/src/bridge_generated.rs @@ -443,6 +443,24 @@ fn wire_payment_by_hash_impl(port_: MessagePort, hash: impl Wire2Api + U }, ) } +fn wire_set_payment_metadata_impl( + port_: MessagePort, + hash: impl Wire2Api + UnwindSafe, + metadata: impl Wire2Api + UnwindSafe, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>( + WrapInfo { + debug_name: "set_payment_metadata", + port: Some(port_), + mode: FfiCallMode::Normal, + }, + move || { + let api_hash = hash.wire2api(); + let api_metadata = metadata.wire2api(); + move |task_callback| set_payment_metadata(api_hash, api_metadata) + }, + ) +} fn wire_send_payment_impl(port_: MessagePort, req: impl Wire2Api + UnwindSafe) { FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, SendPaymentResponse, _>( WrapInfo { diff --git a/libs/sdk-flutter/ios/Classes/bridge_generated.h b/libs/sdk-flutter/ios/Classes/bridge_generated.h index de8f9f876..bcb6cecd2 100644 --- a/libs/sdk-flutter/ios/Classes/bridge_generated.h +++ b/libs/sdk-flutter/ios/Classes/bridge_generated.h @@ -306,6 +306,10 @@ void wire_list_payments(int64_t port_, struct wire_ListPaymentsRequest *req); void wire_payment_by_hash(int64_t port_, struct wire_uint_8_list *hash); +void wire_set_payment_metadata(int64_t port_, + struct wire_uint_8_list *hash, + struct wire_uint_8_list *metadata); + void wire_send_payment(int64_t port_, struct wire_SendPaymentRequest *req); void wire_send_spontaneous_payment(int64_t port_, struct wire_SendSpontaneousPaymentRequest *req); @@ -459,6 +463,7 @@ static int64_t dummy_method_to_enforce_bundling(void) { dummy_var ^= ((int64_t) (void*) wire_parse_input); dummy_var ^= ((int64_t) (void*) wire_list_payments); dummy_var ^= ((int64_t) (void*) wire_payment_by_hash); + dummy_var ^= ((int64_t) (void*) wire_set_payment_metadata); dummy_var ^= ((int64_t) (void*) wire_send_payment); dummy_var ^= ((int64_t) (void*) wire_send_spontaneous_payment); dummy_var ^= ((int64_t) (void*) wire_receive_payment); diff --git a/libs/sdk-flutter/lib/bridge_generated.dart b/libs/sdk-flutter/lib/bridge_generated.dart index 4bb979fff..27072147a 100644 --- a/libs/sdk-flutter/lib/bridge_generated.dart +++ b/libs/sdk-flutter/lib/bridge_generated.dart @@ -145,6 +145,11 @@ abstract class BreezSdkCore { FlutterRustBridgeTaskConstMeta get kPaymentByHashConstMeta; + /// See [BreezServices::set_payment_metadata] + Future setPaymentMetadata({required String hash, required String metadata, dynamic hint}); + + FlutterRustBridgeTaskConstMeta get kSetPaymentMetadataConstMeta; + /// See [BreezServices::send_payment] Future sendPayment({required SendPaymentRequest req, dynamic hint}); @@ -2306,6 +2311,24 @@ class BreezSdkCoreImpl implements BreezSdkCore { argNames: ["hash"], ); + Future setPaymentMetadata({required String hash, required String metadata, dynamic hint}) { + var arg0 = _platform.api2wire_String(hash); + var arg1 = _platform.api2wire_String(metadata); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_set_payment_metadata(port_, arg0, arg1), + parseSuccessData: _wire2api_unit, + parseErrorData: _wire2api_FrbAnyhowException, + constMeta: kSetPaymentMetadataConstMeta, + argValues: [hash, metadata], + hint: hint, + )); + } + + FlutterRustBridgeTaskConstMeta get kSetPaymentMetadataConstMeta => const FlutterRustBridgeTaskConstMeta( + debugName: "set_payment_metadata", + argNames: ["hash", "metadata"], + ); + Future sendPayment({required SendPaymentRequest req, dynamic hint}) { var arg0 = _platform.api2wire_box_autoadd_send_payment_request(req); return _platform.executeNormal(FlutterRustBridgeTask( @@ -5004,6 +5027,25 @@ class BreezSdkCoreWire implements FlutterRustBridgeWireBase { late final _wire_payment_by_hash = _wire_payment_by_hashPtr.asFunction)>(); + void wire_set_payment_metadata( + int port_, + ffi.Pointer hash, + ffi.Pointer metadata, + ) { + return _wire_set_payment_metadata( + port_, + hash, + metadata, + ); + } + + late final _wire_set_payment_metadataPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64, ffi.Pointer, + ffi.Pointer)>>('wire_set_payment_metadata'); + late final _wire_set_payment_metadata = _wire_set_payment_metadataPtr + .asFunction, ffi.Pointer)>(); + void wire_send_payment( int port_, ffi.Pointer req,