Closed rkalis closed 4 years ago
This issue has two parts: the first is exposing a contract instance's UTXOs, and the second is allowing these UTXOs to be used as inputs for a transaction.
Add function to retrieve an instance's UTXOs.
instance.getUtxos(excludeUnconfirmed?: boolean): Promise<Utxo[]>
This function should be similar to the getBalance
function, but instead of balance, it should use bitbox to return the UTXOs + unconfirmed UTXOs. We could add an excludeUnconfirmed
flag too.
Add an optional inputs: Utxo[]
field in TxOptions
.
If this field is used, pass in the inputs
into the getInputsAndOutputs
function, similar to options.fee
.
If this field is used, replace the UTXO selection algorithm inside the getInputsAndOutputs
function. Note that fee
and change
calculation should still be performed regularly.
Test the new functionality. Currently much of the SDK is tested through end-to-end testing on testnet, since it's difficult to test transactions locally. A few failure cases should be tested (e.g. the manual UTXOs are too small for the transaction), and then a success case should be tested (can use any existing contract, like P2PKH). Ideally this test would parse the resulting transaction object to check that the correct UTXOs are used.
Some covenant contracts are reliant on having specific UTXOs as inputs. It should be possible to optionally provide the UTXOs to the transaction manually. For this it should also be possible to retrieve all UTXOs that belong to a contract instance (
instance.getUTXOs()
).