Browse Source

Upgrade `maia`

This gives us access to the `TxBuilder` for the lock transaction.
feature/force-stop-button
Thomas Eizinger 3 years ago
parent
commit
60f8d441c0
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 2
      Cargo.lock
  2. 19
      daemon/src/wallet.rs
  3. 24
      daemon/tests/harness/mocks/wallet.rs

2
Cargo.lock

@ -1441,7 +1441,7 @@ dependencies = [
[[package]]
name = "maia"
version = "0.1.0"
source = "git+https://github.com/comit-network/maia#4dd8adaf88f4c9ec244412319ac5e4ed67b509ec"
source = "git+https://github.com/comit-network/maia#5e6d44882ced923c19f45c55a825b961c9b1e396"
dependencies = [
"anyhow",
"bdk",

19
daemon/src/wallet.rs

@ -5,9 +5,10 @@ use bdk::bitcoin::util::bip32::ExtendedPrivKey;
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
use bdk::bitcoin::{Address, Amount, PublicKey, Script, Transaction, Txid};
use bdk::blockchain::{ElectrumBlockchain, NoopProgress};
use bdk::wallet::tx_builder::TxOrdering;
use bdk::wallet::AddressIndex;
use bdk::{electrum_client, FeeRate, KeychainKind, SignOptions};
use maia::{PartyParams, WalletExt};
use maia::{PartyParams, TxBuilderExt};
use rocket::serde::json::Value;
use std::path::Path;
@ -123,7 +124,21 @@ impl Actor {
identity_pk,
}: BuildPartyParams,
) -> Result<PartyParams> {
self.wallet.build_party_params(amount, identity_pk)
let mut builder = self.wallet.build_tx();
builder
.ordering(TxOrdering::Bip69Lexicographic) // TODO: I think this is pointless but we did this in maia.
.fee_rate(FeeRate::from_sat_per_vb(1.0))
.add_2of2_multisig_recipient(amount);
let (psbt, _) = builder.finish()?;
Ok(PartyParams {
lock_psbt: psbt,
identity_pk,
lock_amount: amount,
address: self.wallet.get_address(AddressIndex::New)?.address,
})
}
pub fn handle_try_broadcast_transaction(

24
daemon/tests/harness/mocks/wallet.rs

@ -2,10 +2,13 @@ use crate::harness::maia::dummy_wallet;
use anyhow::Result;
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
use bdk::bitcoin::{ecdsa, Amount, Txid};
use bdk::wallet::tx_builder::TxOrdering;
use bdk::wallet::AddressIndex;
use bdk::FeeRate;
use daemon::model::{Timestamp, WalletInfo};
use daemon::wallet;
use maia::secp256k1_zkp::Secp256k1;
use maia::{PartyParams, WalletExt};
use maia::{PartyParams, TxBuilderExt};
use mockall::*;
use rand::thread_rng;
use std::sync::Arc;
@ -74,8 +77,19 @@ pub fn build_party_params(msg: wallet::BuildPartyParams) -> Result<PartyParams>
let mut rng = thread_rng();
let wallet = dummy_wallet(&mut rng, Amount::from_btc(0.4).unwrap(), 5).unwrap();
let party_params = wallet
.build_party_params(msg.amount, msg.identity_pk)
.unwrap();
Ok(party_params)
let mut builder = wallet.build_tx();
builder
.ordering(TxOrdering::Bip69Lexicographic) // TODO: I think this is pointless but we did this in maia.
.fee_rate(FeeRate::from_sat_per_vb(1.0))
.add_2of2_multisig_recipient(msg.amount);
let (psbt, _) = builder.finish()?;
Ok(PartyParams {
lock_psbt: psbt,
identity_pk: msg.identity_pk,
lock_amount: msg.amount,
address: wallet.get_address(AddressIndex::New)?.address,
})
}

Loading…
Cancel
Save