7
7
8
8
import { importCoreWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm" ;
9
9
10
- import { createHash } from "crypto" ;
11
-
12
10
import {
13
11
getBatchSummary ,
14
12
parseBatchPriceAttestation ,
@@ -52,7 +50,7 @@ type ListenerConfig = {
52
50
readiness : ListenerReadinessConfig ;
53
51
} ;
54
52
55
- type VaaHash = string ;
53
+ type VaaKey = string ;
56
54
57
55
export class Listener implements PriceStore {
58
56
// Mapping of Price Feed Id to Vaa
@@ -63,7 +61,7 @@ export class Listener implements PriceStore {
63
61
private spyConnectionTime : TimestampInSec | undefined ;
64
62
private readinessConfig : ListenerReadinessConfig ;
65
63
private updateCallbacks : ( ( priceInfo : PriceInfo ) => any ) [ ] ;
66
- private observedVaas : LRUCache < VaaHash , boolean > ;
64
+ private observedVaas : LRUCache < VaaKey , boolean > ;
67
65
68
66
constructor ( config : ListenerConfig , promClient ?: PromClient ) {
69
67
this . promClient = promClient ;
@@ -162,15 +160,16 @@ export class Listener implements PriceStore {
162
160
163
161
const parsedVaa = parse_vaa ( vaa ) ;
164
162
165
- const vaaHash : VaaHash = createHash ( "md5" )
166
- . update ( Buffer . from ( parsedVaa . payload ) )
167
- . digest ( "base64" ) ;
163
+ const vaaEmitterAddressHex = Buffer . from (
164
+ parsedVaa . emitter_address
165
+ ) . toString ( "hex" ) ;
166
+ const vaaKey : VaaKey = `${ parsedVaa . emitter_chain } #${ vaaEmitterAddressHex } #${ parsedVaa . sequence } ` ;
168
167
169
- if ( this . observedVaas . has ( vaaHash ) ) {
168
+ if ( this . observedVaas . has ( vaaKey ) ) {
170
169
return ;
171
170
}
172
171
173
- this . observedVaas . set ( vaaHash , true ) ;
172
+ this . observedVaas . set ( vaaKey , true ) ;
174
173
this . promClient ?. incReceivedVaa ( ) ;
175
174
176
175
let batchAttestation ;
0 commit comments