Skip to content

Commit 06701f8

Browse files
committed
Upgrade to baru 0.2
1 parent 359605d commit 06701f8

File tree

12 files changed

+117
-53
lines changed

12 files changed

+117
-53
lines changed

Cargo.lock

Lines changed: 61 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bobtimus/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ edition = "2018"
77
[dependencies]
88
anyhow = "1"
99
async-trait = "0.1"
10-
baru = "0.1"
10+
baru = "0.2"
1111
bitcoin_hashes = "0.9.0"
1212
diesel = { version = "1.4", features = ["sqlite"] }
1313
diesel_migrations = "1.4"
1414
directories = "3.0"
15-
elements = { version = "0.17", features = ["serde-feature"] }
15+
elements = { version = "0.18", features = ["serde-feature"] }
1616
elements-harness = { git = "https://github.com/comit-network/elements-harness" }
1717
futures = { version = "0.3", default-features = false }
1818
hex = "0.4"

bobtimus/src/elements_rpc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{bail, Context, Result};
22
use bitcoin_hashes::hex::FromHex;
33
use elements::{
4-
bitcoin::{Amount, PrivateKey},
4+
bitcoin::Amount,
55
confidential::{Asset, Nonce, Value},
66
encode::serialize_hex,
77
secp256k1_zkp::{SecretKey, Signature},
@@ -338,18 +338,16 @@ impl Client {
338338
Ok(sig)
339339
}
340340

341-
pub async fn dump_private_key(&self, address: &Address) -> Result<SecretKey> {
342-
let privkey = self.dumpprivkey(address).await?;
343-
let privkey = PrivateKey::from_wif(&privkey)?;
344-
345-
Ok(privkey.key)
346-
}
347-
348341
pub async fn get_blockcount(&self) -> Result<u32> {
349342
let blockcount = self.getblockcount().await?;
350343

351344
Ok(blockcount)
352345
}
346+
347+
pub async fn get_address_blinding_key(&self, address: &Address) -> Result<SecretKey> {
348+
let key = self.dumpblindingkey(address).await?;
349+
Ok(key)
350+
}
353351
}
354352

355353
#[derive(Debug, Deserialize)]

bobtimus/src/lib.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate diesel;
33
#[macro_use]
44
extern crate diesel_migrations;
55

6-
use std::{collections::HashMap, convert::TryInto};
6+
use std::collections::HashMap;
77

88
use crate::{
99
database::{queries, Sqlite},
@@ -45,6 +45,7 @@ pub mod schema;
4545

4646
use crate::loan::{Interest, LoanOffer};
4747
pub use amounts::*;
48+
use elements::bitcoin::PublicKey;
4849
use rust_decimal_macros::dec;
4950

5051
pub const USDT_ASSET_ID: &str = "ce091c998b83c78bb71a632313ba3760f1763d9cfcffae02258ffa9865a37bd2";
@@ -295,17 +296,31 @@ where
295296
// Currently there is no ID for incoming loan requests, that would associate them with an offer,
296297
// so we just have to ensure that the loan is still "acceptable" in the current state of Bobtimus.
297298

299+
let oracle_secret_key = elements::secp256k1_zkp::key::ONE_KEY;
300+
let oralce_priv_key = elements::bitcoin::PrivateKey::new(
301+
oracle_secret_key,
302+
elements::bitcoin::Network::Regtest,
303+
);
304+
let oracle_pk = PublicKey::from_private_key(&self.secp, &oralce_priv_key);
305+
298306
let lender_address = self
299307
.elementsd
300308
.get_new_segwit_confidential_address()
301309
.await
302310
.context("failed to get lender address")?;
303311

312+
let address_blinder = self
313+
.elementsd
314+
.get_address_blinding_key(&lender_address)
315+
.await?;
316+
304317
let lender0 = Lender0::new(
305318
&mut self.rng,
306319
self.btc_asset_id,
307320
self.usdt_asset_id,
308321
lender_address,
322+
address_blinder,
323+
oracle_pk,
309324
)
310325
.unwrap();
311326

@@ -328,7 +343,7 @@ where
328343
let loan_response = lender1.loan_response();
329344

330345
self.lender_states
331-
.insert(loan_response.transaction.txid(), lender1);
346+
.insert(loan_response.transaction().txid(), lender1);
332347

333348
Ok(loan_response)
334349
}
@@ -360,16 +375,14 @@ where
360375

361376
let txid = self.elementsd.send_raw_transaction(&transaction).await?;
362377

363-
let liquidation_tx =
364-
lender.liquidation_transaction(&mut self.rng, &self.secp, Amount::ONE_SAT)?;
365-
let locktime = lender
366-
.timelock
367-
.try_into()
368-
.expect("TODO: locktimes should be modelled as u32");
378+
let liquidation_tx = lender
379+
.liquidation_transaction(&mut self.rng, &self.secp, Amount::ONE_SAT)
380+
.await?;
381+
let locktime = lender.collateral_contract().timelock();
369382

370383
self.db
371384
.do_in_transaction(|conn| {
372-
LiquidationForm::new(txid, &liquidation_tx, locktime).insert(conn)?;
385+
LiquidationForm::new(txid, &liquidation_tx, *locktime).insert(conn)?;
373386

374387
Ok(())
375388
})

coin_selection/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2018"
66

77
[dependencies]
88
bdk = { version = "0.4", default-features = false }
9-
elements = "0.17"
9+
elements = "0.18"
1010
estimate_transaction_size = { path = "../estimate_transaction_size" }
1111
thiserror = "1"

coin_selection/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use bdk::{
2-
bitcoin::{Amount, Denomination},
32
database::{BatchOperations, Database},
43
wallet::coin_selection::{
54
BranchAndBoundCoinSelection, CoinSelectionAlgorithm, CoinSelectionResult,
65
},
76
};
8-
use elements::{AssetId, OutPoint, Script};
7+
use elements::{
8+
bitcoin::{Amount, Denomination},
9+
AssetId, OutPoint, Script,
10+
};
911
use estimate_transaction_size::avg_vbytes;
1012

1113
/// Select a subset of `utxos` to cover the `target` amount.
@@ -70,7 +72,8 @@ pub fn coin_select(
7072
utxos
7173
.iter()
7274
.find(|utxo| {
73-
bdk_utxo.outpoint.txid.as_hash() == utxo.outpoint.txid.as_hash()
75+
format!("{}", bdk_utxo.outpoint.txid)
76+
== format!("{}", utxo.outpoint.txid.as_hash())
7477
&& bdk_utxo.outpoint.vout == utxo.outpoint.vout
7578
})
7679
.expect("same source of utxos")
@@ -100,7 +103,7 @@ pub enum Error {
100103
#[error("All UTXOs must have the same asset ID")]
101104
HeterogeneousUtxos,
102105
#[error("Failed to parse recommended fee: {0}")]
103-
ParseFee(#[from] bdk::bitcoin::util::amount::ParseAmountError),
106+
ParseFee(#[from] elements::bitcoin::util::amount::ParseAmountError),
104107
#[error("Error from bdk: {0}")]
105108
Bdk(#[from] bdk::Error),
106109
}
@@ -121,7 +124,9 @@ impl From<Utxo> for bdk::UTXO {
121124

122125
Self {
123126
outpoint: bdk::bitcoin::OutPoint {
124-
txid: bdk::bitcoin::Txid::from_hash(utxo.outpoint.txid.as_hash()),
127+
txid: format!("{}", utxo.outpoint.txid)
128+
.parse()
129+
.expect("txid to be a txid"),
125130
vout: utxo.outpoint.vout,
126131
},
127132
txout: bdk::bitcoin::TxOut {

extension/wallet/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ default = ["console_error_panic_hook"]
1313
[dependencies]
1414
aes-gcm-siv = { version = "0.9", features = ["std"] }
1515
anyhow = "1"
16-
baru = "0.1"
17-
bdk = { version = "0.4", default-features = false }
16+
baru = "0.2"
1817
bip32 = { version = "0.2", features = ["secp256k1-ffi", "bip39"], default-features = false }
1918
coin_selection = { path = "../../coin_selection" }
2019
conquer-once = "0.3"
2120
console_error_panic_hook = { version = "0.1.6", optional = true }
22-
elements = { version = "0.17", features = ["serde-feature"] }
21+
elements = { version = "0.18", features = ["serde-feature"] }
2322
estimate_transaction_size = { path = "../../estimate_transaction_size" }
2423
futures = "0.3"
2524
getrandom = { version = "0.2", features = ["wasm-bindgen", "js"] }
@@ -48,7 +47,7 @@ wasm-bindgen-test = "0.3.13"
4847
[build-dependencies]
4948
anyhow = "1"
5049
conquer-once = "0.3"
51-
elements = { version = "0.17" }
50+
elements = { version = "0.18" }
5251

5352
# By default wasm-opt is true which makes the build fail.
5453
[package.metadata.wasm-pack.profile.release]

extension/wallet/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub async fn make_loan_request(
240240
// TODO: Change the UI to handle SATs not BTC
241241
let collateral_in_btc = map_err_from_anyhow!(parse_to_bitcoin_amount(collateral))?;
242242
let fee_rate_in_sat = Amount::from_sat(map_err_from_anyhow!(u64::from_str(fee_rate.as_str()))?);
243-
let timeout = map_err_from_anyhow!(u64::from_str(timeout.as_str()))?;
243+
let timeout = map_err_from_anyhow!(u32::from_str(timeout.as_str()))?;
244244
let loan_request = map_err_from_anyhow!(
245245
wallet::make_loan_request(
246246
wallet_name,

extension/wallet/src/wallet.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ impl fmt::Display for ListOfWallets {
310310
pub struct CreateSwapPayload {
311311
pub alice_inputs: Vec<SwapUtxo>,
312312
pub address: Address,
313-
#[serde(with = "bdk::bitcoin::util::amount::serde::as_sat")]
314-
pub amount: bdk::bitcoin::Amount,
313+
#[serde(with = "elements::bitcoin::util::amount::serde::as_sat")]
314+
pub amount: elements::bitcoin::Amount,
315315
}
316316

317317
#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
@@ -426,7 +426,7 @@ pub struct LoanDetails {
426426
pub principal: TradeSide,
427427
pub principal_repayment: Decimal,
428428
// TODO: Express as target date or number of days instead?
429-
pub term: u64,
429+
pub term: u32,
430430
pub txid: Txid,
431431
}
432432

@@ -439,7 +439,7 @@ impl LoanDetails {
439439
principal_asset: AssetId,
440440
principal_amount: Amount,
441441
principal_balance: Decimal,
442-
timelock: u64,
442+
timelock: u32,
443443
txid: Txid,
444444
) -> Result<Self> {
445445
let collateral = TradeSide::new_sell(

0 commit comments

Comments
 (0)