[WIP] Generate actions for Bob's on-chain protocol

Mimics what @thomaseizinger did here [1] and here [2].

This has the advantage that the consumer has more freedom to execute
`Action`s without having to implement particular traits. The error
handling required inside this protocol-executing function is also
reduced.

As discussed with Thomas, for this approach to work well, the
trait functions such as `receive_transfer_proof` should be infallible,
and the implementer should be forced to hide IO errors behind a retry
mechanism.

All of these asynchronous calls need to be "raced" against
the abort condition (determined by the `refund_timelock`), which is
missing in the current state of the implementation.

The initial handshake of the protocol has not been included here,
because it may not be easy to integrate this approach with libp2p, but
a couple of messages still need to exchanged. I need @tcharding to
tell me if it's feasible/good to do it like this.

[1]
https://github.com/comit-network/comit-rs/blob/move-nectar-swap-to-comit/nectar/src/swap/comit/herc20_hbit.rs#L57-L184.
[2] e584d2b14f/nectar/src/swap.rs (L716-L751).
This commit is contained in:
Lucas Soriano del Pino 2020-10-12 17:17:22 +11:00
parent 1ee060b535
commit 5daa3ea9a8
5 changed files with 232 additions and 16 deletions

View file

@ -6,9 +6,8 @@ use bitcoin::{
hashes::{hex::ToHex, Hash},
secp256k1,
util::psbt::PartiallySignedTransaction,
SigHash, Transaction,
SigHash,
};
pub use bitcoin::{Address, Amount, OutPoint, Txid};
use ecdsa_fun::{
adaptor::Adaptor,
fun::{
@ -18,13 +17,14 @@ use ecdsa_fun::{
nonce::Deterministic,
ECDSA,
};
pub use ecdsa_fun::{adaptor::EncryptedSignature, Signature};
use miniscript::{Descriptor, Segwitv0};
use rand::{CryptoRng, RngCore};
use sha2::Sha256;
use std::str::FromStr;
pub use crate::bitcoin::transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund};
pub use bitcoin::{Address, Amount, OutPoint, Transaction, Txid};
pub use ecdsa_fun::{adaptor::EncryptedSignature, Signature};
pub const TX_FEE: u64 = 10_000;