@@ -48,6 +48,7 @@ type InternalService struct {
4848 storageConfig model.StorageConfig
4949 notifier Notifier
5050 client http.Client
51+ indexed bool
5152}
5253
5354func (is * InternalService ) Init () {
@@ -108,19 +109,29 @@ func (is *InternalService) Init() {
108109 if is .currentBlock < startBlock {
109110 is .currentBlock = startBlock
110111 }
111-
112- is .ProcessIndexes ()
113112}
114113
115114func (is * InternalService ) ProcessIndexes () {
116115 var newBlockIndexes = []IndexData {
116+ {
117+ Keys : []bson.M {{"cr_time" : 1 }},
118+ Unique : false ,
119+ },
117120 {
118121 Keys : []bson.M {{"block_id.hash" : 1 }},
119122 Unique : false ,
120123 },
124+ {
125+ Keys : []bson.M {{"block_id.height" : 1 }},
126+ Unique : false ,
127+ },
121128 }
122129
123130 var newTransactionIndexes = []IndexData {
131+ {
132+ Keys : []bson.M {{"cr_time" : 1 }},
133+ Unique : false ,
134+ },
124135 {
125136 Keys : []bson.M {{"hash" : 1 }},
126137 Unique : false ,
@@ -141,6 +152,17 @@ func (is *InternalService) ProcessIndexes() {
141152 Keys : []bson.M {{"tx_result.code" : 1 }},
142153 Unique : false ,
143154 },
155+ {
156+ Keys : []bson.M {
157+ {"tx_result.events.attributes.key" : 1 },
158+ {"tx_result.events.attributes.value" : 1 },
159+ },
160+ Unique : false ,
161+ },
162+ {
163+ Keys : []bson.M {{"tx_result.events.attributes.value" : 1 }},
164+ Unique : false ,
165+ },
144166 }
145167
146168 blockIndexes , err := is .getIndexes (is .config .CollectionName + "_blocks" )
@@ -175,6 +197,7 @@ func (is *InternalService) ProcessIndexes() {
175197 logger .Logger .Debug ("ProcessIndexes" , zap .Any ("indexResp" , indexResp ))
176198 }
177199
200+ is .indexed = true
178201}
179202
180203func hasRequiredIndexes (data interface {}, required []IndexData ) bool {
@@ -315,6 +338,7 @@ func (is *InternalService) handleBlockTxs() error {
315338 }
316339
317340 if len (txArray ) > 0 {
341+
318342 err = is .sendTxsToStorage (txArray )
319343 if err != nil {
320344 logger .Logger .Error ("handleBlockTxs" , zap .Error (err ))
@@ -433,6 +457,10 @@ func (is *InternalService) sendTxsToStorage(txs []model.Tx) error {
433457 }
434458 }
435459
460+ if ! is .indexed {
461+ is .ProcessIndexes ()
462+ }
463+
436464 return nil
437465}
438466
0 commit comments