Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
feat(BUX-291): prevent saving syncTx hwen outgoing tx is rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain committed Nov 6, 2023
1 parent 2e16102 commit 7f51d26
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sync_tx_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func processSyncTransactions(ctx context.Context, maxTransactions int, opts ...M

// Process the incoming transaction
for index := range records {
if err = _processSyncTransaction(
if err = _syncTxDataFromChain(
ctx, records[index], nil,
); err != nil {
return err
Expand Down Expand Up @@ -220,8 +220,8 @@ func broadcastSyncTransaction(ctx context.Context, syncTx *SyncTransaction) erro

/////////////////

// _processSyncTransaction will process the sync transaction record, or save the failure
func _processSyncTransaction(ctx context.Context, syncTx *SyncTransaction, transaction *Transaction) error {
// _syncTxDataFromChain will process the sync transaction record, or save the failure
func _syncTxDataFromChain(ctx context.Context, syncTx *SyncTransaction, transaction *Transaction) error {
// Successfully capture any panics, convert to readable string and log the error
defer recoverAndLog(ctx, syncTx.client.Logger())

Expand Down Expand Up @@ -438,6 +438,7 @@ func _groupByXpub(scTxs []*SyncTransaction) map[string][]*SyncTransaction {
func _bailAndSaveSyncTransaction(ctx context.Context, syncTx *SyncTransaction, status SyncStatus,
action, provider, message string,
) {

if action == syncActionSync {
syncTx.SyncStatus = status
} else if action == syncActionP2P {
Expand All @@ -458,5 +459,10 @@ func _bailAndSaveSyncTransaction(ctx context.Context, syncTx *SyncTransaction, s
Provider: provider,
StatusMessage: message,
})

if syncTx.IsNew() {
return // do not save if new record! caller should decide if want to save new record
}

_ = syncTx.Save(ctx)
}

0 comments on commit 7f51d26

Please sign in to comment.