Skip to content

Commit

Permalink
fix merge conflicts + clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
kumulynja committed Jun 28, 2024
2 parents af6ceb0 + 821fe90 commit 57a34d5
Show file tree
Hide file tree
Showing 39 changed files with 1,722 additions and 759 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/precompile_binaries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [v0.31.2-dev.1, master, main]
branches: [v0.31.2-dev.2, master, main]

name: Precompile Binaries

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.31.2-dev.2]
#### Fixed
- Thread `frb_workerpool` panicked on invalid `Fingerprint`.
- `SignOptions` issue to accept `witness-utxo` while signing.

#### Changed
- Removed `multiSig` variable from `SignOptions`.
- Updated example app to support `mutinynet`.
- Mapped `Hex`, `Address`, `Descriptor` & `Consensus` exceptions.

## [0.31.2-dev.1]
#### Fixed
- Invalid `Bip49Public`, `Bip84Public` & `Bip86Public`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-dev.1
bdk_flutter: ^0.31.2-dev.2
```

### Examples
Expand Down
42 changes: 10 additions & 32 deletions example/lib/bdk_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,18 @@ class BdkLibrary {

Future<Descriptor> createDescriptor(Mnemonic mnemonic) async {
final descriptorSecretKey = await DescriptorSecretKey.create(
network: Network.testnet,
network: Network.signet,
mnemonic: mnemonic,
);
final descriptor = await Descriptor.newBip84(
secretKey: descriptorSecretKey,
network: Network.testnet,
network: Network.signet,
keychain: KeychainKind.externalChain);
return descriptor;
}

Future<Blockchain> initializeBlockchain({
bool isElectrumBlockchain = false,
bool useTestnetDefaults = false,
}) async {
if (useTestnetDefaults) {
return await Blockchain.createWithTestnetDefaults();
} else if (isElectrumBlockchain) {
return await Blockchain.create(
config: const BlockchainConfig.electrum(
config: ElectrumConfig(
stopGap: 10,
timeout: 5,
retry: 5,
url: "ssl://electrum.blockstream.info:60002",
validateDomain: true,
),
),
);
} else {
return await Blockchain.create(
config: const BlockchainConfig.esplora(
config: EsploraConfig(
baseUrl: 'https://blockstream.info/testnet/api',
stopGap: 10,
),
),
);
}
Future<Blockchain> initializeBlockchain() async {
return Blockchain.createMutinynet();
}

Future<Wallet> restoreWallet(Descriptor descriptor) async {
Expand Down Expand Up @@ -118,7 +92,11 @@ class BdkLibrary {
}

sendBitcoin(
Blockchain blockchain, Wallet aliceWallet, String addressStr) async {
Blockchain blockchain,
Wallet aliceWallet,
String addressStr,
int amountSat,
) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
Expand All @@ -127,7 +105,7 @@ class BdkLibrary {
final script = await address.scriptPubkey();
final feeRate = await estimateFeeRate(25, blockchain);
final (psbt, _) = await txBuilder
.addRecipient(script, 750)
.addRecipient(script, amountSat)
.feeRate(feeRate.satPerVb)
.finish(aliceWallet);
final isFinalized = await aliceWallet.sign(psbt: psbt);
Expand Down
1 change: 0 additions & 1 deletion example/lib/multi_sig_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class MultiSigWallet {
await aliceWallet.sign(
psbt: psbt,
signOptions: const SignOptions(
multiSig: true,
trustWitnessUtxo: false,
allowAllSighashes: true,
removePartialSigs: true,
Expand Down
48 changes: 21 additions & 27 deletions example/lib/simple_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,38 @@ class _SimpleWalletState extends State<SimpleWallet> {

generateMnemonicKeys() async {
final res = await lib.createMnemonic();
final mnemonic = await res.asString();
setState(() {
displayText = res.toString();
displayText = mnemonic;
});
if (kDebugMode) {
print(await res.asString());
print(mnemonic);
}
}

restoreWallet() async {
final aliceMnemonic = await Mnemonic.fromString(
'certain sense kiss guide crumble hint transfer crime much stereo warm coral');
'give rate trigger race embrace dream wish column upon steel wrist rice');
final aliceDescriptor = await lib.createDescriptor(aliceMnemonic);
aliceWallet = await lib.restoreWallet(aliceDescriptor);
setState(() {
displayText = "Wallets restored";
});
}

initBlockchain({
bool isElectrumBlockchain = false,
bool useTestnetDefaults = false,
}) async {
blockchain = await lib.initializeBlockchain(
isElectrumBlockchain: isElectrumBlockchain,
useTestnetDefaults: useTestnetDefaults,
);
}

sync() async {
if (blockchain == null) {
// Initialize blockchain with default testnet values and esplora server
await initBlockchain(useTestnetDefaults: true);
}
blockchain ??= await lib.initializeBlockchain();
await lib.sync(blockchain!, aliceWallet);
}

getNewAddress() async {
final res = (await lib.getAddress(aliceWallet));
debugPrint(await res.address.asString());
final address = await res.address.asString();
final addressInfo = await lib.getAddress(aliceWallet);
final address = await addressInfo.address.asString();

debugPrint(address);

setState(() {
displayText = "Address: $address \n Index: ${res.index}";
displayText = "Address: $address \n Index: ${addressInfo.index}";
});
}

Expand Down Expand Up @@ -100,13 +90,13 @@ class _SimpleWalletState extends State<SimpleWallet> {
print(" confirmationTime Height: ${e.confirmationTime?.height}");
final txIn = await e.transaction!.input();
final txOut = await e.transaction!.output();
print(" =============TxIn==============");
print("=============TxIn==============");
for (var e in txIn) {
print(" previousOutout Txid: ${e.previousOutput.txid}");
print(" previousOutout vout: ${e.previousOutput.vout}");
print(" witness: ${e.witness}");
}
print(" =============TxOut==============");
print("=============TxOut==============");
for (var e in txOut) {
print(" script: ${e.scriptPubkey.bytes}");
print(" value: ${e.value}");
Expand Down Expand Up @@ -165,9 +155,13 @@ class _SimpleWalletState extends State<SimpleWallet> {
}
}

sendBit() async {
sendBit(int amountSat) async {
await lib.sendBitcoin(
blockchain!, aliceWallet, "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
blockchain!,
aliceWallet,
"tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f",
amountSat,
);
}

@override
Expand Down Expand Up @@ -299,9 +293,9 @@ class _SimpleWalletState extends State<SimpleWallet> {
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => sendBit(),
onPressed: () => sendBit(100000),
child: const Text(
'Press to send 1200 satoshi',
'Press to send 100k sats',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- bdk_flutter (0.31.2-dev):
- bdk_flutter (0.31.2-dev.2):
- FlutterMacOS
- FlutterMacOS (1.0.0)

Expand All @@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral

SPEC CHECKSUMS:
bdk_flutter: 8280f582b6b9b49deb843763027d4864b231c1d2
bdk_flutter: 5135d700e746fe36b8fb7e3e4dac539652aa3a2b
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 6acf97521436d16fc31cd5e1a02000905acdb3ae
Expand Down
Loading

0 comments on commit 57a34d5

Please sign in to comment.