Type timelock and block height

To ensure no mistake is made (and none were!)
This commit is contained in:
Franck Royer 2020-12-23 16:04:06 +11:00
parent 81cbc24c46
commit bcbc54b569
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
8 changed files with 125 additions and 70 deletions

View file

@ -9,7 +9,6 @@ use futures::{
pin_mut,
};
use libp2p::request_response::ResponseChannel;
use rand::rngs::OsRng;
use sha2::Sha256;
use std::{sync::Arc, time::Duration};
@ -19,9 +18,9 @@ use xmr_btc::{
alice,
alice::State3,
bitcoin::{
poll_until_block_height_is_gte, BroadcastSignedTransaction, EncryptedSignature,
GetBlockHeight, GetRawTransaction, TransactionBlockHeight, TxCancel, TxLock, TxRefund,
WaitForTransactionFinality, WatchForRawTransaction,
poll_until_block_height_is_gte, BlockHeight, BroadcastSignedTransaction,
EncryptedSignature, GetBlockHeight, GetRawTransaction, Timelock, TransactionBlockHeight,
TxCancel, TxLock, TxRefund, WaitForTransactionFinality, WatchForRawTransaction,
},
config::Config,
cross_curve_dleq,
@ -207,7 +206,7 @@ pub async fn publish_cancel_transaction<W>(
tx_lock: TxLock,
a: bitcoin::SecretKey,
B: bitcoin::PublicKey,
cancel_timelock: u32,
cancel_timelock: Timelock,
tx_cancel_sig_bob: bitcoin::Signature,
bitcoin_wallet: Arc<W>,
) -> Result<bitcoin::TxCancel>
@ -253,8 +252,8 @@ where
pub async fn wait_for_bitcoin_refund<W>(
tx_cancel: &TxCancel,
cancel_tx_height: u32,
punish_timelock: u32,
cancel_tx_height: BlockHeight,
punish_timelock: Timelock,
refund_address: &bitcoin::Address,
bitcoin_wallet: Arc<W>,
) -> Result<(bitcoin::TxRefund, Option<bitcoin::Transaction>)>
@ -306,9 +305,9 @@ pub fn extract_monero_private_key(
pub fn build_bitcoin_punish_transaction(
tx_lock: &TxLock,
cancel_timelock: u32,
cancel_timelock: Timelock,
punish_address: &bitcoin::Address,
punish_timelock: u32,
punish_timelock: Timelock,
tx_punish_sig_bob: bitcoin::Signature,
a: bitcoin::SecretKey,
B: bitcoin::PublicKey,

View file

@ -133,24 +133,26 @@ impl GetRawTransaction for Wallet {
#[async_trait]
impl GetBlockHeight for Wallet {
async fn get_block_height(&self) -> u32 {
(|| async { Ok(self.inner.client.getblockcount().await?) })
async fn get_block_height(&self) -> BlockHeight {
let height = (|| async { Ok(self.inner.client.getblockcount().await?) })
.retry(ConstantBackoff::new(Duration::from_secs(1)))
.await
.expect("transient errors to be retried")
.expect("transient errors to be retried");
BlockHeight::new(height)
}
}
#[async_trait]
impl TransactionBlockHeight for Wallet {
async fn transaction_block_height(&self, txid: Txid) -> u32 {
async fn transaction_block_height(&self, txid: Txid) -> BlockHeight {
#[derive(Debug)]
enum Error {
Io,
NotYetMined,
}
(|| async {
let height = (|| async {
let block_height = self
.inner
.transaction_block_height(txid)
@ -164,7 +166,9 @@ impl TransactionBlockHeight for Wallet {
})
.retry(ConstantBackoff::new(Duration::from_secs(1)))
.await
.expect("transient errors to be retried")
.expect("transient errors to be retried");
BlockHeight::new(height)
}
}