@@ -13,6 +13,7 @@ use iota_indexer::{
13
13
models:: transactions:: { OptimisticTransaction , StoredTransaction } ,
14
14
schema:: { transactions, tx_digests} ,
15
15
} ;
16
+ use iota_json_rpc_api:: ReadApiClient ;
16
17
use iota_types:: {
17
18
base_types:: IotaAddress as NativeIotaAddress ,
18
19
effects:: TransactionEffects as NativeTransactionEffects ,
@@ -30,7 +31,7 @@ use crate::{
30
31
connection:: ScanConnection ,
31
32
data:: { self , DataLoader , Db , DbConnection , QueryExecutor } ,
32
33
error:: Error ,
33
- server:: watermark_task:: Watermark ,
34
+ server:: { builder :: get_fullnode_client , watermark_task:: Watermark } ,
34
35
types:: {
35
36
address:: Address ,
36
37
base64:: Base64 ,
@@ -88,6 +89,16 @@ pub(crate) enum TransactionBlockInner {
88
89
} ,
89
90
}
90
91
92
+ impl TransactionBlockInner {
93
+ /// Returns if the transaction is included in a checkpoint.
94
+ fn is_checkpointed ( & self ) -> bool {
95
+ let TransactionBlockInner :: Stored { stored_tx, .. } = & self else {
96
+ return false ;
97
+ } ;
98
+ stored_tx. checkpoint_sequence_number >= 0
99
+ }
100
+ }
101
+
91
102
/// An input filter selecting for either system or programmable transactions.
92
103
#[ derive( Enum , Copy , Clone , Eq , PartialEq , Debug ) ]
93
104
pub ( crate ) enum TransactionBlockKindInput {
@@ -234,6 +245,35 @@ impl TransactionBlock {
234
245
TransactionBlockInner :: DryRun { .. } => None ,
235
246
}
236
247
}
248
+
249
+ /// Returns whether the transaction has been indexed on the fullnode.
250
+ ///
251
+ /// This makes a request to the fullnode if the transaction is not part of
252
+ /// a checkpoint to resolve the index status on the node.
253
+ ///
254
+ /// However, as this relies on the transaction data being already
255
+ /// constructed or fetched from the backing database, it only makes
256
+ /// sense to be used with `Mutation.executeTransactionBlock` on the
257
+ /// resulting effects.
258
+ ///
259
+ /// Otherwise, it is recommended that you use
260
+ /// `Query.isTransactionIndexedOnNode` for optimal performance.
261
+ async fn indexed_on_node ( & self , ctx : & Context < ' _ > ) -> Result < Option < bool > > {
262
+ if self . inner . is_checkpointed ( ) {
263
+ return Ok ( Some ( true ) ) ;
264
+ }
265
+ let Some ( digest) = self . native_signed_data ( ) . map ( |d| d. digest ( ) ) else {
266
+ // dry-run transactions are never indexed
267
+ return Ok ( Some ( false ) ) ;
268
+ } ;
269
+ let fullnode_client = get_fullnode_client ( ctx) ?;
270
+ Ok ( Some (
271
+ fullnode_client
272
+ . http ( )
273
+ . is_transaction_indexed_on_node ( digest)
274
+ . await ?,
275
+ ) )
276
+ }
237
277
}
238
278
239
279
impl TransactionBlock {
0 commit comments