utxostack / rgbpp-sdk

Utilities for Bitcoin and RGB++ asset integration
ISC License
53 stars 18 forks source link

Transfer all BTC without the change output #273

Open ShookLyngs opened 3 months ago

ShookLyngs commented 3 months ago

In the current implementation of the btc lib, all imbalanced transactions without non-fixed outputs, should generate a change output. This means that if there are satoshi left in the inputs, they should be returned as a change output. This can be inappropriate in some scenarios, for example, when a user wants to transfer the entire balance to another address, a change output is redundant.

Overall, the feature has two key points to be resolved:

  1. What is the available balance for the transfer-all action?
  2. How can the redundant change output be removed from the transaction?

Related Issues

ShookLyngs commented 3 months ago

What is the available balance for the transfer-all action?

If an address holds normal BTC UTXOs, RGBPP UTXOs and dust UTXOs, we should only transfer the normal BTC UTXOs and exclude the others. In this case, the sendBtc API is not suitable and we might wanna implement a new API for it.

Ideally, we can fetch the Utxo[] list of the address, and then add all BTC UTXOs to the transaction inputs, while doing this, we should also calculate the total value of the inputs. And then, we can generate an output in the transaction that it contains all the value of the transaction inputs.

How can the redundant change output be removed from the transaction?

The current logic supports:

By setting the output with fixed: false and protected: true should prevent a redundant change output.