@@ -29,6 +29,7 @@ import {
29
29
Transaction ,
30
30
TokenBalanceMap ,
31
31
TxOutputWithIndex ,
32
+ isDecodedValid ,
32
33
} from '@wallet-service/common' ;
33
34
import {
34
35
prepareOutputs ,
@@ -133,8 +134,8 @@ export const metadataDiff = async (_context: Context, event: Event) => {
133
134
}
134
135
135
136
if ( first_block
136
- && first_block . length
137
- && first_block . length > 0 ) {
137
+ && first_block . length
138
+ && first_block . length > 0 ) {
138
139
if ( ! dbTx . height ) {
139
140
return {
140
141
type : METADATA_DIFF_EVENT_TYPES . TX_FIRST_BLOCK ,
@@ -161,7 +162,7 @@ export const metadataDiff = async (_context: Context, event: Event) => {
161
162
} ;
162
163
163
164
export const isBlock = ( version : number ) : boolean => version === hathorLib . constants . BLOCK_VERSION
164
- || version === hathorLib . constants . MERGED_MINED_BLOCK_VERSION ;
165
+ || version === hathorLib . constants . MERGED_MINED_BLOCK_VERSION ;
165
166
166
167
export const handleVertexAccepted = async ( context : Context , _event : Event ) => {
167
168
const mysql = await getDbConnection ( ) ;
@@ -217,7 +218,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
217
218
const txOutputs : TxOutputWithIndex [ ] = prepareOutputs ( outputs , tokens ) ;
218
219
const txInputs : TxInput [ ] = prepareInputs ( inputs , tokens ) ;
219
220
220
- let heightlock : number | null = null ;
221
+ let heightlock : number | null = null ;
221
222
if ( isBlock ( version ) ) {
222
223
if ( typeof height !== 'number' && ! height ) {
223
224
throw new Error ( 'Block with no height set in metadata.' ) ;
@@ -238,7 +239,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
238
239
const blockRewardOutput = outputs [ 0 ] ;
239
240
240
241
// add miner to the miners table
241
- if ( blockRewardOutput . decoded ) {
242
+ if ( isDecodedValid ( blockRewardOutput . decoded ) ) {
242
243
await addMiner ( mysql , blockRewardOutput . decoded . address , hash ) ;
243
244
}
244
245
@@ -303,21 +304,21 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
303
304
304
305
const addressesPerWallet = Object . entries ( addressWalletMap ) . reduce (
305
306
( result : StringMap < { addresses : string [ ] , walletDetails : Wallet } > , [ address , wallet ] : [ string , Wallet ] ) => {
306
- const { walletId } = wallet ;
307
-
308
- // Initialize the array if the walletId is not yet a key in result
309
- if ( ! result [ walletId ] ) {
310
- result [ walletId ] = {
311
- addresses : [ ] ,
312
- walletDetails : wallet ,
307
+ const { walletId } = wallet ;
308
+
309
+ // Initialize the array if the walletId is not yet a key in result
310
+ if ( ! result [ walletId ] ) {
311
+ result [ walletId ] = {
312
+ addresses : [ ] ,
313
+ walletDetails : wallet ,
314
+ }
313
315
}
314
- }
315
316
316
- // Add the current key to the array
317
- result [ walletId ] . addresses . push ( address ) ;
317
+ // Add the current key to the array
318
+ result [ walletId ] . addresses . push ( address ) ;
318
319
319
- return result ;
320
- } , { } ) ;
320
+ return result ;
321
+ } , { } ) ;
321
322
322
323
const seenWallets = Object . keys ( addressesPerWallet ) ;
323
324
@@ -420,7 +421,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
420
421
await mysql . commit ( ) ;
421
422
} catch ( e ) {
422
423
await mysql . rollback ( ) ;
423
- logger . error ( 'Error handling vertex accepted' , {
424
+ console . error ( 'Error handling vertex accepted' , {
424
425
error : ( e as Error ) . message ,
425
426
stack : ( e as Error ) . stack ,
426
427
} ) ;
@@ -615,13 +616,13 @@ export const updateLastSyncedEvent = async (context: Context) => {
615
616
const lastEventId = context . event . event . id ;
616
617
617
618
if ( lastDbSyncedEvent
618
- && lastDbSyncedEvent . last_event_id > lastEventId ) {
619
- logger . error ( 'Tried to store an event lower than the one on the database' , {
620
- lastEventId,
621
- lastDbSyncedEvent : JSON . stringify ( lastDbSyncedEvent ) ,
622
- } ) ;
623
- mysql . destroy ( ) ;
624
- throw new Error ( 'Event lower than stored one.' ) ;
619
+ && lastDbSyncedEvent . last_event_id > lastEventId ) {
620
+ logger . error ( 'Tried to store an event lower than the one on the database' , {
621
+ lastEventId,
622
+ lastDbSyncedEvent : JSON . stringify ( lastDbSyncedEvent ) ,
623
+ } ) ;
624
+ mysql . destroy ( ) ;
625
+ throw new Error ( 'Event lower than stored one.' ) ;
625
626
}
626
627
await dbUpdateLastSyncedEvent ( mysql , lastEventId ) ;
627
628
0 commit comments