Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project structure #23

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rust_input: rust/src/api/**/*.rs
dart_output: lib/rust
dart_output: lib/generated/rust
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Stream<LogEntry> createLogStream(
RustLib.instance.api.crateApiSimpleCreateLogStream(
level: level, logDependencies: logDependencies);

Stream<SyncStatus> createSyncStream() =>
RustLib.instance.api.crateApiSimpleCreateSyncStream();

Stream<ScanProgress> createScanProgressStream() =>
RustLib.instance.api.crateApiSimpleCreateScanProgressStream();

Expand Down Expand Up @@ -51,7 +48,7 @@ String changeBirthday({required String encodedWallet, required int birthday}) =>
String resetWallet({required String encodedWallet}) => RustLib.instance.api
.crateApiSimpleResetWallet(encodedWallet: encodedWallet);

Future<void> syncBlockchain() =>
Future<int> syncBlockchain() =>
RustLib.instance.api.crateApiSimpleSyncBlockchain();

Future<String> scanToTip({required String encodedWallet}) =>
Expand Down
108 changes: 15 additions & 93 deletions lib/rust/frb_generated.dart → lib/generated/rust/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.0.0-dev.37';

@override
int get rustContentHash => -1193702642;
int get rustContentHash => -980625945;

static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
Expand Down Expand Up @@ -89,8 +89,6 @@ abstract class RustLibApi extends BaseApi {

Stream<ScanProgress> crateApiSimpleCreateScanProgressStream();

Stream<SyncStatus> crateApiSimpleCreateSyncStream();

String crateApiSimpleExtractTxFromPsbt({required String psbt});

String crateApiSimpleFillSpOutputs(
Expand Down Expand Up @@ -124,7 +122,7 @@ abstract class RustLibApi extends BaseApi {
required String psbt,
required bool finalize});

Future<void> crateApiSimpleSyncBlockchain();
Future<int> crateApiSimpleSyncBlockchain();
}

class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
Expand Down Expand Up @@ -321,39 +319,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["s"],
);

@override
Stream<SyncStatus> crateApiSimpleCreateSyncStream() {
final s = RustStreamSink<SyncStatus>();
handler.executeSync(SyncTask(
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_StreamSink_sync_status_Sse(s, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 8)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
decodeErrorData: null,
),
constMeta: kCrateApiSimpleCreateSyncStreamConstMeta,
argValues: [s],
apiImpl: this,
));
return s.stream;
}

TaskConstMeta get kCrateApiSimpleCreateSyncStreamConstMeta =>
const TaskConstMeta(
debugName: "create_sync_stream",
argNames: ["s"],
);

@override
String crateApiSimpleExtractTxFromPsbt({required String psbt}) {
return handler.executeSync(SyncTask(
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(psbt, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 9)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 8)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -379,7 +351,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(encodedWallet, serializer);
sse_encode_String(psbt, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 10)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 9)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -403,7 +375,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(encodedWallet, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 11)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 10)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_wallet_status,
Expand All @@ -427,7 +399,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 12, port: port_);
funcId: 11, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
Expand Down Expand Up @@ -455,7 +427,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(encodedWallet, serializer);
sse_encode_String(spentBy, serializer);
sse_encode_list_String(spent, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 13)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 12)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -479,7 +451,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(encodedWallet, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 14)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 13)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -503,7 +475,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(encodedWallet, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 15, port: port_);
funcId: 14, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand Down Expand Up @@ -538,7 +510,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_32(birthday, serializer);
sse_encode_String(network, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 16, port: port_);
funcId: 15, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand Down Expand Up @@ -568,7 +540,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(encodedWallet, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 17)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 16)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_opt_String,
Expand Down Expand Up @@ -596,7 +568,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(encodedWallet, serializer);
sse_encode_String(psbt, serializer);
sse_encode_bool(finalize, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 18)!;
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 17)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -614,15 +586,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);

@override
Future<void> crateApiSimpleSyncBlockchain() {
Future<int> crateApiSimpleSyncBlockchain() {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 19, port: port_);
funcId: 18, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
decodeSuccessData: sse_decode_u_32,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiSimpleSyncBlockchainConstMeta,
Expand Down Expand Up @@ -663,13 +635,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
throw UnimplementedError();
}

@protected
RustStreamSink<SyncStatus> dco_decode_StreamSink_sync_status_Sse(
dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
throw UnimplementedError();
}

@protected
RustStreamSink<BigInt> dco_decode_StreamSink_u_64_Sse(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
Expand Down Expand Up @@ -838,17 +803,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
}

@protected
SyncStatus dco_decode_sync_status(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 1)
throw Exception('unexpected arr length: expect 1 but see ${arr.length}');
return SyncStatus(
blockheight: dco_decode_u_32(arr[0]),
);
}

@protected
int dco_decode_u_32(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
Expand Down Expand Up @@ -917,13 +871,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
throw UnimplementedError('Unreachable ()');
}

@protected
RustStreamSink<SyncStatus> sse_decode_StreamSink_sync_status_Sse(
SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
throw UnimplementedError('Unreachable ()');
}

@protected
RustStreamSink<BigInt> sse_decode_StreamSink_u_64_Sse(
SseDeserializer deserializer) {
Expand Down Expand Up @@ -1105,13 +1052,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return ScanProgress(start: var_start, current: var_current, end: var_end);
}

@protected
SyncStatus sse_decode_sync_status(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_blockheight = sse_decode_u_32(deserializer);
return SyncStatus(blockheight: var_blockheight);
}

@protected
int sse_decode_u_32(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand Down Expand Up @@ -1190,18 +1130,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
serializer);
}

@protected
void sse_encode_StreamSink_sync_status_Sse(
RustStreamSink<SyncStatus> self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_String(
self.setupAndSerialize(
codec: SseCodec(
decodeSuccessData: sse_decode_sync_status,
decodeErrorData: null)),
serializer);
}

@protected
void sse_encode_StreamSink_u_64_Sse(
RustStreamSink<BigInt> self, SseSerializer serializer) {
Expand Down Expand Up @@ -1356,12 +1284,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_32(self.end, serializer);
}

@protected
void sse_encode_sync_status(SyncStatus self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_u_32(self.blockheight, serializer);
}

@protected
void sse_encode_u_32(int self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
RustStreamSink<ScanProgress> dco_decode_StreamSink_scan_progress_Sse(
dynamic raw);

@protected
RustStreamSink<SyncStatus> dco_decode_StreamSink_sync_status_Sse(dynamic raw);

@protected
RustStreamSink<BigInt> dco_decode_StreamSink_u_64_Sse(dynamic raw);

Expand Down Expand Up @@ -91,9 +88,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
ScanProgress dco_decode_scan_progress(dynamic raw);

@protected
SyncStatus dco_decode_sync_status(dynamic raw);

@protected
int dco_decode_u_32(dynamic raw);

Expand Down Expand Up @@ -124,10 +118,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
RustStreamSink<ScanProgress> sse_decode_StreamSink_scan_progress_Sse(
SseDeserializer deserializer);

@protected
RustStreamSink<SyncStatus> sse_decode_StreamSink_sync_status_Sse(
SseDeserializer deserializer);

@protected
RustStreamSink<BigInt> sse_decode_StreamSink_u_64_Sse(
SseDeserializer deserializer);
Expand Down Expand Up @@ -186,9 +176,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
ScanProgress sse_decode_scan_progress(SseDeserializer deserializer);

@protected
SyncStatus sse_decode_sync_status(SseDeserializer deserializer);

@protected
int sse_decode_u_32(SseDeserializer deserializer);

Expand Down Expand Up @@ -220,10 +207,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
void sse_encode_StreamSink_scan_progress_Sse(
RustStreamSink<ScanProgress> self, SseSerializer serializer);

@protected
void sse_encode_StreamSink_sync_status_Sse(
RustStreamSink<SyncStatus> self, SseSerializer serializer);

@protected
void sse_encode_StreamSink_u_64_Sse(
RustStreamSink<BigInt> self, SseSerializer serializer);
Expand Down Expand Up @@ -284,9 +267,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_scan_progress(ScanProgress self, SseSerializer serializer);

@protected
void sse_encode_sync_status(SyncStatus self, SseSerializer serializer);

@protected
void sse_encode_u_32(int self, SseSerializer serializer);

Expand Down
Loading