Skip to content

Commit

Permalink
outgoing tx: check if one of the recipients is known but not the chan…
Browse files Browse the repository at this point in the history
…geAddress (isSendingToSelf)
  • Loading branch information
willyfromtheblock committed Sep 14, 2023
1 parent 93b4604 commit 05d3d1c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
50 changes: 44 additions & 6 deletions lib/providers/wallet_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,47 @@ class WalletProvider with ChangeNotifier {
),
);

//check recipients if one of them is our address but not the current change address (sending coins to oneself)
final changeAddress = getUnusedAddress(identifier);

for (final recipientAddr in buildResult.recipients.keys) {
if (recipientAddr != changeAddress) {
if (openWallet.addresses.firstWhereOrNull(
(element) => element.address == recipientAddr,
) !=
null) {
//found recipient in the transaction that is not the changeAddress but our address
final value = buildResult.recipients[recipientAddr] ?? 0;

LoggerWrapper.logInfo(
'WalletProvider',
'putOutgoingTx',
'isSendingToSelf: $recipientAddr $value',
);

//write tx
openWallet.putTransaction(
WalletTransaction(
txid: buildResult.id,
timestamp: 0,
value: value,
fee: 0,
recipients: {recipientAddr: value},
address: recipientAddr,
direction: 'in',
broadCasted: false,
confirmations: 0,
broadcastHex: '',
opReturn: buildResult.opReturn,
),
);
}
}
}

//flag _unusedAddress as change addr
final addrInWallet = openWallet.addresses.firstWhereOrNull(
(element) => element.address == getUnusedAddress(identifier),
(element) => element.address == changeAddress,
);
if (addrInWallet != null) {
if (buildResult.neededChange == true) {
Expand Down Expand Up @@ -1076,13 +1114,13 @@ class WalletProvider with ChangeNotifier {
String txId,
) async {
final openWallet = getSpecificCoinWallet(identifier);
final tx = openWallet.transactions.firstWhereOrNull(
final tx = openWallet.transactions.where(
(element) => element.txid == txId,
);
if (tx != null) {
tx.broadCasted = true;
tx.resetBroadcastHex();
tx.confirmations = 0;
for (final element in tx) {
element.broadCasted = true;
element.resetBroadcastHex();
element.confirmations = 0;
await openWallet.save();
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/wallet/wallet_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ class _WalletHomeState extends State<WalletHomeScreen>

void rebroadCastUnsendTx() {
var nonBroadcastedTx = _walletTransactions.where(
(element) => element.broadCasted == false && element.confirmations == 0,
(element) =>
element.broadCasted == false &&
element.confirmations == 0 &&
element.direction == 'out',
);
for (var element in nonBroadcastedTx) {
_connectionProvider.broadcastTransaction(
Expand Down

0 comments on commit 05d3d1c

Please sign in to comment.