@@ -10,6 +10,8 @@ import {
10
10
VAA ,
11
11
WormholeCore ,
12
12
WormholeMessageId ,
13
+ createVAA ,
14
+ encoding ,
13
15
} from "@wormhole-foundation/connect-sdk" ;
14
16
import {
15
17
AnyCosmwasmAddress ,
@@ -36,6 +38,9 @@ export class CosmwasmWormholeCore<N extends Network, C extends CosmwasmChains>
36
38
37
39
this . coreAddress = coreAddress ;
38
40
}
41
+ getGuardianSetIndex ( ) : Promise < number > {
42
+ throw new Error ( "Method not implemented." ) ;
43
+ }
39
44
40
45
getMessageFee ( ) : Promise < bigint > {
41
46
throw new Error ( "Method not implemented." ) ;
@@ -66,13 +71,18 @@ export class CosmwasmWormholeCore<N extends Network, C extends CosmwasmChains>
66
71
}
67
72
68
73
async parseTransaction ( txid : string ) : Promise < WormholeMessageId [ ] > {
74
+ const tx = await this . rpc . getTx ( txid ) ;
75
+ if ( ! tx ) throw new Error ( "No transaction found for txid: " + txid ) ;
76
+ return [ CosmwasmWormholeCore . parseWormholeMessageId ( this . chain , this . coreAddress , tx ) ] ;
77
+ }
78
+
79
+ async parseMessages ( txid : string ) : Promise < VAA [ ] > {
69
80
const tx = await this . rpc . getTx ( txid ) ;
70
81
if ( ! tx ) throw new Error ( "No transaction found for txid: " + txid ) ;
71
82
return [ CosmwasmWormholeCore . parseWormholeMessage ( this . chain , this . coreAddress , tx ) ] ;
72
83
}
73
84
74
- // TODO: make consts
75
- static parseWormholeMessage ( chain : Chain , coreAddress : string , tx : IndexedTx ) : WormholeMessageId {
85
+ static parseWormholeMessage ( chain : Chain , coreAddress : string , tx : IndexedTx ) : VAA {
76
86
const events = tx . events . filter (
77
87
( ev ) =>
78
88
ev . type === "wasm" &&
@@ -85,18 +95,36 @@ export class CosmwasmWormholeCore<N extends Network, C extends CosmwasmChains>
85
95
86
96
const [ wasm ] = events ;
87
97
88
- const sequence = wasm ! . attributes . find ( ( e ) => {
89
- return e . key === "message.sequence" ;
90
- } ) ! . value ;
98
+ const obj = Object . fromEntries (
99
+ wasm ! . attributes . map ( ( attr ) => {
100
+ return [ attr . key . split ( "." ) [ 1 ] ! , attr . value ] ;
101
+ } ) ,
102
+ ) ;
103
+
104
+ return createVAA ( "Uint8Array" , {
105
+ emitterChain : chain ,
106
+ emitterAddress : new UniversalAddress ( encoding . hex . decode ( obj [ "sender" ] ! ) ) ,
107
+ sequence : BigInt ( obj [ "sequence" ] ! ) ,
91
108
92
- const emitter = wasm ! . attributes . find ( ( e ) => {
93
- return e . key === "message.sender" ;
94
- } ) ! . value ;
109
+ guardianSet : 0 , // TODO: need to implement guardian set idx
110
+ timestamp : Number ( obj [ "block_time" ] ) ,
111
+ consistencyLevel : 0 ,
112
+ nonce : Number ( obj [ "nonce" ] ) ,
113
+ signatures : [ ] ,
114
+ payload : encoding . hex . decode ( obj [ "message" ] ! ) ,
115
+ } ) ;
116
+ }
117
+ static parseWormholeMessageId (
118
+ chain : Chain ,
119
+ coreAddress : string ,
120
+ tx : IndexedTx ,
121
+ ) : WormholeMessageId {
122
+ const unsignedVaa = CosmwasmWormholeCore . parseWormholeMessage ( chain , coreAddress , tx ) ;
95
123
96
124
return {
97
- chain : chain ,
98
- emitter : new UniversalAddress ( emitter ) ,
99
- sequence : BigInt ( sequence ) ,
125
+ chain : unsignedVaa . emitterChain ,
126
+ emitter : unsignedVaa . emitterAddress ,
127
+ sequence : unsignedVaa . sequence ,
100
128
} ;
101
129
}
102
130
}
0 commit comments