Skip to content

Commit

Permalink
make PjUrl from FfiActiveSession async and add initializeApp to Url's…
Browse files Browse the repository at this point in the history
… fromStr again
  • Loading branch information
kumulynja committed Jul 25, 2024
1 parent 878b90c commit e9fe95c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
3 changes: 2 additions & 1 deletion ios/Classes/frb_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_extrac

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_pj_uri_builder(struct wire_cst_ffi_active_session *that);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_pj_url(struct wire_cst_ffi_active_session *that);
void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_pj_url(int64_t port_,
struct wire_cst_ffi_active_session *that);

void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_process_res(int64_t port_,
struct wire_cst_ffi_active_session *that,
Expand Down
10 changes: 5 additions & 5 deletions lib/receive/v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SessionInitializer extends FfiSessionInitializer {
try {
final res = await super.extractReq();
final request = Request(
url: Url.fromStr(res.$1.url.asString()),
url: await Url.fromStr(res.$1.url.asString()),
body: res.$1.body,
);
return (request, res.$2);
Expand All @@ -66,7 +66,7 @@ class ActiveSession extends FfiActiveSession {
try {
final res = await super.extractReq();
final request = Request(
url: Url.fromStr(res.$1.url.asString()),
url: await Url.fromStr(res.$1.url.asString()),
body: res.$1.body,
);
return (request, res.$2);
Expand All @@ -93,8 +93,8 @@ class ActiveSession extends FfiActiveSession {
/// The contents of the `&pj=` query parameter including the base64url-encoded public key receiver subdirectory.
/// This identifies a session at the payjoin directory server.
@override
Url pjUrl() {
final res = super.pjUrl();
Future<Url> pjUrl() async {
final res = await super.pjUrl();
return Url.fromStr(res.asString());
}

Expand Down Expand Up @@ -310,7 +310,7 @@ class PayjoinProposal extends FfiV2PayjoinProposal {
try {
final res = await super.extractV2Req();
final request = Request(
url: Url.fromStr(res.$1.url.asString()),
url: await Url.fromStr(res.$1.url.asString()),
body: res.$1.body,
);
return (request, res.$2);
Expand Down
4 changes: 2 additions & 2 deletions lib/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RequestContext extends FfiRequestContext {
try {
final res = await super.extractV1();
final request = common.Request(
url: Url.fromStr((res.$1.url.asString())),
url: await Url.fromStr((res.$1.url.asString())),
body: res.$1.body,
);
return (request, ContextV1._(field0: res.$2.field0));
Expand All @@ -99,7 +99,7 @@ class RequestContext extends FfiRequestContext {
ohttpProxyUrl: ohttpProxyUrl,
);
final request = common.Request(
url: Url.fromStr((res.$1.url.asString())),
url: await Url.fromStr((res.$1.url.asString())),
body: res.$1.body,
);
return (request, ContextV2._(field0: res.$2.field0));
Expand Down
3 changes: 2 additions & 1 deletion lib/src/generated/api/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class FfiActiveSession {
that: this,
);

FfiUrl pjUrl() => core.instance.api.crateApiReceiveFfiActiveSessionPjUrl(
Future<FfiUrl> pjUrl() =>
core.instance.api.crateApiReceiveFfiActiveSessionPjUrl(
that: this,
);

Expand Down
12 changes: 7 additions & 5 deletions lib/src/generated/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ abstract class coreApi extends BaseApi {
FfiPjUriBuilder crateApiReceiveFfiActiveSessionPjUriBuilder(
{required FfiActiveSession that});

FfiUrl crateApiReceiveFfiActiveSessionPjUrl({required FfiActiveSession that});
Future<FfiUrl> crateApiReceiveFfiActiveSessionPjUrl(
{required FfiActiveSession that});

Future<FfiV2UncheckedProposal?> crateApiReceiveFfiActiveSessionProcessRes(
{required FfiActiveSession that,
Expand Down Expand Up @@ -650,12 +651,13 @@ class coreApiImpl extends coreApiImplPlatform implements coreApi {
);

@override
FfiUrl crateApiReceiveFfiActiveSessionPjUrl(
Future<FfiUrl> crateApiReceiveFfiActiveSessionPjUrl(
{required FfiActiveSession that}) {
return handler.executeSync(SyncTask(
callFfi: () {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
var arg0 = cst_encode_box_autoadd_ffi_active_session(that);
return wire.wire__crate__api__receive__ffi_active_session_pj_url(arg0);
return wire.wire__crate__api__receive__ffi_active_session_pj_url(
port_, arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_ffi_url,
Expand Down
11 changes: 6 additions & 5 deletions lib/src/generated/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2689,23 +2689,24 @@ class coreWire implements BaseWire {
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_ffi_active_session>)>();

WireSyncRust2DartDco wire__crate__api__receive__ffi_active_session_pj_url(
void wire__crate__api__receive__ffi_active_session_pj_url(
int port_,
ffi.Pointer<wire_cst_ffi_active_session> that,
) {
return _wire__crate__api__receive__ffi_active_session_pj_url(
port_,
that,
);
}

late final _wire__crate__api__receive__ffi_active_session_pj_urlPtr = _lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_ffi_active_session>)>>(
ffi.Void Function(
ffi.Int64, ffi.Pointer<wire_cst_ffi_active_session>)>>(
'frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_pj_url');
late final _wire__crate__api__receive__ffi_active_session_pj_url =
_wire__crate__api__receive__ffi_active_session_pj_urlPtr.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_ffi_active_session>)>();
void Function(int, ffi.Pointer<wire_cst_ffi_active_session>)>();

void wire__crate__api__receive__ffi_active_session_process_res(
int port_,
Expand Down
3 changes: 2 additions & 1 deletion lib/uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ class PjUri extends FfiPjUri {

class Url extends FfiUrl {
Url._({required super.field0});
static Url fromStr(String uri) {
static Future<Url> fromStr(String uri) async {
try {
await PConfig.initializeApp();
final res = FfiUrl.fromStr(url: uri);
return Url._(field0: res.field0);
} on error.PayjoinError catch (e) {
Expand Down
1 change: 0 additions & 1 deletion rust/src/api/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ impl FfiActiveSession {
self.0.public_key()
}

#[frb(sync)]
pub fn pj_url(&self) -> FfiUrl {
self.0.pj_url().into()
}
Expand Down
5 changes: 3 additions & 2 deletions rust/src/frb_generated.io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,9 +1341,10 @@ pub extern "C" fn frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_s

#[no_mangle]
pub extern "C" fn frbgen_payjoin_flutter_wire__crate__api__receive__ffi_active_session_pj_url(
port_: i64,
that: *mut wire_cst_ffi_active_session,
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
wire__crate__api__receive__ffi_active_session_pj_url_impl(that)
) {
wire__crate__api__receive__ffi_active_session_pj_url_impl(port_, that)
}

#[no_mangle]
Expand Down
22 changes: 13 additions & 9 deletions rust/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,25 @@ fn wire__crate__api__receive__ffi_active_session_pj_uri_builder_impl(
)
}
fn wire__crate__api__receive__ffi_active_session_pj_url_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
that: impl CstDecode<crate::api::receive::FfiActiveSession>,
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::<flutter_rust_bridge::for_generated::DcoCodec, _>(
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "ffi_active_session_pj_url",
port: None,
mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync,
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_that = that.cst_decode();
transform_result_dco::<_, _, ()>((move || {
let output_ok =
Result::<_, ()>::Ok(crate::api::receive::FfiActiveSession::pj_url(&api_that))?;
Ok(output_ok)
})())
move |context| {
transform_result_dco::<_, _, ()>((move || {
let output_ok = Result::<_, ()>::Ok(
crate::api::receive::FfiActiveSession::pj_url(&api_that),
)?;
Ok(output_ok)
})())
}
},
)
}
Expand Down

0 comments on commit e9fe95c

Please sign in to comment.