Skip to content

Commit

Permalink
Added build scripts and updated init to use binaries from releases
Browse files Browse the repository at this point in the history
  • Loading branch information
i5hi committed May 12, 2024
1 parent 3ecadf0 commit 7c99ddb
Show file tree
Hide file tree
Showing 37 changed files with 2,545 additions and 4,420 deletions.
6 changes: 6 additions & 0 deletions codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
#!/bin/bash
cd rust
cargo update
cd - || exit 1
flutter_rust_bridge_codegen generate
5 changes: 5 additions & 0 deletions compile.all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
#export PKG_CONFIG_ALLOW_CROSS=1
cd rust || exit 1
make all
cd .. || exit 1
15 changes: 15 additions & 0 deletions compile.native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
mkdir -p build/unit_test_assets
cd rust || exit 1
cargo update
cargo build --release
OS=$(uname -s)
if [ "$OS" = "Linux" ]; then
cp target/release/libbdkbridge.so ../build/unit_test_assets
elif [ "$OS" = "Darwin" ]; then
cp target/release/libbdkbridge.dylib ../build/unit_test_assets
else
echo "Unsupported OS: $OS"
exit 1
fi
cd - || exit 1
186 changes: 93 additions & 93 deletions example/lib/multi_sig_wallet.dart
Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/foundation.dart';
// import 'package:bdk_flutter/bdk_flutter.dart';
// import 'package:flutter/foundation.dart';

class MultiSigWallet {
Future<List<Descriptor>> init2Of3Descriptors(List<Mnemonic> mnemonics) async {
final List<DescriptorKeyInfo> descriptorInfos = [];
for (var e in mnemonics) {
final secret = await DescriptorSecretKey.create(
network: Network.testnet, mnemonic: e);
final public = await secret.asPublic();
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<Descriptor> 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;
}
// class MultiSigWallet {
// Future<List<Descriptor>> init2Of3Descriptors(List<Mnemonic> mnemonics) async {
// final List<DescriptorKeyInfo> descriptorInfos = [];
// for (var e in mnemonics) {
// final secret = await DescriptorSecretKey.create(
// network: Network.testnet, mnemonic: e);
// final public = await secret.asPublic();
// 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<Descriptor> 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<List<Descriptor>> 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<List<Descriptor>> 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<List<Wallet>> 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];
}
// Future<List<Wallet>> 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 aliceWallet, Wallet bobWallet,
String addressStr) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
s: addressStr, network: (await aliceWallet.network()));
final script = await address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: 25);
final (psbt, _) = await txBuilder
.addRecipient(script, 1000)
.feeRate(feeRate.satPerVb)
.finish(aliceWallet);
await aliceWallet.sign(
psbt: psbt,
signOptions: const SignOptions(
multiSig: true,
trustWitnessUtxo: false,
allowAllSighashes: true,
removePartialSigs: true,
tryFinalize: true,
signWithTapInternalKey: true,
allowGrinding: true));
final isFinalized = await bobWallet.sign(psbt: psbt);
if (isFinalized) {
final tx = await psbt.extractTx();
await blockchain.broadcast(transaction: tx);
} else {
debugPrint("Psbt not finalized!");
}
} on FormatException catch (e) {
if (kDebugMode) {
print(e.message);
}
}
}
}
// sendBitcoin(Blockchain blockchain, Wallet aliceWallet, Wallet bobWallet,
// String addressStr) async {
// try {
// final txBuilder = TxBuilder();
// final address = await Address.fromString(
// s: addressStr, network: (await aliceWallet.network()));
// final script = await address.scriptPubkey();
// final feeRate = await blockchain.estimateFee(target: 25);
// final (psbt, _) = await txBuilder
// .addRecipient(script, 1000)
// .feeRate(feeRate.satPerVb)
// .finish(aliceWallet);
// await aliceWallet.sign(
// psbt: psbt,
// signOptions: const SignOptions(
// multiSig: true,
// trustWitnessUtxo: false,
// allowAllSighashes: true,
// removePartialSigs: true,
// tryFinalize: true,
// signWithTapInternalKey: true,
// allowGrinding: true));
// final isFinalized = await bobWallet.sign(psbt: psbt);
// if (isFinalized) {
// final tx = await 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);
}
// class DescriptorKeyInfo {
// final DescriptorSecretKey xprv;
// final DescriptorPublicKey xpub;
// DescriptorKeyInfo(this.xprv, this.xpub);
// }
Loading

0 comments on commit 7c99ddb

Please sign in to comment.