Skip to content

Commit 4053bd4

Browse files
committed
Insert txouts for foreign inputs
Fixes #53
1 parent dfa8f60 commit 4053bd4

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

Diff for: node/tests/integration_tests.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ async fn it_should_allow_outbidding(rig: &TestRig) -> anyhow::Result<()> {
149149
Ok(())
150150
}
151151

152+
153+
async fn it_should_insert_txout_for_bids(rig: &TestRig) -> anyhow::Result<()> {
154+
rig.wait_until_synced().await?;
155+
rig.wait_until_wallet_synced(BOB).await?;
156+
157+
let tx = rig.spaced.client
158+
.wallet_list_transactions(BOB, 10, 0).await?.iter()
159+
.filter(|tx| tx.events.iter().any(|event| event.kind == TxEventKind::Bid))
160+
.next()
161+
.expect("a bid").clone();
162+
163+
assert!(tx.fee.is_some(), "must be able to calculate fees");
164+
Ok(())
165+
}
166+
152167
/// Eve makes an invalid bid with a burn increment of 0 only refunding Bob's money
153168
async fn it_should_only_accept_forced_zero_value_bid_increments_and_revoke(
154169
rig: &TestRig,
@@ -658,7 +673,7 @@ async fn it_should_replace_mempool_bids(rig: &TestRig) -> anyhow::Result<()> {
658673

659674
assert!(
660675
txs.iter().all(|tx| tx.txid != eve_replacement_txid),
661-
"Eve's tx shouldn't be listed in Alice's wallet"
676+
"Eve's tx shouldn't be listed in Alice's wallet"
662677
);
663678
Ok(())
664679
}
@@ -727,14 +742,15 @@ async fn run_auction_tests() -> anyhow::Result<()> {
727742
load_wallet(&rig, wallets_path.clone(), BOB).await?;
728743
load_wallet(&rig, wallets_path, EVE).await?;
729744

730-
it_should_open_a_space_for_auction(&rig).await?;
731-
it_should_allow_outbidding(&rig).await?;
732-
it_should_only_accept_forced_zero_value_bid_increments_and_revoke(&rig).await?;
733-
it_should_allow_claim_on_or_after_claim_height(&rig).await?;
734-
it_should_allow_batch_transfers_refreshing_expire_height(&rig).await?;
735-
it_should_allow_applying_script_in_batch(&rig).await?;
736-
it_should_replace_mempool_bids(&rig).await?;
737-
it_should_maintain_locktime_when_fee_bumping(&rig).await?;
745+
it_should_open_a_space_for_auction(&rig).await.expect("should open auction");
746+
it_should_allow_outbidding(&rig).await.expect("should allow outbidding");
747+
it_should_insert_txout_for_bids(&rig).await.expect("should insert txout");
748+
it_should_only_accept_forced_zero_value_bid_increments_and_revoke(&rig).await.expect("should only revoke a bid");
749+
it_should_allow_claim_on_or_after_claim_height(&rig).await.expect("should allow claim on or above height");
750+
it_should_allow_batch_transfers_refreshing_expire_height(&rig).await.expect("should allow batch transfers refresh expire height");
751+
it_should_allow_applying_script_in_batch(&rig).await.expect("should allow batch applying script");
752+
it_should_replace_mempool_bids(&rig).await.expect("should replace mempool bids");
753+
it_should_maintain_locktime_when_fee_bumping(&rig).await.expect("should maintain locktime");
738754

739755
Ok(())
740756
}

Diff for: wallet/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ impl SpacesWallet {
405405
let txid = tx_record.tx.compute_txid();
406406
self.apply_unconfirmed_tx(tx_record.tx, seen);
407407

408+
// Insert txouts for foreign inputs to be able to calculate fees
409+
for (outpoint, txout) in tx_record.txouts {
410+
self.internal.insert_txout(outpoint, txout);
411+
}
412+
408413
let db_tx = self.connection.transaction()
409414
.context("could not create wallet db transaction")?;
410415
for event in tx_record.events {

Diff for: wallet/src/tx_event.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bdk_wallet::{
77
ToSql,
88
},
99
};
10-
use bitcoin::{Amount, OutPoint, ScriptBuf, Transaction, Txid};
10+
use bitcoin::{Amount, OutPoint, ScriptBuf, Transaction, TxOut, Txid};
1111
use serde::{Deserialize, Serialize};
1212
use protocol::{Covenant, FullSpaceOut};
1313
use crate::rusqlite_impl::{migrate_schema, Impl};
@@ -17,6 +17,7 @@ use crate::SpacesWallet;
1717
pub struct TxRecord {
1818
pub tx: Transaction,
1919
pub events: Vec<TxEvent>,
20+
pub txouts: Vec<(OutPoint, TxOut)>
2021
}
2122

2223
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -245,16 +246,14 @@ impl TxEvent {
245246

246247
impl TxRecord {
247248
pub fn new(tx: Transaction) -> Self {
248-
Self {
249-
events: Vec::new(),
250-
tx,
251-
}
249+
Self::new_with_events(tx, vec![])
252250
}
253251

254252
pub fn new_with_events(tx: Transaction, events: Vec<TxEvent>) -> Self {
255253
Self {
256254
events,
257255
tx,
256+
txouts: vec![],
258257
}
259258
}
260259

@@ -362,13 +361,22 @@ impl TxRecord {
362361
Covenant::Bid { total_burned, .. } => total_burned,
363362
_ => panic!("expected a bid"),
364363
};
364+
let foreign_input = match wallet.is_mine(previous.spaceout.script_pubkey.clone()) {
365+
false => Some(previous.outpoint()),
366+
true => None
367+
};
368+
369+
if foreign_input.is_some() {
370+
self.txouts.push((previous.outpoint(), TxOut {
371+
value: previous.spaceout.value,
372+
script_pubkey: previous.spaceout.script_pubkey.clone(),
373+
}))
374+
}
375+
365376
self.events.push(TxEvent {
366377
kind: TxEventKind::Bid,
367378
space: Some(space.name.to_string()),
368-
foreign_input: match wallet.is_mine(previous.spaceout.script_pubkey.clone()) {
369-
false => Some(previous.outpoint()),
370-
true => None
371-
},
379+
foreign_input,
372380
details: Some(
373381
serde_json::to_value(BidEventDetails {
374382
bid_current: amount,

0 commit comments

Comments
 (0)