Skip to content
Merged
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
3 changes: 3 additions & 0 deletions flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rust_input: crate::api
rust_root: rust/
dart_output: lib/src/rust
13 changes: 13 additions & 0 deletions integration_test/simple_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:resonance_network_wallet/main.dart';
import 'package:resonance_network_wallet/src/rust/frb_generated.dart';
import 'package:integration_test/integration_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async => await RustLib.init());
testWidgets('Can call rust function', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.textContaining('Result: `Hello, Tom!`'), findsOneWidget);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
39 changes: 39 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import 'package:intl/intl.dart';
import 'substrate_service.dart';
import 'account_profile.dart';

import 'package:flutter/material.dart';
import 'package:resonance_network_wallet/src/rust/api/crypto.dart';
import 'package:resonance_network_wallet/src/rust/frb_generated.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SubstrateService().initialize();
await RustLib.init();
runApp(ResonanceWalletApp());
}

Expand Down Expand Up @@ -1491,3 +1496,37 @@ class Transaction {
required this.status,
});
}

// test app for rust bindings below

// import 'package:flutter/material.dart';
// import 'package:resonance_network_wallet/src/rust/api/crypto.dart';
// import 'package:resonance_network_wallet/src/rust/frb_generated.dart';

// Future<void> main() async {
// await RustLib.init();
// runApp(const MyApp());
// }

// class MyApp extends StatelessWidget {
// const MyApp({super.key});

// @override
// Widget build(BuildContext context) {
// final keypair = crystalAlice();
// final accountId = toAccountId(obj: keypair);

// print("alice: ${keypair.publicKey}");
// print("bob: ${crystalBob().publicKey}");
// print("charlie: ${crystalCharlie().publicKey}");

// return MaterialApp(
// home: Scaffold(
// appBar: AppBar(title: const Text('flutter_rust_bridge quickstart')),
// body: Center(
// child: Text('Action: Call Rust gen key\nResult: $accountId'),
// ),
// ),
// );
// }
// }
45 changes: 45 additions & 0 deletions lib/src/rust/api/crypto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.9.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These functions are ignored because they are not marked as `pub`: `to_account_id`

String toAccountId({required Keypair obj}) =>
RustLib.instance.api.crateApiCryptoToAccountId(obj: obj);

Keypair generateKeypair({required String mnemonicStr}) => RustLib.instance.api
.crateApiCryptoGenerateKeypair(mnemonicStr: mnemonicStr);

Keypair generateKeypairFromSeed({required List<int> seed}) =>
RustLib.instance.api.crateApiCryptoGenerateKeypairFromSeed(seed: seed);

Keypair crystalAlice() => RustLib.instance.api.crateApiCryptoCrystalAlice();

Keypair crystalBob() => RustLib.instance.api.crateApiCryptoCrystalBob();

Keypair crystalCharlie() => RustLib.instance.api.crateApiCryptoCrystalCharlie();

class Keypair {
final Uint8List publicKey;
final Uint8List secretKey;

const Keypair({
required this.publicKey,
required this.secretKey,
});

@override
int get hashCode => publicKey.hashCode ^ secretKey.hashCode;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Keypair &&
runtimeType == other.runtimeType &&
publicKey == other.publicKey &&
secretKey == other.secretKey;
}
10 changes: 10 additions & 0 deletions lib/src/rust/api/simple.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.9.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

String greet({required String name}) =>
RustLib.instance.api.crateApiSimpleGreet(name: name);
Loading