Skip to content

Commit

Permalink
feat: cardano multiplatform lib plugin structure (#441)
Browse files Browse the repository at this point in the history
* chore: melos bootstrap

* feat: add federated package structure for cardano_multiplatform_lib

* style: improve changelog style to fix analyzer issues

* docs: document better instance initialization with assertions

* chore: add cardano multiplatform lib related words to cspell dictionary

* chore: run melos bootstrap before running tests to make sure melos overrides paths to local packages

* fix: remove empty tests which cause code coverage failure

* refactor: rename cardano_multiplatform_lib to catalyst_cardano
  • Loading branch information
dtscalac authored Apr 19, 2024
1 parent 3676b95 commit 1099447
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,5 @@ xctest
xctestrun
xcworkspace
yoroi
multiplatform
Multiplatform
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ coverage/

# Melos
*pubspec_overrides.yaml
melos*.iml

# Secrets
dev-catalyst-voice-9f78f27c6bc5.json
Expand Down
1 change: 1 addition & 0 deletions catalyst_voices/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ test-unit:
FROM +deps
COPY ../+repo-catalyst-voices-all/repo repo/
WORKDIR repo
RUN melos bootstrap
RUN melos run test-report
WAIT
SAVE ARTIFACT test_reports AS LOCAL test_reports
Expand Down
29 changes: 0 additions & 29 deletions catalyst_voices/melos_catalyst_voices.iml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0

* Initial release.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# catalyst_cardano
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:catalyst_analysis/analysis_options.1.0.0.yaml

analyzer:
exclude: [build/**, lib/*.g.dart, lib/generated/**]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/catalyst_cardano.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:catalyst_cardano_platform_interface/catalyst_cardano_platform_interface.dart';

/// Prints hello message, function to be removed later by providing actual
/// implementations of methods related to cardano multiplatform lib.
Future<void> printCatalystCardanoHello() async {
// ignore: avoid_print, will be replaced later by actual implementation
await CatalystCardanoPlatform.instance.printHello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: catalyst_cardano
description: Flutter plugin wrapping the Cardano Multiplatform Lib Rust library.
repository: https://github.com/input-output-hk/catalyst-voices/tree/main/catalyst_voices_packages/catalyst_cardano/catalyst_cardano
issue_tracker: https://github.com/input-output-hk/catalyst-voices/issues
topics: [blockchain, cardano, cryptocurrency, wallet]
version: 1.0.0

environment:
sdk: ">=3.3.0 <4.0.0"
flutter: 3.19.5

flutter:
plugin:
platforms:
web:
default_package: catalyst_cardano_web

dependencies:
catalyst_cardano_platform_interface: ^1.0.0
catalyst_cardano_web: ^1.0.0
flutter:
sdk: flutter

dev_dependencies:
catalyst_analysis:
path: ../../catalyst_analysis
flutter_test:
sdk: flutter
plugin_platform_interface: ^2.1.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0

* Initial release.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# catalyst_cardano_platform_interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:catalyst_analysis/analysis_options.1.0.0.yaml

analyzer:
exclude: [build/**, lib/*.g.dart, lib/generated/**]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/catalyst_cardano_platform.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:async';

import 'package:plugin_platform_interface/plugin_platform_interface.dart';

/// The interface that implementations of catalyst_cardano must
/// implement.
///
/// Platform implementations should extend this class rather than implement
/// it as `catalyst_cardano` does not consider newly added methods to
/// be breaking changes. Extending this class (using `extends`) ensures that the
/// subclass will get the default implementation, while platform implementations
/// that `implements` this interface will be broken by newly added
/// [CatalystCardanoPlatform] methods.
abstract class CatalystCardanoPlatform extends PlatformInterface {
static final Object _token = Object();

static CatalystCardanoPlatform? _instance;

/// The default instance of [CatalystCardanoPlatform] to use.
///
/// Must be set with [instance] setter before it can be used.
static CatalystCardanoPlatform get instance {
assert(
_instance != null,
'Make sure to register the instance via '
'instance setter before it is used.',
);
return _instance!;
}

/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [CatalystCardanoPlatform] when they register
/// themselves.
static set instance(CatalystCardanoPlatform instance) {
PlatformInterface.verify(instance, _token);
_instance = instance;
}

/// Constructs a CatalystCardanoPlatform.
CatalystCardanoPlatform() : super(token: _token);

/// Temporary method which will be replaced by actual implementation of
/// cardano multiplatform lib.
Future<void> printHello() {
throw UnimplementedError('printHello() has not been implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: catalyst_cardano_platform_interface
description: A common platform interface for the catalyst_cardano plugin.
repository: https://github.com/input-output-hk/catalyst-voices/tree/main/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_platform_interface
issue_tracker: https://github.com/input-output-hk/catalyst-voices/issues
topics: [blockchain, cardano, cryptocurrency, wallet]
version: 1.0.0

environment:
sdk: ">=3.3.0 <4.0.0"
flutter: 3.19.5

dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.7

dev_dependencies:
catalyst_analysis:
path: ../../catalyst_analysis
flutter_test:
sdk: flutter
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0

* Initial release.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# catalyst_cardano_web
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:catalyst_analysis/analysis_options.1.0.0.yaml

analyzer:
exclude: [build/**, lib/*.g.dart, lib/generated/**]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:async';

import 'package:catalyst_cardano_platform_interface/catalyst_cardano_platform_interface.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart' show Registrar;

/// The web implementation of [CatalystCardanoPlatform].
///
/// This class implements the `package:catalyst_cardano` functionality
/// for the web.
class CatalystCardanoPlugin extends CatalystCardanoPlatform {
/// A constructor that allows tests to override the window object used by the
/// plugin.
CatalystCardanoPlugin();

@override
Future<void> printHello() async {
// ignore: avoid_print
print('hello world from cardano multiplatform');
}

/// Registers this class as the default instance of
/// [CatalystCardanoPlatform].
static void registerWith(Registrar registrar) {
CatalystCardanoPlatform.instance = CatalystCardanoPlugin();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: catalyst_cardano_web
description: Web platform implementation of catalyst_cardano
repository: https://github.com/input-output-hk/catalyst-voices/tree/main/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web
issue_tracker: https://github.com/input-output-hk/catalyst-voices/issues
topics: [blockchain, cardano, cryptocurrency, wallet]
version: 1.0.0

environment:
sdk: ^3.3.0
flutter: 3.19.5

flutter:
plugin:
implements: catalyst_cardano
platforms:
web:
pluginClass: CatalystCardanoPlugin
fileName: catalyst_cardano_web.dart

dependencies:
catalyst_cardano_platform_interface: ^1.0.0
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
web: ^0.5.0

dev_dependencies:
catalyst_analysis:
path: ../../catalyst_analysis
flutter_test:
sdk: flutter
1 change: 1 addition & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ command:
formz: ^0.7.0
meta: ^1.10.0
result_type: ^0.2.0
plugin_platform_interface: ^2.1.7
dev_dependencies:
test: ^1.24.9
build_runner: ^2.3.3
Expand Down
12 changes: 0 additions & 12 deletions melos_catalyst_voices.iml

This file was deleted.

0 comments on commit 1099447

Please sign in to comment.