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

@ -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)
}
}