-
Notifications
You must be signed in to change notification settings - Fork 96
feat: add cardano #970
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
Closed
Closed
feat: add cardano #970
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
27d319c
feat: add cardano
detherminal 5b324a0
fix: remove special lib usage
detherminal 49ad183
fix: add new packages used in cardano
detherminal 2af6e32
Merge branch 'staging' into staging
sneurlax 56dcc0b
Merge branch 'cypherstack:staging' into staging
detherminal e3d040b
refactor: enhance ada txs
detherminal 02dc5c9
refactor: show only lovelaces
detherminal 1ec7ee9
feat: total tor support for cardano
detherminal e0051c8
Merge branch 'staging' into staging
detherminal 6cbc37f
fix: post req body
detherminal d22c89e
Merge branch 'staging' into staging
sneurlax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
| import 'package:cbor/simple.dart'; | ||
| import 'package:on_chain/ada/src/provider/blockfrost/core/core.dart'; | ||
| import 'package:on_chain/ada/src/provider/service/service.dart'; | ||
|
|
||
| import '../../../utilities/logger.dart'; | ||
|
|
||
| class BlockfrostHttpProvider implements BlockfrostServiceProvider { | ||
| BlockfrostHttpProvider({ | ||
| required this.url, | ||
| this.version = "v0", | ||
| this.projectId, | ||
| HttpClient? client, | ||
| this.defaultRequestTimeout = const Duration(seconds: 30), | ||
| }) : client = client ?? HttpClient(); | ||
| @override | ||
| final String url; | ||
| final String version; | ||
| final String? projectId; | ||
| final HttpClient client; | ||
| final Duration defaultRequestTimeout; | ||
|
|
||
| @override | ||
| Future<dynamic> get(BlockforestRequestDetails params, | ||
| [Duration? timeout,]) async { | ||
| final response = await client.getUrl(Uri.parse(params.url(url, "api/$version"))).timeout(timeout ?? defaultRequestTimeout); | ||
| response.headers.add("Content-Type", "application/json"); | ||
| response.headers.add("Accept", "application/json"); | ||
| if (projectId != null) { | ||
| response.headers.add("project_id", projectId!); | ||
| } | ||
| final responseStream = await response.close(); | ||
| final data = json.decode(await responseStream.transform(utf8.decoder).join()); | ||
| return data; | ||
| } | ||
|
|
||
| @override | ||
| Future<dynamic> post(BlockforestRequestDetails params, | ||
| [Duration? timeout,]) async { | ||
| final request = await client.postUrl(Uri.parse(params.url(url, "api/$version"))).timeout(timeout ?? defaultRequestTimeout); | ||
| // Need to change this for other operations than submitting transactions | ||
| request.headers.add("Content-Type", "application/cbor"); | ||
| request.headers.add("Accept", "application/json"); | ||
| if (projectId != null) { | ||
| request.headers.add("project_id", projectId!); | ||
| } | ||
| request.add(params.body as List<int>); | ||
| final response = await request.close(); | ||
| final data = json.decode(await response.transform(utf8.decoder).join()); | ||
| return data; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import '../../../models/isar/models/blockchain_data/address.dart'; | ||
| import '../../../models/node_model.dart'; | ||
| import '../../../utilities/default_nodes.dart'; | ||
| import '../../../utilities/enums/derive_path_type_enum.dart'; | ||
| import '../crypto_currency.dart'; | ||
| import '../intermediate/bip39_currency.dart'; | ||
|
|
||
| class Cardano extends Bip39Currency { | ||
| Cardano(super.network) { | ||
| _idMain = "cardano"; | ||
| _uriScheme = "cardano"; | ||
| switch (network) { | ||
| case CryptoCurrencyNetwork.main: | ||
| _id = _idMain; | ||
| _name = "Cardano"; | ||
| _ticker = "ADA"; | ||
| default: | ||
| throw Exception("Unsupported network: $network"); | ||
| } | ||
| } | ||
|
|
||
| late final String _id; | ||
|
|
||
| @override | ||
| String get identifier => _id; | ||
|
|
||
| late final String _idMain; | ||
|
|
||
| @override | ||
| String get mainNetId => _idMain; | ||
|
|
||
| late final String _name; | ||
|
|
||
| @override | ||
| String get prettyName => _name; | ||
|
|
||
| late final String _uriScheme; | ||
|
|
||
| @override | ||
| String get uriScheme => _uriScheme; | ||
|
|
||
| late final String _ticker; | ||
|
|
||
| @override | ||
| String get ticker => _ticker; | ||
|
|
||
| @override | ||
| AddressType get defaultAddressType => AddressType.cardanoShelley; | ||
|
|
||
| @override | ||
| Uri defaultBlockExplorer(String txid) { | ||
| switch (network) { | ||
| case CryptoCurrencyNetwork.main: | ||
| return Uri.parse( | ||
| "https://explorer.cardano.org/en/transaction?id=$txid"); | ||
| default: | ||
| throw Exception( | ||
| "Unsupported network for defaultBlockExplorer(): $network", | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| DerivePathType get defaultDerivePathType => DerivePathType.cardanoShelley; | ||
|
|
||
| @override | ||
| NodeModel get defaultNode { | ||
| switch (network) { | ||
| case CryptoCurrencyNetwork.main: | ||
| return NodeModel( | ||
| host: "https://cardano.stackwallet.com", | ||
| port: 443, | ||
| name: DefaultNodes.defaultName, | ||
| id: DefaultNodes.buildId(this), | ||
| useSSL: true, | ||
| enabled: true, | ||
| coinName: identifier, | ||
| isFailover: true, | ||
| isDown: false, | ||
| ); | ||
|
|
||
| default: | ||
| throw Exception("Unsupported network: $network"); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| int get defaultSeedPhraseLength => 15; | ||
|
|
||
| @override | ||
| int get fractionDigits => 6; | ||
|
|
||
| @override | ||
| String get genesisHash => "f0f7892b5c333cffc4b3c4344de48af4cc63f55e44936196f365a9ef2244134f"; | ||
|
|
||
| @override | ||
| bool get hasBuySupport => false; | ||
|
|
||
| @override | ||
| bool get hasMnemonicPassphraseSupport => false; | ||
|
|
||
| @override | ||
| int get minConfirms => 2; | ||
|
|
||
| @override | ||
| List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength]; | ||
|
|
||
| @override | ||
| BigInt get satsPerCoin => BigInt.from(1000000); | ||
|
|
||
| @override | ||
| int get targetBlockTimeSeconds => 20; | ||
|
|
||
| @override | ||
| bool get torSupport => true; | ||
|
|
||
| @override | ||
| bool validateAddress(String address) { | ||
| switch (network) { | ||
| case CryptoCurrencyNetwork.main: | ||
| return RegExp(r"^addr1[0-9a-zA-Z]{98}$").hasMatch(address); | ||
| default: | ||
| throw Exception("Unsupported network: $network"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.