@@ -34,7 +34,7 @@ use common::{
3434        tokens:: TokenAuxiliaryData , 
3535        tokens:: { get_tokens_issuance_count,  TokenId } , 
3636        AccountNonce ,  AccountType ,  Block ,  ChainConfig ,  GenBlock ,  GenBlockId ,  OutPointSourceId , 
37-         Transaction ,  TxOutput ,  UtxoOutPoint , 
37+         SignedTransaction ,   Transaction ,   TxMainChainIndex ,  TxOutput ,  UtxoOutPoint , 
3838    } , 
3939    primitives:: { id:: WithId ,  BlockDistance ,  BlockHeight ,  Id ,  Idable } , 
4040    time_getter:: TimeGetter , 
@@ -162,6 +162,14 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
162162        self . time_getter . get_time ( ) 
163163    } 
164164
165+     pub  fn  get_is_transaction_index_enabled ( & self )  -> Result < bool ,  PropertyQueryError >  { 
166+         Ok ( self 
167+             . db_tx 
168+             . get_is_mainchain_tx_index_enabled ( ) 
169+             . map_err ( PropertyQueryError :: from) ?
170+             . expect ( "Must be set on node initialization" ) ) 
171+     } 
172+ 
165173    pub  fn  get_best_block_id ( & self )  -> Result < Id < GenBlock > ,  PropertyQueryError >  { 
166174        self . db_tx 
167175            . get_best_block_id ( ) 
@@ -188,11 +196,36 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
188196    pub  fn  get_mainchain_tx_index ( 
189197        & self , 
190198        tx_id :  & OutPointSourceId , 
191-     )  -> Result < Option < common :: chain :: TxMainChainIndex > ,  PropertyQueryError >  { 
199+     )  -> Result < Option < TxMainChainIndex > ,  PropertyQueryError >  { 
192200        log:: trace!( "Loading transaction index of id: {:?}" ,  tx_id) ; 
193201        self . db_tx . get_mainchain_tx_index ( tx_id) . map_err ( PropertyQueryError :: from) 
194202    } 
195203
204+     pub  fn  get_transaction_in_block ( 
205+         & self , 
206+         id :  Id < Transaction > , 
207+     )  -> Result < Option < SignedTransaction > ,  PropertyQueryError >  { 
208+         log:: trace!( "Loading whether tx index is enabled: {}" ,  id) ; 
209+         let  is_tx_index_enabled = self . get_is_transaction_index_enabled ( ) ?; 
210+         if  !is_tx_index_enabled { 
211+             return  Err ( PropertyQueryError :: TransactionIndexDisabled ) ; 
212+         } 
213+         log:: trace!( "Loading transaction index with id: {}" ,  id) ; 
214+         let  tx_index = self . db_tx . get_mainchain_tx_index ( & OutPointSourceId :: Transaction ( id) ) ?; 
215+         let  tx_index = match  tx_index { 
216+             Some ( tx_index)  => tx_index, 
217+             None  => return  Ok ( None ) , 
218+         } ; 
219+         log:: trace!( "Loading transaction with id: {}" ,  id) ; 
220+         let  position = match  tx_index. position ( )  { 
221+             common:: chain:: SpendablePosition :: Transaction ( pos)  => pos, 
222+             common:: chain:: SpendablePosition :: BlockReward ( _)  => { 
223+                 panic ! ( "In get_transaction(), a tx id led to a block reward" ) 
224+             } 
225+         } ; 
226+         Ok ( self . db_tx . get_mainchain_tx_by_position ( position) ?) 
227+     } 
228+ 
196229    pub  fn  get_block_id_by_height ( 
197230        & self , 
198231        height :  & BlockHeight , 
0 commit comments