@stellar-expert/tx-meta-effects-parser 7.0.0-rc.8 → 7.0.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 +92 -14
- package/package.json +21 -21
- package/src/aggregation/events-analyzer.js +323 -301
- package/src/aggregation/sac-contract-mapper.js +3 -3
- package/src/effect-types.js +104 -101
- package/src/effects-analyzer.js +1142 -1123
- package/src/index.js +226 -233
- package/src/parser/ledger-entry-changes-parser.js +331 -312
- package/src/parser/normalization.js +73 -0
- package/src/parser/tx-xdr-parser-utils.js +299 -322
- package/tmp +0 -100
|
@@ -1,313 +1,332 @@
|
|
|
1
|
-
const {StrKey} = require('@stellar/stellar-base')
|
|
2
|
-
const {TxMetaEffectParserError, UnexpectedTxMetaChangeError} = require('../errors')
|
|
3
|
-
const {xdrParseAsset, xdrParseAccountAddress, xdrParseClaimant, xdrParsePrice, xdrParseSignerKey} = require('./tx-xdr-parser-utils')
|
|
4
|
-
const {generateContractStateEntryHash, generateContractCodeEntryHash} = require('./ledger-key')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {{}} ParsedLedgerEntryMeta
|
|
8
|
-
* @property {'account'|'trustline'|'offer'|'data'|'liquidityPool'|'claimableBalance'|'contractData'|'contractCode'|'ttl'} type - Ledger entry type
|
|
9
|
-
* @property {'created'|'updated'|'removed'} action - Ledger modification action
|
|
10
|
-
* @property {{}} before - Ledger entry state before changes applied
|
|
11
|
-
* @property {{}} after - Ledger entry state after changes application
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {LedgerEntryChange[]} ledgerEntryChanges
|
|
16
|
-
* @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
change.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
1
|
+
const {StrKey} = require('@stellar/stellar-base')
|
|
2
|
+
const {TxMetaEffectParserError, UnexpectedTxMetaChangeError} = require('../errors')
|
|
3
|
+
const {xdrParseAsset, xdrParseAccountAddress, xdrParseClaimant, xdrParsePrice, xdrParseSignerKey} = require('./tx-xdr-parser-utils')
|
|
4
|
+
const {generateContractStateEntryHash, generateContractCodeEntryHash} = require('./ledger-key')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {{}} ParsedLedgerEntryMeta
|
|
8
|
+
* @property {'account'|'trustline'|'offer'|'data'|'liquidityPool'|'claimableBalance'|'contractData'|'contractCode'|'ttl'} type - Ledger entry type
|
|
9
|
+
* @property {'created'|'updated'|'removed'|'restored'} action - Ledger modification action
|
|
10
|
+
* @property {{}} before - Ledger entry state before changes applied
|
|
11
|
+
* @property {{}} after - Ledger entry state after changes application
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {LedgerEntryChange[]} ledgerEntryChanges
|
|
16
|
+
* @param {Set<string>} [filter]
|
|
17
|
+
* @return {ParsedLedgerEntryMeta[]}
|
|
18
|
+
*/
|
|
19
|
+
function parseLedgerEntryChanges(ledgerEntryChanges, filter = undefined) {
|
|
20
|
+
const changes = []
|
|
21
|
+
let state
|
|
22
|
+
let containsTtl = false
|
|
23
|
+
for (let i = 0; i < ledgerEntryChanges.length; i++) {
|
|
24
|
+
const entry = ledgerEntryChanges[i]
|
|
25
|
+
const type = entry._value._arm || entry._value._attributes.data._arm
|
|
26
|
+
if (filter && !filter.has(type)) //skip filtered ledger entry types
|
|
27
|
+
continue
|
|
28
|
+
const action = entry._arm
|
|
29
|
+
const stateData = parseEntry(entry, action)
|
|
30
|
+
if (stateData === undefined)
|
|
31
|
+
continue
|
|
32
|
+
const change = {action, type}
|
|
33
|
+
switch (action) {
|
|
34
|
+
case 'state':
|
|
35
|
+
state = stateData
|
|
36
|
+
continue
|
|
37
|
+
case 'created':
|
|
38
|
+
if (type === 'contractCode')
|
|
39
|
+
continue //processed in operation handler
|
|
40
|
+
change.before = null
|
|
41
|
+
change.after = stateData
|
|
42
|
+
change.type = stateData.entry
|
|
43
|
+
break
|
|
44
|
+
case 'updated':
|
|
45
|
+
if (type === 'contractCode')
|
|
46
|
+
console.warn(new UnexpectedTxMetaChangeError({type, action})) //happens only in protocol 20
|
|
47
|
+
change.before = state
|
|
48
|
+
change.after = stateData
|
|
49
|
+
change.type = stateData.entry
|
|
50
|
+
break
|
|
51
|
+
case 'restored':
|
|
52
|
+
change.before = stateData
|
|
53
|
+
change.after = stateData
|
|
54
|
+
change.type = stateData.entry
|
|
55
|
+
state = change.after
|
|
56
|
+
break
|
|
57
|
+
case 'removed':
|
|
58
|
+
if (!state && type === 'ttl')
|
|
59
|
+
continue //skip expiration processing for now
|
|
60
|
+
change.before = state
|
|
61
|
+
change.after = null
|
|
62
|
+
change.type = state.entry
|
|
63
|
+
break
|
|
64
|
+
default:
|
|
65
|
+
throw new TxMetaEffectParserError(`Unknown change entry type: ${action}`)
|
|
66
|
+
}
|
|
67
|
+
if (change.type === 'ttl') {
|
|
68
|
+
containsTtl = true
|
|
69
|
+
}
|
|
70
|
+
changes.push(change)
|
|
71
|
+
}
|
|
72
|
+
if (containsTtl) { //put ttl entries into the end of array
|
|
73
|
+
changes.sort((a, b) =>
|
|
74
|
+
a.type !== 'ttl' && b.type === 'ttl' ?
|
|
75
|
+
-1 : 0)
|
|
76
|
+
}
|
|
77
|
+
return changes
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseEntry(entry, actionType) {
|
|
81
|
+
if (actionType === 'removed')
|
|
82
|
+
return null
|
|
83
|
+
const value = entry.value()
|
|
84
|
+
const parsed = parseEntryData(value.data())
|
|
85
|
+
if (parsed === null)
|
|
86
|
+
return null
|
|
87
|
+
//parsed.modified = entry.lastModifiedLedgerSeq()
|
|
88
|
+
return parseLedgerEntryExt(parsed, value)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parseEntryData(data) {
|
|
92
|
+
const updatedEntryType = data.arm()
|
|
93
|
+
switch (updatedEntryType) {
|
|
94
|
+
case 'account':
|
|
95
|
+
return parseAccountEntry(data)
|
|
96
|
+
case 'trustline':
|
|
97
|
+
case 'trustLine':
|
|
98
|
+
return parseTrustlineEntry(data)
|
|
99
|
+
case 'offer':
|
|
100
|
+
return parseOfferEntry(data)
|
|
101
|
+
case 'data':
|
|
102
|
+
case 'datum':
|
|
103
|
+
return parseDataEntry(data)
|
|
104
|
+
case 'claimableBalance':
|
|
105
|
+
return parseClaimableBalanceEntry(data)
|
|
106
|
+
case 'liquidityPool':
|
|
107
|
+
return parseLiquidityPoolEntry(data)
|
|
108
|
+
case 'contractData':
|
|
109
|
+
return parseContractData(data)
|
|
110
|
+
case 'contractCode':
|
|
111
|
+
return parseContractCode(data)
|
|
112
|
+
case 'ttl':
|
|
113
|
+
return parseTtl(data)
|
|
114
|
+
default:
|
|
115
|
+
throw new TxMetaEffectParserError(`Unknown meta entry type: ${updatedEntryType}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseLedgerEntryExt(data, entry) {
|
|
120
|
+
const v1 = entry.ext()?.v1()
|
|
121
|
+
if (v1) {
|
|
122
|
+
const sponsor = v1.sponsoringId()
|
|
123
|
+
if (sponsor) {
|
|
124
|
+
data.sponsor = xdrParseAccountAddress(sponsor)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return data
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseAccountEntry(value) {
|
|
131
|
+
const accountEntryXdr = value.value()
|
|
132
|
+
const data = {
|
|
133
|
+
entry: 'account',
|
|
134
|
+
address: xdrParseAccountAddress(accountEntryXdr.accountId()),
|
|
135
|
+
sequence: accountEntryXdr.seqNum().toString(),
|
|
136
|
+
balance: accountEntryXdr.balance().toString(),
|
|
137
|
+
homeDomain: accountEntryXdr.homeDomain().toString('UTF8'),
|
|
138
|
+
inflationDest: xdrParseAccountAddress(accountEntryXdr.inflationDest()),
|
|
139
|
+
flags: accountEntryXdr.flags(),
|
|
140
|
+
signers: accountEntryXdr.signers().map(signer => ({
|
|
141
|
+
key: xdrParseSignerKey(signer.key()),
|
|
142
|
+
weight: signer.weight()
|
|
143
|
+
}))
|
|
144
|
+
}
|
|
145
|
+
const thresholds = accountEntryXdr.thresholds()
|
|
146
|
+
data.thresholds = thresholds.slice(1).join()
|
|
147
|
+
data.masterWeight = thresholds[0]
|
|
148
|
+
const extV1 = accountEntryXdr.ext()?.v1()
|
|
149
|
+
if (extV1) {
|
|
150
|
+
const extV2 = extV1.ext()?.v2()
|
|
151
|
+
if (extV2) {
|
|
152
|
+
const sponsoringIDs = extV2.signerSponsoringIDs()
|
|
153
|
+
if (sponsoringIDs.length > 0) {
|
|
154
|
+
for (let i = 0; i < data.signers.length; i++) {
|
|
155
|
+
const sponsor = sponsoringIDs[i]
|
|
156
|
+
if (sponsor) { //attach sponsors directly to the signers
|
|
157
|
+
data.signers[i].sponsor = xdrParseAccountAddress(sponsor)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//ignored fields: numSubEntries, extV1.liabilities, extV2.numSponsored, extV2.numSponsoring, extV3.seqLedger, extv3.seqTime
|
|
164
|
+
return data
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function parseTrustlineEntry(value) {
|
|
168
|
+
const trustlineEntryXdr = value.value()
|
|
169
|
+
const trustlineAsset = trustlineEntryXdr.asset()
|
|
170
|
+
const trustlineType = trustlineAsset.switch()
|
|
171
|
+
let asset
|
|
172
|
+
switch (trustlineType.value) {
|
|
173
|
+
case 0:
|
|
174
|
+
case 1:
|
|
175
|
+
case 2:
|
|
176
|
+
asset = xdrParseAsset(trustlineAsset)
|
|
177
|
+
break
|
|
178
|
+
case 3:
|
|
179
|
+
asset = trustlineEntryXdr.asset().liquidityPoolId().toString('hex')
|
|
180
|
+
//data.liquidityPoolUseCount = trustlineEntryXdr.liquidityPoolUseCount()
|
|
181
|
+
break
|
|
182
|
+
default:
|
|
183
|
+
throw new TxMetaEffectParserError(`Unsupported trustline type ` + trustlineType)
|
|
184
|
+
}
|
|
185
|
+
const data = {
|
|
186
|
+
entry: 'trustline',
|
|
187
|
+
account: xdrParseAccountAddress(trustlineEntryXdr.accountId()),
|
|
188
|
+
asset,
|
|
189
|
+
balance: trustlineEntryXdr.balance().toString(),
|
|
190
|
+
limit: trustlineEntryXdr.limit().toString(),
|
|
191
|
+
flags: trustlineEntryXdr.flags()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
//ignored
|
|
196
|
+
const extV1 = trustlineEntryXdr.ext()?.v1()
|
|
197
|
+
if (extV1) {
|
|
198
|
+
const liabilities = extV1.liabilities()
|
|
199
|
+
data.buying_liabilities = liabilities.buying().toString()
|
|
200
|
+
data.selling_liabilities = liabilities.selling().toString()
|
|
201
|
+
}*/
|
|
202
|
+
|
|
203
|
+
return data
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function parseDataEntry(value) {
|
|
207
|
+
const dataEntryXdr = value.value()
|
|
208
|
+
return {
|
|
209
|
+
entry: 'data',
|
|
210
|
+
account: xdrParseAccountAddress(dataEntryXdr.accountId()),
|
|
211
|
+
name: dataEntryXdr.dataName().toString(),
|
|
212
|
+
value: dataEntryXdr.dataValue().toString('base64')
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function parseLiquidityPoolEntry(value) {
|
|
217
|
+
const liquidityPoolEntryXdr = value.value()
|
|
218
|
+
const body = liquidityPoolEntryXdr.body().value()
|
|
219
|
+
const params = body.params()
|
|
220
|
+
return {
|
|
221
|
+
entry: 'liquidityPool',
|
|
222
|
+
pool: liquidityPoolEntryXdr.liquidityPoolId().toString('hex'),
|
|
223
|
+
asset: [xdrParseAsset(params.assetA()), xdrParseAsset(params.assetB())],
|
|
224
|
+
fee: params.fee(),
|
|
225
|
+
amount: [body.reserveA().toString(), body.reserveB().toString()],
|
|
226
|
+
shares: body.totalPoolShares().toString(),
|
|
227
|
+
accounts: body.poolSharesTrustLineCount().low
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function parseOfferEntry(value) {
|
|
232
|
+
const offerEntryXdr = value.value()
|
|
233
|
+
const rprice = offerEntryXdr.price()
|
|
234
|
+
const data = {
|
|
235
|
+
entry: 'offer',
|
|
236
|
+
id: offerEntryXdr.offerId().toString(),
|
|
237
|
+
account: xdrParseAccountAddress(offerEntryXdr.sellerId()),
|
|
238
|
+
asset: [xdrParseAsset(offerEntryXdr.selling()), xdrParseAsset(offerEntryXdr.buying())],
|
|
239
|
+
amount: offerEntryXdr.amount().toString(),
|
|
240
|
+
price: xdrParsePrice(rprice),
|
|
241
|
+
rprice: rprice._attributes,
|
|
242
|
+
flags: offerEntryXdr.flags()
|
|
243
|
+
}
|
|
244
|
+
return data
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function parseClaimableBalanceEntry(value) {
|
|
248
|
+
const claimableBalanceXdr = value.value()
|
|
249
|
+
const data = {
|
|
250
|
+
balanceId: Buffer.from(claimableBalanceXdr.balanceId().value()).toString('hex'),
|
|
251
|
+
entry: 'claimableBalance',
|
|
252
|
+
asset: xdrParseAsset(claimableBalanceXdr.asset()),
|
|
253
|
+
amount: claimableBalanceXdr.amount().toString(),
|
|
254
|
+
claimants: claimableBalanceXdr.claimants().map(claimant => xdrParseClaimant(claimant))
|
|
255
|
+
}
|
|
256
|
+
const extV1 = claimableBalanceXdr.ext()?.v1()
|
|
257
|
+
if (extV1) {
|
|
258
|
+
data.flags = extV1.flags()
|
|
259
|
+
}
|
|
260
|
+
return data
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function parseContractData(value) {
|
|
264
|
+
const data = value.value()
|
|
265
|
+
const owner = parseStateOwnerDataAddress(data.contract())
|
|
266
|
+
|
|
267
|
+
const valueAttr = data.val()
|
|
268
|
+
const entry = {
|
|
269
|
+
entry: 'contractData',
|
|
270
|
+
owner,
|
|
271
|
+
key: data.key().toXDR('base64'),
|
|
272
|
+
value: valueAttr.toXDR('base64'),
|
|
273
|
+
durability: data.durability().name,
|
|
274
|
+
keyHash: generateContractStateEntryHash(data)
|
|
275
|
+
}
|
|
276
|
+
if (data.key().switch()?.name === 'scvLedgerKeyContractInstance' && entry.durability === 'persistent') {
|
|
277
|
+
entry.durability = 'instance'
|
|
278
|
+
const instance = valueAttr.instance()._attributes
|
|
279
|
+
const type = instance.executable._switch.name
|
|
280
|
+
switch (type) {
|
|
281
|
+
case 'contractExecutableStellarAsset':
|
|
282
|
+
entry.kind = 'fromAsset'
|
|
283
|
+
if (instance.storage?.length) { //if not -- the asset has been created "fromAddress" - no metadata in this case
|
|
284
|
+
const metaArgs = instance.storage[0]._attributes
|
|
285
|
+
if (metaArgs.key._value.toString() !== 'METADATA')
|
|
286
|
+
throw new TxMetaEffectParserError('Unexpected asset initialization metadata')
|
|
287
|
+
entry.asset = xdrParseAsset(metaArgs.val._value[1]._attributes.val._value.toString())
|
|
288
|
+
}
|
|
289
|
+
break
|
|
290
|
+
case 'contractExecutableWasm':
|
|
291
|
+
entry.kind = 'wasm'
|
|
292
|
+
entry.wasmHash = instance.executable.wasmHash().toString('hex')
|
|
293
|
+
break
|
|
294
|
+
default:
|
|
295
|
+
throw new TxMetaEffectParserError('Unsupported executable type: ' + type)
|
|
296
|
+
}
|
|
297
|
+
if (instance.storage?.length) {
|
|
298
|
+
entry.storage = instance.storage.map(entry => ({
|
|
299
|
+
key: entry.key().toXDR('base64'),
|
|
300
|
+
val: entry.val().toXDR('base64')
|
|
301
|
+
}))
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return entry
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function parseTtl(data) {
|
|
308
|
+
const attrs = data._value._attributes
|
|
309
|
+
return {
|
|
310
|
+
entry: 'ttl',
|
|
311
|
+
keyHash: attrs.keyHash.toString('hex'),
|
|
312
|
+
ttl: attrs.liveUntilLedgerSeq
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function parseStateOwnerDataAddress(contract) {
|
|
317
|
+
if (contract.switch().name === 'scAddressTypeContract')
|
|
318
|
+
return StrKey.encodeContract(contract.contractId())
|
|
319
|
+
return xdrParseAccountAddress(contract.accountId())
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function parseContractCode(value) {
|
|
323
|
+
const contract = value.value()
|
|
324
|
+
const hash = contract.hash()
|
|
325
|
+
return {
|
|
326
|
+
entry: 'contractCode',
|
|
327
|
+
hash: hash.toString('hex'),
|
|
328
|
+
keyHash: generateContractCodeEntryHash(hash)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
313
332
|
module.exports = {parseLedgerEntryChanges}
|