Skip to content

Commit 87fbe96

Browse files
committed
block height in TxInfo
1 parent cc487f5 commit 87fbe96

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

client/src/wallets.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use spaces_protocol::{
1717
use spaces_wallet::{
1818
address::SpaceAddress,
1919
bdk_wallet::{
20-
chain::{local_chain::CheckPoint, BlockId},
20+
chain::{local_chain::CheckPoint, BlockId, ChainPosition},
2121
KeychainKind,
2222
},
2323
bitcoin,
@@ -69,8 +69,9 @@ pub struct ListSpacesResponse {
6969
#[derive(Tabled, Debug, Clone, Serialize, Deserialize)]
7070
#[tabled(rename_all = "UPPERCASE")]
7171
pub struct TxInfo {
72+
#[tabled(display_with = "display_block_height")]
73+
pub block_height: Option<u32>,
7274
pub txid: Txid,
73-
pub confirmed: bool,
7475
pub sent: Amount,
7576
pub received: Amount,
7677
#[tabled(display_with = "display_fee")]
@@ -79,6 +80,13 @@ pub struct TxInfo {
7980
pub events: Vec<TxEvent>,
8081
}
8182

83+
fn display_block_height(block_height: &Option<u32>) -> String {
84+
match block_height {
85+
None => "Unconfirmed".to_string(),
86+
Some(block_height) => block_height.to_string(),
87+
}
88+
}
89+
8290
fn display_fee(fee: &Option<Amount>) -> String {
8391
match fee {
8492
None => "--".to_string(),
@@ -720,14 +728,17 @@ impl RpcWallet {
720728
.skip(skip)
721729
.take(count)
722730
.map(|ctx| {
731+
let block_height = match ctx.chain_position {
732+
ChainPosition::Confirmed { anchor, .. } => Some(anchor.block_id.height),
733+
ChainPosition::Unconfirmed { .. } => None,
734+
};
723735
let tx = ctx.tx_node.tx.clone();
724736
let txid = ctx.tx_node.txid.clone();
725-
let confirmed = ctx.chain_position.is_confirmed();
726737
let (sent, received) = wallet.sent_and_received(&tx);
727738
let fee = wallet.calculate_fee(&tx).ok();
728739
TxInfo {
740+
block_height,
729741
txid,
730-
confirmed,
731742
sent,
732743
received,
733744
fee,

client/tests/integration_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ async fn it_should_replace_mempool_bids(rig: &TestRig) -> anyhow::Result<()> {
689689
.wallet_list_transactions(ALICE, 1000, 0)
690690
.await
691691
.expect("list transactions");
692-
let unconfirmed: Vec<_> = txs.iter().filter(|tx| !tx.confirmed).collect();
692+
let unconfirmed: Vec<_> = txs.iter().filter(|tx| tx.block_height.is_none()).collect();
693693
for tx in &unconfirmed {
694694
println!("Alice's unconfiremd: {}", tx.txid);
695695
}
@@ -726,7 +726,7 @@ async fn it_should_replace_mempool_bids(rig: &TestRig) -> anyhow::Result<()> {
726726
assert!(
727727
eve_txs
728728
.iter()
729-
.any(|tx| tx.txid == eve_replacement_txid && tx.confirmed),
729+
.any(|tx| tx.txid == eve_replacement_txid && tx.block_height.is_some()),
730730
"Eve's tx should be confirmed"
731731
);
732732

0 commit comments

Comments
 (0)