Open chris-belcher opened 2 years ago
I implemented part of this issue in this and the surrounding commits: https://github.com/bitcoin-teleport/teleport-transactions/commit/9b256b1d6ca9dac3af3fb68b73c56cd2b2d79f92
I need it pretty soon in order to spend from a contract UTXO with the hashlock branch, and to use that to test whether a watchtower will behave properly.
We need a new main method which sends bitcoins out from the wallet. It would take a destination address and amount as input, and create a regular transaction just like any other bitcoin wallet does.
Because of the way coinswap works with the multisig and private key handover, it's not possible to send a coinswap directly to any address like you can with coinjoin/joinmarket. You first need to do a coinswap and then spend those coins (when coinswap is used by regular users these two functions can be combined into one button so that the user doesn't have to think).
Now is the right time to implement this is because we can use the same function to test how watchtowers respond to a coinswap peer deviating from the protocol. We could use this method to simulate a malicious taker who broadcasts a contract transaction instead of continuing the protocol. And then they could spend it with the timelock or hashlock branch, or some other way, and we could test what the watchtower does in response.
The new main method should allow coin control by optionally accepting a list of outpoints in our wallet to spend. That's part of the reason why I made the
568a4e..83a2e8:0
shortened format for easier copypasting.If not using coin control, you can have Bitcoin Core select coins to spend in the same way that the teleport wallet already does: https://github.com/bitcoin-teleport/teleport-transactions/blob/522000c903163f9e114afc951d78e129048092e6/src/wallet_sync.rs#L1164
Probably the best way to implement this in code is to generalize the code in the
create_spending_txes
function and reuse that code for this new method.The new main method should allow choosing the amount to spend, but also allow a sweep spend where the entire list of UTXO are sent without creating a change address. Electrum uses the "!" character on the command line to mean sweep, so maybe the command line option can be either a number of satoshis or a "!" character.
Remember that right now in the code there's three kinds of UTXOs we are able to spend 1) single-sig UTXO from the HD wallet 2) 2of2 multisig UTXO from a successful coinswap and 3) UTXO protected by a timelock from an aborted coinswap following the timeout branch.
So for example these are command lines which spend:
cargo run -- direct-send 1000000 bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
(sending a million satoshi to the given address)cargo run -- direct-send ! bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
(sending all the money in the wallet to the given address)cargo run -- direct-send 1000000 bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq 568a4e..83a2e8:0
(sending a million satoshi to the given address by only spending the given outpoint, sending the rest to a change address)cargo run -- direct-send 1000000 bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq 568a4e..83a2e8:0 4ef47f..c8744c:1
(sending a million satoshi to the given address by only spending the two given outpoints, sending the rest to a change address)cargo run -- direct-send ! bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq 568a4e..83a2e8:0 4ef47f..c8744c:1
(sending all the money in those two given outpoints to the given address)(I don't know if
direct-send
is the best name for this method, it's just something I made up now, maybesend
ornormal-send
is better, but it doesn't really matter)