Skip to content

Commit

Permalink
adding dart bindings for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse authored Jan 25, 2024
1 parent c335126 commit 19e614d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ pub fn payment_by_hash(hash: String) -> Result<Option<Payment>> {
.map_err(anyhow::Error::new::<SdkError>)
}

/// 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::<SdkError>)
}

/* Lightning Payment API's */

/// See [BreezServices::send_payment]
Expand Down
9 changes: 9 additions & 0 deletions libs/sdk-core/src/bridge_generated.io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions libs/sdk-core/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,24 @@ fn wire_payment_by_hash_impl(port_: MessagePort, hash: impl Wire2Api<String> + U
},
)
}
fn wire_set_payment_metadata_impl(
port_: MessagePort,
hash: impl Wire2Api<String> + UnwindSafe,
metadata: impl Wire2Api<String> + 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<SendPaymentRequest> + UnwindSafe) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, SendPaymentResponse, _>(
WrapInfo {
Expand Down
5 changes: 5 additions & 0 deletions libs/sdk-flutter/ios/Classes/bridge_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions libs/sdk-flutter/lib/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ abstract class BreezSdkCore {

FlutterRustBridgeTaskConstMeta get kPaymentByHashConstMeta;

/// See [BreezServices::set_payment_metadata]
Future<void> setPaymentMetadata({required String hash, required String metadata, dynamic hint});

FlutterRustBridgeTaskConstMeta get kSetPaymentMetadataConstMeta;

/// See [BreezServices::send_payment]
Future<SendPaymentResponse> sendPayment({required SendPaymentRequest req, dynamic hint});

Expand Down Expand Up @@ -2306,6 +2311,24 @@ class BreezSdkCoreImpl implements BreezSdkCore {
argNames: ["hash"],
);

Future<void> 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<SendPaymentResponse> sendPayment({required SendPaymentRequest req, dynamic hint}) {
var arg0 = _platform.api2wire_box_autoadd_send_payment_request(req);
return _platform.executeNormal(FlutterRustBridgeTask(
Expand Down Expand Up @@ -5004,6 +5027,25 @@ class BreezSdkCoreWire implements FlutterRustBridgeWireBase {
late final _wire_payment_by_hash =
_wire_payment_by_hashPtr.asFunction<void Function(int, ffi.Pointer<wire_uint_8_list>)>();

void wire_set_payment_metadata(
int port_,
ffi.Pointer<wire_uint_8_list> hash,
ffi.Pointer<wire_uint_8_list> 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<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>)>>('wire_set_payment_metadata');
late final _wire_set_payment_metadata = _wire_set_payment_metadataPtr
.asFunction<void Function(int, ffi.Pointer<wire_uint_8_list>, ffi.Pointer<wire_uint_8_list>)>();

void wire_send_payment(
int port_,
ffi.Pointer<wire_SendPaymentRequest> req,
Expand Down

0 comments on commit 19e614d

Please sign in to comment.