@@ -12,13 +12,19 @@ import IndexerTransaction from 'services/tx/indexer-transaction'
1212
1313import IndexerRPC from './indexer-rpc'
1414
15+ export interface LockHashInfo {
16+ lockHash : string
17+ isImport : boolean | undefined
18+ }
19+
1520enum TxPointType {
1621 CreatedBy = 'createdBy' ,
1722 ConsumedBy = 'consumedBy' ,
1823}
1924
2025export default class IndexerQueue {
21- private lockHashes : string [ ]
26+ // private lockHashes: string[]
27+ private lockHashInfos : LockHashInfo [ ]
2228 private indexerRPC : IndexerRPC
2329 private getBlocksService : GetBlocks
2430 private per = 50
@@ -34,8 +40,9 @@ export default class IndexerQueue {
3440
3541 private resetFlag = false
3642
37- constructor ( url : string , lockHashes : string [ ] , tipNumberSubject : Subject < string | undefined > ) {
38- this . lockHashes = lockHashes
43+ constructor ( url : string , lockHashInfos : LockHashInfo [ ] , tipNumberSubject : Subject < string | undefined > ) {
44+ // this.lockHashes = lockHashes
45+ this . lockHashInfos = lockHashInfos
3946 this . indexerRPC = new IndexerRPC ( url )
4047 this . getBlocksService = new GetBlocks ( )
4148 this . blockNumberService = new BlockNumber ( )
@@ -46,8 +53,9 @@ export default class IndexerQueue {
4653 } )
4754 }
4855
49- public setLockHashes = ( lockHashes : string [ ] ) : void => {
50- this . lockHashes = lockHashes
56+ public setLockHashInfos = ( lockHashInfos : LockHashInfo [ ] ) : void => {
57+ // this.lockHashes = lockHashes
58+ this . lockHashInfos = lockHashInfos
5159 this . indexed = false
5260 }
5361
@@ -65,13 +73,14 @@ export default class IndexerQueue {
6573 await this . blockNumberService . updateCurrent ( BigInt ( 0 ) )
6674 this . resetFlag = false
6775 }
68- const { lockHashes } = this
76+ const { lockHashInfos } = this
6977 const currentBlockNumber : bigint = await this . blockNumberService . getCurrent ( )
7078 if ( ! this . indexed || currentBlockNumber !== this . tipBlockNumber ) {
7179 if ( ! this . indexed ) {
72- await this . indexLockHashes ( lockHashes )
80+ await this . indexLockHashes ( lockHashInfos )
7381 this . indexed = true
7482 }
83+ const lockHashes : string [ ] = lockHashInfos . map ( info => info . lockHash )
7584 const minBlockNumber = await this . getCurrentBlockNumber ( lockHashes )
7685 for ( const lockHash of lockHashes ) {
7786 await this . pipeline ( lockHash , TxPointType . CreatedBy , currentBlockNumber )
@@ -130,13 +139,14 @@ export default class IndexerQueue {
130139 return minBlockNumber
131140 }
132141
133- public indexLockHashes = async ( lockHashes : string [ ] ) => {
142+ public indexLockHashes = async ( lockHashInfos : LockHashInfo [ ] ) => {
134143 const lockHashIndexStates = await this . indexerRPC . getLockHashIndexStates ( )
135144 const indexedLockHashes : string [ ] = lockHashIndexStates . map ( state => state . lockHash )
136- const nonIndexedLockHashes = lockHashes . filter ( i => ! indexedLockHashes . includes ( i ) )
145+ const nonIndexedLockHashInfos = lockHashInfos . filter ( i => ! indexedLockHashes . includes ( i . lockHash ) )
137146
138- await Utils . mapSeries ( nonIndexedLockHashes , async ( lockHash : string ) => {
139- await this . indexerRPC . indexLockHash ( lockHash )
147+ await Utils . mapSeries ( nonIndexedLockHashInfos , async ( info : LockHashInfo ) => {
148+ const indexFrom : string | undefined = info . isImport ? '0' : undefined
149+ await this . indexerRPC . indexLockHash ( info . lockHash , indexFrom )
140150 } )
141151 }
142152
0 commit comments