amp-rust 0.0.9

A Rust client for the Blockstream AMP API, providing interfaces for asset management, user operations, and token handling on the Liquid Network.
Documentation
# Testing the Confidential Transaction Blinding Fix

## Overview
This fix resolves the "bad-txns-in-ne-out, value in != value out" error in the `test_end_to_end_distribution_workflow` test by properly handling confidential transaction blinding.

## Prerequisites

1. **Elements Node Running**: Ensure your Elements node is running and accessible
2. **Environment Variables**: Make sure your `.env` file has the correct credentials
3. **Wallet Funded**: The test wallet should have sufficient L-BTC and test assets

## Testing Steps

### 1. Clean Previous State (IMPORTANT)
Before running the test, always clean up any pending distributions:

```bash
cargo run --example cancel_test_asset_distribution
```

This is crucial because failed test runs leave assets in a pending state that prevents new distributions.

### 2. Run the Fixed Test
```bash
cargo test test_end_to_end_distribution_workflow -- --ignored
```

### 3. Expected Output
With the fix, you should see:
```
✅ Transaction built successfully
✅ Transaction blinded for confidential assets  
✅ Transaction signed with LWK
✅ Transaction broadcast successfully
✅ Waiting for confirmations...
✅ Distribution completed successfully
```

## What the Fix Does

### Before (Broken)
1. Elements creates raw transaction with its own blinding factors
2. LWK signs with different blinding factors (mismatch!)
3. Broadcast fails: "bad-txns-in-ne-out, value in != value out"

### After (Fixed)
1. Elements creates raw transaction
2. **NEW**: Elements blinds transaction with wallet-compatible factors
3. LWK signs the properly blinded transaction
4. Broadcast succeeds ✅

## Troubleshooting

### If the test still fails:

1. **Check Elements Node**:
   ```bash
   # Test connectivity
   curl -u user:pass -X POST -H "Content-Type: application/json" \
     -d '{"jsonrpc":"1.0","id":"test","method":"getnetworkinfo","params":[]}' \
     http://localhost:18884/
   ```

2. **Verify Wallet**:
   ```bash
   # Check if wallet exists and has funds
   cargo run --example diagnose_utxo_issues
   ```

3. **Clean State Again**:
   ```bash
   cargo run --example cancel_test_asset_distribution
   cargo run --example cleanup_resources
   ```

### Common Issues

- **"Wallet not found"**: The Elements wallet may not be loaded
- **"Insufficient funds"**: Need L-BTC for transaction fees
- **"Asset not found"**: Previous test cleanup may be needed
- **"Connection refused"**: Elements node not running

## Verification

### Success Indicators
- ✅ No "bad-txns-in-ne-out" error
- ✅ Transaction broadcasts successfully
- ✅ Confirmations are received
- ✅ Asset distribution completes

### Log Messages to Look For
```
✅ Successfully blinded transaction - original: X chars, blinded: Y chars
✅ Successfully signed transaction with UTXOs. TXID: abc123...
✅ Successfully broadcast transaction with ID: abc123...
✅ Transaction confirmed with 2 confirmations
```

## Additional Tests

You can also run related tests:
```bash
# Test the blinding functionality specifically
cargo run --bin test_blinding_fix

# Run all distribution tests
cargo test distribution -- --ignored

# Test asset cleanup workflow
cargo run --example test_asset_cleanup_workflow
```

## Support

If you continue to experience issues:

1. Check the detailed error messages (they now provide specific guidance)
2. Review the `CONFIDENTIAL_TRANSACTION_BLINDING_FIX.md` for technical details
3. Ensure your Elements node supports `blindrawtransaction` RPC
4. Verify that your wallet has the necessary blinding keys

The fix should resolve the blinding mismatch issue and allow confidential asset distributions to work correctly.