├── .gitattributes ├── .github └── workflows │ └── dart.yml ├── .gitignore ├── .metadata ├── .vscode └── launch.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ ├── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ │ └── LaunchImage.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ └── README.md │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h │ └── RunnerTests │ │ └── RunnerTests.swift ├── lib │ ├── bitcoin_cash │ │ ├── burn_token_example.dart │ │ ├── create_cash_token_example.dart │ │ ├── create_nft_example.dart │ │ ├── make_vout0_example.dart │ │ ├── minting_nft_example.dart │ │ ├── old_examples │ │ │ └── old_example.dart │ │ ├── p2sh32_spend_example.dart │ │ ├── send_ft_token_example.dart │ │ └── transfer_bch_example.dart │ ├── global │ │ ├── bch_example.dart │ │ ├── btc_examples_multisig_taproot_legacy_uncomp.dart │ │ ├── old_examples │ │ │ ├── bitcoin_example.dart │ │ │ ├── dash_example │ │ │ │ └── dash.dart │ │ │ ├── doge_example │ │ │ │ └── doge_example.dart │ │ │ ├── litecoin_example │ │ │ │ └── litecoin_example.dart │ │ │ ├── spending_with_scripts │ │ │ │ ├── spending_builders.dart │ │ │ │ └── spending_single_type.dart │ │ │ └── spending_with_transaction_builder │ │ │ │ ├── multi_sig_transactions.dart │ │ │ │ └── transaction_builder_example.dart │ │ ├── transfer_from_7_account_to_6_accout_example.dart │ │ └── transfer_to_8_account_example.dart │ ├── main.dart │ ├── musig │ │ ├── methods.dart │ │ └── musig_example.dart │ ├── psbt │ │ ├── psbt_example.dart │ │ └── psbt_musig2_example.dart │ └── services_examples │ │ ├── cross_platform_websocket │ │ ├── core.dart │ │ ├── cross.dart │ │ ├── io.dart │ │ └── web.dart │ │ ├── electrum │ │ ├── electrum_ssl_service.dart │ │ ├── electrum_tcp_service.dart │ │ ├── electrum_websocket_service.dart │ │ └── request_completer.dart │ │ └── explorer_service │ │ └── explorer_service.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── app_icon_1024.png │ │ │ │ ├── app_icon_128.png │ │ │ │ ├── app_icon_16.png │ │ │ │ ├── app_icon_256.png │ │ │ │ ├── app_icon_32.png │ │ │ │ ├── app_icon_512.png │ │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ │ └── MainMenu.xib │ │ ├── Configs │ │ │ ├── AppInfo.xcconfig │ │ │ ├── Debug.xcconfig │ │ │ ├── Release.xcconfig │ │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements │ └── RunnerTests │ │ └── RunnerTests.swift ├── pubspec.lock ├── pubspec.yaml ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── bitcoin_base.dart └── src │ ├── bitcoin │ ├── address │ │ ├── address.dart │ │ ├── core.dart │ │ ├── legacy_address.dart │ │ ├── network_address.dart │ │ ├── segwit_address.dart │ │ └── utils │ │ │ └── address_utils.dart │ ├── bitcoin.dart │ ├── script │ │ ├── input.dart │ │ ├── op_code │ │ │ └── constant.dart │ │ ├── output.dart │ │ ├── script.dart │ │ ├── scripts.dart │ │ ├── sequence.dart │ │ ├── transaction.dart │ │ ├── utils.dart │ │ └── witness.dart │ └── taproot │ │ ├── constants │ │ └── constants.dart │ │ ├── taproot.dart │ │ ├── types │ │ └── types.dart │ │ └── utils │ │ └── utils.dart │ ├── bitcoin_cash │ ├── bcmr.dart │ ├── bcmr_registery.dart │ └── bitcoin_cash.dart │ ├── cash_token │ └── cash_token.dart │ ├── crypto │ ├── crypto.dart │ ├── keypair │ │ ├── ec_private.dart │ │ └── ec_public.dart │ └── musig │ │ └── signer.dart │ ├── exception │ └── exception.dart │ ├── models │ └── network.dart │ ├── provider │ ├── api_provider.dart │ ├── constant │ │ └── constant.dart │ ├── core │ │ ├── methods.dart │ │ └── params.dart │ ├── electrum_methods │ │ ├── methods.dart │ │ └── methods │ │ │ ├── add_peer.dart │ │ │ ├── block_headers.dart │ │ │ ├── broad_cast.dart │ │ │ ├── donate_address.dart │ │ │ ├── electrum_version.dart │ │ │ ├── estimate_fee.dart │ │ │ ├── get_balance.dart │ │ │ ├── get_fee_histogram.dart │ │ │ ├── get_history.dart │ │ │ ├── get_mempool.dart │ │ │ ├── get_merkle.dart │ │ │ ├── get_raw_transaction.dart │ │ │ ├── get_transaction.dart │ │ │ ├── get_unspet.dart │ │ │ ├── get_value_proof.dart │ │ │ ├── get_verbose_transaction.dart │ │ │ ├── header.dart │ │ │ ├── headers_subscribe.dart │ │ │ ├── id_from_pos.dart │ │ │ ├── masternode_announce_broadcast.dart │ │ │ ├── masternode_list.dart │ │ │ ├── masternode_subscribe.dart │ │ │ ├── ping.dart │ │ │ ├── protx_diff.dart │ │ │ ├── protx_info.dart │ │ │ ├── relay_fee.dart │ │ │ ├── script_hash_subscribe.dart │ │ │ ├── scripthash_unsubscribe.dart │ │ │ ├── server_banner.dart │ │ │ ├── server_features.dart │ │ │ └── server_peer_subscribe.dart │ ├── models │ │ ├── block_cypher │ │ │ └── block_cypher_models.dart │ │ ├── config.dart │ │ ├── electrum │ │ │ └── models.dart │ │ ├── fee_rate │ │ │ └── fee_rate.dart │ │ ├── mempool │ │ │ └── mempol_models.dart │ │ ├── models.dart │ │ ├── multisig_script.dart │ │ └── utxo_details.dart │ ├── providers │ │ ├── electrum.dart │ │ └── explorer.dart │ └── services │ │ ├── electrum.dart │ │ └── explorer.dart │ ├── psbt │ ├── psbt.dart │ ├── psbt_builder │ │ ├── builder.dart │ │ ├── core │ │ │ └── psbt_builder.dart │ │ ├── impl │ │ │ ├── input.dart │ │ │ ├── output.dart │ │ │ └── signer.dart │ │ ├── types │ │ │ ├── internal_types.dart │ │ │ └── types.dart │ │ └── versiones │ │ │ ├── v1.dart │ │ │ └── v2.dart │ ├── reader │ │ └── byte_reader.dart │ ├── signer │ │ └── signer.dart │ ├── types │ │ ├── types.dart │ │ └── types │ │ │ ├── global.dart │ │ │ ├── inputs.dart │ │ │ ├── outputs.dart │ │ │ ├── psbt.dart │ │ │ └── types.dart │ └── utils │ │ └── utils.dart │ ├── transaction_builder │ ├── builder.dart │ ├── core.dart │ ├── forked_transaction_builder.dart │ └── transaction_builder.dart │ └── utils │ ├── btc_utils.dart │ ├── enumerate.dart │ └── utils.dart ├── pubspec.yaml └── test ├── bcmr ├── art_collection.dart ├── bcmr_test.dart ├── decentralized_application.dart ├── fungible_token.dart └── payouts_or_dividends.dart ├── bitcoin_cash_address_test.dart ├── bitcoin_cash_token_encoding_test.dart ├── deserialize_test.dart ├── encode_decode_transaction_test.dart ├── keys_test.dart ├── p2kh_tr_test.dart ├── p2sh_test.dart ├── p2tr_test.dart ├── p2wpkh_test.dart ├── p2wsh_test.dart └── psbt ├── bip_0174_test.dart ├── bip_0370_test.dart ├── bip_0371_test.dart ├── bip_0373_test.dart └── builder ├── psbt_builder_sighash_none_test.dart ├── psbt_builder_sighash_single_test.dart ├── psbt_builder_update_input_test.dart ├── psbt_builder_v0_test.dart ├── psbt_update_output_test.dart ├── utxos_vector.dart └── utxos_vector2.dart /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/dart.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Dart 7 | 8 | on: 9 | push: 10 | branches: [ "main" ] 11 | pull_request: 12 | branches: [ "main" ] 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v3 20 | 21 | # Note: This workflow uses the latest stable version of the Dart SDK. 22 | # You can specify other versions if desired, see documentation here: 23 | # https://github.com/dart-lang/setup-dart/blob/main/README.md 24 | # - uses: dart-lang/setup-dart@v1 25 | - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603 26 | 27 | # - name: Install dependencies 28 | # run: dart pub get --no-example 29 | 30 | # Uncomment this step to verify the use of 'dart format' on each commit. 31 | # - name: Verify formatting 32 | # run: dart format --output=none --set-exit-if-changed . 33 | 34 | # Consider passing '--fatal-infos' for slightly stricter analysis. 35 | # - name: Analyze project source 36 | # run: dart analyze 37 | 38 | # Your project will need to have tests in test/ and a dependency on 39 | # package:test for this step to succeed. Note that Flutter projects will 40 | # want to change this to 'flutter test'. 41 | - name: Run tests 42 | run: dart test ./test 43 | 44 | - name: Run tests web 45 | run: dart test -p chrome ./test --timeout=20m 46 | 47 | - name: Run tests web wasm 48 | run: dart test -p chrome ./test -c dart2wasm --timeout=20m 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | .packages 30 | build/ 31 | *.zip 32 | /example/test 33 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "bitcoin_base", 9 | "request": "launch", 10 | "type": "dart" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright 2023 MRTNETWORK 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at https://dart.dev/lints. 17 | # 18 | # Instead of disabling a lint rule for the entire project in the 19 | # section below, it can also be suppressed for a single line of code 20 | # or a specific dart file by using the `// ignore: name_of_lint` and 21 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 22 | # producing the lint. 23 | rules: 24 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 25 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 26 | 27 | # Additional information about this file can be found at 28 | # https://dart.dev/guides/language/analysis-options 29 | 30 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Symbolication related 35 | app.*.symbols 36 | 37 | # Obfuscation related 38 | app.*.map.json 39 | 40 | # Android Studio will place build artifacts here 41 | /android/app/debug 42 | /android/app/profile 43 | /android/app/release 44 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9" 8 | channel: "stable" 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 17 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 18 | - platform: android 19 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 20 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 21 | - platform: ios 22 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 23 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 24 | - platform: linux 25 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 26 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 27 | - platform: macos 28 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 29 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 30 | - platform: web 31 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 32 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 33 | - platform: windows 34 | create_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 35 | base_revision: 78666c8dc57e9f7548ca9f8dd0740fbf0c658dc9 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at https://dart.dev/lints. 17 | # 18 | # Instead of disabling a lint rule for the entire project in the 19 | # section below, it can also be suppressed for a single line of code 20 | # or a specific dart file by using the `// ignore: name_of_lint` and 21 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 22 | # producing the lint. 23 | rules: 24 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 25 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 26 | 27 | # Additional information about this file can be found at 28 | # https://dart.dev/guides/language/analysis-options 29 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id "kotlin-android" 4 | id "dev.flutter.flutter-gradle-plugin" 5 | } 6 | 7 | def localProperties = new Properties() 8 | def localPropertiesFile = rootProject.file('local.properties') 9 | if (localPropertiesFile.exists()) { 10 | localPropertiesFile.withReader('UTF-8') { reader -> 11 | localProperties.load(reader) 12 | } 13 | } 14 | 15 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 16 | if (flutterVersionCode == null) { 17 | flutterVersionCode = '1' 18 | } 19 | 20 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 21 | if (flutterVersionName == null) { 22 | flutterVersionName = '1.0' 23 | } 24 | 25 | android { 26 | namespace "com.example.example" 27 | compileSdkVersion flutter.compileSdkVersion 28 | ndkVersion flutter.ndkVersion 29 | 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_1_8 32 | targetCompatibility JavaVersion.VERSION_1_8 33 | } 34 | 35 | kotlinOptions { 36 | jvmTarget = '1.8' 37 | } 38 | 39 | sourceSets { 40 | main.java.srcDirs += 'src/main/kotlin' 41 | } 42 | 43 | defaultConfig { 44 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 45 | applicationId "com.example.example" 46 | // You can update the following values to match your application needs. 47 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. 48 | minSdkVersion flutter.minSdkVersion 49 | targetSdkVersion flutter.targetSdkVersion 50 | versionCode flutterVersionCode.toInteger() 51 | versionName flutterVersionName 52 | } 53 | 54 | buildTypes { 55 | release { 56 | // TODO: Add your own signing config for the release build. 57 | // Signing with the debug keys for now, so `flutter run --release` works. 58 | signingConfig signingConfigs.debug 59 | } 60 | } 61 | } 62 | 63 | flutter { 64 | source '../..' 65 | } 66 | 67 | dependencies {} 68 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 14 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.7.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 10 | } 11 | } 12 | 13 | allprojects { 14 | repositories { 15 | google() 16 | mavenCentral() 17 | } 18 | } 19 | 20 | rootProject.buildDir = '../build' 21 | subprojects { 22 | project.buildDir = "${rootProject.buildDir}/${project.name}" 23 | } 24 | subprojects { 25 | project.evaluationDependsOn(':app') 26 | } 27 | 28 | tasks.register("clean", Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4G 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip 6 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | def flutterSdkPath = { 3 | def properties = new Properties() 4 | file("local.properties").withInputStream { properties.load(it) } 5 | def flutterSdkPath = properties.getProperty("flutter.sdk") 6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 7 | return flutterSdkPath 8 | } 9 | settings.ext.flutterSdkPath = flutterSdkPath() 10 | 11 | includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") 12 | 13 | repositories { 14 | google() 15 | mavenCentral() 16 | gradlePluginPortal() 17 | } 18 | 19 | plugins { 20 | id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false 21 | } 22 | } 23 | 24 | plugins { 25 | id "dev.flutter.flutter-plugin-loader" version "1.0.0" 26 | id "com.android.application" version "7.3.0" apply false 27 | } 28 | 29 | include ":app" 30 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | CADisableMinimumFrameDurationOnPhone 45 | 46 | UIApplicationSupportsIndirectInputEvents 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/ios/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/lib/bitcoin_cash/make_vout0_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/bitcoin_base.dart'; 2 | import 'package:blockchain_utils/blockchain_utils.dart'; 3 | import 'package:example/services_examples/electrum/electrum_ssl_service.dart'; 4 | 5 | /// make vout 0 for account for create token hash 6 | /// estimate transaction to your self with input 0 7 | 8 | void main() async { 9 | /// connect to electrum service with ssl 10 | /// please see `services_examples` folder for how to create electrum ssl service 11 | final service = 12 | await ElectrumSSLService.connect("chipnet.imaginary.cash:50002"); 13 | 14 | /// create provider with service 15 | final provider = ElectrumProvider(service); 16 | 17 | /// initialize private key 18 | final privateKey = ECPrivate.fromBytes(BytesUtils.fromHexString( 19 | "f9061c5cb343c6b6a73900ee29509bb0bd2213319eea46d2f2a431068c9da06b")); 20 | 21 | /// public key 22 | final publicKey = privateKey.getPublic(); 23 | 24 | /// network 25 | const network = BitcoinCashNetwork.testnet; 26 | 27 | /// Derives a P2PKH address from the given public key and converts it to a Bitcoin Cash address 28 | /// for enhanced accessibility within the network. 29 | final p2pkhAddress = publicKey.toAddress(); 30 | 31 | /// Reads all UTXOs (Unspent Transaction Outputs) associated with the account. 32 | /// We does not need tokens utxo and we set to false. 33 | final elctrumUtxos = 34 | await provider.request(ElectrumRequestScriptHashListUnspent( 35 | scriptHash: p2pkhAddress.pubKeyHash(), 36 | includeTokens: false, 37 | )); 38 | 39 | /// Converts all UTXOs to a list of UtxoWithAddress, containing UTXO information along with address details. 40 | final List utxos = elctrumUtxos 41 | .map((e) => UtxoWithAddress( 42 | utxo: e.toUtxo(p2pkhAddress.type), 43 | ownerDetails: UtxoAddressDetails( 44 | publicKey: publicKey.toHex(), address: p2pkhAddress))) 45 | .toList(); 46 | 47 | /// som of utxos in satoshi 48 | final sumOfUtxo = utxos.sumOfUtxosValue(); 49 | 50 | final bchTransaction = ForkedTransactionBuilder( 51 | outPuts: [ 52 | BitcoinOutput( 53 | address: p2pkhAddress, 54 | value: sumOfUtxo - BtcUtils.toSatoshi("0.00003"), 55 | ) 56 | ], 57 | fee: BtcUtils.toSatoshi("0.00003"), 58 | network: network, 59 | 60 | /// Bitcoin Cash Metadata Registries 61 | /// pleas see https://cashtokens.org/docs/bcmr/chip/ for how to create cash metadata 62 | /// we does not create metadata for this token 63 | memo: null, 64 | utxos: utxos, 65 | ); 66 | final transaaction = 67 | bchTransaction.buildTransaction((trDigest, utxo, publicKey, sighash) { 68 | return privateKey.signECDSA(trDigest, sighash: sighash); 69 | }); 70 | 71 | /// transaction ID 72 | final _ = transaaction.txId(); 73 | 74 | /// for calculation fee (serialized transaction bytes length) 75 | transaaction.getSize(); 76 | 77 | /// raw of encoded transaction in hex 78 | final transactionRaw = transaaction.toHex(); 79 | 80 | /// send transaction to network 81 | await provider.request( 82 | ElectrumRequestBroadCastTransaction(transactionRaw: transactionRaw)); 83 | 84 | /// done! check the transaction in block explorer 85 | /// https://chipnet.imaginary.cash/tx/b20d4c13fe67adc2f73aee0161eb51c7e813643ddc8eb655c6bd9ae72b7562cb 86 | } 87 | -------------------------------------------------------------------------------- /example/lib/global/bch_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/bitcoin_base.dart'; 2 | import 'package:blockchain_utils/blockchain_utils.dart'; 3 | import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; 4 | 5 | void main() async { 6 | /// connect to electrum service with websocket 7 | /// please see `services_examples` folder for how to create electrum websocket service 8 | final service = await ElectrumWebSocketService.connect( 9 | "wss://chipnet.imaginary.cash:50004"); 10 | 11 | /// create provider with service 12 | final provider = ElectrumProvider(service); 13 | 14 | /// initialize private key 15 | final privateKey = ECPrivate.fromBytes(BytesUtils.fromHexString( 16 | "f9061c5cb343c6b6a73900ee29509bb0bd2213319eea46d2f2a431068c9da06b")); 17 | 18 | /// public key 19 | final publicKey = privateKey.getPublic(); 20 | 21 | /// network 22 | const network = BitcoinCashNetwork.testnet; 23 | 24 | /// Derives a P2PKH address from the given public key and converts it to a Bitcoin Cash address 25 | /// for enhanced accessibility within the network. 26 | final p2pkhAddress = 27 | BitcoinCashAddress.fromBaseAddress(publicKey.toAddress()); 28 | 29 | /// Initialize two P2SH32 addresses for receiving funds. 30 | final p2sh32Example1 = BitcoinCashAddress( 31 | "bchtest:pw054wtjjc70rrvx4ftl4p63gluedyt0qmpgz705f8x3gxygrzarzls7vp2sj", 32 | network: network); 33 | final p2sh32Example2 = BitcoinCashAddress( 34 | "bchtest:pvw39llgap0a4vm8jn9sjsvfsthah4wgemjlh6epdtzr3pl2fqtmsn3s4vcm7", 35 | network: network); 36 | 37 | /// Reads all UTXOs (Unspent Transaction Outputs) associated with the account. 38 | /// We does not need tokens utxo and we set to false. 39 | final elctrumUtxos = 40 | await provider.request(ElectrumRequestScriptHashListUnspent( 41 | scriptHash: p2pkhAddress.baseAddress.pubKeyHash(), 42 | includeTokens: false, 43 | )); 44 | 45 | /// Converts all UTXOs to a list of UtxoWithAddress, containing UTXO information along with address details. 46 | final List utxos = elctrumUtxos 47 | .map((e) => UtxoWithAddress( 48 | utxo: e.toUtxo(p2pkhAddress.type), 49 | ownerDetails: UtxoAddressDetails( 50 | publicKey: publicKey.toHex(), address: p2pkhAddress.baseAddress))) 51 | .toList(); 52 | 53 | /// som of utxos in satoshi 54 | final sumOfUtxo = utxos.sumOfUtxosValue(); 55 | if (sumOfUtxo == BigInt.zero) { 56 | return; 57 | } 58 | 59 | final bchTransaction = ForkedTransactionBuilder( 60 | outPuts: [ 61 | /// change input (sumofutxos - spend) 62 | BitcoinOutput( 63 | address: p2pkhAddress.baseAddress, 64 | value: sumOfUtxo - 65 | (BtcUtils.toSatoshi("0.0001") + 66 | BtcUtils.toSatoshi("0.0001") + 67 | BtcUtils.toSatoshi("0.00003")), 68 | ), 69 | BitcoinOutput( 70 | address: p2sh32Example1.baseAddress, 71 | value: BtcUtils.toSatoshi("0.0001"), 72 | ), 73 | BitcoinOutput( 74 | address: p2sh32Example2.baseAddress, 75 | value: BtcUtils.toSatoshi("0.0001"), 76 | ), 77 | ], 78 | fee: BtcUtils.toSatoshi("0.00003"), 79 | network: network, 80 | utxos: utxos, 81 | ); 82 | final transaaction = 83 | bchTransaction.buildTransaction((trDigest, utxo, publicKey, sighash) { 84 | return privateKey.signECDSA(trDigest, sighash: sighash); 85 | }); 86 | 87 | /// transaction ID 88 | transaaction.txId(); 89 | 90 | /// for calculation fee 91 | transaaction.getSize(); 92 | 93 | /// raw of encoded transaction in hex 94 | final transactionRaw = transaaction.toHex(); 95 | 96 | /// send transaction to network 97 | await provider.request( 98 | ElectrumRequestBroadCastTransaction(transactionRaw: transactionRaw)); 99 | 100 | /// done! check the transaction in block explorer 101 | /// https://chipnet.imaginary.cash/tx/9e534f8a64f76b1af5ccf2522392697f2242fd215206a458cfe286bca4a3ec0a 102 | } 103 | -------------------------------------------------------------------------------- /example/lib/musig/methods.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/bitcoin_base.dart'; 2 | import 'package:example/services_examples/electrum/electrum_ssl_service.dart'; 3 | 4 | Future getProvider( 5 | {String url = "testnet4-electrumx.wakiyamap.dev:51002"}) async { 6 | // final service = await ElectrumSSLService.connect( 7 | // "testnet4-electrumx.wakiyamap.dev:51002"); 8 | 9 | final service = 10 | await ElectrumSSLService.connect("testnet.aranguren.org:51002"); 11 | return ElectrumProvider(service); 12 | } 13 | 14 | class PsbtUtxoRequest { 15 | final BitcoinBaseAddress address; 16 | final Script? p2shRedeemScript; 17 | final Script? witnessScript; 18 | final TapLeafMerkleProof? merkleProof; 19 | final TaprootTree? treeScript; 20 | final TaprootLeaf? leafScript; 21 | final List? xOnlyOrInternalPubKey; 22 | final List? merkleRoot; 23 | final List? leafScripts; 24 | final List privateKeys; 25 | final List? muSig2ParticipantPublicKeys; 26 | final List? ripemd160; 27 | final List? sha256; 28 | final List? hash160; 29 | final List? hash256; 30 | const PsbtUtxoRequest( 31 | {required this.address, 32 | this.p2shRedeemScript, 33 | this.witnessScript, 34 | this.leafScript, 35 | this.merkleProof, 36 | this.treeScript, 37 | this.xOnlyOrInternalPubKey, 38 | this.merkleRoot, 39 | this.leafScripts, 40 | this.privateKeys = const [], 41 | this.muSig2ParticipantPublicKeys, 42 | this.ripemd160, 43 | this.hash160, 44 | this.hash256, 45 | this.sha256}); 46 | } 47 | 48 | Future> getPsbtUtxo( 49 | {required List addresses, 50 | bool local = true, 51 | List>? data}) async { 52 | final provider = await getProvider(); 53 | 54 | final utxos = await Future.wait(addresses.map((e) async { 55 | return await provider.request(ElectrumRequestScriptHashListUnspent( 56 | scriptHash: e.address.pubKeyHash())); 57 | })); 58 | 59 | final utxoss = List.generate(utxos.length, (i) async { 60 | final request = addresses[i]; 61 | final accountUtxos = utxos[i]; 62 | final er = await Future.wait(accountUtxos 63 | .map((e) => provider.request(ElectrumRequestGetRawTransaction(e.txId))) 64 | .toList()); 65 | return List.generate( 66 | accountUtxos.length, 67 | (index) { 68 | return PsbtUtxo( 69 | utxo: accountUtxos[index].toUtxo(request.address.type), 70 | p2shRedeemScript: request.p2shRedeemScript, 71 | p2wshWitnessScript: request.witnessScript, 72 | tx: er[index], 73 | scriptPubKey: request.address.toScriptPubKey(), 74 | leafScript: request.leafScript, 75 | leafScripts: request.leafScripts, 76 | merkleProof: request.merkleProof, 77 | treeScript: request.treeScript, 78 | merkleRoot: request.merkleRoot, 79 | xOnlyOrInternalPubKey: request.xOnlyOrInternalPubKey, 80 | muSig2ParticipantPublicKeys: request.muSig2ParticipantPublicKeys, 81 | hash160: request.hash160, 82 | hash256: request.hash256, 83 | ripemd160: request.ripemd160, 84 | sha256: request.sha256); 85 | }, 86 | ); 87 | }); 88 | final e = await Future.wait(utxoss); 89 | return e.expand((e) => e).toList(); 90 | } 91 | -------------------------------------------------------------------------------- /example/lib/psbt/psbt_musig2_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/bitcoin_base.dart'; 2 | import 'package:blockchain_utils/blockchain_utils.dart'; 3 | import 'package:example/musig/methods.dart'; 4 | 5 | Bip32Slip10Secp256k1 _deriveKey( 6 | {String key = 7 | "tprv8ZgxMBicQKsPdgBQV2Y9EVPSjAGhyZXArhwSzHwnV3FytzPRr8KCR8EKEpLeHbANAncgbc31a6QoXjBTARQiZ2h1Z2NgSCjFYeTqKpAN5Gc", 8 | String path = "m/86'/1'/0'/0/1"}) { 9 | Bip32Slip10Secp256k1 secp = Bip32Slip10Secp256k1.fromExtendedKey( 10 | key, Bip44Coins.bitcoinTestnet.conf.keyNetVer); 11 | return secp.derivePath(path) as Bip32Slip10Secp256k1; 12 | } 13 | 14 | ECPrivate _getPrivateKey({String path = "m/86'/1'/0'/0/1"}) { 15 | final key = _deriveKey(path: path); 16 | return ECPrivate.fromBytes(key.privateKey.raw); 17 | } 18 | 19 | void main() async { 20 | final key = _getPrivateKey(); 21 | final key2 = _getPrivateKey(path: "m/86'/1'/0'/0/2"); 22 | final key3 = _getPrivateKey(path: "m/86'/1'/0'/0/3"); 23 | 24 | final aggpk = Musig2Signer.generate( 25 | [key.getPublic(), key2.getPublic(), key3.getPublic()]); 26 | final address = 27 | P2trAddress.fromInternalKey(internalKey: aggpk.aggPublicKey.toXOnly()); 28 | final utxo = await getPsbtUtxo(addresses: [ 29 | PsbtUtxoRequest( 30 | address: address, 31 | xOnlyOrInternalPubKey: aggpk.aggPublicKey.toXOnly(), 32 | muSig2ParticipantPublicKeys: [ 33 | PsbtInputMuSig2ParticipantPublicKeys( 34 | aggregatePubKey: aggpk.aggPublicKey, pubKeys: aggpk.publicKeys) 35 | ]) 36 | ]); 37 | final psbt = PsbtBuilderV0.create(); 38 | psbt.addUtxos(utxo); 39 | psbt.addOutput(PsbtTransactionOutput( 40 | amount: BtcUtils.toSatoshi('0.00001'), address: address)); 41 | for (int i = 0; i < utxo.length; i++) { 42 | final noncePub1 = aggpk.generateNonce(key.getPublic()); 43 | final noncePub2 = aggpk.generateNonce(key2.getPublic()); 44 | final noncePub3 = aggpk.generateNonce(key3.getPublic()); 45 | psbt.musig2AddPubKeyNonce( 46 | i, 47 | PsbtInputMuSig2PublicNonce( 48 | publicKey: key.getPublic(), 49 | plainPublicKey: aggpk.aggPublicKey, 50 | publicNonce: noncePub1.pubnonce)); 51 | psbt.musig2AddPubKeyNonce( 52 | i, 53 | PsbtInputMuSig2PublicNonce( 54 | publicKey: key2.getPublic(), 55 | plainPublicKey: aggpk.aggPublicKey, 56 | publicNonce: noncePub2.pubnonce)); 57 | psbt.musig2AddPubKeyNonce( 58 | i, 59 | PsbtInputMuSig2PublicNonce( 60 | publicKey: key3.getPublic(), 61 | plainPublicKey: aggpk.aggPublicKey, 62 | publicNonce: noncePub3.pubnonce)); 63 | psbt.signInput( 64 | signer: (p0) => PsbtSignerResponse(signers: [ 65 | PsbtMusig2DefaultSigner( 66 | privateKey: key, 67 | aggPublicKey: aggpk.aggPublicKey, 68 | publicKeys: aggpk.publicKeys, 69 | nonce: noncePub1), 70 | PsbtMusig2DefaultSigner( 71 | privateKey: key2, 72 | aggPublicKey: aggpk.aggPublicKey, 73 | publicKeys: aggpk.publicKeys, 74 | nonce: noncePub2), 75 | PsbtMusig2DefaultSigner( 76 | privateKey: key3, 77 | aggPublicKey: aggpk.aggPublicKey, 78 | publicKeys: aggpk.publicKeys, 79 | nonce: noncePub3), 80 | ]), 81 | index: i); 82 | } 83 | // ignore: unused_local_variable 84 | final finalTx = psbt.finalizeAll(); 85 | } 86 | -------------------------------------------------------------------------------- /example/lib/services_examples/cross_platform_websocket/core.dart: -------------------------------------------------------------------------------- 1 | /// I haven't implemented any specific HTTP service or socket service within this plugin. 2 | /// The reason is that different applications may use various plugins or methods 3 | /// to interact with network protocols. However, 4 | /// I have included numerous examples to demonstrate 5 | /// how Electrum and HTTP services can be utilized. You can 6 | /// leverage these examples as a reference to easily create 7 | /// your own services tailored to your application's specific needs. 8 | import 'cross.dart' 9 | if (dart.library.html) 'web.dart' 10 | if (dart.library.io) 'io.dart'; 11 | 12 | abstract class WebSocketCore { 13 | void close({int? code}); 14 | void sink(List message); 15 | Stream get stream; 16 | bool get isConnected; 17 | static Future connect(String url, 18 | {List? protocols}) async => 19 | connectSoc(url, protocols: protocols); 20 | } 21 | -------------------------------------------------------------------------------- /example/lib/services_examples/cross_platform_websocket/cross.dart: -------------------------------------------------------------------------------- 1 | import 'core.dart'; 2 | 3 | Future connectSoc(String url, {List? protocols}) => 4 | throw UnsupportedError( 5 | 'Cannot create a instance without dart:html or dart:io.'); 6 | -------------------------------------------------------------------------------- /example/lib/services_examples/cross_platform_websocket/io.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:io'; 3 | import 'core.dart'; 4 | 5 | Future connectSoc(String url, {List? protocols}) async => 6 | await WebsocketIO.connect(url); 7 | 8 | class WebsocketIO implements WebSocketCore { 9 | final WebSocket _socket; 10 | final StreamController _streamController = 11 | StreamController(); 12 | @override 13 | bool get isConnected => _socket.readyState == WebSocket.open; 14 | WebsocketIO._(this._socket) { 15 | _socket.listen( 16 | (dynamic data) { 17 | _streamController.add(data); 18 | }, 19 | onDone: () { 20 | _streamController.close(); 21 | }, 22 | onError: (dynamic error) { 23 | // Handle errors as needed 24 | _streamController.addError(error); 25 | }, 26 | ); 27 | } 28 | 29 | @override 30 | void close({int? code}) { 31 | _socket.close(code, 'Closed by client.'); 32 | } 33 | 34 | @override 35 | Stream get stream => _streamController.stream; 36 | 37 | static Future connect(String url, 38 | {List? protocols}) async { 39 | final completer = Completer(); 40 | final socket = await WebSocket.connect(url, protocols: protocols); 41 | completer.complete(WebsocketIO._(socket)); 42 | 43 | return completer.future; 44 | } 45 | 46 | @override 47 | void sink(List message) { 48 | _socket.add(message); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example/lib/services_examples/cross_platform_websocket/web.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'core.dart'; 4 | // ignore: avoid_web_libraries_in_flutter 5 | import 'dart:html'; 6 | 7 | Future connectSoc(String url, {List? protocols}) async => 8 | await WebsocketWeb.connect(url); 9 | 10 | class WebsocketWeb implements WebSocketCore { 11 | final WebSocket _socket; 12 | final StreamController _streamController = 13 | StreamController(); 14 | final Completer _connectedCompleter = Completer(); 15 | 16 | WebsocketWeb._(this._socket) { 17 | _socket.onOpen.listen((Event event) { 18 | _connectedCompleter.complete(); 19 | }); 20 | 21 | _socket.onMessage.listen((MessageEvent event) { 22 | _streamController.add(event.data); 23 | }); 24 | 25 | _socket.onClose.listen((CloseEvent event) { 26 | _streamController.close(); 27 | }); 28 | } 29 | 30 | @override 31 | void close({int? code}) { 32 | _socket.close(code, ''); 33 | } 34 | 35 | @override 36 | bool get isConnected => _socket.readyState == WebSocket.OPEN; 37 | @override 38 | Stream get stream => _streamController.stream; 39 | 40 | static Future connect(String url, 41 | {List? protocols}) async { 42 | final completer = Completer(); 43 | final socket = WebSocket(url, protocols); 44 | WebsocketWeb._(socket)._connectedCompleter.future.then((_) { 45 | completer.complete(WebsocketWeb._(socket)); 46 | }); 47 | return completer.future; 48 | } 49 | 50 | @override 51 | void sink(List message) { 52 | _socket.send(message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/lib/services_examples/electrum/electrum_ssl_service.dart: -------------------------------------------------------------------------------- 1 | /// Simple example how to send request to electurm with secure socket 2 | 3 | import 'dart:async'; 4 | import 'dart:convert'; 5 | import 'dart:io'; 6 | import 'package:bitcoin_base/bitcoin_base.dart'; 7 | import 'package:blockchain_utils/service/models/params.dart'; 8 | import 'package:blockchain_utils/utils/string/string.dart'; 9 | import 'package:example/services_examples/electrum/request_completer.dart'; 10 | 11 | class ElectrumSSLService with ElectrumServiceProvider { 12 | ElectrumSSLService._( 13 | this.url, 14 | SecureSocket channel, { 15 | this.defaultRequestTimeOut = const Duration(seconds: 30), 16 | }) : _socket = channel { 17 | _subscription = 18 | _socket!.listen(_onMessge, onError: _onClose, onDone: _onDone); 19 | } 20 | SecureSocket? _socket; 21 | StreamSubscription>? _subscription; 22 | final Duration defaultRequestTimeOut; 23 | 24 | Map requests = {}; 25 | bool _isDiscounnect = false; 26 | 27 | bool get isConnected => _isDiscounnect; 28 | 29 | final String url; 30 | 31 | void add(List params) { 32 | if (_isDiscounnect) { 33 | throw StateError("socket has been discounected"); 34 | } 35 | _socket?.add(params); 36 | } 37 | 38 | void _onClose(Object? error) { 39 | _isDiscounnect = true; 40 | 41 | _socket = null; 42 | _subscription?.cancel().catchError((e) {}); 43 | _subscription = null; 44 | } 45 | 46 | void _onDone() { 47 | _onClose(null); 48 | } 49 | 50 | void discounnect() { 51 | _onClose(null); 52 | } 53 | 54 | static Future connect( 55 | String url, { 56 | Iterable? protocols, 57 | Duration defaultRequestTimeOut = const Duration(seconds: 30), 58 | final Duration connectionTimeOut = const Duration(seconds: 30), 59 | }) async { 60 | final parts = url.split(":"); 61 | final channel = await SecureSocket.connect( 62 | parts[0], 63 | int.parse(parts[1]), 64 | onBadCertificate: (certificate) => true, 65 | ).timeout(connectionTimeOut); 66 | 67 | return ElectrumSSLService._(url, channel, 68 | defaultRequestTimeOut: defaultRequestTimeOut); 69 | } 70 | 71 | String? ddd; 72 | void _onMessge(List event) { 73 | final msg = utf8.decode(event); 74 | if (msg.contains("jsonrpc")) { 75 | ddd = msg; 76 | } else { 77 | ddd = "$ddd$msg"; 78 | } 79 | Map? decode = StringUtils.tryToJson(ddd); 80 | if (decode?.containsKey("id") ?? false) { 81 | final int id = int.parse(decode!["id"]!.toString()); 82 | final request = requests.remove(id); 83 | request?.completer.complete(decode); 84 | } 85 | } 86 | 87 | @override 88 | Future> doRequest(ElectrumRequestDetails params, 89 | {Duration? timeout}) async { 90 | final AsyncRequestCompleter compeleter = 91 | AsyncRequestCompleter(params.params); 92 | try { 93 | requests[params.requestID] = compeleter; 94 | add(params.toTCPParams()); 95 | final result = await compeleter.completer.future 96 | .timeout(timeout ?? defaultRequestTimeOut); 97 | return params.toResponse(result); 98 | } finally { 99 | requests.remove(params.requestID); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /example/lib/services_examples/electrum/electrum_tcp_service.dart: -------------------------------------------------------------------------------- 1 | /// Simple example how to send request to electurm with tcp 2 | 3 | import 'dart:async'; 4 | import 'dart:convert'; 5 | import 'dart:io'; 6 | import 'package:bitcoin_base/bitcoin_base.dart'; 7 | import 'package:blockchain_utils/service/models/params.dart'; 8 | import 'package:example/services_examples/electrum/request_completer.dart'; 9 | 10 | class ElectrumTCPService with ElectrumServiceProvider { 11 | ElectrumTCPService._( 12 | this.url, 13 | Socket channel, { 14 | this.defaultRequestTimeOut = const Duration(seconds: 30), 15 | }) : _socket = channel { 16 | _subscription = 17 | _socket!.listen(_onMessge, onError: _onClose, onDone: _onDone); 18 | } 19 | Socket? _socket; 20 | StreamSubscription>? _subscription; 21 | final Duration defaultRequestTimeOut; 22 | 23 | Map requests = {}; 24 | bool _isDiscounnect = false; 25 | 26 | bool get isConnected => _isDiscounnect; 27 | 28 | final String url; 29 | 30 | void add(List params) { 31 | if (_isDiscounnect) { 32 | throw StateError("socket has been discounected"); 33 | } 34 | _socket?.add(params); 35 | } 36 | 37 | void _onClose(Object? error) { 38 | _isDiscounnect = true; 39 | 40 | _socket = null; 41 | _subscription?.cancel().catchError((e) {}); 42 | _subscription = null; 43 | } 44 | 45 | void _onDone() { 46 | _onClose(null); 47 | } 48 | 49 | void discounnect() { 50 | _onClose(null); 51 | } 52 | 53 | static Future connect( 54 | String url, { 55 | Iterable? protocols, 56 | Duration defaultRequestTimeOut = const Duration(seconds: 30), 57 | final Duration connectionTimeOut = const Duration(seconds: 30), 58 | }) async { 59 | final parts = url.split(":"); 60 | final channel = await Socket.connect(parts[0], int.parse(parts[1])) 61 | .timeout(connectionTimeOut); 62 | 63 | return ElectrumTCPService._(url, channel, 64 | defaultRequestTimeOut: defaultRequestTimeOut); 65 | } 66 | 67 | void _onMessge(List event) { 68 | final Map decode = json.decode(utf8.decode(event)); 69 | if (decode.containsKey("id")) { 70 | final int id = int.parse(decode["id"]!.toString()); 71 | final request = requests.remove(id); 72 | request?.completer.complete(decode); 73 | } 74 | } 75 | 76 | @override 77 | Future> doRequest(ElectrumRequestDetails params, 78 | {Duration? timeout}) async { 79 | final AsyncRequestCompleter compeleter = 80 | AsyncRequestCompleter(params.params); 81 | try { 82 | requests[params.requestID] = compeleter; 83 | add(params.toTCPParams()); 84 | final result = await compeleter.completer.future 85 | .timeout(timeout ?? defaultRequestTimeOut); 86 | return params.toResponse(result); 87 | } finally { 88 | requests.remove(params.requestID); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /example/lib/services_examples/electrum/electrum_websocket_service.dart: -------------------------------------------------------------------------------- 1 | /// Simple example how to send request to electurm with websocket 2 | import 'dart:async'; 3 | import 'dart:convert'; 4 | import 'package:bitcoin_base/bitcoin_base.dart'; 5 | import 'package:blockchain_utils/service/models/params.dart'; 6 | import 'package:example/services_examples/cross_platform_websocket/core.dart'; 7 | import 'package:example/services_examples/electrum/request_completer.dart'; 8 | 9 | class ElectrumWebSocketService with ElectrumServiceProvider { 10 | ElectrumWebSocketService._( 11 | this.url, 12 | WebSocketCore channel, { 13 | this.defaultRequestTimeOut = const Duration(seconds: 30), 14 | }) : _socket = channel { 15 | _subscription = channel.stream 16 | .cast() 17 | .listen(_onMessge, onError: _onClose, onDone: _onDone); 18 | } 19 | WebSocketCore? _socket; 20 | StreamSubscription? _subscription; 21 | final Duration defaultRequestTimeOut; 22 | 23 | Map requests = {}; 24 | bool _isDiscounnect = false; 25 | 26 | bool get isConnected => _isDiscounnect; 27 | 28 | final String url; 29 | 30 | void add(List params) { 31 | if (_isDiscounnect) { 32 | throw StateError("socket has been discounected"); 33 | } 34 | _socket?.sink(params); 35 | } 36 | 37 | void _onClose(Object? error) { 38 | _isDiscounnect = true; 39 | 40 | _socket = null; 41 | _subscription?.cancel().catchError((e) {}); 42 | _subscription = null; 43 | } 44 | 45 | void _onDone() { 46 | _onClose(null); 47 | } 48 | 49 | void discounnect() { 50 | _onClose(null); 51 | } 52 | 53 | static Future connect( 54 | String url, { 55 | Iterable? protocols, 56 | Duration defaultRequestTimeOut = const Duration(seconds: 30), 57 | final Duration connectionTimeOut = const Duration(seconds: 30), 58 | }) async { 59 | final channel = 60 | await WebSocketCore.connect(url, protocols: protocols?.toList()); 61 | 62 | return ElectrumWebSocketService._(url, channel, 63 | defaultRequestTimeOut: defaultRequestTimeOut); 64 | } 65 | 66 | void _onMessge(String event) { 67 | final Map decode = json.decode(event); 68 | if (decode.containsKey("id")) { 69 | final int id = int.parse(decode["id"]!.toString()); 70 | final request = requests.remove(id); 71 | request?.completer.complete(decode); 72 | } 73 | } 74 | 75 | @override 76 | Future> doRequest(ElectrumRequestDetails params, 77 | {Duration? timeout}) async { 78 | final AsyncRequestCompleter compeleter = 79 | AsyncRequestCompleter(params.params); 80 | try { 81 | requests[params.requestID] = compeleter; 82 | add(params.toWebSocketParams()); 83 | final result = await compeleter.completer.future 84 | .timeout(timeout ?? defaultRequestTimeOut); 85 | return params.toResponse(result); 86 | } finally { 87 | requests.remove(params.requestID); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /example/lib/services_examples/electrum/request_completer.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | class AsyncRequestCompleter { 4 | AsyncRequestCompleter(this.params); 5 | final Completer> completer = Completer(); 6 | final Map params; 7 | } 8 | -------------------------------------------------------------------------------- /example/lib/services_examples/explorer_service/explorer_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:bitcoin_base/bitcoin_base.dart' show ApiService; 4 | import 'package:blockchain_utils/blockchain_utils.dart'; 5 | import 'package:http/http.dart' as http; 6 | 7 | class ApiProviderException implements Exception { 8 | final String message; 9 | final int? statusCode; 10 | final Map? responseData; 11 | const ApiProviderException(this.message, 12 | [this.statusCode, this.responseData]); 13 | @override 14 | String toString() { 15 | return "status: $statusCode $message ${responseData ?? ""}"; 16 | } 17 | } 18 | 19 | class BitcoinApiService implements ApiService { 20 | BitcoinApiService([http.Client? client]) : _client = client ?? http.Client(); 21 | final http.Client _client; 22 | @override 23 | Future get(String url) async { 24 | final response = await _client.get(Uri.parse(url)); 25 | return _readResponse(response); 26 | } 27 | 28 | @override 29 | Future post(String url, 30 | {Map headers = const {"Content-Type": "application/json"}, 31 | Object? body}) async { 32 | final response = 33 | await _client.post(Uri.parse(url), headers: headers, body: body); 34 | return _readResponse(response); 35 | } 36 | 37 | T _readResponse(http.Response response) { 38 | final String toString = _readBody(response); 39 | switch (T) { 40 | case String: 41 | return toString as T; 42 | case List: 43 | case Map: 44 | return jsonDecode(toString) as T; 45 | default: 46 | try { 47 | return jsonDecode(toString) as T; 48 | } catch (e) { 49 | throw const ApiProviderException("invalid request"); 50 | } 51 | } 52 | } 53 | 54 | String _readBody(http.Response response) { 55 | _readErr(response); 56 | return StringUtils.decode(response.bodyBytes); 57 | } 58 | 59 | void _readErr(http.Response response) { 60 | if (response.statusCode == 200 || response.statusCode == 201) return; 61 | String toString = StringUtils.decode(response.bodyBytes); 62 | Map? errorResult; 63 | try { 64 | if (toString.isNotEmpty) { 65 | errorResult = StringUtils.toJson(toString); 66 | } 67 | // ignore: empty_catches 68 | } catch (e) {} 69 | toString = toString.isEmpty ? "request_error" : toString; 70 | throw ApiProviderException(toString, response.statusCode, errorResult); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import FlutterMacOS 2 | import Cocoa 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2024 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrtnetwork/bitcoin_base/01d00bbbd1770ac5ca15a246f4cd26bd88f46ae4/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr) 51 | -1; // remove the trailing null character 52 | int input_length = (int)wcslen(utf16_string); 53 | std::string utf8_string; 54 | if (target_length <= 0 || target_length > utf8_string.max_size()) { 55 | return utf8_string; 56 | } 57 | utf8_string.resize(target_length); 58 | int converted_length = ::WideCharToMultiByte( 59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 60 | input_length, utf8_string.data(), target_length, nullptr, nullptr); 61 | if (converted_length == 0) { 62 | return std::string(); 63 | } 64 | return utf8_string; 65 | } 66 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | -------------------------------------------------------------------------------- /lib/bitcoin_base.dart: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | export 'src/bitcoin/bitcoin.dart'; 4 | 5 | export 'src/exception/exception.dart'; 6 | 7 | export 'src/crypto/crypto.dart'; 8 | 9 | export 'src/models/network.dart'; 10 | 11 | export 'src/provider/api_provider.dart'; 12 | 13 | export 'src/utils/btc_utils.dart'; 14 | 15 | export 'src/cash_token/cash_token.dart'; 16 | 17 | export 'src/bitcoin_cash/bitcoin_cash.dart'; 18 | 19 | export 'src/transaction_builder/builder.dart'; 20 | 21 | export 'src/psbt/psbt.dart'; 22 | -------------------------------------------------------------------------------- /lib/src/bitcoin/address/address.dart: -------------------------------------------------------------------------------- 1 | // Library for Bitcoin addresses handling in the bitcoin_base package. 2 | // 3 | // The library includes essential components such as: 4 | // - Core address functionality. 5 | // - encode/decode Legacy address support. 6 | // - Utility functions for address manipulation. 7 | // - encode/decode Segregated Witness (SegWit) address implementation. 8 | // - Enhanced functionality for improved handling of addresses across diverse networks. 9 | library; 10 | 11 | import 'package:bitcoin_base/src/bitcoin/script/scripts.dart'; 12 | import 'package:bitcoin_base/src/bitcoin/taproot/taproot.dart'; 13 | import 'package:bitcoin_base/src/exception/exception.dart'; 14 | import 'package:bitcoin_base/src/models/network.dart'; 15 | import 'package:bitcoin_base/src/utils/enumerate.dart'; 16 | import 'package:blockchain_utils/blockchain_utils.dart'; 17 | part 'core.dart'; 18 | part 'legacy_address.dart'; 19 | part 'utils/address_utils.dart'; 20 | part 'segwit_address.dart'; 21 | part 'network_address.dart'; 22 | -------------------------------------------------------------------------------- /lib/src/bitcoin/bitcoin.dart: -------------------------------------------------------------------------------- 1 | export 'address/address.dart'; 2 | export 'script/scripts.dart'; 3 | export 'taproot/taproot.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/bitcoin/script/output.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | import 'package:bitcoin_base/src/cash_token/cash_token.dart'; 3 | import 'package:bitcoin_base/src/bitcoin/script/script.dart'; 4 | import 'package:bitcoin_base/src/exception/exception.dart'; 5 | import 'package:blockchain_utils/helper/extensions/extensions.dart'; 6 | import 'package:blockchain_utils/utils/utils.dart'; 7 | import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; 8 | 9 | /// Represents a transaction output. 10 | /// 11 | /// [amount] the value we want to send to this output in satoshis 12 | /// [scriptPubKey] the script that will lock this amount 13 | class TxOutput { 14 | factory TxOutput.negativeOne() { 15 | return TxOutput._( 16 | amount: BitcoinOpCodeConst.negativeSatoshi, 17 | scriptPubKey: Script(script: [])); 18 | } 19 | // BitcoinOpCodeConst.negativeSatoshi 20 | const TxOutput._( 21 | {required this.amount, required this.scriptPubKey, this.cashToken}); 22 | factory TxOutput( 23 | {required BigInt amount, 24 | required Script scriptPubKey, 25 | CashToken? cashToken}) { 26 | try { 27 | return TxOutput._( 28 | amount: amount.asInt64, 29 | scriptPubKey: scriptPubKey, 30 | cashToken: cashToken); 31 | } catch (_) { 32 | throw DartBitcoinPluginException("Invalid output amount."); 33 | } 34 | } 35 | final CashToken? cashToken; 36 | final BigInt amount; 37 | final Script scriptPubKey; 38 | 39 | /// creates a copy of the object 40 | TxOutput clone() { 41 | return TxOutput( 42 | amount: amount, 43 | scriptPubKey: Script(script: List.from(scriptPubKey.script)), 44 | cashToken: cashToken); 45 | } 46 | 47 | List toBytes() { 48 | final amountBytes = 49 | BigintUtils.toBytes(amount, length: 8, order: Endian.little); 50 | final scriptBytes = [ 51 | ...cashToken?.toBytes() ?? [], 52 | ...scriptPubKey.toBytes() 53 | ]; 54 | final data = [ 55 | ...amountBytes, 56 | ...IntUtils.encodeVarint(scriptBytes.length), 57 | ...scriptBytes 58 | ]; 59 | return data; 60 | } 61 | 62 | static Tuple deserialize( 63 | {required List bytes, required int cursor}) { 64 | final value = BigintUtils.fromBytes(bytes.sublist(cursor, cursor + 8), 65 | byteOrder: Endian.little) 66 | .toSigned(64); 67 | cursor += 8; 68 | 69 | final vi = IntUtils.decodeVarint(bytes.sublist(cursor)); 70 | cursor += vi.item2; 71 | final token = CashToken.deserialize(bytes.sublist(cursor)); 72 | 73 | final lockScript = bytes.sublist(cursor + token.item2, cursor + vi.item1); 74 | cursor += vi.item1; 75 | return Tuple( 76 | TxOutput( 77 | amount: value, 78 | cashToken: token.item1, 79 | scriptPubKey: Script.deserialize(bytes: lockScript)), 80 | cursor); 81 | } 82 | 83 | Map toJson() { 84 | return { 85 | 'cashToken': cashToken?.toJson(), 86 | 'amount': amount.toString(), 87 | 'scriptPubKey': scriptPubKey.script 88 | }; 89 | } 90 | 91 | @override 92 | String toString() { 93 | return 'TxOutput{cashToken: ${cashToken?.toString()}}, amount: $amount, script: ${scriptPubKey.toString()}}'; 94 | } 95 | 96 | @override 97 | operator ==(other) { 98 | if (identical(this, other)) return true; 99 | if (other is! TxOutput) return false; 100 | return amount == other.amount && 101 | scriptPubKey == other.scriptPubKey && 102 | cashToken == other.cashToken; 103 | } 104 | 105 | @override 106 | int get hashCode => 107 | HashCodeGenerator.generateHashCode([amount, scriptPubKey, cashToken]); 108 | } 109 | -------------------------------------------------------------------------------- /lib/src/bitcoin/script/scripts.dart: -------------------------------------------------------------------------------- 1 | export 'input.dart'; 2 | export 'output.dart'; 3 | export 'script.dart'; 4 | export 'sequence.dart'; 5 | export 'transaction.dart'; 6 | export 'witness.dart'; 7 | export 'utils.dart'; 8 | export 'op_code/constant.dart'; 9 | -------------------------------------------------------------------------------- /lib/src/bitcoin/script/sequence.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; 3 | import 'package:bitcoin_base/src/exception/exception.dart'; 4 | import 'package:blockchain_utils/utils/utils.dart'; 5 | 6 | /// Helps setting up appropriate sequence. Used to provide the sequence to transaction inputs and to scripts. 7 | /// 8 | /// [value] The value of the block height or the 512 seconds increments 9 | /// [seqType] Specifies the type of sequence (.typeRelativeTimelock | .typeAbsoluteTimelock | .typeReplaceByFee 10 | /// [isTypeBlock] If type is .typeRelativeTimelock then this specifies its type (block height or 512 secs increments) 11 | class Sequence { 12 | Sequence( 13 | {required this.seqType, required this.value, this.isTypeBlock = true}) { 14 | if (seqType == BitcoinOpCodeConst.typeRelativeTimelock && 15 | (value < 1 || value > mask16)) { 16 | throw const DartBitcoinPluginException( 17 | 'Sequence should be between 1 and 65535'); 18 | } 19 | } 20 | final int seqType; 21 | final int value; 22 | final bool isTypeBlock; 23 | 24 | /// Serializes the relative sequence as required in a transaction 25 | List forInputSequence() { 26 | if (seqType == BitcoinOpCodeConst.typeAbsoluteTimelock) { 27 | return List.from(BitcoinOpCodeConst.absoluteTimelockSequence); 28 | } 29 | 30 | if (seqType == BitcoinOpCodeConst.typeReplaceByFee) { 31 | return List.from(BitcoinOpCodeConst.replaceByFeeSequence); 32 | } 33 | if (seqType == BitcoinOpCodeConst.typeRelativeTimelock) { 34 | int seq = 0; 35 | if (!isTypeBlock) { 36 | seq |= 1 << 22; 37 | } 38 | seq |= value; 39 | return IntUtils.toBytes(seq, length: 4, byteOrder: Endian.little); 40 | } 41 | 42 | throw const DartBitcoinPluginException('Invalid seqType'); 43 | } 44 | 45 | /// Returns the appropriate integer for a script; e.g. for relative timelocks 46 | int forScript() { 47 | if (seqType == BitcoinOpCodeConst.typeReplaceByFee) { 48 | throw const DartBitcoinPluginException( 49 | 'RBF is not to be included in a script.'); 50 | } 51 | var scriptIntiger = value; 52 | if (seqType == BitcoinOpCodeConst.typeRelativeTimelock && !isTypeBlock) { 53 | scriptIntiger |= 1 << 22; 54 | } 55 | return scriptIntiger; 56 | } 57 | 58 | @override 59 | String toString() { 60 | return 'Sequence{seqType: $seqType, value: $value, isTypeBlock: $isTypeBlock}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib/src/bitcoin/script/witness.dart: -------------------------------------------------------------------------------- 1 | import 'package:blockchain_utils/helper/extensions/extensions.dart'; 2 | import 'package:blockchain_utils/utils/utils.dart'; 3 | 4 | /// A list of the witness items required to satisfy the locking conditions of a segwit input (aka witness stack). 5 | /// 6 | /// [stack] the witness items (hex str) list 7 | class TxWitnessInput { 8 | TxWitnessInput({required List stack}) : stack = stack.immutable; 9 | final List stack; 10 | 11 | /// creates a copy of the object (classmethod) 12 | TxWitnessInput clone() { 13 | return TxWitnessInput(stack: stack); 14 | } 15 | 16 | factory TxWitnessInput.deserialize(List bytes) { 17 | final length = IntUtils.decodeVarint(bytes); 18 | int offset = length.item2; 19 | final List stack = []; 20 | for (int n = 0; n < length.item1; n++) { 21 | List witness = []; 22 | final itemLen = IntUtils.decodeVarint(bytes.sublist(offset)); 23 | offset += itemLen.item2; 24 | if (itemLen.item1 != 0) { 25 | witness = bytes.sublist(offset, offset + itemLen.item1); 26 | } 27 | offset += itemLen.item1; 28 | stack.add(BytesUtils.toHexString(witness)); 29 | } 30 | 31 | return TxWitnessInput(stack: stack); 32 | } 33 | 34 | /// returns a serialized byte version of the witness items list 35 | List toBytes() { 36 | final bytes = DynamicByteTracker(); 37 | final length = IntUtils.encodeVarint(stack.length); 38 | bytes.add(length); 39 | for (final item in stack) { 40 | final itemBytes = BytesUtils.fromHexString(item); 41 | final varint = IntUtils.prependVarint(itemBytes); 42 | bytes.add(varint); 43 | } 44 | 45 | return bytes.toBytes(); 46 | } 47 | 48 | Map toJson() { 49 | return {'stack': stack}; 50 | } 51 | 52 | @override 53 | String toString() { 54 | return "TxWitnessInput{stack: ${stack.join(", ")}}"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lib/src/bitcoin/taproot/constants/constants.dart: -------------------------------------------------------------------------------- 1 | class TaprootConst { 2 | static const List tapBranchHashDomain = [ 3 | 25, 4 | 65, 5 | 161, 6 | 242, 7 | 229, 8 | 110, 9 | 185, 10 | 95, 11 | 162, 12 | 169, 13 | 241, 14 | 148, 15 | 190, 16 | 92, 17 | 1, 18 | 247, 19 | 33, 20 | 111, 21 | 51, 22 | 237, 23 | 130, 24 | 176, 25 | 145, 26 | 70, 27 | 52, 28 | 144, 29 | 208, 30 | 91, 31 | 245, 32 | 22, 33 | 160, 34 | 21 35 | ]; 36 | static const List tapTweakHashDomain = [ 37 | 232, 38 | 15, 39 | 225, 40 | 99, 41 | 156, 42 | 156, 43 | 160, 44 | 80, 45 | 227, 46 | 175, 47 | 27, 48 | 57, 49 | 193, 50 | 67, 51 | 198, 52 | 62, 53 | 66, 54 | 156, 55 | 188, 56 | 235, 57 | 21, 58 | 217, 59 | 64, 60 | 251, 61 | 181, 62 | 197, 63 | 161, 64 | 244, 65 | 175, 66 | 87, 67 | 197, 68 | 233 69 | ]; 70 | static const List tapLeafHashDomain = [ 71 | 174, 72 | 234, 73 | 143, 74 | 220, 75 | 66, 76 | 8, 77 | 152, 78 | 49, 79 | 5, 80 | 115, 81 | 75, 82 | 88, 83 | 8, 84 | 29, 85 | 30, 86 | 38, 87 | 56, 88 | 211, 89 | 95, 90 | 28, 91 | 181, 92 | 64, 93 | 8, 94 | 212, 95 | 211, 96 | 87, 97 | 202, 98 | 3, 99 | 190, 100 | 120, 101 | 233, 102 | 238 103 | ]; 104 | 105 | static const List tapSigHshDomain = [ 106 | 244, 107 | 10, 108 | 72, 109 | 223, 110 | 75, 111 | 42, 112 | 112, 113 | 200, 114 | 180, 115 | 146, 116 | 75, 117 | 242, 118 | 101, 119 | 70, 120 | 97, 121 | 237, 122 | 61, 123 | 149, 124 | 253, 125 | 102, 126 | 163, 127 | 19, 128 | 235, 129 | 135, 130 | 35, 131 | 117, 132 | 151, 133 | 198, 134 | 40, 135 | 228, 136 | 160, 137 | 49 138 | ]; 139 | } 140 | -------------------------------------------------------------------------------- /lib/src/bitcoin/taproot/taproot.dart: -------------------------------------------------------------------------------- 1 | export 'types/types.dart'; 2 | export 'utils/utils.dart'; 3 | -------------------------------------------------------------------------------- /lib/src/bitcoin_cash/bcmr.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/bitcoin/script/scripts.dart'; 2 | import 'package:bitcoin_base/src/cash_token/cash_token.dart'; 3 | import 'package:bitcoin_base/src/provider/models/utxo_details.dart'; 4 | import 'package:blockchain_utils/blockchain_utils.dart'; 5 | 6 | /// Bitcoin Cash Metadata Registries Script to convert uris and content hash to bitcoin output script 7 | class BCMR implements BitcoinScriptOutput { 8 | /// Bitcoin Cash Metadata Registries PREFIX 9 | static const String _pcmrInHex = '42434d52'; 10 | BCMR({required this.uris, required this.hash}) 11 | : assert( 12 | () { 13 | if (uris.isEmpty) return false; 14 | if (!StringUtils.isHexBytes(hash)) return false; 15 | if (BytesUtils.fromHexString(hash).length != SHA256.digestLength) { 16 | return false; 17 | } 18 | return true; 19 | }(), 20 | uris.isEmpty 21 | ? 'URIs must not be empty.' 22 | : 'The BCMR hash should be the SHA-256 hash of the URI contents', 23 | ); 24 | 25 | /// list of uris 26 | final List uris; 27 | 28 | /// uris content SHA-256 29 | final String hash; 30 | 31 | /// 'script' property from the interface to define the specific script for Bitcoin Cash Metadata Registries OP_RETURN script. 32 | @override 33 | Script get script => Script(script: [ 34 | 'OP_RETURN', 35 | _pcmrInHex, 36 | hash, 37 | ...uris.map((e) => BytesUtils.toHexString(StringUtils.encode(e))) 38 | ]); 39 | 40 | /// To Transaction output 41 | @override 42 | TxOutput get toOutput => TxOutput(amount: BigInt.zero, scriptPubKey: script); 43 | 44 | /// output value. always zero 45 | @override 46 | final BigInt value = BigInt.zero; 47 | 48 | @override 49 | CashToken? get token => null; 50 | } 51 | -------------------------------------------------------------------------------- /lib/src/bitcoin_cash/bitcoin_cash.dart: -------------------------------------------------------------------------------- 1 | export 'bcmr.dart'; 2 | export 'bcmr_registery.dart'; 3 | -------------------------------------------------------------------------------- /lib/src/crypto/crypto.dart: -------------------------------------------------------------------------------- 1 | export 'keypair/ec_private.dart'; 2 | export 'keypair/ec_public.dart'; 3 | export 'musig/signer.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/exception/exception.dart: -------------------------------------------------------------------------------- 1 | import 'package:blockchain_utils/blockchain_utils.dart'; 2 | 3 | class DartBitcoinPluginException extends BlockchainUtilsException { 4 | const DartBitcoinPluginException(super.message, {super.details}); 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/provider/api_provider.dart: -------------------------------------------------------------------------------- 1 | export 'models/models.dart'; 2 | export 'providers/explorer.dart'; 3 | export 'providers/electrum.dart'; 4 | export 'electrum_methods/methods.dart'; 5 | export 'services/electrum.dart'; 6 | export 'services/explorer.dart'; 7 | export 'core/methods.dart'; 8 | export 'core/params.dart'; 9 | -------------------------------------------------------------------------------- /lib/src/provider/constant/constant.dart: -------------------------------------------------------------------------------- 1 | class BtcApiConst { 2 | static const String blockCypherBaseURL = 3 | 'https://api.blockcypher.com/v1/btc/test3'; 4 | static const String mempoolBaseURL = 'https://mempool.space/testnet/api'; 5 | static const String mempoolTestnet4BaseURL = 6 | 'https://mempool.space/testnet4/api'; 7 | static const String blockstreamBaseURL = 8 | 'https://blockstream.info/testnet/api'; 9 | static const String blockCypherMainBaseURL = 10 | 'https://api.blockcypher.com/v1/btc/main'; 11 | static const String mempoolMainBaseURL = 'https://mempool.space/api'; 12 | static const String blockstreamMainBaseURL = 'https://blockstream.info/api'; 13 | // 14 | static const String blockCypherDashBaseUri = 15 | 'https://api.blockcypher.com/v1/dash/main'; 16 | static const String blockCypherDogeBaseUri = 17 | 'https://api.blockcypher.com/v1/doge/main'; 18 | static const String blockCypherLitecoinBaseUri = 19 | 'https://api.blockcypher.com/v1/ltc/main'; 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/provider/core/params.dart: -------------------------------------------------------------------------------- 1 | import 'package:blockchain_utils/blockchain_utils.dart'; 2 | 3 | /// Represents details of an Electrum request, including id, method, and parameters. 4 | class ElectrumRequestDetails extends BaseServiceRequestParams { 5 | const ElectrumRequestDetails( 6 | {required super.requestID, 7 | this.path, 8 | required this.method, 9 | required this.params, 10 | required super.type, 11 | super.headers = ServiceConst.defaultPostHeaders}); 12 | 13 | final String? path; 14 | final String method; 15 | final Map params; 16 | 17 | List toTCPParams() { 18 | final param = '${StringUtils.fromJson(params)}\n'; 19 | return StringUtils.encode(param); 20 | } 21 | 22 | List toWebSocketParams() { 23 | return StringUtils.encode(StringUtils.fromJson(params)); 24 | } 25 | 26 | @override 27 | List? body() { 28 | return toWebSocketParams(); 29 | } 30 | 31 | @override 32 | Map toJson() { 33 | return { 34 | 'method': method, 35 | 'body': params, 36 | }; 37 | } 38 | 39 | @override 40 | Uri toUri(String uri) { 41 | return Uri.parse(uri); 42 | } 43 | } 44 | 45 | /// Abstract class representing an Electrum request with generic result and response types. 46 | abstract class ElectrumRequest 47 | extends BaseServiceRequest { 48 | abstract final String method; 49 | List toJson(); 50 | 51 | @override 52 | ElectrumRequestDetails buildRequest(int requestID) { 53 | final inJson = toJson(); 54 | inJson.removeWhere((v) => v == null); 55 | final params = ServiceProviderUtils.buildJsonRPCParams( 56 | requestId: requestID, method: method, params: inJson); 57 | return ElectrumRequestDetails( 58 | requestID: requestID, 59 | params: params, 60 | method: method, 61 | type: RequestServiceType.post); 62 | } 63 | 64 | @override 65 | RequestServiceType get requestType => RequestServiceType.post; 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods.dart: -------------------------------------------------------------------------------- 1 | export 'methods/broad_cast.dart'; 2 | export 'methods/estimate_fee.dart'; 3 | export 'methods/get_transaction.dart'; 4 | export 'methods/get_unspet.dart'; 5 | export 'methods/get_balance.dart'; 6 | export 'methods/server_banner.dart'; 7 | export 'methods/server_features.dart'; 8 | export 'methods/header.dart'; 9 | export 'methods/headers_subscribe.dart'; 10 | export 'methods/add_peer.dart'; 11 | export 'methods/block_headers.dart'; 12 | export 'methods/donate_address.dart'; 13 | export 'methods/electrum_version.dart'; 14 | export 'methods/get_fee_histogram.dart'; 15 | export 'methods/get_history.dart'; 16 | export 'methods/get_mempool.dart'; 17 | export 'methods/get_merkle.dart'; 18 | export 'methods/get_value_proof.dart'; 19 | export 'methods/id_from_pos.dart'; 20 | export 'methods/masternode_announce_broadcast.dart'; 21 | export 'methods/masternode_list.dart'; 22 | export 'methods/masternode_subscribe.dart'; 23 | export 'methods/ping.dart'; 24 | export 'methods/protx_diff.dart'; 25 | export 'methods/protx_info.dart'; 26 | export 'methods/relay_fee.dart'; 27 | export 'methods/scripthash_unsubscribe.dart'; 28 | export 'methods/server_peer_subscribe.dart'; 29 | export 'methods/script_hash_subscribe.dart'; 30 | export 'methods/get_raw_transaction.dart'; 31 | export 'methods/get_verbose_transaction.dart'; 32 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/add_peer.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// A newly-started server uses this call to get itself into other servers’ peers lists. 5 | /// It should not be used by wallet clients. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestAddPeer extends ElectrumRequest { 8 | ElectrumRequestAddPeer({required this.features}); 9 | 10 | /// The same information that a call to the sender’s server.features() RPC call would return. 11 | final Map features; 12 | 13 | /// server.add_peer 14 | @override 15 | String get method => ElectrumRequestMethods.serverAddPeer.method; 16 | 17 | @override 18 | List toJson() { 19 | return [features]; 20 | } 21 | 22 | /// A boolean indicating whether the request was tentatively accepted 23 | /// The requesting server will appear in server.peers.subscribe() when further sanity checks complete successfully. 24 | @override 25 | bool onResonse(result) { 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/block_headers.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a concatenated chunk of block headers from the main chain. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestBlockHeaders 7 | extends ElectrumRequest, Map> { 8 | ElectrumRequestBlockHeaders( 9 | {required this.startHeight, required this.count, required this.cpHeight}); 10 | 11 | /// The height of the first header requested, a non-negative integer. 12 | final int startHeight; 13 | 14 | /// The number of headers requested, a non-negative integer. 15 | final int count; 16 | 17 | /// Checkpoint height, a non-negative integer. Ignored if zero 18 | final int cpHeight; 19 | 20 | /// blockchain.block.headers 21 | @override 22 | String get method => ElectrumRequestMethods.blockHeaders.method; 23 | 24 | @override 25 | List toJson() { 26 | return [startHeight, count, cpHeight]; 27 | } 28 | 29 | /// A dictionary 30 | @override 31 | Map onResonse(result) { 32 | return result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/broad_cast.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Broadcast a transaction to the network. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestBroadCastTransaction 7 | extends ElectrumRequest { 8 | ElectrumRequestBroadCastTransaction({required this.transactionRaw}); 9 | 10 | /// The raw transaction as a hexadecimal string. 11 | final String transactionRaw; 12 | 13 | /// blockchain.transaction.broadcast 14 | @override 15 | String get method => ElectrumRequestMethods.broadCast.method; 16 | 17 | @override 18 | List toJson() { 19 | return [transactionRaw]; 20 | } 21 | 22 | /// The transaction hash as a hexadecimal string. 23 | @override 24 | String onResonse(result) { 25 | return result; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/donate_address.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a server donation address. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestDonationAddress extends ElectrumRequest { 7 | /// server.donation_address 8 | @override 9 | String get method => ElectrumRequestMethods.serverDontionAddress.method; 10 | 11 | @override 12 | List toJson() { 13 | return []; 14 | } 15 | 16 | @override 17 | String onResonse(result) { 18 | return result; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/electrum_version.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Identify the client to the server and negotiate the protocol version. Only the first server.version() message is accepted. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestVersion 7 | extends ElectrumRequest, List> { 8 | ElectrumRequestVersion( 9 | {required this.clientName, required this.protocolVersion}); 10 | 11 | /// A string identifying the connecting client software. 12 | final String clientName; 13 | 14 | /// An array [protocol_min, protocol_max], each of which is a string. 15 | final List protocolVersion; 16 | 17 | /// blockchain.version 18 | @override 19 | String get method => ElectrumRequestMethods.version.method; 20 | 21 | @override 22 | List toJson() { 23 | return [clientName, protocolVersion]; 24 | } 25 | 26 | /// identifying the server and the protocol version that will be used for future communication. 27 | @override 28 | List onResonse(result) { 29 | return List.from(result); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/estimate_fee.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | import 'package:bitcoin_base/src/utils/btc_utils.dart'; 4 | 5 | /// Return the estimated transaction fee per kilobyte for a transaction to be confirmed within a certain number of blocks. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestEstimateFee extends ElectrumRequest { 8 | ElectrumRequestEstimateFee({this.numberOfBlock = 2}); 9 | 10 | /// The number of blocks to target for confirmation. 11 | final int numberOfBlock; 12 | 13 | /// blockchain.estimatefee 14 | @override 15 | String get method => ElectrumRequestMethods.estimateFee.method; 16 | 17 | @override 18 | List toJson() { 19 | return [numberOfBlock]; 20 | } 21 | 22 | /// The estimated transaction fee in Bigint(satoshi) 23 | @override 24 | BigInt? onResonse(result) { 25 | final fee = BtcUtils.toSatoshi(result.toString()); 26 | if (fee.isNegative) return null; 27 | return fee; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_balance.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return the confirmed and unconfirmed balances of a script hash. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestGetScriptHashBalance 7 | extends ElectrumRequest, Map> { 8 | ElectrumRequestGetScriptHashBalance({required this.scriptHash}); 9 | 10 | /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 11 | final String scriptHash; 12 | 13 | /// blockchain.scripthash.get_balance 14 | @override 15 | String get method => ElectrumRequestMethods.getBalance.method; 16 | 17 | @override 18 | List toJson() { 19 | return [scriptHash]; 20 | } 21 | 22 | /// A dictionary with keys confirmed and unconfirmed. 23 | /// The value of each is the appropriate balance in minimum coin units (satoshis). 24 | @override 25 | Map onResonse(Map result) { 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_fee_histogram.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a histogram of the fee rates paid by transactions in the memory pool, weighted by transaction size. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestGetFeeHistogram 7 | extends ElectrumRequest>, List> { 8 | /// mempool.get_fee_histogram 9 | @override 10 | String get method => ElectrumRequestMethods.getFeeHistogram.method; 11 | 12 | @override 13 | List toJson() { 14 | return []; 15 | } 16 | 17 | /// The histogram is an array of [fee, vsize] pairs, where vsizen is the cumulative virtual size of mempool transactions with a fee rate in the interval [feen-1, feen], and feen-1 > feen. 18 | /// Fee intervals may have variable size. The choice of appropriate intervals is currently not part of the protocol. 19 | /// fee uses sat/vbyte as unit, and must be a non-negative integer or float. 20 | /// vsize uses vbyte as unit, and must be a non-negative integer. 21 | @override 22 | List> onResonse(result) { 23 | return result 24 | .map((e) => (e as List).map((e) => (e as num).toDouble()).toList()) 25 | .toList(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_history.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return the confirmed and unconfirmed history of a script hash. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestScriptHashGetHistory 7 | extends ElectrumRequest>, List> { 8 | ElectrumRequestScriptHashGetHistory({required this.scriptHash}); 9 | 10 | /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 11 | final String scriptHash; 12 | 13 | /// blockchain.scripthash.get_history 14 | @override 15 | String get method => ElectrumRequestMethods.getHistory.method; 16 | 17 | @override 18 | List toJson() { 19 | return [scriptHash]; 20 | } 21 | 22 | /// A list of confirmed transactions in blockchain order, 23 | /// with the output of blockchain.scripthash.get_mempool() appended to the list. 24 | /// Each confirmed transaction is a dictionary 25 | @override 26 | List> onResonse(List result) { 27 | return result.map((e) => Map.from(e)).toList(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_mempool.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return the unconfirmed transactions of a script hash. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestScriptHashGetMempool 7 | extends ElectrumRequest>, List> { 8 | ElectrumRequestScriptHashGetMempool({required this.scriptHash}); 9 | 10 | /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 11 | final String scriptHash; 12 | 13 | /// blockchain.scripthash.get_mempool 14 | @override 15 | String get method => ElectrumRequestMethods.getMempool.method; 16 | 17 | @override 18 | List toJson() { 19 | return [scriptHash]; 20 | } 21 | 22 | /// A list of mempool transactions in arbitrary order. Each mempool transaction is a dictionary 23 | @override 24 | List> onResonse(List result) { 25 | return result.map((e) => Map.from(e)).toList(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_merkle.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | import 'package:bitcoin_base/src/provider/models/electrum/models.dart'; 4 | 5 | /// Return the merkle branch to a confirmed transaction given its hash and height. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestGetMerkle 8 | extends ElectrumRequest> { 9 | ElectrumRequestGetMerkle( 10 | {required this.transactionHash, required this.height}); 11 | 12 | /// The transaction hash as a hexadecimal string. 13 | final String transactionHash; 14 | 15 | /// he height at which it was confirmed. 16 | final int height; 17 | 18 | /// blockchain.transaction.get_merkle 19 | @override 20 | String get method => ElectrumRequestMethods.getMerkle.method; 21 | 22 | @override 23 | List toJson() { 24 | return [transactionHash, height]; 25 | } 26 | 27 | @override 28 | ElectrumGetMerkleResponse onResonse(result) { 29 | return ElectrumGetMerkleResponse.fromJson(result); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_raw_transaction.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/bitcoin/script/transaction.dart'; 2 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 3 | import 'package:bitcoin_base/src/provider/core/params.dart'; 4 | import 'package:blockchain_utils/utils/binary/utils.dart'; 5 | 6 | /// Return a raw transaction. 7 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 8 | class ElectrumRequestGetRawTransaction 9 | extends ElectrumRequest { 10 | ElectrumRequestGetRawTransaction(this.transactionHash); 11 | 12 | /// The transaction hash as a hexadecimal string. 13 | final String transactionHash; 14 | 15 | /// blockchain.transaction.get 16 | @override 17 | String get method => ElectrumRequestMethods.getTransaction.method; 18 | 19 | @override 20 | List toJson() { 21 | return [transactionHash, false]; 22 | } 23 | 24 | @override 25 | BtcTransaction onResonse(String result) { 26 | final txBytes = BytesUtils.fromHexString(result); 27 | final tx = BtcTransaction.deserialize(txBytes); 28 | assert(BytesUtils.bytesEqual(tx.toBytes(), txBytes), result); 29 | return tx; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_transaction.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a raw transaction. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestGetTransaction extends ElectrumRequest { 7 | ElectrumRequestGetTransaction( 8 | {required this.transactionHash, this.verbose = false}); 9 | 10 | /// The transaction hash as a hexadecimal string. 11 | final String transactionHash; 12 | 13 | /// Whether a verbose coin-specific response is required. 14 | final bool verbose; 15 | 16 | /// blockchain.transaction.get 17 | @override 18 | String get method => ElectrumRequestMethods.getTransaction.method; 19 | 20 | @override 21 | List toJson() { 22 | return [transactionHash, verbose]; 23 | } 24 | 25 | /// If verbose is false: 26 | /// The raw transaction as a hexadecimal string. 27 | /// 28 | /// If verbose is true: 29 | /// The result is a coin-specific dictionary – whatever the coin daemon returns when asked for a verbose form of the raw transaction. 30 | @override 31 | dynamic onResonse(result) { 32 | return result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_unspet.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/models/electrum/models.dart'; 2 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 3 | import 'package:bitcoin_base/src/provider/core/params.dart'; 4 | 5 | /// Return an ordered list of UTXOs sent to a script hash. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestScriptHashListUnspent 8 | extends ElectrumRequest, List> { 9 | ElectrumRequestScriptHashListUnspent( 10 | {required this.scriptHash, this.includeTokens = false}); 11 | 12 | /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 13 | final String scriptHash; 14 | 15 | /// only work in bitcoin cash network 16 | final bool includeTokens; 17 | 18 | /// blockchain.scripthash.listunspent 19 | @override 20 | String get method => ElectrumRequestMethods.listunspent.method; 21 | 22 | @override 23 | List toJson() { 24 | return [scriptHash, if (includeTokens) 'include_tokens']; 25 | } 26 | 27 | /// A list of unspent outputs in blockchain order. 28 | /// This function takes the mempool into account. 29 | /// Mempool transactions paying to the address are included at the end of the list in an undefined order. 30 | /// Any output that is spent in the mempool does not appear. 31 | @override 32 | List onResonse(result) { 33 | final utxos = result.map((e) => ElectrumUtxo.fromJson(e)).toList(); 34 | return utxos; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_value_proof.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Returns a name resolution proof, suitable for low-latency (single round-trip) resolution. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestGetValueProof 7 | extends ElectrumRequest, dynamic> { 8 | ElectrumRequestGetValueProof( 9 | {required this.scriptHash, required this.cpHeight}); 10 | 11 | /// Script hash of the name being resolved. 12 | final String scriptHash; 13 | 14 | /// Checkpoint height. 15 | final int cpHeight; 16 | 17 | /// blockchain.name.get_value_proof 18 | @override 19 | String get method => ElectrumRequestMethods.getValueProof.method; 20 | 21 | @override 22 | List toJson() { 23 | return [scriptHash, cpHeight]; 24 | } 25 | 26 | /// A dictionary with transaction and proof data for each transaction associated with the name, 27 | /// from the most recent update back to either the registration transaction or a 28 | /// checkpointed transaction (whichever is later). 29 | @override 30 | Map onResonse(result) { 31 | return Map.from(result); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/get_verbose_transaction.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | import 'package:bitcoin_base/src/provider/models/electrum/models.dart'; 4 | 5 | /// Return a raw transaction. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestGetVerboseTransaction 8 | extends ElectrumRequest> { 9 | ElectrumRequestGetVerboseTransaction(this.transactionHash); 10 | 11 | /// The transaction hash as a hexadecimal string. 12 | final String transactionHash; 13 | 14 | /// blockchain.transaction.get 15 | @override 16 | String get method => ElectrumRequestMethods.getTransaction.method; 17 | 18 | @override 19 | List toJson() { 20 | return [transactionHash, true]; 21 | } 22 | 23 | /// If verbose is false: 24 | /// The raw transaction as a hexadecimal string. 25 | /// 26 | /// If verbose is true: 27 | /// The result is a coin-specific dictionary – whatever the coin daemon returns when asked for a verbose form of the raw transaction. 28 | @override 29 | ElectrumVerbosTxResponse onResonse(result) { 30 | return ElectrumVerbosTxResponse.fromJson(result); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/header.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return the block header at the given height. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestBlockHeader extends ElectrumRequest { 7 | ElectrumRequestBlockHeader( 8 | {required this.startHeight, required this.cpHeight}); 9 | final int startHeight; 10 | final int cpHeight; 11 | 12 | /// blockchain.block.header 13 | @override 14 | String get method => ElectrumRequestMethods.blockHeader.method; 15 | 16 | @override 17 | List toJson() { 18 | return [startHeight, cpHeight]; 19 | } 20 | 21 | /// If cp_height is zero, the raw block header as a hexadecimal string. 22 | 23 | /// Otherwise a dictionary with the following keys. 24 | /// This provides a proof that the given header is present in the blockchain; 25 | /// presumably the client has the merkle root hard-coded as a checkpoint. 26 | @override 27 | dynamic onResonse(result) { 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/headers_subscribe.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | import 'package:bitcoin_base/src/provider/models/electrum/models.dart'; 4 | 5 | /// Subscribe to receive block headers when a new block is found. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestHeaderSubscribe extends ElectrumRequest< 8 | ElectrumHeaderSubscribeResponse, Map> { 9 | @override 10 | String get method => ElectrumRequestMethods.headersSubscribe.method; 11 | 12 | @override 13 | List toJson() { 14 | return []; 15 | } 16 | 17 | /// The header of the current block chain tip. 18 | @override 19 | ElectrumHeaderSubscribeResponse onResonse(result) { 20 | return ElectrumHeaderSubscribeResponse.fromJson(result); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/id_from_pos.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a transaction hash and optionally a merkle proof, given a block height and a position in the block. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestIdFromPos extends ElectrumRequest { 7 | ElectrumRequestIdFromPos( 8 | {required this.height, required this.txPos, this.merkle = false}); 9 | 10 | /// The main chain block height, a non-negative integer. 11 | final int height; 12 | 13 | /// A zero-based index of the transaction in the given block, an integer. 14 | final int txPos; 15 | 16 | /// Whether a merkle proof should also be returned, a boolean. 17 | final bool merkle; 18 | 19 | /// blockchain.transaction.id_from_pos 20 | @override 21 | String get method => ElectrumRequestMethods.idFromPos.method; 22 | 23 | @override 24 | List toJson() { 25 | return [height, txPos, merkle]; 26 | } 27 | 28 | /// If merkle is false, the transaction hash as a hexadecimal string. If true, a dictionary 29 | @override 30 | dynamic onResonse(result) { 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/masternode_announce_broadcast.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Pass through the masternode announce message to be broadcast by the daemon. 5 | /// Whenever a masternode comes online or a client is syncing, 6 | /// they will send this message which describes the masternode entry and how to validate messages from it. 7 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 8 | class ElectrumRequestMasternodeAnnounceBroadcast 9 | extends ElectrumRequest { 10 | ElectrumRequestMasternodeAnnounceBroadcast({required this.signmnb}); 11 | final String signmnb; 12 | 13 | /// masternode.announce.broadcast 14 | @override 15 | String get method => 16 | ElectrumRequestMethods.masternodeAnnounceBroadcast.method; 17 | 18 | @override 19 | List toJson() { 20 | return [signmnb]; 21 | } 22 | 23 | /// true if the message was broadcasted successfully otherwise false. 24 | @override 25 | bool onResonse(result) { 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/masternode_list.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Returns the list of masternodes. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestMasternodeList 7 | extends ElectrumRequest, List> { 8 | ElectrumRequestMasternodeList({required this.payees}); 9 | 10 | /// An array of masternode payee addresses. 11 | final List payees; 12 | 13 | /// masternode.list 14 | @override 15 | String get method => ElectrumRequestMethods.masternodeList.method; 16 | 17 | @override 18 | List toJson() { 19 | return [payees]; 20 | } 21 | 22 | /// An array with the masternodes information. 23 | @override 24 | List onResonse(result) { 25 | return List.from(result); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/masternode_subscribe.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Returns the status of masternode. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestMasternodeSubscribe 7 | extends ElectrumRequest { 8 | ElectrumRequestMasternodeSubscribe({required this.collateral}); 9 | 10 | /// The txId and the index of the collateral. Example ("8c59133e714797650cf69043d05e409bbf45670eed7c4e4a386e52c46f1b5e24-0") 11 | final String collateral; 12 | 13 | /// masternode.subscribe 14 | @override 15 | String get method => ElectrumRequestMethods.masternodeSubscribe.method; 16 | 17 | @override 18 | List toJson() { 19 | return [collateral]; 20 | } 21 | 22 | /// As this is a subscription, the client will receive a notification when the masternode status changes. 23 | /// The status depends on the server the masternode is hosted, 24 | /// the internet connection, the offline time and even the collateral 25 | /// amount, so this subscription notice these changes to the user. 26 | @override 27 | String onResonse(result) { 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/ping.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Ping the server to ensure it is responding, and to keep the session alive. The server may disconnect clients that have sent no requests for roughly 10 minutes. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestPing extends ElectrumRequest { 7 | @override 8 | String get method => ElectrumRequestMethods.ping.method; 9 | 10 | @override 11 | List toJson() { 12 | return []; 13 | } 14 | 15 | @override 16 | dynamic onResonse(result) { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/protx_diff.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Returns a diff between two deterministic masternode lists. The result also contains proof data.. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestProtXDiff 7 | extends ElectrumRequest, dynamic> { 8 | ElectrumRequestProtXDiff({required this.baseHeight, required this.height}); 9 | 10 | /// The starting block height 11 | final int baseHeight; 12 | 13 | /// The ending block height. 14 | final int height; 15 | 16 | /// protx.diff 17 | @override 18 | String get method => ElectrumRequestMethods.protxDiff.method; 19 | 20 | @override 21 | List toJson() { 22 | return [baseHeight, height]; 23 | } 24 | 25 | /// A dictionary with deterministic masternode lists diff plus proof data. 26 | @override 27 | Map onResonse(result) { 28 | return Map.from(result); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/protx_info.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Returns detailed information about a deterministic masternode. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestProtXInfo 7 | extends ElectrumRequest, dynamic> { 8 | ElectrumRequestProtXInfo({required this.protxHash}); 9 | 10 | /// The hash of the initial ProRegTx 11 | final String protxHash; 12 | 13 | /// protx.info 14 | @override 15 | String get method => ElectrumRequestMethods.protxInfo.method; 16 | 17 | @override 18 | List toJson() { 19 | return [protxHash]; 20 | } 21 | 22 | /// A dictionary with detailed deterministic masternode data 23 | @override 24 | Map onResonse(result) { 25 | return Map.from(result); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/relay_fee.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | import 'package:bitcoin_base/src/utils/btc_utils.dart'; 4 | 5 | /// Return the minimum fee a low-priority transaction must pay in order to be accepted to the daemon’s memory pool. 6 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 7 | class ElectrumRequestRelayFee extends ElectrumRequest { 8 | /// blockchain.relayfee 9 | @override 10 | String get method => ElectrumRequestMethods.relayFee.method; 11 | 12 | @override 13 | List toJson() { 14 | return []; 15 | } 16 | 17 | /// relay fee in Bigint(satoshi) 18 | @override 19 | BigInt onResonse(result) { 20 | return BtcUtils.toSatoshi(result.toString()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/script_hash_subscribe.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Subscribe to a script hash. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestScriptHashSubscribe 7 | extends ElectrumRequest { 8 | ElectrumRequestScriptHashSubscribe({required this.scriptHash}); 9 | 10 | /// /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 11 | final String scriptHash; 12 | 13 | /// blockchain.scripthash.subscribe 14 | @override 15 | String get method => ElectrumRequestMethods.scriptHashSubscribe.method; 16 | 17 | @override 18 | List toJson() { 19 | return [scriptHash]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/scripthash_unsubscribe.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Unsubscribe from a script hash, preventing future notifications if its status changes. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestScriptHashUnSubscribe extends ElectrumRequest { 7 | ElectrumRequestScriptHashUnSubscribe({required this.scriptHash}); 8 | 9 | /// The script hash as a hexadecimal string (BitcoinBaseAddress.pubKeyHash()) 10 | final String scriptHash; 11 | 12 | /// blockchain.scripthash.unsubscribe 13 | @override 14 | String get method => ElectrumRequestMethods.scriptHashUnSubscribe.method; 15 | 16 | @override 17 | List toJson() { 18 | return [scriptHash]; 19 | } 20 | 21 | /// Returns True if the scripthash was subscribed to, 22 | /// otherwise False. Note that False might be returned even 23 | /// for something subscribed to earlier, because the server can drop subscriptions in rare circumstances. 24 | @override 25 | bool onResonse(result) { 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/server_banner.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a banner to be shown in the Electrum console. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestServerBanner extends ElectrumRequest { 7 | @override 8 | String get method => ElectrumRequestMethods.serverBanner.method; 9 | 10 | @override 11 | List toJson() { 12 | return []; 13 | } 14 | 15 | @override 16 | String onResonse(result) { 17 | return result.toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/server_features.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a list of features and services supported by the server. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestServerFeatures extends ElectrumRequest { 7 | /// server.features 8 | @override 9 | String get method => ElectrumRequestMethods.serverFeatures.method; 10 | 11 | @override 12 | List toJson() { 13 | return []; 14 | } 15 | 16 | /// A dictionary of keys and values. Each key represents a feature or service of the server, 17 | /// and the value gives additional information. 18 | @override 19 | dynamic onResonse(result) { 20 | return result; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/provider/electrum_methods/methods/server_peer_subscribe.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/methods.dart'; 2 | import 'package:bitcoin_base/src/provider/core/params.dart'; 3 | 4 | /// Return a list of peer servers. Despite the name this is not a subscription and the server must send no notifications.. 5 | /// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html 6 | class ElectrumRequestServerPeersSubscribe 7 | extends ElectrumRequest, List> { 8 | /// server.peers.subscribe 9 | @override 10 | String get method => ElectrumRequestMethods.serverPeersSubscribe.method; 11 | 12 | @override 13 | List toJson() { 14 | return []; 15 | } 16 | 17 | /// An array of peer servers, each returned as a 3-element array 18 | @override 19 | List onResonse(result) { 20 | return result; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/provider/models/fee_rate/fee_rate.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/exception/exception.dart'; 2 | 3 | enum BitcoinFeeRateType { low, medium, high } 4 | 5 | class BitcoinFeeRate { 6 | BitcoinFeeRate( 7 | {required this.high, 8 | required this.medium, 9 | required this.low, 10 | this.economyFee, 11 | this.hourFee}); 12 | 13 | /// High fee rate in satoshis per kilobyte 14 | final BigInt high; 15 | 16 | /// Medium fee rate in satoshis per kilobyte 17 | final BigInt medium; 18 | 19 | /// low fee rate in satoshis per kilobyte 20 | final BigInt low; 21 | 22 | /// only mnenpool api 23 | final BigInt? economyFee; 24 | 25 | /// only mnenpool api 26 | final BigInt? hourFee; 27 | 28 | BigInt _feeRatrete(BitcoinFeeRateType feeRateType) { 29 | switch (feeRateType) { 30 | case BitcoinFeeRateType.low: 31 | return low; 32 | case BitcoinFeeRateType.medium: 33 | return medium; 34 | default: 35 | return high; 36 | } 37 | } 38 | 39 | /// GetEstimate calculates the estimated fee in satoshis for a given transaction size 40 | /// and fee rate (in satoshis per kilobyte) using the formula: 41 | // 42 | /// EstimatedFee = (TransactionSize * FeeRate) / 1024 43 | // 44 | /// Parameters: 45 | /// - trSize: An integer representing the transaction size in bytes. 46 | /// - feeRate: A BigInt representing the fee rate in satoshis per kilobyte. 47 | // 48 | /// Returns: 49 | /// - BigInt: A BigInt containing the estimated fee in satoshis. 50 | BigInt getEstimate(int trSize, 51 | {BigInt? customFeeRatePerKb, 52 | BitcoinFeeRateType feeRateType = BitcoinFeeRateType.medium}) { 53 | final feeRate = customFeeRatePerKb ?? _feeRatrete(feeRateType); 54 | final trSizeBigInt = BigInt.from(trSize); 55 | return (trSizeBigInt * feeRate) ~/ BigInt.from(1000); 56 | } 57 | 58 | @override 59 | String toString() { 60 | return 'high: ${high.toString()} medium: ${medium.toString()} low: ${low.toString()}, economyFee: $economyFee hourFee: $hourFee'; 61 | } 62 | 63 | /// NewBitcoinFeeRateFromMempool creates a BitcoinFeeRate structure from JSON data retrieved 64 | /// from a mempool API response. The function parses the JSON map and extracts fee rate 65 | /// information for high, medium, and low fee levels. 66 | factory BitcoinFeeRate.fromMempool(Map json) { 67 | return BitcoinFeeRate( 68 | high: _parseMempoolFees(json['fastestFee']), 69 | medium: _parseMempoolFees(json['halfHourFee']), 70 | low: _parseMempoolFees(json['minimumFee']), 71 | economyFee: json['economyFee'] == null 72 | ? null 73 | : _parseMempoolFees(json['economyFee']), 74 | hourFee: 75 | json['hourFee'] == null ? null : _parseMempoolFees(json['hourFee']), 76 | ); 77 | } 78 | 79 | /// NewBitcoinFeeRateFromBlockCypher creates a BitcoinFeeRate structure from JSON data retrieved 80 | /// from a BlockCypher API response. The function parses the JSON map and extracts fee rate 81 | /// information for high, medium, and low fee levels. 82 | factory BitcoinFeeRate.fromBlockCypher(Map json) { 83 | return BitcoinFeeRate( 84 | high: BigInt.from((json['high_fee_per_kb'] as int)), 85 | medium: BigInt.from((json['medium_fee_per_kb'] as int)), 86 | low: BigInt.from((json['low_fee_per_kb'] as int))); 87 | } 88 | } 89 | 90 | /// ParseMempoolFees takes a data dynamic and converts it to a BigInt representing 91 | /// mempool fees in satoshis per kilobyte (sat/KB). The function performs the conversion 92 | /// based on the type of the input data, which can be either a double (floating-point 93 | /// fee rate) or an int (integer fee rate in satoshis per byte). 94 | BigInt _parseMempoolFees(dynamic data) { 95 | const kb = 1024; 96 | 97 | if (data is double) { 98 | return BigInt.from((data * kb).toInt()); 99 | } else if (data is int) { 100 | return BigInt.from((data * kb)); 101 | } else { 102 | throw DartBitcoinPluginException( 103 | 'cannot parse mempool fees expected double, string got ${data.runtimeType}'); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /lib/src/provider/models/models.dart: -------------------------------------------------------------------------------- 1 | export 'block_cypher/block_cypher_models.dart'; 2 | export 'fee_rate/fee_rate.dart'; 3 | export 'mempool/mempol_models.dart'; 4 | export 'config.dart'; 5 | export 'utxo_details.dart'; 6 | export 'multisig_script.dart'; 7 | export 'electrum/models.dart'; 8 | -------------------------------------------------------------------------------- /lib/src/provider/providers/electrum.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/params.dart'; 2 | import 'package:bitcoin_base/src/provider/services/electrum.dart'; 3 | import 'package:blockchain_utils/blockchain_utils.dart'; 4 | import 'dart:async'; 5 | 6 | class ElectrumProvider extends BaseProvider { 7 | final ElectrumServiceProvider rpc; 8 | ElectrumProvider(this.rpc); 9 | 10 | /// The unique identifier for each JSON-RPC request. 11 | int _id = 0; 12 | 13 | /// Sends a request to the Electrum server using the specified [request] parameter. 14 | /// 15 | /// The [timeout] parameter, if provided, sets the maximum duration for the request. 16 | @override 17 | Future request( 18 | BaseServiceRequest 19 | request, 20 | {Duration? timeout}) async { 21 | final r = await requestDynamic(request, timeout: timeout); 22 | return request.onResonse(r); 23 | } 24 | 25 | /// Sends a request to the Electrum server using the specified [request] parameter. 26 | /// 27 | /// The [timeout] parameter, if provided, sets the maximum duration for the request. 28 | @override 29 | Future requestDynamic( 30 | BaseServiceRequest 31 | request, 32 | {Duration? timeout}) async { 33 | final params = request.buildRequest(_id++); 34 | final response = 35 | await rpc.doRequest>(params, timeout: timeout); 36 | return _findResult(params: params, response: response); 37 | } 38 | 39 | SERVICERESPONSE _findResult( 40 | {required BaseServiceResponse> response, 41 | required ElectrumRequestDetails params}) { 42 | final data = response.getResult(params); 43 | final error = data['error']; 44 | if (error != null) { 45 | final errorJson = StringUtils.tryToJson>(error); 46 | final code = IntUtils.tryParse(errorJson?['code']); 47 | final message = errorJson?['message']?.toString(); 48 | throw RPCError( 49 | errorCode: code, 50 | message: message ?? error.toString(), 51 | request: params.toJson(), 52 | details: errorJson); 53 | } 54 | return ServiceProviderUtils.parseResponse( 55 | object: data['result'], params: params); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/provider/services/electrum.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/provider/core/params.dart'; 2 | import 'package:blockchain_utils/service/models/params.dart'; 3 | 4 | /// A mixin defining the service provider contract for interacting with the bitcoin (elctrum) network. 5 | mixin ElectrumServiceProvider 6 | implements BaseServiceProvider { 7 | @override 8 | Future> doRequest(ElectrumRequestDetails params, 9 | {Duration? timeout}); 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/provider/services/explorer.dart: -------------------------------------------------------------------------------- 1 | /// The [ApiService] abstract class defines a contract for making HTTP requests. 2 | abstract class ApiService { 3 | /// Performs an HTTP GET request to the specified [url]. 4 | /// 5 | /// The type parameter [T] specifies the expected response type. 6 | Future get(String url); 7 | 8 | /// Performs an HTTP POST request to the specified [url]. 9 | /// 10 | /// The type parameter [T] specifies the expected response type. 11 | /// 12 | /// Optional parameters: 13 | /// - [headers]: A map of headers to be included in the request. 14 | /// - [body]: The request body, typically in JSON format. 15 | Future post(String url, 16 | {Map headers = const {'Content-Type': 'application/json'}, 17 | Object? body}); 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/psbt/psbt.dart: -------------------------------------------------------------------------------- 1 | export 'types/types/global.dart'; 2 | export 'types/types/inputs.dart'; 3 | export 'types/types/outputs.dart'; 4 | export 'psbt_builder/builder.dart'; 5 | export 'types/types/psbt.dart'; 6 | export 'utils/utils.dart'; 7 | export 'signer/signer.dart'; 8 | -------------------------------------------------------------------------------- /lib/src/psbt/psbt_builder/builder.dart: -------------------------------------------------------------------------------- 1 | export 'types/types.dart'; 2 | import 'package:bitcoin_base/src/bitcoin/script/scripts.dart'; 3 | import 'package:bitcoin_base/src/exception/exception.dart'; 4 | import 'package:bitcoin_base/src/psbt/types/types/global.dart'; 5 | import 'package:bitcoin_base/src/psbt/types/types/inputs.dart'; 6 | import 'package:bitcoin_base/src/psbt/types/types/outputs.dart'; 7 | import 'package:bitcoin_base/src/psbt/psbt_builder/types/types.dart'; 8 | import 'package:bitcoin_base/src/psbt/types/types/psbt.dart'; 9 | import 'package:bitcoin_base/src/psbt/utils/utils.dart'; 10 | import 'package:blockchain_utils/blockchain_utils.dart'; 11 | part 'core/psbt_builder.dart'; 12 | part 'versiones/v1.dart'; 13 | part 'versiones/v2.dart'; 14 | part 'impl/signer.dart'; 15 | part 'impl/input.dart'; 16 | part 'impl/output.dart'; 17 | -------------------------------------------------------------------------------- /lib/src/psbt/psbt_builder/impl/output.dart: -------------------------------------------------------------------------------- 1 | part of 'package:bitcoin_base/src/psbt/psbt_builder/builder.dart'; 2 | 3 | mixin PsbtOutputImpl on PsbtBuilderImpl { 4 | /// Adds a new transaction output to the PSBT. 5 | /// 6 | /// This method appends the given `PsbtTransactionOutput` to the transaction. 7 | /// 8 | /// Note: If any existing input contains a signature with an unmodifiable 9 | /// sighash (e.g., `SIGHASH_ALL`), or if an input is already finalized with 10 | /// an unmodifiable sighash, this operation will result in an error. 11 | void addOutput(PsbtTransactionOutput output) { 12 | _addNewTxOutput(output); 13 | } 14 | 15 | /// Updates an existing transaction output in the PSBT. 16 | /// 17 | /// Replaces the output at the specified index with a new `PsbtTransactionOutput`. 18 | /// 19 | /// Note: If any existing input contains a signature with an unmodifiable 20 | /// sighash (e.g., `SIGHASH_ALL`), or if an input is already finalized with 21 | /// an unmodifiable sighash, this operation will result in an error. 22 | void updateOutput(int index, PsbtTransactionOutput output) { 23 | _updateTxOutput(index, output); 24 | } 25 | 26 | /// Removes a transaction output from the PSBT. 27 | /// 28 | /// Deletes the output at the specified index. 29 | /// 30 | /// Note: If any existing input contains a signature with an unmodifiable 31 | /// sighash (e.g., `SIGHASH_ALL`), or if an input is already finalized with 32 | /// an unmodifiable sighash, this operation will result in an error. 33 | void removeOutput(int index) { 34 | _removeOutput(index); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/psbt/reader/byte_reader.dart: -------------------------------------------------------------------------------- 1 | import 'package:blockchain_utils/blockchain_utils.dart'; 2 | 3 | class PsbtByteReader { 4 | final List bytes; 5 | PsbtByteReader(List bytes) : bytes = bytes.immutable; 6 | int _offset = 0; 7 | int get offset => _offset; 8 | int get length => bytes.length; 9 | List read(int length) { 10 | final bytes = this.bytes.sublist(_offset, _offset + length); 11 | _offset += length; 12 | return bytes; 13 | } 14 | 15 | void skip(int length) { 16 | assert(_offset + 1 <= bytes.length); 17 | _offset += length; 18 | } 19 | 20 | int at() { 21 | return bytes[_offset]; 22 | } 23 | 24 | int readLength() { 25 | final length = IntUtils.decodeVarint(bytes.sublist(_offset)); 26 | _offset += length.item2; 27 | return length.item1; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/psbt/types/types.dart: -------------------------------------------------------------------------------- 1 | export 'types/global.dart'; 2 | export 'types/inputs.dart'; 3 | export 'types/outputs.dart'; 4 | export 'types/psbt.dart'; 5 | export 'types/types.dart'; 6 | -------------------------------------------------------------------------------- /lib/src/psbt/types/types/types.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/bitcoin/script/script.dart'; 2 | import 'package:blockchain_utils/blockchain_utils.dart'; 3 | 4 | class PsbtTapTree { 5 | final int depth; 6 | final int leafVersion; 7 | final Script script; 8 | PsbtTapTree( 9 | {required int depth, required int leafVersion, required this.script}) 10 | : depth = depth.asUint8, 11 | leafVersion = leafVersion.asUint8; 12 | List serialize() { 13 | final scriptBytes = IntUtils.prependVarint(script.toBytes()); 14 | return [depth, leafVersion, ...scriptBytes]; 15 | } 16 | 17 | Map toJson() { 18 | return { 19 | "depth": depth, 20 | "leafVersion": leafVersion, 21 | "script": script.toJson() 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/transaction_builder/builder.dart: -------------------------------------------------------------------------------- 1 | export 'forked_transaction_builder.dart'; 2 | export 'core.dart'; 3 | export 'transaction_builder.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/transaction_builder/core.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/bitcoin/script/scripts.dart'; 2 | import 'package:bitcoin_base/src/provider/models/utxo_details.dart'; 3 | 4 | typedef BitcoinSignerCallBack = String Function( 5 | List trDigest, UtxoWithAddress utxo, String publicKey, int sighash); 6 | typedef BitcoinSignerCallBackAsync = Future Function( 7 | List trDigest, UtxoWithAddress utxo, String publicKey, int sighash); 8 | 9 | abstract class BasedBitcoinTransacationBuilder { 10 | BtcTransaction buildTransaction(BitcoinSignerCallBack sign); 11 | Future buildTransactionAsync(BitcoinSignerCallBackAsync sign); 12 | 13 | /// how many signature we need for each publicKey (utxo) 14 | Map getSignatureCount(); 15 | } 16 | 17 | enum BitcoinOrdering { bip69, shuffle, none } 18 | -------------------------------------------------------------------------------- /lib/src/utils/btc_utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:bitcoin_base/src/crypto/keypair/ec_public.dart'; 2 | import 'package:bitcoin_base/src/exception/exception.dart'; 3 | import 'package:blockchain_utils/bip/ecc/keys/ecdsa_keys.dart'; 4 | import 'package:blockchain_utils/utils/numbers/rational/big_rational.dart'; 5 | import 'package:blockchain_utils/utils/string/string.dart'; 6 | 7 | class BtcUtils { 8 | static PublicKeyType determinatePubKeyModeHex(String publicKey) { 9 | publicKey = StringUtils.strip0x(publicKey.toLowerCase()); 10 | if (publicKey.length != EcdsaKeysConst.pubKeyCompressedByteLen * 2 && 11 | publicKey.length != EcdsaKeysConst.pubKeyUncompressedByteLen * 2) { 12 | throw DartBitcoinPluginException("Invalid Secp256k1 Publickey length."); 13 | } 14 | final isCompressed = 15 | publicKey.length == EcdsaKeysConst.pubKeyCompressedByteLen * 2; 16 | if (isCompressed) return PublicKeyType.compressed; 17 | return PublicKeyType.uncompressed; 18 | } 19 | 20 | static PublicKeyType determinatePubKeyMode(List publicKey) { 21 | if (publicKey.length != EcdsaKeysConst.pubKeyCompressedByteLen && 22 | publicKey.length != EcdsaKeysConst.pubKeyUncompressedByteLen) { 23 | throw DartBitcoinPluginException("Invalid Secp256k1 Publickey length."); 24 | } 25 | final isCompressed = 26 | publicKey.length == EcdsaKeysConst.pubKeyCompressedByteLen; 27 | if (isCompressed) return PublicKeyType.compressed; 28 | return PublicKeyType.uncompressed; 29 | } 30 | 31 | static BigInt toSatoshi(String decimal) { 32 | var dec = BigRational.parseDecimal(decimal); 33 | dec = dec * BigRational(BigInt.from(10).pow(8)); 34 | return dec.toBigInt(); 35 | } 36 | 37 | static String toBtc(BigInt amount) { 38 | BigRational dec = BigRational(amount); 39 | dec = dec / BigRational(BigInt.from(10).pow(8)); 40 | return dec.toDecimal(digits: 8); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/src/utils/enumerate.dart: -------------------------------------------------------------------------------- 1 | abstract class Enumerate { 2 | String get value; 3 | 4 | @override 5 | bool operator ==(other) { 6 | if (identical(other, this)) return true; 7 | if (other is! Enumerate) return false; 8 | return other.runtimeType == runtimeType && value == other.value; 9 | } 10 | 11 | @override 12 | int get hashCode => value.hashCode; 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/utils/utils.dart: -------------------------------------------------------------------------------- 1 | export 'btc_utils.dart'; 2 | export 'enumerate.dart'; 3 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: bitcoin_base 2 | description: A versatile library for Bitcoin, Dogecoin, Litecoin, Dash, BSV, and BCH. Supports P2PKH, P2SH, P2WPKH, P2WSH, P2TR, with advanced creation, signing, and spending capabilities. 3 | version: 6.5.0 4 | homepage: "https://github.com/mrtnetwork/bitcoin_base" 5 | repository: "https://github.com/mrtnetwork/bitcoin_base" 6 | Author: mrhaydari.t@gmail.com 7 | topics: 8 | - bitcoin 9 | - dogecoin 10 | - litecoin 11 | - bitcoincash 12 | - dash 13 | 14 | environment: 15 | sdk: '>=3.3.0 <4.0.0' 16 | 17 | 18 | dependencies: 19 | blockchain_utils: ^5.0.0 20 | 21 | # blockchain_utils: 22 | # path: ../blockchain_utils 23 | 24 | 25 | dev_dependencies: 26 | lints: ^5.1.1 27 | test: ^1.25.9 28 | flutter_lints: ^5.0.0 29 | 30 | 31 | # For information on the generic Dart part of this file, see the 32 | # following page: https://dart.dev/tools/pub/pubspec 33 | 34 | # The following section is specific to Flutter packages. 35 | flutter: 36 | 37 | # To add assets to your package, add an assets section, like this: 38 | # assets: 39 | # - images/a_dot_burr.jpeg 40 | # - images/a_dot_ham.jpeg 41 | # 42 | # For details regarding assets in packages, see 43 | # https://flutter.dev/assets-and-images/#from-packages 44 | # 45 | # An image asset can refer to one or more resolution-specific "variants", see 46 | # https://flutter.dev/assets-and-images/#resolution-aware 47 | 48 | # To add custom fonts to your package, add a fonts section here, 49 | # in this "flutter" section. Each entry in this list should have a 50 | # "family" key with the font family name, and a "fonts" key with a 51 | # list giving the asset and other descriptors for the font. For 52 | # example: 53 | # fonts: 54 | # - family: Schyler 55 | # fonts: 56 | # - asset: fonts/Schyler-Regular.ttf 57 | # - asset: fonts/Schyler-Italic.ttf 58 | # style: italic 59 | # - family: Trajan Pro 60 | # fonts: 61 | # - asset: fonts/TrajanPro.ttf 62 | # - asset: fonts/TrajanPro_Bold.ttf 63 | # weight: 700 64 | # 65 | # For details regarding fonts in packages, see 66 | # https://flutter.dev/custom-fonts/#from-packages 67 | -------------------------------------------------------------------------------- /test/bcmr/bcmr_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:bitcoin_base/bitcoin_base.dart'; 3 | import 'package:test/test.dart'; 4 | import 'art_collection.dart'; 5 | import 'decentralized_application.dart'; 6 | import 'fungible_token.dart'; 7 | import 'payouts_or_dividends.dart'; 8 | 9 | /// https://github.com/bitjson/chip-bcmr/tree/master/examples 10 | void main() { 11 | test('pcmr test', () { 12 | final registry = Registry.fromJson(payoutsOrDividends); 13 | expect(json.encode(registry.toJson()), json.encode(payoutsOrDividends)); 14 | final registry2 = Registry.fromJson(artCollection); 15 | expect(json.encode(registry2.toJson()), json.encode(artCollection)); 16 | final registry3 = Registry.fromJson(fungibleToken); 17 | expect(json.encode(registry3.toJson()), json.encode(fungibleToken)); 18 | final registry4 = Registry.fromJson(decentralizedApplication); 19 | expect( 20 | json.encode(registry4.toJson()), json.encode(decentralizedApplication)); 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /test/bcmr/fungible_token.dart: -------------------------------------------------------------------------------- 1 | const fungibleToken = { 2 | r'$schema': 'https://cashtokens.org/bcmr-v2.schema.json', 3 | 'version': {'major': 1, 'minor': 1, 'patch': 0}, 4 | 'latestRevision': '2023-04-14T00:00:17.720Z', 5 | 'registryIdentity': { 6 | 'name': 'Example.com Token Registry', 7 | 'description': 8 | 'An example registry demonstrating how the issuer of a single kind of fungible token might publish information about the token.', 9 | 'uris': { 10 | 'icon': 'https://example.com/registry-icon.svg', 11 | 'web': 'https://example.com/', 12 | 'registry': 13 | 'https://example.com/.well-known/bitcoin-cash-metadata-registry.json' 14 | } 15 | }, 16 | 'identities': { 17 | '89cad9e3e34280eb1e8bc420542c00a7fcc01002b663dbf7f38bceddf80e680c': { 18 | '2023-01-03T00:00:00.000Z': { 19 | 'name': 'Example Asset', 20 | 'description': 21 | "This is a record of an older entry for the token identity. The token was rebranded (from EXAMPLE to XAMPL) and redenominated (from 8 to 6 decimals), but the existing token category was not modified: users were not required to trade their original EXAMPLE tokens for the redenominated XAMPL tokens, their wallets simply updated the way tokens are displayed using the new metadata. Note, this entry has likely been updated by the issuer to provide useful historical information rather than attempting to preserve the precise contents of the old snapshot; the 'web' URI links to a blog post about XAMPL's re-denomination/re-brand, and outdated URI information is excluded. There may have been metadata updates published between this snapshot and the latest snapshot, but they've been excluded because registries should strive to present a useful history of only meaningful changes to identities. This information can be used in user interfaces to improve continuity following metadata updates or to offer historical context.", 22 | 'token': { 23 | 'category': 24 | '89cad9e3e34280eb1e8bc420542c00a7fcc01002b663dbf7f38bceddf80e680c', 25 | 'decimals': 8, 26 | 'symbol': 'EXAMPLE' 27 | }, 28 | 'uris': { 29 | 'icon': 'https://example.com/old-example-asset-icon.png', 30 | 'web': 'https://blog.example.com/example-asset-is-now-XAMPL' 31 | } 32 | } 33 | } 34 | }, 35 | 'license': 'CC0-1.0' 36 | }; 37 | --------------------------------------------------------------------------------