Merge pull request #64 from comit-network/bitcoin-harness-rpc-client

Upgrade bitcoin-harness
This commit is contained in:
Franck Royer 2020-12-07 14:22:19 +11:00 committed by GitHub
commit b47c6cad37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 15 deletions

27
Cargo.lock generated
View File

@ -254,14 +254,15 @@ dependencies = [
[[package]]
name = "bitcoin-harness"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f4cd49a4bc53eaeab332d66022a158515f0b5bb4b381a1583a07a0c667ac280"
source = "git+https://github.com/coblox/bitcoin-harness-rs?rev=864b55fcba2e770105f135781dd2e3002c503d12#864b55fcba2e770105f135781dd2e3002c503d12"
dependencies = [
"async-trait",
"base64 0.12.3",
"bitcoin",
"bitcoincore-rpc-json",
"futures",
"hex 0.4.2",
"jsonrpc_client",
"reqwest",
"serde",
"serde_json",
@ -1551,6 +1552,28 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "jsonrpc_client"
version = "0.3.0"
source = "git+https://github.com/thomaseizinger/rust-jsonrpc-client?rev=c7010817e0f86ab24b3dc10d6bb0463faa0aace4#c7010817e0f86ab24b3dc10d6bb0463faa0aace4"
dependencies = [
"async-trait",
"jsonrpc_client_macro",
"reqwest",
"serde",
"serde_json",
"url",
]
[[package]]
name = "jsonrpc_client_macro"
version = "0.1.0"
source = "git+https://github.com/thomaseizinger/rust-jsonrpc-client?rev=c7010817e0f86ab24b3dc10d6bb0463faa0aace4#c7010817e0f86ab24b3dc10d6bb0463faa0aace4"
dependencies = [
"quote 1.0.7",
"syn 1.0.48",
]
[[package]]
name = "keccak"
version = "0.1.0"

View File

@ -13,7 +13,7 @@ atty = "0.2"
backoff = { version = "0.2", features = ["tokio"] }
base64 = "0.12"
bitcoin = { version = "0.25", features = ["rand", "use-serde"] }
bitcoin-harness = "0.2"
bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs", rev = "864b55fcba2e770105f135781dd2e3002c503d12" }
conquer-once = "0.3"
derivative = "2"
ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", rev = "cdfbc766045ea678a41780919d6228dd5acee3be", features = ["libsecp_compat", "serde"] }

View File

@ -1,11 +1,10 @@
use std::time::Duration;
use anyhow::Result;
use anyhow::{Context, Result};
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin::util::psbt::PartiallySignedTransaction;
use bitcoin_harness::bitcoind_rpc::PsbtBase64;
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, BitcoindRpcApi};
use reqwest::Url;
use std::time::Duration;
use tokio::time::interval;
use xmr_btc::{
bitcoin::{
@ -44,7 +43,15 @@ impl Wallet {
.0
.get_wallet_transaction(txid)
.await
.map(|res| bitcoin::Amount::from_btc(-res.fee))??;
.map(|res| {
res.fee.map(|signed_amount| {
signed_amount
.abs()
.to_unsigned()
.expect("Absolute value is always positive")
})
})?
.context("Rpc response did not contain a fee")?;
Ok(fee)
}
@ -116,7 +123,7 @@ impl GetRawTransaction for Wallet {
#[async_trait]
impl BlockHeight for Wallet {
async fn block_height(&self) -> u32 {
(|| async { Ok(self.0.block_height().await?) })
(|| async { Ok(self.0.client.getblockcount().await?) })
.retry(ConstantBackoff::new(Duration::from_secs(1)))
.await
.expect("transient errors to be retried")

View File

@ -16,6 +16,7 @@ use crate::{
state::{Alice, Bob, Swap},
};
use anyhow::Result;
use bitcoin_harness::BitcoindRpcApi;
use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic};
use futures::{
future::{select, Either},
@ -163,7 +164,7 @@ pub async fn alice_recover(
.transaction_block_height(state.tx_lock.txid())
.await;
let block_height = bitcoin_wallet.0.block_height().await?;
let block_height = bitcoin_wallet.0.client.getblockcount().await?;
let refund_absolute_expiry = tx_lock_height + state.refund_timelock;
info!("Checking refund timelock");

View File

@ -29,7 +29,7 @@ tracing = "0.1"
[dev-dependencies]
backoff = { version = "0.2", features = ["tokio"] }
base64 = "0.12"
bitcoin-harness = "0.2"
bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs", rev = "864b55fcba2e770105f135781dd2e3002c503d12" }
futures = "0.3"
monero-harness = { path = "../monero-harness" }
reqwest = { version = "0.10", default-features = false }

View File

@ -1,8 +1,8 @@
use anyhow::Result;
use anyhow::{Context, Result};
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin::{util::psbt::PartiallySignedTransaction, Address, Amount, Transaction, Txid};
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, Bitcoind};
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, Bitcoind, BitcoindRpcApi};
use reqwest::Url;
use std::time::Duration;
use tokio::time;
@ -35,7 +35,15 @@ impl Wallet {
.0
.get_wallet_transaction(txid)
.await
.map(|res| bitcoin::Amount::from_btc(-res.fee))??;
.map(|res| {
res.fee.map(|signed_amount| {
signed_amount
.abs()
.to_unsigned()
.expect("Absolute value is always positive")
})
})?
.context("Rpc response did not contain a fee")?;
Ok(fee)
}
@ -121,7 +129,7 @@ impl WatchForRawTransaction for Wallet {
#[async_trait]
impl BlockHeight for Wallet {
async fn block_height(&self) -> u32 {
(|| async { Ok(self.0.block_height().await?) })
(|| async { Ok(self.0.client.getblockcount().await?) })
.retry(ConstantBackoff::new(Duration::from_secs(1)))
.await
.expect("transient errors to be retried")