Skip to content

Commit

Permalink
Combine regular mix and split ticket mix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Nov 7, 2024
1 parent 74578b7 commit 29ee36d
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5893,7 +5893,7 @@ func rpcTxFee(tx *ListTransactionsResult) uint64 {
return 0
}

func isMixTx(tx *wire.MsgTx) (isMix bool, mixDenom int64) {
func isRegularMix(tx *wire.MsgTx) (isMix bool, mixDenom int64) {
if len(tx.TxOut) < 3 || len(tx.TxIn) < 3 {
return false, 0
}
Expand Down Expand Up @@ -5955,6 +5955,14 @@ func isMixedSplitTx(tx *wire.MsgTx) (isMix bool, tikPrice int64) {
return true, tikPrice
}

func isMixTx(tx *wire.MsgTx) (isMix bool, mixDenom int64) {
if isMix, mixDenom = isRegularMix(tx); isMix {
return
}

return isMixedSplitTx(tx)
}

// idUnknownTx identifies the type and details of a transaction either made
// or received by the wallet.
func (dcr *ExchangeWallet) idUnknownTx(ctx context.Context, ltxr *ListTransactionsResult) (*asset.WalletTransaction, error) {
Expand Down Expand Up @@ -6192,40 +6200,6 @@ func (dcr *ExchangeWallet) idUnknownTx(ctx context.Context, ltxr *ListTransactio
}, nil
}

if isMix, tikPrice := isMixedSplitTx(tx.MsgTx); isMix {
var mixedAmount uint64
for _, txOut := range tx.MsgTx.TxOut {
if txOut.Value == tikPrice {
_, addrs := stdscript.ExtractAddrs(scriptVersion, txOut.PkScript, dcr.chainParams)
if err != nil {
dcr.log.Errorf("ExtractAddrs error: %w", err)
continue
}
if len(addrs) != 1 { // sanity check
continue
}

addr := addrs[0]
owns, err := dcr.wallet.WalletOwnsAddress(ctx, addr)
if err != nil {
dcr.log.Errorf("walletOwnsAddress error: %w", err)
continue
}

if owns {
mixedAmount += uint64(txOut.Value)
}
}
}

return &asset.WalletTransaction{
Type: asset.Mix,
ID: ltxr.TxID,
Amount: mixedAmount,
Fees: fee,
}, nil
}

getRecipient := func(msgTx *wire.MsgTx, receive bool) *string {
for _, txOut := range msgTx.TxOut {
_, addrs := stdscript.ExtractAddrs(scriptVersion, txOut.PkScript, dcr.chainParams)
Expand Down

0 comments on commit 29ee36d

Please sign in to comment.