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