Skip to content

Commit

Permalink
BROADCAST PAYJOIN BABY
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Dec 19, 2024
1 parent fec3723 commit 3bba3cc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/_pkg/payjoin/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ class PayjoinManager {
return;
}
final signedPayjoin = result!.$1;
final broadcastedTx = (await blockchain(isTestnet))
await (await blockchain(isTestnet))
.broadcast(transaction: signedPayjoin);
print('Broadcasted transaction: $broadcastedTx');
print('Broadcasted transaction: $signedPayjoin');
await _cleanupSession(sessionId);
} else if (message is Err) {
print('err: $message');
Expand Down
16 changes: 13 additions & 3 deletions lib/_pkg/wallet/bdk/sensitive_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,24 @@ class BDKSensitiveCreate {
Future<(bdk.Wallet?, Err?)> loadPrivateBdkWallet(
Wallet wallet,
Seed seed,
) async {
return await loadPrivateBdkWalletWithDb(
wallet,
seed,
const bdk.DatabaseConfig.memory(),
);
}

Future<(bdk.Wallet?, Err?)> loadPrivateBdkWalletWithDb(
Wallet wallet,
Seed seed,
bdk.DatabaseConfig dbConfig,
) async {
try {
final network = wallet.network == BBNetwork.Testnet
? bdk.Network.testnet
: bdk.Network.bitcoin;

print('network: $network');
final mn = await bdk.Mnemonic.fromString(seed.mnemonic);
final pp = wallet.hasPassphrase()
? seed.passphrases.firstWhere(
Expand Down Expand Up @@ -449,8 +461,6 @@ class BDKSensitiveCreate {
);
}

const dbConfig = bdk.DatabaseConfig.memory();

final bdkWallet = await bdk.Wallet.create(
descriptor: external,
changeDescriptor: internal,
Expand Down
9 changes: 7 additions & 2 deletions lib/_pkg/wallet/bdk/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class BDKTransactions {
// required String address,
}) async {
try {
print('signTx psbt: $psbt');
printWrapped('signTx psbt: $psbt');
final psbtStruct = await bdk.PartiallySignedTransaction.fromString(psbt);
final tx = psbtStruct.extractTx();
final _ = await bdkWallet.sign(
Expand All @@ -610,7 +610,7 @@ class BDKTransactions {
);
// final extracted = await finalized;
final psbtStr = psbtStruct.serialize();
print('signTx psbtStr: ${base64Encode(psbtStr)}');
printWrapped('signTx psbtStr: ${base64Encode(psbtStr)}');
return ((tx, base64Encode(psbtStr)), null);
} on Exception catch (e) {
return (
Expand Down Expand Up @@ -854,3 +854,8 @@ class BDKTransactions {
return false;
}
}

void printWrapped(String text) {
final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((match) => print(match.group(0)));
}
24 changes: 23 additions & 1 deletion lib/_pkg/wallet/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:bb_mobile/_pkg/wallet/repository/sensitive_storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_pkg/wallet/update.dart';
import 'package:bdk_flutter/bdk_flutter.dart' as bdk;
import 'package:path_provider/path_provider.dart';

class WalletTx implements IWalletTransactions {
WalletTx({
Expand Down Expand Up @@ -169,6 +170,9 @@ class WalletTx implements IWalletTransactions {
final (bdkSignerWallet, errSigner) =
await _bdkSensitiveCreate.loadPrivateBdkWallet(wallet, seed!);
if (errSigner != null) throw errSigner;
final signerTxs =
await bdkSignerWallet!.listTransactions(includeRaw: false);
print('signer txs: ${signerTxs.length}');
final (signed, errSign) = await _bdkTransactions.signTx(
psbt: psbt,
bdkWallet: bdkSignerWallet!,
Expand Down Expand Up @@ -235,13 +239,31 @@ class WalletTx implements IWalletTransactions {
try {
final (bdkWallet, errWallet) = _walletsRepository.getBdkWallet(wallet.id);
if (errWallet != null) throw errWallet;
final walletTxs = await bdkWallet!.listTransactions(includeRaw: false);
print('wallet txs: ${walletTxs.length}');
final (seed, errSeed) = await _walletSensitiveStorageRepository.readSeed(
fingerprintIndex: wallet.getRelatedSeedStorageString(),
);
if (errSeed != null) throw errSeed;
final appDocDir = await getApplicationDocumentsDirectory();
final String dbDir =
'${appDocDir.path}/${wallet.getWalletStorageString()}';

final dbConfig = bdk.DatabaseConfig.sqlite(
config: bdk.SqliteDbConfiguration(path: dbDir),
);
final (bdkSignerWallet, errSigner) =
await _bdkSensitiveCreate.loadPrivateBdkWallet(wallet, seed!);
await _bdkSensitiveCreate.loadPrivateBdkWalletWithDb(
wallet,
seed!,
dbConfig,
);
// final (blockchain, errNetwork) = _networkRepository.bdkBlockchain;
// await bdkSignerWallet!.sync(blockchain: blockchain!);
if (errSigner != null) throw errSigner;
final signerTxs =
await bdkSignerWallet!.listTransactions(includeRaw: false);
print('signer txs: ${signerTxs.length}');
return await _bdkTransactions.signTx(
psbt: psbt,
bdkWallet: bdkSignerWallet!,
Expand Down

0 comments on commit 3bba3cc

Please sign in to comment.