Skip to content

Commit

Permalink
Merge pull request #39 from DanGould/to-from-json
Browse files Browse the repository at this point in the history
- Release payjoin-flutter 0.21.0
- Expose de/serialize functions for persistence
- Implement unimplemented Receiver.id() 
- Expose Sender.pjEndpoint() for use in persistence
  • Loading branch information
DanGould authored Dec 11, 2024
2 parents 68caf49 + 5a4c840 commit 0124ef6
Show file tree
Hide file tree
Showing 23 changed files with 958 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [0.21.0]
This release updates the bindings libraries to `payjoin` version `0.21.0`.

#### APIs changed
- Major overhaul to attempt a stable BIP 77 protocol implementation.
- v1 support is now only available through the V2 backwards-compatible APIs.
- see [payjoin-0.21.0 changelog](https://github.com/payjoin/rust-payjoin/blob/master/payjoin/CHANGELOG.md#0210) for more details.

## [0.20.0]
#### APIs added
- Make backwards-compatible `v2` to `v1` sends possible.
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.20.0"
version: "0.21.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
20 changes: 20 additions & 0 deletions ios/Classes/frb_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ typedef struct wire_cst_PayjoinError_InputPairError {
struct wire_cst_list_prim_u_8_strict *message;
} wire_cst_PayjoinError_InputPairError;

typedef struct wire_cst_PayjoinError_SerdeJsonError {
struct wire_cst_list_prim_u_8_strict *message;
} wire_cst_PayjoinError_SerdeJsonError;

typedef union PayjoinErrorKind {
struct wire_cst_PayjoinError_InvalidAddress InvalidAddress;
struct wire_cst_PayjoinError_InvalidScript InvalidScript;
Expand All @@ -261,6 +265,7 @@ typedef union PayjoinErrorKind {
struct wire_cst_PayjoinError_OutputSubstitutionError OutputSubstitutionError;
struct wire_cst_PayjoinError_InputContributionError InputContributionError;
struct wire_cst_PayjoinError_InputPairError InputPairError;
struct wire_cst_PayjoinError_SerdeJsonError SerdeJsonError;
} PayjoinErrorKind;

typedef struct wire_cst_payjoin_error {
Expand Down Expand Up @@ -352,6 +357,8 @@ void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_create(int64
void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_extract_req(int64_t port_,
struct wire_cst_ffi_receiver *that);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_from_json(struct wire_cst_list_prim_u_8_strict *json);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_id(struct wire_cst_ffi_receiver *that);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_pj_uri_builder(struct wire_cst_ffi_receiver *that);
Expand All @@ -364,6 +371,8 @@ void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_process_res(
struct wire_cst_list_prim_u_8_loose *body,
struct wire_cst_client_response *ctx);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_to_json(struct wire_cst_ffi_receiver *that);

void frbgen_payjoin_flutter_wire__crate__api__receive__ffi_unchecked_proposal_assume_interactive_receiver(int64_t port_,
struct wire_cst_ffi_unchecked_proposal *that);

Expand Down Expand Up @@ -431,6 +440,10 @@ void frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_extract_v2(int64_
struct wire_cst_ffi_sender *that,
struct wire_cst_ffi_url *ohttp_proxy_url);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_from_json(struct wire_cst_list_prim_u_8_strict *json);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_to_json(struct wire_cst_ffi_sender *that);

void frbgen_payjoin_flutter_wire__crate__api__send__ffi_v_1_context_process_response(int64_t port_,
struct wire_cst_ffi_v_1_context *that,
struct wire_cst_list_prim_u_8_loose *response);
Expand Down Expand Up @@ -471,6 +484,8 @@ WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_bu
WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_builder_pjos(struct wire_cst_ffi_pj_uri_builder *that,
bool pjos);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_pj_endpoint(struct wire_cst_ffi_pj_uri *that);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__uri__ffi_uri_address(struct wire_cst_ffi_uri *that);

WireSyncRust2DartDco frbgen_payjoin_flutter_wire__crate__api__uri__ffi_uri_amount_sats(struct wire_cst_ffi_uri *that);
Expand Down Expand Up @@ -732,10 +747,12 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_provisional_proposal_finalize_proposal);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_create);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_extract_req);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_from_json);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_id);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_pj_uri_builder);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_pj_url);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_process_res);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_receiver_to_json);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_unchecked_proposal_assume_interactive_receiver);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_unchecked_proposal_check_broadcast_suitability);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__receive__ffi_unchecked_proposal_extract_tx_to_schedule_broadcast);
Expand All @@ -753,6 +770,8 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_builder_from_psbt_and_uri);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_extract_v1);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_extract_v2);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_from_json);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_sender_to_json);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_v_1_context_process_response);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_v_2_get_context_extract_req);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__send__ffi_v_2_get_context_process_response);
Expand All @@ -766,6 +785,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_builder_label);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_builder_message);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_builder_pjos);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_pj_uri_pj_endpoint);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_uri_address);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_uri_amount_sats);
dummy_var ^= ((int64_t) (void*) frbgen_payjoin_flutter_wire__crate__api__uri__ffi_uri_as_string);
Expand Down
17 changes: 17 additions & 0 deletions lib/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class Receiver {
}
}

String id() {
return _ffiReceiver.id();
}

/// The contents of the `&pj=` query parameter including the base64url-encoded public key receiver subdirectory.
/// This identifies a session at the payjoin directory server.
Future<Url> pjUrl() async {
Expand All @@ -73,6 +77,19 @@ class Receiver {
final res = _ffiReceiver.pjUriBuilder();
return PjUriBuilder(internal: res.internal);
}

String toJson() {
return _ffiReceiver.toJson();
}

static Receiver fromJson(String json) {
try {
final res = FfiReceiver.fromJson(json: json);
return Receiver._(ffiReceiver: res);
} on error.PayjoinError catch (e) {
throw mapPayjoinError(e);
}
}
}

class UncheckedProposal {
Expand Down
11 changes: 11 additions & 0 deletions lib/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ class Sender extends FfiSender {
throw mapPayjoinError(e);
}
}

// toJson automatically exposed since class extends FfiSender

static Sender fromJson(String json) {
try {
final res = FfiSender.fromJson(json: json);
return Sender._(field0: res.field0);
} on error.PayjoinError catch (e) {
throw mapPayjoinError(e);
}
}
}

class V1Context extends FfiV1Context {
Expand Down
1 change: 1 addition & 0 deletions lib/src/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ PayjoinException mapPayjoinError(error.PayjoinError e) {
outputSubstitutionError: (e) => PayjoinException(message: e.message),
inputContributionError: (e) => PayjoinException(message: e.message),
inputPairError: (e) => PayjoinException(message: e.message),
serdeJsonError: (e) => PayjoinException(message: e.message),
);
}
7 changes: 7 additions & 0 deletions lib/src/generated/api/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class FfiReceiver {
that: this,
);

static FfiReceiver fromJson({required String json}) =>
core.instance.api.crateApiReceiveFfiReceiverFromJson(json: json);

///The per-session public key to use as an identifier
String id() => core.instance.api.crateApiReceiveFfiReceiverId(
that: this,
Expand All @@ -250,6 +253,10 @@ class FfiReceiver {
core.instance.api.crateApiReceiveFfiReceiverProcessRes(
that: this, body: body, ctx: ctx);

String toJson() => core.instance.api.crateApiReceiveFfiReceiverToJson(
that: this,
);

@override
int get hashCode => field0.hashCode;

Expand Down
7 changes: 7 additions & 0 deletions lib/src/generated/api/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class FfiSender {
core.instance.api.crateApiSendFfiSenderExtractV2(
that: this, ohttpProxyUrl: ohttpProxyUrl);

static FfiSender fromJson({required String json}) =>
core.instance.api.crateApiSendFfiSenderFromJson(json: json);

String toJson() => core.instance.api.crateApiSendFfiSenderToJson(
that: this,
);

@override
int get hashCode => field0.hashCode;

Expand Down
4 changes: 4 additions & 0 deletions lib/src/generated/api/uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class FfiPjUri {
that: this,
);

String pjEndpoint() => core.instance.api.crateApiUriFfiPjUriPjEndpoint(
that: this,
);

@override
int get hashCode => field0.hashCode;

Expand Down
Loading

0 comments on commit 0124ef6

Please sign in to comment.