Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement normal spend from wallet #42

Open
chris-belcher opened this issue Dec 8, 2021 · 1 comment
Open

Implement normal spend from wallet #42

chris-belcher opened this issue Dec 8, 2021 · 1 comment

Comments

@chris-belcher
Copy link
Contributor

chris-belcher commented Dec 8, 2021

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:

let psbt_result = rpc.wallet_create_funded_psbt(

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, maybe send or normal-send is better, but it doesn't really matter)

@chris-belcher
Copy link
Contributor Author

I implemented part of this issue in this and the surrounding commits: 9b256b1

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant