Skip to content

Commit 78c55c5

Browse files
Merge pull request #134 from kumulynja/default-ltbl-esplora
add default config methods for Blockchain
2 parents 821fe90 + 57a34d5 commit 78c55c5

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

example/lib/bdk_library.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class BdkLibrary {
2020
}
2121

2222
Future<Blockchain> initializeBlockchain() async {
23-
return await Blockchain.create(
24-
config: const BlockchainConfig.esplora(
25-
config: EsploraConfig(
26-
baseUrl: 'https://mutinynet.com/api', stopGap: 10)));
23+
return Blockchain.createMutinynet();
2724
}
2825

2926
Future<Wallet> restoreWallet(Descriptor descriptor) async {
@@ -95,7 +92,11 @@ class BdkLibrary {
9592
}
9693

9794
sendBitcoin(
98-
Blockchain blockchain, Wallet aliceWallet, String addressStr) async {
95+
Blockchain blockchain,
96+
Wallet aliceWallet,
97+
String addressStr,
98+
int amountSat,
99+
) async {
99100
try {
100101
final txBuilder = TxBuilder();
101102
final address = await Address.fromString(
@@ -104,7 +105,7 @@ class BdkLibrary {
104105
final script = await address.scriptPubkey();
105106
final feeRate = await estimateFeeRate(25, blockchain);
106107
final (psbt, _) = await txBuilder
107-
.addRecipient(script, 750)
108+
.addRecipient(script, amountSat)
108109
.feeRate(feeRate.satPerVb)
109110
.finish(aliceWallet);
110111
final isFinalized = await aliceWallet.sign(psbt: psbt);

example/lib/simple_wallet.dart

+16-9
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ class _SimpleWalletState extends State<SimpleWallet> {
2525

2626
generateMnemonicKeys() async {
2727
final res = await lib.createMnemonic();
28+
final mnemonic = await res.asString();
2829
setState(() {
29-
displayText = res.toString();
30+
displayText = mnemonic;
3031
});
3132
if (kDebugMode) {
32-
print(await res.asString());
33+
print(mnemonic);
3334
}
3435
}
3536

@@ -49,11 +50,13 @@ class _SimpleWalletState extends State<SimpleWallet> {
4950
}
5051

5152
getNewAddress() async {
52-
final res = (await (await lib.getAddress(aliceWallet)).address.asString());
53-
debugPrint(res);
53+
final addressInfo = await lib.getAddress(aliceWallet);
54+
final address = await addressInfo.address.asString();
55+
56+
debugPrint(address);
5457

5558
setState(() {
56-
displayText = "Address: $res";
59+
displayText = "Address: $address \n Index: ${addressInfo.index}";
5760
});
5861
}
5962

@@ -152,9 +155,13 @@ class _SimpleWalletState extends State<SimpleWallet> {
152155
}
153156
}
154157

155-
sendBit() async {
158+
sendBit(int amountSat) async {
156159
await lib.sendBitcoin(
157-
blockchain!, aliceWallet, "tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f");
160+
blockchain!,
161+
aliceWallet,
162+
"tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f",
163+
amountSat,
164+
);
158165
}
159166

160167
@override
@@ -286,9 +293,9 @@ class _SimpleWalletState extends State<SimpleWallet> {
286293
fontWeight: FontWeight.w800),
287294
)),
288295
TextButton(
289-
onPressed: () => sendBit(),
296+
onPressed: () => sendBit(100000),
290297
child: const Text(
291-
'Press to send 1200 satoshi',
298+
'Press to send 100k sats',
292299
style: TextStyle(
293300
color: Colors.indigoAccent,
294301
fontSize: 12,

lib/src/root.dart

+24
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ class Blockchain extends BdkBlockchain {
6161
}
6262
}
6363

64+
static Future<Blockchain> createMutinynet({
65+
int stopGap = 20,
66+
}) async {
67+
final config = BlockchainConfig.esplora(
68+
config: EsploraConfig(
69+
baseUrl: 'https://mutinynet.ltbl.io/api',
70+
stopGap: stopGap,
71+
),
72+
);
73+
return create(config: config);
74+
}
75+
76+
static Future<Blockchain> createTestnet({
77+
int stopGap = 20,
78+
}) async {
79+
final config = BlockchainConfig.esplora(
80+
config: EsploraConfig(
81+
baseUrl: 'https://testnet.ltbl.io/api',
82+
stopGap: stopGap,
83+
),
84+
);
85+
return create(config: config);
86+
}
87+
6488
///Estimate the fee rate required to confirm a transaction in a given target of blocks
6589
@override
6690
Future<FeeRate> estimateFee({required int target, hint}) async {

0 commit comments

Comments
 (0)