Skip to content

Commit 1503fb2

Browse files
committed
feat(joinstr): repin bindings to the #40 merge and consume the coinjoin progress stream
1 parent e7e3ac5 commit 1503fb2

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

lib/features/joinstr/data/joinstr_datasource.dart

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class JoinstrDatasource {
7373
denominationSat: pool.denominationSat,
7474
proxy: proxy,
7575
);
76-
return jns.joinCoinjoin(poolRawJson: pool.rawJson, peer: peer);
76+
return _awaitBroadcast(
77+
jns.joinCoinjoin(poolRawJson: pool.rawJson, peer: peer),
78+
);
7779
});
7880
}
7981

@@ -99,19 +101,45 @@ class JoinstrDatasource {
99101
denominationSat: denominationSat,
100102
proxy: proxy,
101103
);
102-
return jns.initiateCoinjoin(
103-
config: jns.FfiPoolConfig(
104-
denominationBtc: Joinstr.denominationBtc(denominationSat),
105-
fee: feeRateSatPerVb,
106-
maxDuration: BigInt.from(maxDuration.inSeconds),
107-
peers: peers,
108-
network: _network(wallet.network),
104+
return _awaitBroadcast(
105+
jns.initiateCoinjoin(
106+
config: jns.FfiPoolConfig(
107+
denominationBtc: Joinstr.denominationBtc(denominationSat),
108+
fee: feeRateSatPerVb,
109+
maxDuration: BigInt.from(maxDuration.inSeconds),
110+
peers: peers,
111+
network: _network(wallet.network),
112+
),
113+
peer: peer,
109114
),
110-
peer: peer,
111115
);
112116
});
113117
}
114118

119+
/// Collapses the bindings' progress stream to the single result the rest of
120+
/// the app consumes: the txid once the coinjoin broadcasts. The intermediate
121+
/// steps are for a progress UI the domain layer does not model yet, so they
122+
/// are drained silently; the terminal `failed` step (and a stream that closes
123+
/// without any terminal step) surface as a [JoinstrException].
124+
Future<String> _awaitBroadcast(Stream<jns.FfiCoinjoinUpdate> updates) async {
125+
await for (final update in updates) {
126+
switch (update.step) {
127+
case jns.FfiCoinjoinStep.done:
128+
final txid = update.txid;
129+
if (txid != null) return txid;
130+
throw JoinstrException(JoinstrIssue.coinjoinFailed);
131+
case jns.FfiCoinjoinStep.failed:
132+
throw JoinstrException(
133+
JoinstrIssue.coinjoinFailed,
134+
detail: update.error,
135+
);
136+
default:
137+
continue;
138+
}
139+
}
140+
throw JoinstrException(JoinstrIssue.coinjoinFailed);
141+
}
142+
115143
Future<jns.FfiPeerConfig> _peerConfig({
116144
required Wallet wallet,
117145
required String mnemonic,

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ packages:
12321232
dependency: "direct main"
12331233
description:
12341234
path: dart
1235-
ref: d1bb9f8
1236-
resolved-ref: d1bb9f867aa40af7d4480e5d09e2196e5e9b0203
1235+
ref: "6e4e2e3"
1236+
resolved-ref: "6e4e2e387249678424add40c881c6aaba32dcd7d"
12371237
url: "https://github.com/rust-joinstr/joinstr"
12381238
source: git
12391239
version: "0.1.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies:
4343
joinstr_flutter:
4444
git:
4545
url: https://github.com/rust-joinstr/joinstr
46-
ref: d1bb9f8
46+
ref: 6e4e2e3
4747
path: dart
4848
qr_flutter: ^4.1.0
4949
dio: ^5.9.0

0 commit comments

Comments
 (0)