@@ -555,7 +555,7 @@ fn filter_block_txs<T: Send>(
555
555
pub ( crate ) struct OutPointStatus {
556
556
outpoint : OutPoint ,
557
557
funding : Option < Height > ,
558
- spending : Option < ( Txid , Height ) > ,
558
+ spending : Option < ( Txid , u32 , Height ) > ,
559
559
tip : BlockHash ,
560
560
}
561
561
@@ -568,8 +568,9 @@ impl Serialize for OutPointStatus {
568
568
if let Some ( funding) = & self . funding {
569
569
map. serialize_entry ( "height" , & funding) ?;
570
570
}
571
- if let Some ( ( txid, height) ) = & self . spending {
571
+ if let Some ( ( txid, index , height) ) = & self . spending {
572
572
map. serialize_entry ( "spender_txhash" , & txid) ?;
573
+ map. serialize_entry ( "spender_vin" , & index) ?;
573
574
map. serialize_entry ( "spender_height" , & height) ?;
574
575
}
575
576
map. end ( )
@@ -642,22 +643,26 @@ impl OutPointStatus {
642
643
index : & Index ,
643
644
daemon : & Daemon ,
644
645
mempool : & Mempool ,
645
- ) -> Result < Option < ( Txid , Height ) > > {
646
+ ) -> Result < Option < ( Txid , u32 , Height ) > > {
646
647
let chain = index. chain ( ) ;
647
648
if !self . is_reorg ( chain) {
648
- if let Some ( ( _, Height :: Confirmed { .. } ) ) = & self . spending {
649
+ if let Some ( ( _, _ , Height :: Confirmed { .. } ) ) = & self . spending {
649
650
return Ok ( self . spending ) ;
650
651
}
651
652
}
652
653
let spending_blockhashes = index. filter_by_spending ( self . outpoint ) ;
653
654
let mut confirmed = None ;
654
655
daemon. for_blocks ( spending_blockhashes, |blockhash, block| {
655
656
for tx in block. txdata {
656
- for txi in & tx. input {
657
+ for ( index , txi) in ( & tx. input ) . iter ( ) . enumerate ( ) {
657
658
if txi. previous_output == self . outpoint {
658
659
// TODO: there should be only one spending input
659
660
assert ! ( confirmed. is_none( ) , "double spend of {}" , self . outpoint) ;
660
- confirmed = Some ( ( tx. txid ( ) , Height :: from_blockhash ( blockhash, chain) ) ) ;
661
+ confirmed = Some ( (
662
+ tx. txid ( ) ,
663
+ index as u32 ,
664
+ Height :: from_blockhash ( blockhash, chain) ,
665
+ ) ) ;
661
666
return ;
662
667
}
663
668
}
@@ -666,9 +671,14 @@ impl OutPointStatus {
666
671
Ok ( confirmed. or_else ( || {
667
672
let entries = mempool. filter_by_spending ( & self . outpoint ) ;
668
673
assert ! ( entries. len( ) <= 1 , "double spend of {}" , self . outpoint) ;
669
- entries
670
- . first ( )
671
- . map ( |entry| ( entry. txid , Height :: unconfirmed ( entry) ) )
674
+ entries. first ( ) . map ( |entry| {
675
+ for ( index, txi) in entry. tx . input . iter ( ) . enumerate ( ) {
676
+ if txi. previous_output == self . outpoint {
677
+ return ( entry. txid , index as u32 , Height :: unconfirmed ( entry) ) ;
678
+ }
679
+ }
680
+ panic ! ( ) ;
681
+ } )
672
682
} ) )
673
683
}
674
684
}
0 commit comments