@stellar-expert/contract-wasm-interface-parser 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,14 +22,16 @@ Example output:
22
22
  {
23
23
  "enums": {
24
24
  "SubscriptionStatus": {
25
- "Active": {
26
- "value": 0
27
- },
28
- "Cancelled": {
29
- "value": 2
30
- },
31
- "Suspended": {
32
- "value": 1
25
+ "cases": {
26
+ "Active": {
27
+ "value": 0
28
+ },
29
+ "Cancelled": {
30
+ "value": 2
31
+ },
32
+ "Suspended": {
33
+ "value": 1
34
+ }
33
35
  }
34
36
  }
35
37
  },
@@ -178,82 +180,92 @@ Example output:
178
180
  },
179
181
  "structs": {
180
182
  "ConfigData": {
181
- "admin": {
182
- "type": "address"
183
- },
184
- "fee": {
185
- "type": "u64"
186
- },
187
- "token": {
188
- "type": "address"
183
+ "fields": {
184
+ "admin": {
185
+ "type": "address"
186
+ },
187
+ "fee": {
188
+ "type": "u64"
189
+ },
190
+ "token": {
191
+ "type": "address"
192
+ }
189
193
  }
190
194
  },
191
195
  "CreateSubscription": {
192
- "asset1": {
193
- "type": "TickerAsset"
194
- },
195
- "asset2": {
196
- "type": "TickerAsset"
197
- },
198
- "heartbeat": {
199
- "type": "u32"
200
- },
201
- "owner": {
202
- "type": "address"
203
- },
204
- "threshold": {
205
- "type": "u32"
206
- },
207
- "webhook": {
208
- "type": "bytes"
196
+ "fields": {
197
+ "asset1": {
198
+ "type": "TickerAsset"
199
+ },
200
+ "asset2": {
201
+ "type": "TickerAsset"
202
+ },
203
+ "heartbeat": {
204
+ "type": "u32"
205
+ },
206
+ "owner": {
207
+ "type": "address"
208
+ },
209
+ "threshold": {
210
+ "type": "u32"
211
+ },
212
+ "webhook": {
213
+ "type": "bytes"
214
+ }
209
215
  }
210
216
  },
211
217
  "Subscription": {
212
- "asset1": {
213
- "type": "TickerAsset"
214
- },
215
- "asset2": {
216
- "type": "TickerAsset"
217
- },
218
- "balance": {
219
- "type": "u64"
220
- },
221
- "heartbeat": {
222
- "type": "u32"
223
- },
224
- "last_charge": {
225
- "type": "u64"
226
- },
227
- "owner": {
228
- "type": "address"
229
- },
230
- "status": {
231
- "type": "SubscriptionStatus"
232
- },
233
- "threshold": {
234
- "type": "u32"
235
- },
236
- "webhook": {
237
- "type": "bytes"
218
+ "fields": {
219
+ "asset1": {
220
+ "type": "TickerAsset"
221
+ },
222
+ "asset2": {
223
+ "type": "TickerAsset"
224
+ },
225
+ "balance": {
226
+ "type": "u64"
227
+ },
228
+ "heartbeat": {
229
+ "type": "u32"
230
+ },
231
+ "last_charge": {
232
+ "type": "u64"
233
+ },
234
+ "owner": {
235
+ "type": "address"
236
+ },
237
+ "status": {
238
+ "type": "SubscriptionStatus"
239
+ },
240
+ "threshold": {
241
+ "type": "u32"
242
+ },
243
+ "webhook": {
244
+ "type": "bytes"
245
+ }
238
246
  }
239
247
  },
240
248
  "TickerAsset": {
241
- "asset": {
242
- "type": "Asset"
243
- },
244
- "source": {
245
- "type": "string"
249
+ "fields": {
250
+ "asset": {
251
+ "type": "Asset"
252
+ },
253
+ "source": {
254
+ "type": "string"
255
+ }
246
256
  }
247
257
  }
248
258
  },
249
259
  "unions": {
250
260
  "Asset": {
251
- "Other": [
252
- "symbol"
253
- ],
254
- "Stellar": [
255
- "address"
256
- ]
261
+ "cases": {
262
+ "Other": [
263
+ "symbol"
264
+ ],
265
+ "Stellar": [
266
+ "address"
267
+ ]
268
+ }
257
269
  }
258
270
  },
259
271
  "interfaceVersion": "85899345920",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/contract-wasm-interface-parser",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Contract interface metadata parser for binary WASM",
5
5
  "main": "index.js",
6
6
  "module": "./index.js",
@@ -73,13 +73,13 @@ class SpecParser {
73
73
  into[attr.name.toString()] = this.withDocs({
74
74
  inputs,
75
75
  outputs: attr.outputs.map(o => this.parseParameterType(o))
76
- }, attr.doc)
76
+ }, attr)
77
77
  }
78
78
 
79
79
  parseStruct(attr, into) {
80
80
  const fields = {}
81
81
  attr.fields.forEach(f => this.parseParameter(f, fields))
82
- into[this.parseStructName(attr)] = this.withDocs(fields, attr.doc)
82
+ into[this.parseStructName(attr)] = this.withDocs({fields}, attr)
83
83
  }
84
84
 
85
85
  parseUnion(attr, into) {
@@ -90,7 +90,7 @@ class SpecParser {
90
90
  value.type().map(t => this.parseParameterType(t)) :
91
91
  []
92
92
  })
93
- into[this.parseStructName(attr)] = this.withDocs(cases, attr.doc)
93
+ into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
94
94
  }
95
95
 
96
96
  parseEnum(attr, into) {
@@ -100,14 +100,18 @@ class SpecParser {
100
100
  if (value.name) {
101
101
  cases[value.name().toString()] = value.value()
102
102
  } else {
103
- cases[c._attributes.name.toString()] = this.withDocs({value}, c.doc())
103
+ const attr = c._attributes
104
+ cases[attr.name.toString()] = this.withDocs({value}, attr)
104
105
  }
105
106
  })
106
- into[this.parseStructName(attr)] = this.withDocs(cases, attr.doc)
107
+ into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
107
108
  }
108
109
 
109
110
  parseError(attr, into) {
110
- attr.cases.forEach(c => into[c.name().toString()] = this.withDocs({value: c.value()}, c.doc()))
111
+ attr.cases.forEach(c => {
112
+ const attr = c._attributes
113
+ into[attr.name.toString()] = this.withDocs({value: attr.value}, attr)
114
+ })
111
115
  }
112
116
 
113
117
  parseParameterType(type) {
@@ -141,13 +145,13 @@ class SpecParser {
141
145
  }
142
146
 
143
147
  parseParameter(param, into) {
144
- const {_attributes: attr} = param
145
- into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr.doc)
148
+ const attr = param._attributes
149
+ into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr)
146
150
  }
147
151
 
148
- withDocs(descriptor, doc) {
149
- if (doc?.length) {
150
- descriptor.doc = doc.toString()
152
+ withDocs(descriptor, attr) {
153
+ if (attr.doc?.length) {
154
+ descriptor.doc = attr.doc.toString()
151
155
  }
152
156
  return descriptor
153
157
  }