Fix Dogecoin & Monero multi-output refunds with proper fee handling #84

Merged
russellballestrini merged 11 commits from feature/multi-output-refunds into master 2025-10-03 11:15:29 -04:00

11 commits

Author SHA1 Message Date
9432375bcb Add shop ribbon color styling to links in product and content descriptions
- Modify protect_links function to apply shop theme_link_color to all links
- Add custom CSS validation using regex patterns for security
- Support hex colors (#fff, #ffffff), rgb(), rgba(), hsl(), hsla(), and named colors
- Reject malicious inputs like javascript: schemes
- Add style attribute to allowed attributes for anchor tags
- Pass shop reference through cleaner object for color access
2025-10-03 09:46:20 -04:00
2657f982ec Fix crypto_watcher tests after sendtoaddress changes
- Update DOGE sweep tests to expect _call method with subtractfeefromamount
- Fix refund tests to properly mock sendmany method calls
- Update sweep_restocking_fee to use consistent _call interface
- Adjust tests to account for estimatesmartfee calls before sweeps
- Update XMR refund tests to match actual implementation flow

All 101 crypto_watcher tests now pass successfully.
2025-10-02 19:55:27 -04:00
24bd698ecd Fix DOGE sweep insufficient funds error using subtractfeefromamount
- Use subtractfeefromamount=True parameter in sendtoaddress for DOGE sweeps
- This allows Dogecoin to automatically deduct network fee from the sweep amount
- Resolves 500 errors when trying to sweep the exact wallet balance
- Regular payment sweeps remain single-output transactions (no multi-output needed)
2025-10-02 19:26:53 -04:00
f545e0e3e4 modified: make_post_sell/lib/crypto_watcher/__init__.py
modified:   make_post_sell/lib/crypto_watcher/crypto_clients.py
	modified:   make_post_sell/models/invoice.py
	modified:   make_post_sell/scripts/alembic/versions/0915b3ff883d_add_swept_confirmations_to_track_sweep_.py
	modified:   make_post_sell/tests/test_crypto_watcher.py
	modified:   make_post_sell/tests/test_multi_output_refunds.py
	modified:   make_post_sell/views/crypto.py
2025-10-02 19:22:38 -04:00
d90f41c5d9 Fix sweep confirmation monitoring to use coin-specific thresholds
- Query DOGE sweeps only if < 2 confirmations
- Query XMR sweeps only if < 10 confirmations
- Set model default to 0 for new sweeps
- Migration sets server_default to 10 for existing records
- This prevents monitoring already-confirmed legacy sweeps
2025-10-02 19:15:09 -04:00
a74bf72e6a Add sweep transaction confirmation monitoring
- Added global OUTBOUND_CONFIRMATIONS_REQUIRED config (2 for DOGE, 10 for XMR)
- Added swept_confirmations field to CryptoPayment model
- Modified auto-sweep functions to track confirmations instead of immediately transitioning to confirmed-complete
- Added process_sweep_confirmations() to monitor sweep transactions
- Standardized confirmation requirements for both sweeps and refunds
- Created alembic migration 0915b3ff883d for swept_confirmations field

This ensures we track when funds actually leave the hot wallet and provides consistent monitoring for all outbound transactions.
2025-10-02 19:04:13 -04:00
dc092d920d Fix redirect after purchase to check for digital products properly
- Add check for is_physical=False in addition to has_product_file
- Add detailed logging to diagnose redirect issues
- Physical products should always redirect to invoice
- Digital products without files should redirect to invoice
- Only digital products with files should redirect to product page
2025-10-02 16:42:44 -04:00
3289702d50 Move Dogecoin fee buffer to global constant for easier ops access
- DOGE_REFUND_FEE_BUFFER now defined at top of file (line 22)
- Clear comments explaining when/why to adjust it
- Error messages point directly to the constant
- Still overridable via environment variable
2025-10-02 16:35:24 -04:00
8836fb6333 Add better fee error handling and monitoring
- Log clear error messages when fee buffer is too low
- Show exact shortfall amount and required action
- Add DOGE_REFUND_FEE_BUFFER environment variable for dynamic adjustment
- Log actual fee buffer used on successful refunds
- Add helpful comment in vars.sh about the fee buffer setting

Now when watching crypto-watcher logs, admins will see:
- 'INSUFFICIENT FUNDS - Fee estimate too low\!'
- Current buffer, shortfall amount, and line number to fix
- Success messages show actual vs estimated fee usage

This makes it much easier to adjust the fee buffer without diving into code.
2025-10-02 16:34:16 -04:00
d4a239d748 Clean up multi-output refund code
- Reduce fee buffer from 0.01 to 0.005 DOGE (actual fee was 0.0026)
- Remove excessive logging throughout refund process
- Simplify sendmany retry logic - just try funded account then default
- Remove unnecessary balance checks and debug logging
- Fix test mocks to use sendmany instead of _call

This reduces the dust left in temporary wallets from ~0.011 to ~0.005 DOGE
2025-10-02 16:27:33 -04:00
d2d09e8851 Fix Dogecoin multi-output refunds with proper fee handling
- Add payment amount to shop output for overpayment refunds
- Both XMR and DOGE now send payment + restocking fee to shop
- Fix insufficient funds error by using conservative fee buffer (0.01 DOGE)
- Round outputs down to 3 decimal places to avoid precision issues
- Update sendmany to try actual account first (where funds are located)
- Add better error handling for different account formats
- Fix fee calculation to properly account for Dogecoin's fee-on-top model

The issue was that sendmany adds network fee on top of outputs, and we
were trying to send exactly the wallet balance, leaving no room for fees.
Now we reserve 0.01 DOGE for fees and round conservatively.
2025-10-02 16:19:23 -04:00