From 4fb437dfb9a5e7e107cd3e18a8705e6414b95d57 Mon Sep 17 00:00:00 2001 From: StaxOLotl Date: Fri, 29 Nov 2024 11:45:00 -0500 Subject: [PATCH 1/5] Rebase with main --- CHANGELOG.md | 2 +- lib/bdk_flutter.dart | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54038dc..7b5d94d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -174,4 +174,4 @@ Updated API to match bdk-ffi - Create Transaction - Sign Transaction - Broadcast Transaction -- Quick Send +- Quick Send \ No newline at end of file diff --git a/lib/bdk_flutter.dart b/lib/bdk_flutter.dart index 48f3898..0494835 100644 --- a/lib/bdk_flutter.dart +++ b/lib/bdk_flutter.dart @@ -40,4 +40,11 @@ export './src/generated/api/types.dart' export './src/generated/api/wallet.dart' hide BdkWallet, finishBumpFeeTxBuilder, txBuilderFinish; export './src/root.dart'; -export 'src/utils/exceptions.dart' hide mapBdkError, BdkFfiException; +export 'src/utils/exceptions.dart' + hide + mapBdkError, + mapAddressError, + mapConsensusError, + mapDescriptorError, + mapHexError, + BdkFfiException; From 853fbc5f50ce42b9d63a215ae4ea08cb352d4856 Mon Sep 17 00:00:00 2001 From: StaxOLotl Date: Sat, 30 Nov 2024 11:50:00 -0500 Subject: [PATCH 2/5] version & dependencies updated --- analysis_options.yaml | 2 +- example/macos/Podfile.lock | 2 +- example/pubspec.lock | 26 +++++--------------------- ios/bdk_flutter.podspec | 2 +- macos/bdk_flutter.podspec | 2 +- pubspec.lock | 30 +++++++----------------------- pubspec.yaml | 15 +++++++-------- rust/Cargo.lock | 2 +- rust/Cargo.toml | 11 +++++++---- 9 files changed, 31 insertions(+), 61 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index c2b7743..a40d945 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:lints/recommended.yaml +include: package:lints/core.yaml # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 2d92140..78c676d 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - bdk_flutter (0.31.2): + - bdk_flutter (0.31.3): - FlutterMacOS - FlutterMacOS (1.0.0) diff --git a/example/pubspec.lock b/example/pubspec.lock index 2735c84..d3df361 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -39,7 +39,7 @@ packages: path: ".." relative: true source: path - version: "0.31.2" + version: "0.31.3" boolean_selector: dependency: transitive description: @@ -156,10 +156,10 @@ packages: dependency: transitive description: name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" file: dependency: transitive description: @@ -211,10 +211,10 @@ packages: dependency: transitive description: name: freezed_annotation - sha256: f54946fdb1fa7b01f780841937b1a80783a20b393485f3f6cdf336fd6f4705f2 + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.4.4" fuchsia_remote_debug_protocol: dependency: transitive description: flutter @@ -374,14 +374,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" stack_trace: dependency: transitive description: @@ -438,14 +430,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" - uuid: - dependency: transitive - description: - name: uuid - sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" - url: "https://pub.dev" - source: hosted - version: "4.4.0" vector_math: dependency: transitive description: diff --git a/ios/bdk_flutter.podspec b/ios/bdk_flutter.podspec index 6d40826..a4dfcd4 100644 --- a/ios/bdk_flutter.podspec +++ b/ios/bdk_flutter.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'bdk_flutter' - s.version = "0.31.2" + s.version = "0.31.3" s.summary = 'A Flutter library for the Bitcoin Development Kit (https://bitcoindevkit.org/)' s.description = <<-DESC A new Flutter plugin project. diff --git a/macos/bdk_flutter.podspec b/macos/bdk_flutter.podspec index c1ff53e..5e88ecd 100644 --- a/macos/bdk_flutter.podspec +++ b/macos/bdk_flutter.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'bdk_flutter' - s.version = "0.31.2" + s.version = "0.31.3" s.summary = 'A Flutter library for the Bitcoin Development Kit (https://bitcoindevkit.org/)' s.description = <<-DESC A new Flutter plugin project. diff --git a/pubspec.lock b/pubspec.lock index 6902f64..1d3c732 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -197,10 +197,10 @@ packages: dependency: "direct main" description: name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" ffigen: dependency: "direct dev" description: @@ -255,10 +255,10 @@ packages: dependency: "direct main" description: name: freezed_annotation - sha256: f54946fdb1fa7b01f780841937b1a80783a20b393485f3f6cdf336fd6f4705f2 + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.4.4" frontend_server_client: dependency: transitive description: @@ -351,10 +351,10 @@ packages: dependency: "direct dev" description: name: lints - sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235" + sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.0.0" logging: dependency: transitive description: @@ -488,14 +488,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" stack_trace: dependency: transitive description: @@ -560,14 +552,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" - uuid: - dependency: "direct main" - description: - name: uuid - sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" - url: "https://pub.dev" - source: hosted - version: "4.4.0" vector_math: dependency: transitive description: @@ -633,5 +617,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.5.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 04a0e4c..f2c2ee1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bdk_flutter description: A Flutter library for the Bitcoin Development Kit(bdk) (https://bitcoindevkit.org/) -version: 0.31.2 +version: 0.31.3 homepage: https://github.com/LtbLightning/bdk-flutter environment: @@ -11,12 +11,11 @@ dependencies: flutter: sdk: flutter flutter_rust_bridge: ">=2.0.0 < 2.1.0" - ffi: ^2.0.1 - freezed_annotation: ^2.2.0 - mockito: ^5.4.0 - meta: ^1.10.0 - uuid: ^4.2.2 + ffi: ^2.1.3 + freezed_annotation: ^2.4.4 + mockito: ^5.4.4 collection: ^1.18.0 + meta: ^1.15.0 dev_dependencies: flutter_test: @@ -24,7 +23,7 @@ dev_dependencies: ffigen: ^12.0.0 freezed: ^2.5.2 build_runner: ^2.4.8 - lints: ^4.0.0 + lints: ^5.0.0 flutter: plugin: @@ -34,4 +33,4 @@ flutter: ios: ffiPlugin: true macos: - ffiPlugin: true \ No newline at end of file + ffiPlugin: true diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 845c186..4e3fbdf 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -185,7 +185,7 @@ dependencies = [ [[package]] name = "bdk_flutter" -version = "0.31.2" +version = "0.31.3" dependencies = [ "anyhow", "assert_matches", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 00455be..c837221 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk_flutter" -version = "0.31.2" +version = "0.31.3" edition = "2021" [lib] @@ -11,7 +11,12 @@ anyhow = "1.0.68" [dependencies] flutter_rust_bridge = "=2.0.0" rand = "0.8" -bdk = { version = "0.29.0", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled", "rpc"] } +bdk = { version = "0.29.0", features = [ + "all-keys", + "use-esplora-ureq", + "sqlite-bundled", + "rpc", +] } serde = "1.0.89" serde_json = "1.0.96" anyhow = "1.0.68" @@ -22,5 +27,3 @@ opt-level = 3 lto = true codegen-units = 1 panic = "abort" - - From 21e76748db43af160337dcfc41fc1504cc0d1470 Mon Sep 17 00:00:00 2001 From: StaxOLotl Date: Sun, 1 Dec 2024 03:10:00 -0500 Subject: [PATCH 3/5] .md files updated --- CHANGELOG.md | 2 ++ README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b5d94d..77d8f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [0.31.3] + ## [0.31.2] Updated `flutter_rust_bridge` to `2.0.0`. #### APIs added diff --git a/README.md b/README.md index 0852f50..8e596aa 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To use the `bdk_flutter` package in your project, add it as a dependency in your ```dart dependencies: - bdk_flutter: ^0.31.2 + bdk_flutter: ^0.31.3 ``` ### Examples From 9c9106bc5d26f926f853a80b49b5ca1e76aa2613 Mon Sep 17 00:00:00 2001 From: StaxOLotl Date: Mon, 2 Dec 2024 22:33:00 -0500 Subject: [PATCH 4/5] multi-sig integration test added --- .../integration_test /full_cycle_test.dart | 63 ------- example/integration_test /multi_sig_test.dart | 167 ++++++++++++++++++ example/lib/multi_sig_wallet.dart | 97 ---------- 3 files changed, 167 insertions(+), 160 deletions(-) delete mode 100644 example/integration_test /full_cycle_test.dart create mode 100644 example/integration_test /multi_sig_test.dart delete mode 100644 example/lib/multi_sig_wallet.dart diff --git a/example/integration_test /full_cycle_test.dart b/example/integration_test /full_cycle_test.dart deleted file mode 100644 index 867af91..0000000 --- a/example/integration_test /full_cycle_test.dart +++ /dev/null @@ -1,63 +0,0 @@ -import 'dart:typed_data'; - -import 'package:bdk_flutter/bdk_flutter.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:integration_test/integration_test.dart'; - -void main() { - IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - group('Descriptor & Wallet', () { - setUp(() async {}); - testWidgets('generating psbt using a muti-sig wallet', (_) async { - final externalDescriptor = await Descriptor.create( - descriptor: - "wsh(thresh(2,pk(tpubD6NzVbkrYhZ4XJBfEJ6gt9DiVdfWJijsQTCE3jtXByW3Tk6AVGQ3vL1NNxg3SjB7QkJAuutACCQjrXD8zdZSM1ZmBENszCqy49ECEHmD6rf/0/*),sj:and_v(v:pk(tpubD6NzVbkrYhZ4YfAr3jCBRk4SpqB9L1Hh442y83njwfMaker7EqZd7fHMqyTWrfRYJ1e5t2ue6BYjW5i5yQnmwqbzY1a3kfqNxog1AFcD1aE/0/*),n:older(6)),snj:and_v(v:pk(tprv8ZgxMBicQKsPeitVUz3s6cfyCECovNP7t82FaKPa4UKqV1kssWcXgLkMDjzDbgG9GWoza4pL7z727QitfzkiwX99E1Has3T3a1MKHvYWmQZ/0/*),after(630000))))", - network: Network.signet); - final internalDescriptor = await Descriptor.create( - descriptor: - "wsh(thresh(2,pk(tpubD6NzVbkrYhZ4XJBfEJ6gt9DiVdfWJijsQTCE3jtXByW3Tk6AVGQ3vL1NNxg3SjB7QkJAuutACCQjrXD8zdZSM1ZmBENszCqy49ECEHmD6rf/1/*),sj:and_v(v:pk(tpubD6NzVbkrYhZ4YfAr3jCBRk4SpqB9L1Hh442y83njwfMaker7EqZd7fHMqyTWrfRYJ1e5t2ue6BYjW5i5yQnmwqbzY1a3kfqNxog1AFcD1aE/1/*),n:older(6)),snj:and_v(v:pk(tprv8ZgxMBicQKsPeitVUz3s6cfyCECovNP7t82FaKPa4UKqV1kssWcXgLkMDjzDbgG9GWoza4pL7z727QitfzkiwX99E1Has3T3a1MKHvYWmQZ/1/*),after(630000))))", - network: Network.signet); - - final wallet = await Wallet.create( - descriptor: externalDescriptor, - changeDescriptor: internalDescriptor, - network: Network.signet, - databaseConfig: const DatabaseConfig.memory()); - final blockchain = await Blockchain.createMutinynet(); - wallet.sync(blockchain: blockchain); - debugPrint("Wallet balance: ${wallet.getBalance().total}"); - final toAddress = wallet - .getAddress(addressIndex: const AddressIndex.increase()) - .address; - debugPrint("Wallet address: ${toAddress.toString()}"); - final externalWalletPolicy = wallet.policies(KeychainKind.externalChain); - final ineternalWalletPolicy = wallet.policies(KeychainKind.internalChain); - if (externalWalletPolicy != null && ineternalWalletPolicy != null) { - // Construct external and internal policy paths - final extPath = { - ineternalWalletPolicy.id(): Uint32List.fromList([0, 1]) - }; - debugPrint("External Policy path: $extPath\n"); - - final intPath = { - ineternalWalletPolicy.id(): Uint32List.fromList([0, 1]) - }; - debugPrint("Internal Policy Path: $intPath\n"); - - // Build the transaction - final txBuilder = TxBuilder() - .addRecipient( - toAddress.scriptPubkey(), - BigInt.from(1000), - ) - .doNotSpendChange() - .policyPath(KeychainKind.internalChain, intPath) - .policyPath(KeychainKind.externalChain, extPath); - - final (psbt, _) = await txBuilder.finish(wallet); - debugPrint("Transaction serialized: ${psbt.toString()}\n"); - } - }); - }); -} diff --git a/example/integration_test /multi_sig_test.dart b/example/integration_test /multi_sig_test.dart new file mode 100644 index 0000000..d3ad408 --- /dev/null +++ b/example/integration_test /multi_sig_test.dart @@ -0,0 +1,167 @@ +import 'package:bdk_flutter/bdk_flutter.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +/// Derives extended descriptor keys (secret and public) based on the provided +/// hardened and unhardened derivation paths and mnemonic. +Future<(DescriptorSecretKey, DescriptorPublicKey)> deriveDescriptorKeys( + DerivationPath hardenedPath, + DerivationPath unHardenedPath, + Mnemonic mnemonic, +) async { + // Create the root secret key from the mnemonic + final secretKey = await DescriptorSecretKey.create( + mnemonic: mnemonic, network: Network.signet); + + // Derive the key at the hardened path + final derivedSecretKey = await secretKey.derive(hardenedPath); + + // Extend the derived secret key further using the unhardened path + final derivedExtendedSecretKey = + await derivedSecretKey.extend(unHardenedPath); + + // Convert the derived secret key to its public counterpart + final publicKey = derivedSecretKey.toPublic(); + + // Extend the public key using the same unhardened path + final derivedExtendedPublicKey = await publicKey.extend(path: unHardenedPath); + + return (derivedExtendedSecretKey, derivedExtendedPublicKey); +} + +/// Constructs a wallet descriptor using timelock conditions and public keys. +String createWalletDescriptor( + String primaryReceivingSecret, // Alice's descriptor derived from m/0 + String secondaryReceivingPublic, // Bob's public key derived from m/0 + int primaryTimelock, // Alice's timelock + int secondaryTimelock, // Bob's timelock + String primaryChangePublic, // Alice's public key derived from m/1 + String secondaryChangePublic, // Bob's public key derived from m/1 +) { + // Define the multi-sig condition based on timelock priority + String multi = (primaryTimelock < secondaryTimelock) + ? 'multi(2,$primaryReceivingSecret,$secondaryReceivingPublic)' + : 'multi(2,$secondaryReceivingPublic,$primaryReceivingSecret)'; + + // Define the timelock conditions for Bob and Alice + String timelockBob = + 'and_v(v:older($secondaryTimelock),pk($secondaryChangePublic))'; + String timelockAlice = + 'and_v(v:older($primaryTimelock),pk($primaryChangePublic))'; + + // Combine the timelock conditions + String timelockCondition = (primaryTimelock < secondaryTimelock) + ? 'or_i($timelockAlice,$timelockBob)' + : 'or_i($timelockBob,$timelockAlice)'; + + // Return the final wallet descriptor + return 'wsh(or_d($multi,$timelockCondition))'; +} + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('Time-locked multi-sig wallet synchronization', () { + setUp(() async { + // Setup for test group + }); + + test("Alice and Bob should have the same initial address and balance", + () async { + // Define mnemonics for Alice and Bob + final alice = await Mnemonic.fromString( + 'thumb member wage display inherit music elevator need side setup tube panther broom giant auction banner split potato'); + final bob = await Mnemonic.fromString( + 'tired shine hat tired hover timber reward bridge verb aerobic safe economy'); + + // Define timelocks for Alice and Bob + const aliceTimelock = 25; + const bobTimeLock = 35; + + // Define derivation paths + final hardenedDerivationPath = + await DerivationPath.create(path: "m/84h/1h/0h"); + final receivingDerivationPath = await DerivationPath.create(path: "m/0"); + final changeDerivationPath = await DerivationPath.create(path: "m/1"); + + // Derive keys for Alice + final (aliceReceivingSecretKey, aliceReceivingPublicKey) = + await deriveDescriptorKeys( + hardenedDerivationPath, receivingDerivationPath, alice); + final (aliceChangeSecretKey, aliceChangePublicKey) = + await deriveDescriptorKeys( + hardenedDerivationPath, changeDerivationPath, alice); + + // Derive keys for Bob + final (bobReceivingSecretKey, bobReceivingPublicKey) = + await deriveDescriptorKeys( + hardenedDerivationPath, receivingDerivationPath, bob); + final (bobChangeSecretKey, bobChangePublicKey) = + await deriveDescriptorKeys( + hardenedDerivationPath, changeDerivationPath, bob); + + // Create wallet descriptors for Alice and Bob + final aliceDescriptor = createWalletDescriptor( + aliceReceivingSecretKey.toString(), + bobReceivingPublicKey.toString(), + aliceTimelock, + bobTimeLock, + aliceChangePublicKey.toString(), + bobChangePublicKey.toString()); + final bobDescriptor = createWalletDescriptor( + bobReceivingSecretKey.toString(), + aliceReceivingPublicKey.toString(), + bobTimeLock, + aliceTimelock, + bobChangePublicKey.toString(), + aliceChangePublicKey.toString()); + + // Debug print descriptors + debugPrint("Alice's descriptor: $aliceDescriptor"); + debugPrint("Bob's descriptor: $bobDescriptor"); + + // Create wallets + final aliceWallet = await Wallet.create( + descriptor: await Descriptor.create( + descriptor: aliceDescriptor, network: Network.signet), + network: Network.signet, + databaseConfig: const DatabaseConfig.memory()); + final bobWallet = await Wallet.create( + descriptor: await Descriptor.create( + descriptor: bobDescriptor, network: Network.signet), + network: Network.signet, + databaseConfig: const DatabaseConfig.memory()); + + // Get initial addresses + final aliceAddress = aliceWallet + .getAddress(addressIndex: const AddressIndex.peek(index: 0)) + .address + .toString(); + final bobAddress = bobWallet + .getAddress(addressIndex: const AddressIndex.peek(index: 0)) + .address + .toString(); + assert(aliceAddress == bobAddress, "Addresses should match"); + + debugPrint("Alice's receiving address: $aliceAddress"); + debugPrint("Bob's receiving address: $bobAddress"); + + // Sync wallets + final blockchain = await Blockchain.createMutinynet(); + debugPrint("Syncing Bob's wallet..."); + await bobWallet.sync(blockchain: blockchain); + debugPrint("Syncing Alice's wallet..."); + await aliceWallet.sync(blockchain: blockchain); + debugPrint("Synchronization complete"); + + // Check balances + final bobBalance = bobWallet.getBalance().total.toInt(); + final aliceBalance = aliceWallet.getBalance().total.toInt(); + assert(bobBalance == aliceBalance, "Balances should match"); + + debugPrint("Alice's balance: $aliceBalance"); + debugPrint("Bob's balance: $bobBalance"); + }); + }); +} diff --git a/example/lib/multi_sig_wallet.dart b/example/lib/multi_sig_wallet.dart deleted file mode 100644 index 44f7834..0000000 --- a/example/lib/multi_sig_wallet.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:bdk_flutter/bdk_flutter.dart'; -import 'package:flutter/foundation.dart'; - -class MultiSigWallet { - Future> init2Of3Descriptors(List mnemonics) async { - final List descriptorInfos = []; - for (var e in mnemonics) { - final secret = await DescriptorSecretKey.create( - network: Network.testnet, mnemonic: e); - final public = secret.toPublic(); - descriptorInfos.add(DescriptorKeyInfo(secret, public)); - } - final alice = - "wsh(sortedmulti(2,${descriptorInfos[0].xprv},${descriptorInfos[1].xpub},${descriptorInfos[2].xpub}))"; - final bob = - "wsh(sortedmulti(2,${descriptorInfos[1].xprv},${descriptorInfos[2].xpub},${descriptorInfos[0].xpub}))"; - final dave = - "wsh(sortedmulti(2,${descriptorInfos[2].xprv},${descriptorInfos[0].xpub},${descriptorInfos[1].xpub}))"; - final List descriptors = []; - final parsedDes = [alice, bob, dave]; - for (var e in parsedDes) { - final res = - await Descriptor.create(descriptor: e, network: Network.testnet); - descriptors.add(res); - } - return descriptors; - } - - Future> createDescriptors() async { - final alice = await Mnemonic.fromString( - 'thumb member wage display inherit music elevator need side setup tube panther broom giant auction banner split potato'); - final bob = await Mnemonic.fromString( - 'tired shine hat tired hover timber reward bridge verb aerobic safe economy'); - final dave = await Mnemonic.fromString( - 'lawsuit upper gospel minimum cinnamon common boss wage benefit betray ribbon hour'); - final descriptors = await init2Of3Descriptors([alice, bob, dave]); - return descriptors; - } - - Future> init20f3Wallets() async { - final descriptors = await createDescriptors(); - final alice = await Wallet.create( - descriptor: descriptors[0], - network: Network.testnet, - databaseConfig: const DatabaseConfig.memory()); - final bob = await Wallet.create( - descriptor: descriptors[1], - network: Network.testnet, - databaseConfig: const DatabaseConfig.memory()); - final dave = await Wallet.create( - descriptor: descriptors[2], - network: Network.testnet, - databaseConfig: const DatabaseConfig.memory()); - return [alice, bob, dave]; - } - - sendBitcoin(Blockchain blockchain, Wallet wallet, Wallet bobWallet, - String addressStr) async { - try { - final txBuilder = TxBuilder(); - final address = - await Address.fromString(s: addressStr, network: wallet.network()); - final script = address.scriptPubkey(); - final feeRate = await blockchain.estimateFee(target: BigInt.from(25)); - final (psbt, _) = await txBuilder - .addRecipient(script, BigInt.from(1200)) - .feeRate(feeRate.satPerVb) - .finish(wallet); - await wallet.sign( - psbt: psbt, - signOptions: const SignOptions( - trustWitnessUtxo: false, - allowAllSighashes: true, - removePartialSigs: true, - tryFinalize: true, - signWithTapInternalKey: true, - allowGrinding: true)); - final isFinalized = await bobWallet.sign(psbt: psbt); - if (isFinalized) { - final tx = psbt.extractTx(); - await blockchain.broadcast(transaction: tx); - } else { - debugPrint("Psbt not finalized!"); - } - } on FormatException catch (e) { - if (kDebugMode) { - print(e.message); - } - } - } -} - -class DescriptorKeyInfo { - final DescriptorSecretKey xprv; - final DescriptorPublicKey xpub; - DescriptorKeyInfo(this.xprv, this.xpub); -} From 11642da5be3365d7c06073bad6cd53b9a616c447 Mon Sep 17 00:00:00 2001 From: StaxOLotl Date: Tue, 3 Dec 2024 20:45:00 -0500 Subject: [PATCH 5/5] code clean up --- example/lib/main.dart | 4 ++-- example/lib/{simple_wallet.dart => wallet.dart} | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename example/lib/{simple_wallet.dart => wallet.dart} (98%) diff --git a/example/lib/main.dart b/example/lib/main.dart index 4f12fa0..3b7e0e3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,6 @@ -import 'package:bdk_flutter_example/simple_wallet.dart'; +import 'package:bdk_flutter_example/wallet.dart'; import 'package:flutter/material.dart'; void main() { - runApp(const SimpleWallet()); + runApp(const ExampleWallet()); } diff --git a/example/lib/simple_wallet.dart b/example/lib/wallet.dart similarity index 98% rename from example/lib/simple_wallet.dart rename to example/lib/wallet.dart index c0af426..159e368 100644 --- a/example/lib/simple_wallet.dart +++ b/example/lib/wallet.dart @@ -4,14 +4,14 @@ import 'package:flutter/material.dart'; import 'bdk_library.dart'; -class SimpleWallet extends StatefulWidget { - const SimpleWallet({super.key}); +class ExampleWallet extends StatefulWidget { + const ExampleWallet({super.key}); @override - State createState() => _SimpleWalletState(); + State createState() => _ExampleWalletState(); } -class _SimpleWalletState extends State { +class _ExampleWalletState extends State { String displayText = ""; BigInt balance = BigInt.zero; late Wallet wallet;