@sentio/sdk 2.23.0 → 2.24.0-rc.1

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.
Files changed (228) hide show
  1. package/lib/aptos/aptos-processor.d.ts +1 -2
  2. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  3. package/lib/aptos/aptos-processor.js +11 -11
  4. package/lib/aptos/aptos-processor.js.map +1 -1
  5. package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
  6. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  7. package/lib/aptos/aptos-resource-processor-template.js +6 -6
  8. package/lib/aptos/builtin/0x1.d.ts +342 -339
  9. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  10. package/lib/aptos/builtin/0x1.js +65 -188
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts +73 -54
  13. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  14. package/lib/aptos/builtin/0x3.js +24 -65
  15. package/lib/aptos/builtin/0x3.js.map +1 -1
  16. package/lib/aptos/codegen/codegen.d.ts.map +1 -1
  17. package/lib/aptos/codegen/codegen.js +40 -10
  18. package/lib/aptos/codegen/codegen.js.map +1 -1
  19. package/lib/aptos/context.d.ts +1 -2
  20. package/lib/aptos/context.d.ts.map +1 -1
  21. package/lib/aptos/context.js +2 -2
  22. package/lib/aptos/context.js.map +1 -1
  23. package/lib/aptos/ext/coin-event.js +1 -1
  24. package/lib/aptos/ext/coin.js +193 -193
  25. package/lib/aptos/ext/coin.js.map +1 -1
  26. package/lib/aptos/index.d.ts +4 -4
  27. package/lib/aptos/index.d.ts.map +1 -1
  28. package/lib/aptos/index.js +3 -4
  29. package/lib/aptos/index.js.map +1 -1
  30. package/lib/aptos/models.d.ts +2 -2
  31. package/lib/aptos/models.d.ts.map +1 -1
  32. package/lib/aptos/move-coder.d.ts +1 -13
  33. package/lib/aptos/move-coder.d.ts.map +1 -1
  34. package/lib/aptos/move-coder.js +4 -55
  35. package/lib/aptos/move-coder.js.map +1 -1
  36. package/lib/aptos/network.d.ts +1 -0
  37. package/lib/aptos/network.d.ts.map +1 -1
  38. package/lib/aptos/network.js +8 -1
  39. package/lib/aptos/network.js.map +1 -1
  40. package/lib/eth/codegen/codegen.d.ts.map +1 -1
  41. package/lib/eth/codegen/codegen.js +4 -3
  42. package/lib/eth/codegen/codegen.js.map +1 -1
  43. package/lib/move/ext/move-dex.d.ts +1 -1
  44. package/lib/move/ext/move-dex.d.ts.map +1 -1
  45. package/lib/move/ext/move-dex.js +4 -4
  46. package/lib/move/index.d.ts +1 -4
  47. package/lib/move/index.d.ts.map +1 -1
  48. package/lib/move/index.js +1 -4
  49. package/lib/move/index.js.map +1 -1
  50. package/lib/move/move-context.d.ts +3 -3
  51. package/lib/move/move-context.d.ts.map +1 -1
  52. package/lib/move/move-context.js.map +1 -1
  53. package/lib/move/shared-network-codegen.d.ts +14 -0
  54. package/lib/move/shared-network-codegen.d.ts.map +1 -0
  55. package/lib/move/shared-network-codegen.js +116 -0
  56. package/lib/move/shared-network-codegen.js.map +1 -0
  57. package/lib/sui/builtin/0x1.d.ts +4 -2
  58. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  59. package/lib/sui/builtin/0x1.js +7 -14
  60. package/lib/sui/builtin/0x1.js.map +1 -1
  61. package/lib/sui/builtin/0x2.d.ts +52 -168
  62. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  63. package/lib/sui/builtin/0x2.js +24 -65
  64. package/lib/sui/builtin/0x2.js.map +1 -1
  65. package/lib/sui/builtin/0x3.d.ts +113 -331
  66. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  67. package/lib/sui/builtin/0x3.js +13 -32
  68. package/lib/sui/builtin/0x3.js.map +1 -1
  69. package/lib/sui/codegen/codegen.d.ts.map +1 -1
  70. package/lib/sui/codegen/codegen.js +72 -51
  71. package/lib/sui/codegen/codegen.js.map +1 -1
  72. package/lib/sui/context.d.ts +4 -4
  73. package/lib/sui/context.d.ts.map +1 -1
  74. package/lib/sui/context.js +2 -2
  75. package/lib/sui/context.js.map +1 -1
  76. package/lib/sui/ext/coin.js +74 -74
  77. package/lib/sui/ext/move-dex.d.ts +2 -3
  78. package/lib/sui/ext/move-dex.d.ts.map +1 -1
  79. package/lib/sui/index.d.ts +4 -4
  80. package/lib/sui/index.d.ts.map +1 -1
  81. package/lib/sui/index.js +4 -4
  82. package/lib/sui/index.js.map +1 -1
  83. package/lib/sui/models.d.ts +2 -2
  84. package/lib/sui/models.d.ts.map +1 -1
  85. package/lib/sui/move-coder.d.ts +1 -16
  86. package/lib/sui/move-coder.d.ts.map +1 -1
  87. package/lib/sui/move-coder.js +4 -93
  88. package/lib/sui/move-coder.js.map +1 -1
  89. package/lib/sui/network.d.ts +3 -2
  90. package/lib/sui/network.d.ts.map +1 -1
  91. package/lib/sui/network.js +10 -3
  92. package/lib/sui/network.js.map +1 -1
  93. package/lib/sui/sui-object-processor-template.d.ts +1 -1
  94. package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
  95. package/lib/sui/sui-object-processor-template.js +7 -7
  96. package/lib/sui/sui-object-processor-template.js.map +1 -1
  97. package/lib/sui/sui-object-processor.d.ts +1 -1
  98. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  99. package/lib/sui/sui-object-processor.js +5 -5
  100. package/lib/sui/sui-processor.d.ts +2 -2
  101. package/lib/sui/sui-processor.d.ts.map +1 -1
  102. package/lib/sui/sui-processor.js +10 -10
  103. package/lib/sui/sui-processor.js.map +1 -1
  104. package/lib/sui/utils.d.ts +2 -2
  105. package/lib/sui/utils.d.ts.map +1 -1
  106. package/lib/sui/utils.js +3 -4
  107. package/lib/sui/utils.js.map +1 -1
  108. package/lib/testing/aptos-facet.d.ts.map +1 -1
  109. package/lib/testing/aptos-facet.js +8 -9
  110. package/lib/testing/aptos-facet.js.map +1 -1
  111. package/lib/testing/sui-facet.d.ts +1 -1
  112. package/lib/testing/sui-facet.d.ts.map +1 -1
  113. package/lib/testing/sui-facet.js +8 -9
  114. package/lib/testing/sui-facet.js.map +1 -1
  115. package/package.json +10 -7
  116. package/src/aptos/aptos-processor.ts +13 -12
  117. package/src/aptos/aptos-resource-processor-template.ts +7 -7
  118. package/src/aptos/builtin/0x1.ts +970 -1168
  119. package/src/aptos/builtin/0x3.ts +205 -249
  120. package/src/aptos/codegen/codegen.ts +50 -11
  121. package/src/aptos/context.ts +4 -4
  122. package/src/aptos/ext/coin-event.ts +2 -2
  123. package/src/aptos/ext/coin.ts +193 -193
  124. package/src/aptos/index.ts +15 -4
  125. package/src/aptos/models.ts +2 -2
  126. package/src/aptos/move-coder.ts +4 -73
  127. package/src/aptos/network.ts +9 -1
  128. package/src/eth/codegen/codegen.ts +5 -4
  129. package/src/move/ext/move-dex.ts +5 -5
  130. package/src/move/index.ts +2 -4
  131. package/src/move/move-context.ts +3 -3
  132. package/src/move/shared-network-codegen.ts +160 -0
  133. package/src/sui/builtin/0x1.ts +17 -41
  134. package/src/sui/builtin/0x2.ts +196 -410
  135. package/src/sui/builtin/0x3.ts +271 -479
  136. package/src/sui/codegen/codegen.ts +80 -54
  137. package/src/sui/context.ts +8 -7
  138. package/src/sui/ext/coin.ts +75 -75
  139. package/src/sui/ext/move-dex.ts +3 -3
  140. package/src/sui/index.ts +5 -5
  141. package/src/sui/models.ts +2 -2
  142. package/src/sui/move-coder.ts +4 -108
  143. package/src/sui/network.ts +12 -4
  144. package/src/sui/sui-object-processor-template.ts +8 -8
  145. package/src/sui/sui-object-processor.ts +6 -6
  146. package/src/sui/sui-processor.ts +12 -16
  147. package/src/sui/utils.ts +6 -7
  148. package/src/testing/aptos-facet.ts +8 -9
  149. package/src/testing/sui-facet.ts +9 -10
  150. package/lib/aptos/aptos-chain-adapter.d.ts +0 -15
  151. package/lib/aptos/aptos-chain-adapter.d.ts.map +0 -1
  152. package/lib/aptos/aptos-chain-adapter.js +0 -72
  153. package/lib/aptos/aptos-chain-adapter.js.map +0 -1
  154. package/lib/aptos/module-client.d.ts +0 -7
  155. package/lib/aptos/module-client.d.ts.map +0 -1
  156. package/lib/aptos/module-client.js +0 -25
  157. package/lib/aptos/module-client.js.map +0 -1
  158. package/lib/aptos/module-client.test.d.ts +0 -2
  159. package/lib/aptos/module-client.test.d.ts.map +0 -1
  160. package/lib/aptos/module-client.test.js.map +0 -1
  161. package/lib/aptos/move-types.d.ts +0 -17
  162. package/lib/aptos/move-types.d.ts.map +0 -1
  163. package/lib/aptos/move-types.js +0 -53
  164. package/lib/aptos/move-types.js.map +0 -1
  165. package/lib/aptos/utils.d.ts +0 -2
  166. package/lib/aptos/utils.d.ts.map +0 -1
  167. package/lib/aptos/utils.js +0 -16
  168. package/lib/aptos/utils.js.map +0 -1
  169. package/lib/move/abstract-codegen.d.ts +0 -50
  170. package/lib/move/abstract-codegen.d.ts.map +0 -1
  171. package/lib/move/abstract-codegen.js +0 -489
  172. package/lib/move/abstract-codegen.js.map +0 -1
  173. package/lib/move/abstract-move-coder.d.ts +0 -29
  174. package/lib/move/abstract-move-coder.d.ts.map +0 -1
  175. package/lib/move/abstract-move-coder.js +0 -301
  176. package/lib/move/abstract-move-coder.js.map +0 -1
  177. package/lib/move/account.d.ts +0 -16
  178. package/lib/move/account.d.ts.map +0 -1
  179. package/lib/move/account.js +0 -71
  180. package/lib/move/account.js.map +0 -1
  181. package/lib/move/chain-adapter.d.ts +0 -13
  182. package/lib/move/chain-adapter.d.ts.map +0 -1
  183. package/lib/move/chain-adapter.js +0 -7
  184. package/lib/move/chain-adapter.js.map +0 -1
  185. package/lib/move/internal-models.d.ts +0 -35
  186. package/lib/move/internal-models.d.ts.map +0 -1
  187. package/lib/move/internal-models.js +0 -7
  188. package/lib/move/internal-models.js.map +0 -1
  189. package/lib/move/ts-type.test.d.ts +0 -2
  190. package/lib/move/ts-type.test.d.ts.map +0 -1
  191. package/lib/move/ts-type.test.js.map +0 -1
  192. package/lib/move/types.d.ts +0 -42
  193. package/lib/move/types.d.ts.map +0 -1
  194. package/lib/move/types.js +0 -205
  195. package/lib/move/types.js.map +0 -1
  196. package/lib/move/utils.d.ts +0 -16
  197. package/lib/move/utils.d.ts.map +0 -1
  198. package/lib/move/utils.js +0 -53
  199. package/lib/move/utils.js.map +0 -1
  200. package/lib/move/utils.test.d.ts +0 -2
  201. package/lib/move/utils.test.d.ts.map +0 -1
  202. package/lib/move/utils.test.js.map +0 -1
  203. package/lib/sui/module-client.d.ts +0 -4
  204. package/lib/sui/module-client.d.ts.map +0 -1
  205. package/lib/sui/module-client.js +0 -7
  206. package/lib/sui/module-client.js.map +0 -1
  207. package/lib/sui/move-types.d.ts +0 -9
  208. package/lib/sui/move-types.d.ts.map +0 -1
  209. package/lib/sui/move-types.js +0 -82
  210. package/lib/sui/move-types.js.map +0 -1
  211. package/lib/sui/sui-chain-adapter.d.ts +0 -15
  212. package/lib/sui/sui-chain-adapter.d.ts.map +0 -1
  213. package/lib/sui/sui-chain-adapter.js +0 -71
  214. package/lib/sui/sui-chain-adapter.js.map +0 -1
  215. package/src/aptos/aptos-chain-adapter.ts +0 -86
  216. package/src/aptos/module-client.ts +0 -30
  217. package/src/aptos/move-types.ts +0 -73
  218. package/src/aptos/utils.ts +0 -15
  219. package/src/move/abstract-codegen.ts +0 -596
  220. package/src/move/abstract-move-coder.ts +0 -337
  221. package/src/move/account.ts +0 -81
  222. package/src/move/chain-adapter.ts +0 -24
  223. package/src/move/internal-models.ts +0 -40
  224. package/src/move/types.ts +0 -241
  225. package/src/move/utils.ts +0 -69
  226. package/src/sui/module-client.ts +0 -7
  227. package/src/sui/move-types.ts +0 -108
  228. package/src/sui/sui-chain-adapter.ts +0 -93
@@ -1,337 +0,0 @@
1
- import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'
2
- import { DecodedStruct, matchType, parseMoveType, TypeDescriptor } from './types.js'
3
- import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'
4
- import { bytesToBigInt } from '../utils/index.js'
5
- import { ChainAdapter } from './chain-adapter.js'
6
-
7
- export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
8
- protected moduleMapping = new Map<string, InternalMoveModule>()
9
- private typeMapping = new Map<string, InternalMoveStruct>()
10
- private funcMapping = new Map<string, InternalMoveFunction>()
11
- network: Network
12
- adapter: ChainAdapter<Network, ModuleType, StructType>
13
-
14
- protected constructor(network: Network) {
15
- this.network = network
16
- }
17
-
18
- contains(account: string, name: string) {
19
- return this.moduleMapping.has(moduleQname({ address: account, name }))
20
- }
21
-
22
- abstract load(module: ModuleType): InternalMoveModule
23
-
24
- protected loadInternal(module: InternalMoveModule) {
25
- const account = this.adapter.validateAndNormalizeAddress(module.address)
26
- if (this.contains(account, module.name)) {
27
- return
28
- }
29
- this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module)
30
-
31
- for (const struct of module.structs) {
32
- // TODO move to util
33
- const key = [account, module.name, struct.name].join(SPLITTER)
34
- this.typeMapping.set(key, struct)
35
- }
36
-
37
- for (const func of module.exposedFunctions) {
38
- // if (!func.isEntry) {
39
- // continue
40
- // }
41
- const key = [account, module.name, func.name].join(SPLITTER)
42
- this.funcMapping.set(key, func)
43
- }
44
- }
45
-
46
- protected decodeBigInt(data: any): bigint {
47
- if (Array.isArray(data)) {
48
- // Only sui function need this, strange
49
- const bytes = data as number[]
50
- return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))
51
- } else {
52
- return BigInt(data)
53
- }
54
- }
55
-
56
- protected encodeBigInt(data: bigint): any {
57
- return '0x' + data.toString(16)
58
- }
59
-
60
- private requestMap = new Map<string, Promise<InternalMoveModule>>()
61
-
62
- async getMoveStruct(type: string): Promise<InternalMoveStruct> {
63
- const [account_, module, typeName] = type.split(SPLITTER)
64
- const account = this.adapter.validateAndNormalizeAddress(account_)
65
- type = [account, module, typeName].join(SPLITTER)
66
-
67
- let struct = this.typeMapping.get(type)
68
- if (struct) {
69
- return struct
70
- }
71
- const key = account + SPLITTER + module
72
- let resp = this.requestMap.get(account + SPLITTER + module)
73
- if (!resp) {
74
- resp = this.adapter.fetchModule(account, module, this.network).then((m) => {
75
- return this.load(m)
76
- })
77
- this.requestMap.set(key, resp)
78
- }
79
- await resp
80
- struct = this.typeMapping.get(type)
81
- if (struct) {
82
- return struct
83
- }
84
- throw new Error('Failed to load function ' + type + ' type are not imported anywhere')
85
- }
86
-
87
- async getMoveFunction(type: string): Promise<InternalMoveFunction> {
88
- const [account_, module, typeName] = type.split(SPLITTER)
89
- const account = this.adapter.validateAndNormalizeAddress(account_)
90
- type = [account, module, typeName].join(SPLITTER)
91
-
92
- let func = this.funcMapping.get(type)
93
- if (func) {
94
- return func
95
- }
96
- const key = account + SPLITTER + module
97
- let resp = this.requestMap.get(account + SPLITTER + module)
98
- if (!resp) {
99
- resp = this.adapter.fetchModule(account, module, this.network).then((m) => {
100
- return this.load(m)
101
- })
102
- this.requestMap.set(key, resp)
103
- }
104
- await resp
105
- func = this.funcMapping.get(type)
106
- if (func) {
107
- return func
108
- }
109
- throw new Error('Failed to load function ' + type + ' type are not imported anywhere')
110
- }
111
-
112
- protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {
113
- // process simple type
114
- if (type.reference) {
115
- return data
116
- }
117
- switch (type.qname) {
118
- case 'signer': // TODO check this, aptos only
119
- case 'address':
120
- case 'Address':
121
- case '0x1::string::String':
122
- case 'bool':
123
- case 'Bool':
124
- case 'u8':
125
- case 'U8':
126
- case 'u16':
127
- case 'U16':
128
- case 'u32':
129
- case 'U32':
130
- return data
131
- case 'u64':
132
- case 'U64':
133
- case 'u128':
134
- case 'U128':
135
- case 'u256':
136
- case 'U256':
137
- return this.decodeBigInt(data) as any
138
- }
139
-
140
- // process vector
141
- if (type.qname.toLowerCase() === VECTOR_STR) {
142
- // vector<u8> as hex string
143
- if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
144
- return data
145
- }
146
-
147
- const res = []
148
- for (const entry of data) {
149
- res.push(await this.decode(entry, type.typeArgs[0]))
150
- }
151
- return res as any
152
- }
153
-
154
- // Process complex type
155
- const struct = await this.getMoveStruct(type.qname)
156
-
157
- const typeCtx = new Map<string, TypeDescriptor>()
158
- for (const [idx, typeArg] of type.typeArgs.entries()) {
159
- typeCtx.set('T' + idx, typeArg)
160
- }
161
-
162
- const typedData: any = {}
163
-
164
- for (const field of struct.fields) {
165
- let filedType = field.type
166
- filedType = filedType.applyTypeArgs(typeCtx)
167
- const fieldValue = this.adapter.getData(data)[field.name]
168
- const value = await this.decode(fieldValue, filedType)
169
- typedData[field.name] = value
170
- }
171
- return typedData
172
- }
173
-
174
- protected async encode(data: any, type: TypeDescriptor): Promise<any> {
175
- // process simple type
176
- if (type.reference) {
177
- return data
178
- }
179
- switch (type.qname) {
180
- case 'signer': // TODO check this, aptos only
181
- case 'address':
182
- case 'Address':
183
- case '0x2::object::ID':
184
- case '0x2::coin::Coin':
185
- case '0x1::string::String':
186
- case 'bool':
187
- case 'Bool':
188
- case 'u8':
189
- case 'U8':
190
- case 'u16':
191
- case 'U16':
192
- case 'u32':
193
- case 'U32':
194
- return data
195
- case 'u64':
196
- case 'U64':
197
- case 'u128':
198
- case 'U128':
199
- case 'u256':
200
- case 'U256':
201
- return this.encodeBigInt(data)
202
- }
203
-
204
- // process vector
205
- if (type.qname.toLowerCase() === VECTOR_STR) {
206
- // vector<u8> as hex string
207
- if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
208
- return data
209
- }
210
-
211
- const res = []
212
- for (const entry of data) {
213
- res.push(this.encode(entry, type.typeArgs[0]))
214
- }
215
- return res
216
- }
217
-
218
- // Process complex type
219
- const struct = await this.getMoveStruct(type.qname)
220
-
221
- const typeCtx = new Map<string, TypeDescriptor>()
222
- for (const [idx, typeArg] of type.typeArgs.entries()) {
223
- typeCtx.set('T' + idx, typeArg)
224
- }
225
-
226
- const typedData: any = {}
227
-
228
- for (const field of struct.fields) {
229
- let filedType = field.type
230
- filedType = filedType.applyTypeArgs(typeCtx)
231
- const value = await this.encode(data[field.name], filedType)
232
- typedData[field.name] = value
233
- }
234
- return typedData
235
- }
236
-
237
- async decodeArray(entries: any[], types: TypeDescriptor[], strict = true): Promise<any[]> {
238
- const entriesDecoded: any[] = []
239
- for (const [idx, arg] of entries.entries()) {
240
- // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
241
- const argType = types[idx]
242
- try {
243
- if (!strict && arg === undefined) {
244
- entriesDecoded.push(arg)
245
- } else {
246
- entriesDecoded.push(await this.decode(arg, argType))
247
- }
248
- } catch (e) {
249
- throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())
250
- }
251
- }
252
- return entriesDecoded
253
- }
254
-
255
- async encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]> {
256
- const entries: any[] = []
257
- for (const [idx, arg] of entriesDecoded.entries()) {
258
- // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
259
- const argType = types[idx]
260
- try {
261
- entries.push(await this.encode(arg, argType))
262
- } catch (e) {
263
- throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())
264
- }
265
- }
266
- return entries
267
- }
268
-
269
- async encodeCallArgs(args: any[], func: string): Promise<any[]> {
270
- const f = await this.getMoveFunction(func)
271
- return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))
272
- }
273
-
274
- async decodeCallResult(res: any[], func: string): Promise<any[]> {
275
- const f = await this.getMoveFunction(func)
276
- return this.decodeArray(res, f.return)
277
- }
278
-
279
- async filterAndDecodeStruct<T, ST extends StructType>(
280
- typeMatcher: TypeDescriptor<T>,
281
- structsWithTags: ST[]
282
- ): Promise<DecodedStruct<ST, T>[]> {
283
- if (!structsWithTags) {
284
- return [] as any
285
- }
286
- // const typeMatcherDescriptor = parseMoveType(typeMatcher)
287
- const results: DecodedStruct<ST, T>[] = []
288
- for (const resource of structsWithTags) {
289
- const resourceType = this.adapter.getType(resource)
290
- const resourceTypeDescriptor = parseMoveType(resourceType)
291
- if (!matchType(typeMatcher, resourceTypeDescriptor)) {
292
- continue
293
- }
294
-
295
- const result = await this.decodedStruct<T, ST>(resource)
296
- if (result) {
297
- results.push(result)
298
- } else {
299
- console.error('decoding error')
300
- }
301
- }
302
- return results
303
- }
304
-
305
- protected async decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined> {
306
- const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))
307
- const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
308
-
309
- let dataTyped = undefined
310
- try {
311
- dataTyped = await this.decode(typeStruct, typeDescriptor)
312
- } catch (e) {
313
- throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString())
314
- // return undefined
315
- }
316
- return {
317
- ...typeStruct,
318
- data_decoded: dataTyped,
319
- type_arguments: typeArguments,
320
- }
321
- }
322
- async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {
323
- if (typeStruct === null || typeStruct == undefined) {
324
- return typeStruct as any
325
- }
326
- if (typeof typeStruct === 'object') {
327
- if ('type' in typeStruct) {
328
- const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')
329
- if (!matchType(type, typeInStruct)) {
330
- return undefined
331
- }
332
- }
333
- }
334
-
335
- return await this.decode(typeStruct, type)
336
- }
337
- }
@@ -1,81 +0,0 @@
1
- import { moduleQname, moduleQnameForType } from './utils.js'
2
- import { InternalMoveModule } from './internal-models.js'
3
-
4
- export class AccountModulesImportInfo {
5
- // account to module
6
- imports: Map<string, Set<string>>
7
- account: string
8
- moduleName: string
9
-
10
- constructor(account: string, tsModuleName: string) {
11
- this.account = account
12
- this.moduleName = tsModuleName
13
- this.imports = new Map<string, Set<string>>()
14
- }
15
-
16
- addImport(account: string, module: string) {
17
- if (account === this.account) {
18
- return
19
- }
20
- let accountModules = this.imports.get(account)
21
- if (!accountModules) {
22
- accountModules = new Set<string>()
23
- this.imports.set(account, accountModules)
24
- }
25
- accountModules.add(module)
26
- }
27
- }
28
-
29
- export class AccountRegister {
30
- accountImports = new Map<string, AccountModulesImportInfo>()
31
- pendingAccounts = new Set<string>()
32
-
33
- register(module: InternalMoveModule, tsModuleName: string): AccountModulesImportInfo {
34
- const currentModuleFqn = moduleQname(module)
35
-
36
- let accountModuleImports = this.accountImports.get(module.address)
37
- if (!accountModuleImports) {
38
- accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)
39
- this.accountImports.set(module.address, accountModuleImports)
40
- // the account has already be processed, delete pending task
41
- this.pendingAccounts.delete(module.address)
42
- }
43
-
44
- this.registerStruct(module, accountModuleImports)
45
- this.registerFunctions(module, accountModuleImports)
46
-
47
- this.accountImports.set(currentModuleFqn, accountModuleImports)
48
- return accountModuleImports
49
- }
50
-
51
- private registerFunctions(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {
52
- for (const func of module.exposedFunctions) {
53
- if (!func.isEntry) {
54
- continue
55
- }
56
- for (const param of func.params) {
57
- for (const type of param.dependedTypes()) {
58
- const [account, module] = moduleQnameForType(type)
59
- accountModuleImports.addImport(account, module)
60
- if (!this.accountImports.has(account)) {
61
- this.pendingAccounts.add(account)
62
- }
63
- }
64
- }
65
- }
66
- }
67
-
68
- private registerStruct(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {
69
- for (const struct of module.structs) {
70
- for (const field of struct.fields) {
71
- for (const type of field.type.dependedTypes()) {
72
- const [account, module] = moduleQnameForType(type)
73
- accountModuleImports.addImport(account, module)
74
- if (!this.accountImports.has(account)) {
75
- this.pendingAccounts.add(account)
76
- }
77
- }
78
- }
79
- }
80
- }
81
- }
@@ -1,24 +0,0 @@
1
- import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
2
- import { TypeDescriptor } from './types.js'
3
- import { accountAddressString } from './utils.js'
4
-
5
- export abstract class ChainAdapter<NetworkType, ModuleType, StructType> {
6
- abstract fetchModule(account: string, module: string, network: NetworkType): Promise<ModuleType>
7
-
8
- abstract fetchModules(account: string, network: NetworkType): Promise<ModuleType[]>
9
- abstract toInternalModules(modules: ModuleType[]): InternalMoveModule[]
10
-
11
- // Get all structs that represent Events
12
- abstract getAllEventStructs(module: InternalMoveModule[]): Map<string, InternalMoveStruct>
13
-
14
- // Get the parameters that actually have arguments in runtime
15
- // Aptos first signer and Sui's last TxContext are no use
16
- abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
17
-
18
- abstract getType(base: StructType): string
19
- abstract getData<T>(base: StructType): any
20
-
21
- validateAndNormalizeAddress(address: string): string {
22
- return accountAddressString(address)
23
- }
24
- }
@@ -1,40 +0,0 @@
1
- import { TypeDescriptor } from './types.js'
2
-
3
- export interface InternalMoveModule {
4
- address: string
5
- name: string
6
- exposedFunctions: InternalMoveFunction[]
7
- structs: InternalMoveStruct[]
8
- }
9
-
10
- export interface InternalMoveFunction {
11
- name: string
12
- visibility: InternalMoveFunctionVisibility
13
- isEntry: boolean
14
- typeParams: InternalMoveTypeParam[]
15
- params: TypeDescriptor[]
16
- return: TypeDescriptor[]
17
- }
18
-
19
- export interface InternalMoveStruct {
20
- name: string
21
- isNative: boolean
22
- abilities: string[]
23
- typeParams: InternalMoveTypeParam[]
24
- fields: InternalMoveStructField[]
25
- }
26
-
27
- export interface InternalMoveStructField {
28
- name: string
29
- type: TypeDescriptor
30
- }
31
-
32
- export enum InternalMoveFunctionVisibility {
33
- PRIVATE = 'private',
34
- PUBLIC = 'public',
35
- FRIEND = 'friend',
36
- }
37
-
38
- export type InternalMoveTypeParam = {
39
- constraints: string[]
40
- }