@sentio/sdk 2.60.0-rc.3 → 2.60.0-rc.5
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/lib/aptos/builtin/0x1.d.ts +211 -0
- package/lib/aptos/builtin/0x1.d.ts.map +1 -1
- package/lib/aptos/builtin/0x1.js +328 -1
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.js +1 -1
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/builtin/0x4.js +1 -1
- package/lib/aptos/builtin/0x4.js.map +1 -1
- package/lib/iota/builtin/0x1.d.ts +817 -0
- package/lib/iota/builtin/0x1.d.ts.map +1 -0
- package/lib/iota/builtin/0x1.js +4385 -0
- package/lib/iota/builtin/0x1.js.map +1 -0
- package/lib/iota/builtin/0x2.d.ts +4529 -0
- package/lib/iota/builtin/0x2.d.ts.map +1 -0
- package/lib/iota/builtin/0x2.js +17109 -0
- package/lib/iota/builtin/0x2.js.map +1 -0
- package/lib/iota/builtin/0x3.d.ts +2293 -0
- package/lib/iota/builtin/0x3.d.ts.map +1 -0
- package/lib/iota/builtin/0x3.js +6522 -0
- package/lib/iota/builtin/0x3.js.map +1 -0
- package/lib/iota/builtin/index.d.ts +4 -0
- package/lib/iota/builtin/index.d.ts.map +1 -0
- package/lib/iota/builtin/index.js +7 -0
- package/lib/iota/builtin/index.js.map +1 -0
- package/lib/iota/codegen/codegen.d.ts +2 -0
- package/lib/iota/codegen/codegen.d.ts.map +1 -0
- package/lib/iota/codegen/codegen.js +94 -0
- package/lib/iota/codegen/codegen.js.map +1 -0
- package/lib/iota/codegen/index.d.ts +2 -0
- package/lib/iota/codegen/index.d.ts.map +1 -0
- package/lib/iota/codegen/index.js +2 -0
- package/lib/iota/codegen/index.js.map +1 -0
- package/lib/iota/codegen/run.d.ts +2 -0
- package/lib/iota/codegen/run.d.ts.map +1 -0
- package/lib/iota/codegen/run.js +12 -0
- package/lib/iota/codegen/run.js.map +1 -0
- package/lib/iota/context.d.ts +50 -0
- package/lib/iota/context.d.ts.map +1 -0
- package/lib/iota/context.js +134 -0
- package/lib/iota/context.js.map +1 -0
- package/lib/iota/ext/coin.d.ts +17 -0
- package/lib/iota/ext/coin.d.ts.map +1 -0
- package/lib/iota/ext/coin.js +532 -0
- package/lib/iota/ext/coin.js.map +1 -0
- package/lib/iota/ext/index.d.ts +3 -0
- package/lib/iota/ext/index.d.ts.map +1 -0
- package/lib/iota/ext/index.js +3 -0
- package/lib/iota/ext/index.js.map +1 -0
- package/lib/iota/ext/move-dex.d.ts +19 -0
- package/lib/iota/ext/move-dex.d.ts.map +1 -0
- package/lib/iota/ext/move-dex.js +24 -0
- package/lib/iota/ext/move-dex.js.map +1 -0
- package/lib/iota/index.d.ts +11 -0
- package/lib/iota/index.d.ts.map +1 -0
- package/lib/iota/index.js +12 -0
- package/lib/iota/index.js.map +1 -0
- package/lib/iota/iota-object-processor-template.d.ts +44 -0
- package/lib/iota/iota-object-processor-template.d.ts.map +1 -0
- package/lib/iota/iota-object-processor-template.js +171 -0
- package/lib/iota/iota-object-processor-template.js.map +1 -0
- package/lib/iota/iota-object-processor.d.ts +83 -0
- package/lib/iota/iota-object-processor.d.ts.map +1 -0
- package/lib/iota/iota-object-processor.js +193 -0
- package/lib/iota/iota-object-processor.js.map +1 -0
- package/lib/iota/iota-plugin-part.d.ts +12 -0
- package/lib/iota/iota-plugin-part.d.ts.map +1 -0
- package/lib/iota/iota-plugin-part.js +178 -0
- package/lib/iota/iota-plugin-part.js.map +1 -0
- package/lib/iota/iota-plugin.d.ts +3 -0
- package/lib/iota/iota-plugin.d.ts.map +1 -0
- package/lib/iota/iota-plugin.js +4 -0
- package/lib/iota/iota-plugin.js.map +1 -0
- package/lib/iota/iota-processor.d.ts +47 -0
- package/lib/iota/iota-processor.d.ts.map +1 -0
- package/lib/iota/iota-processor.js +223 -0
- package/lib/iota/iota-processor.js.map +1 -0
- package/lib/iota/models.d.ts +12 -0
- package/lib/iota/models.d.ts.map +1 -0
- package/lib/iota/models.js +2 -0
- package/lib/iota/models.js.map +1 -0
- package/lib/iota/move-coder.d.ts +4 -0
- package/lib/iota/move-coder.d.ts.map +1 -0
- package/lib/iota/move-coder.js +12 -0
- package/lib/iota/move-coder.js.map +1 -0
- package/lib/iota/network.d.ts +10 -0
- package/lib/iota/network.d.ts.map +1 -0
- package/lib/iota/network.js +24 -0
- package/lib/iota/network.js.map +1 -0
- package/lib/iota/utils.d.ts +3 -0
- package/lib/iota/utils.d.ts.map +1 -0
- package/lib/iota/utils.js +41 -0
- package/lib/iota/utils.js.map +1 -0
- package/lib/sui/builtin/0x2.d.ts +73 -0
- package/lib/sui/builtin/0x2.d.ts.map +1 -1
- package/lib/sui/builtin/0x2.js +237 -1
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +2 -0
- package/lib/sui/builtin/0x3.d.ts.map +1 -1
- package/lib/sui/builtin/0x3.js +21 -1
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/network.d.ts.map +1 -1
- package/lib/sui/network.js +0 -3
- package/lib/sui/network.js.map +1 -1
- package/lib/sui/sui-plugin-part.d.ts +12 -0
- package/lib/sui/sui-plugin-part.d.ts.map +1 -0
- package/lib/sui/sui-plugin-part.js +178 -0
- package/lib/sui/sui-plugin-part.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +4 -0
- package/lib/sui/sui-plugin.d.ts.map +1 -1
- package/lib/sui/sui-plugin.js +12 -159
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/testing/iota-facet.d.ts +14 -0
- package/lib/testing/iota-facet.d.ts.map +1 -0
- package/lib/testing/iota-facet.js +124 -0
- package/lib/testing/iota-facet.js.map +1 -0
- package/lib/testing/test-processor-server.d.ts +2 -0
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +3 -0
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +21 -9
- package/src/aptos/abis/0x1.json +1040 -45
- package/src/aptos/abis/0x3.json +2 -2
- package/src/aptos/abis/0x4.json +17 -17
- package/src/aptos/builtin/0x1.ts +615 -1
- package/src/aptos/builtin/0x3.ts +1 -1
- package/src/aptos/builtin/0x4.ts +1 -1
- package/src/iota/abis/0x1.json +4213 -0
- package/src/iota/abis/0x2.json +26692 -0
- package/src/iota/abis/0x3.json +10598 -0
- package/src/iota/builtin/0x1.ts +6292 -0
- package/src/iota/builtin/0x2.ts +26198 -0
- package/src/iota/builtin/0x3.ts +11144 -0
- package/src/iota/builtin/index.ts +6 -0
- package/src/iota/codegen/codegen.ts +118 -0
- package/src/iota/codegen/index.ts +1 -0
- package/src/iota/codegen/run.ts +13 -0
- package/src/iota/context.ts +200 -0
- package/src/iota/ext/coin.ts +565 -0
- package/src/iota/ext/index.ts +2 -0
- package/src/iota/ext/move-dex.ts +52 -0
- package/src/iota/index.ts +29 -0
- package/src/iota/iota-object-processor-template.ts +277 -0
- package/src/iota/iota-object-processor.ts +386 -0
- package/src/iota/iota-plugin-part.ts +211 -0
- package/src/iota/iota-plugin.ts +2 -0
- package/src/iota/iota-processor.ts +339 -0
- package/src/iota/models.ts +14 -0
- package/src/iota/move-coder.ts +15 -0
- package/src/iota/network.ts +27 -0
- package/src/iota/utils.ts +52 -0
- package/src/sui/abis/0x2.json +269 -0
- package/src/sui/abis/0x3.json +29 -0
- package/src/sui/builtin/0x2.ts +367 -1
- package/src/sui/builtin/0x3.ts +29 -1
- package/src/sui/network.ts +0 -3
- package/src/sui/sui-plugin-part.ts +211 -0
- package/src/sui/sui-plugin.ts +12 -178
- package/src/testing/iota-facet.ts +143 -0
- package/src/testing/test-processor-server.ts +3 -0
@@ -0,0 +1,277 @@
|
|
1
|
+
import { HandleInterval, MoveAccountFetchConfig, MoveFetchConfig } from '@sentio/protos'
|
2
|
+
import { ListStateStorage } from '@sentio/runtime'
|
3
|
+
import { IotaAddressContext, IotaContext, IotaObjectContext } from './context.js'
|
4
|
+
import { IotaMoveObject, IotaTransactionBlockResponse } from '@iota/iota-sdk/client'
|
5
|
+
import { PromiseOrVoid } from '../core/index.js'
|
6
|
+
import {
|
7
|
+
DEFAULT_ACCOUNT_FETCH_CONFIG,
|
8
|
+
IotaAccountProcessorState,
|
9
|
+
IotaAddressProcessor,
|
10
|
+
IotaBaseObjectOrAddressProcessor,
|
11
|
+
IotaObjectBindOptions,
|
12
|
+
IotaObjectProcessor,
|
13
|
+
IotaWrappedObjectProcessor
|
14
|
+
} from './iota-object-processor.js'
|
15
|
+
import { TemplateInstanceState } from '../core/template.js'
|
16
|
+
import { IotaBindOptions } from './iota-processor.js'
|
17
|
+
import { TransactionFilter, accountAddressString } from '../move/index.js'
|
18
|
+
import { ServerError, Status } from 'nice-grpc'
|
19
|
+
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
20
|
+
|
21
|
+
class ObjectHandler<HandlerType> {
|
22
|
+
type?: string
|
23
|
+
checkpointInterval?: HandleInterval
|
24
|
+
timeIntervalInMinutes?: HandleInterval
|
25
|
+
handlerName: string
|
26
|
+
handler: HandlerType
|
27
|
+
fetchConfig: MoveAccountFetchConfig
|
28
|
+
}
|
29
|
+
|
30
|
+
export class IotaAccountProcessorTemplateState extends ListStateStorage<
|
31
|
+
IotaObjectOrAddressProcessorTemplate<any, any, any>
|
32
|
+
> {
|
33
|
+
static INSTANCE = new IotaAccountProcessorTemplateState()
|
34
|
+
}
|
35
|
+
|
36
|
+
export abstract class IotaObjectOrAddressProcessorTemplate<
|
37
|
+
HandlerType,
|
38
|
+
OptionType extends IotaObjectBindOptions | IotaBindOptions,
|
39
|
+
ProcessorType extends IotaBaseObjectOrAddressProcessor<HandlerType>
|
40
|
+
> {
|
41
|
+
id: number
|
42
|
+
objectHandlers: ObjectHandler<HandlerType>[] = []
|
43
|
+
binds = new Set<string>()
|
44
|
+
|
45
|
+
constructor() {
|
46
|
+
this.id = IotaAccountProcessorTemplateState.INSTANCE.getValues().length
|
47
|
+
IotaAccountProcessorTemplateState.INSTANCE.addValue(this)
|
48
|
+
return proxyProcessor(this)
|
49
|
+
}
|
50
|
+
|
51
|
+
protected abstract createProcessor(options: IotaObjectBindOptions | IotaBindOptions): ProcessorType
|
52
|
+
|
53
|
+
bind(options: OptionType, ctx: IotaContext): void {
|
54
|
+
options.network = options.network || ctx.network
|
55
|
+
options.startCheckpoint = options.startCheckpoint || ctx.checkpoint
|
56
|
+
let id = (options as IotaObjectBindOptions).objectId || (options as IotaBindOptions).address
|
57
|
+
|
58
|
+
if (id === '*') {
|
59
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "can't bind template instance with *")
|
60
|
+
}
|
61
|
+
id = accountAddressString(id)
|
62
|
+
|
63
|
+
const sig = [options.network, id].join('_')
|
64
|
+
if (this.binds.has(sig)) {
|
65
|
+
console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
|
66
|
+
return
|
67
|
+
}
|
68
|
+
this.binds.add(sig)
|
69
|
+
|
70
|
+
const processor = this.createProcessor(options)
|
71
|
+
for (const h of this.objectHandlers) {
|
72
|
+
processor.onInterval(
|
73
|
+
h.handler,
|
74
|
+
h.timeIntervalInMinutes,
|
75
|
+
h.checkpointInterval,
|
76
|
+
h.type,
|
77
|
+
h.fetchConfig,
|
78
|
+
h.handlerName
|
79
|
+
)
|
80
|
+
}
|
81
|
+
const config = processor.config
|
82
|
+
|
83
|
+
ctx.update({
|
84
|
+
states: {
|
85
|
+
configUpdated: true
|
86
|
+
}
|
87
|
+
})
|
88
|
+
TemplateInstanceState.INSTANCE.addValue({
|
89
|
+
templateId: this.id,
|
90
|
+
contract: {
|
91
|
+
name: '',
|
92
|
+
chainId: config.network,
|
93
|
+
address: config.address,
|
94
|
+
abi: ''
|
95
|
+
},
|
96
|
+
startBlock: config.startCheckpoint,
|
97
|
+
endBlock: config.endCheckpoint || 0n,
|
98
|
+
baseLabels: config.baseLabels
|
99
|
+
})
|
100
|
+
console.log(`successfully bind template ${sig}`)
|
101
|
+
}
|
102
|
+
|
103
|
+
unbind(options: OptionType, ctx: IotaContext): void {
|
104
|
+
options.network = options.network || ctx.network
|
105
|
+
options.startCheckpoint = options.startCheckpoint || ctx.checkpoint
|
106
|
+
let id = (options as IotaObjectBindOptions).objectId || (options as IotaBindOptions).address
|
107
|
+
|
108
|
+
if (id === '*') {
|
109
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "can't delete template instance bind with *")
|
110
|
+
}
|
111
|
+
id = accountAddressString(id)
|
112
|
+
|
113
|
+
const sig = [options.network, id].join('_')
|
114
|
+
if (!this.binds.has(sig)) {
|
115
|
+
console.log(`the template instance ${sig} not existed or already unbind`)
|
116
|
+
return
|
117
|
+
}
|
118
|
+
this.binds.delete(sig)
|
119
|
+
|
120
|
+
let deleted = 0
|
121
|
+
const oldTemplateInstances = TemplateInstanceState.INSTANCE.unregister()
|
122
|
+
for (const templateInstance of oldTemplateInstances) {
|
123
|
+
if (templateInstance.contract?.chainId === options.network && templateInstance.contract.address == id) {
|
124
|
+
deleted++
|
125
|
+
continue
|
126
|
+
}
|
127
|
+
TemplateInstanceState.INSTANCE.addValue(templateInstance)
|
128
|
+
}
|
129
|
+
|
130
|
+
if (deleted !== 1) {
|
131
|
+
throw new ServerError(
|
132
|
+
Status.INVALID_ARGUMENT,
|
133
|
+
`Failed to delete template instance ${sig}, deleted ${deleted} times`
|
134
|
+
)
|
135
|
+
}
|
136
|
+
|
137
|
+
const oldProcessors = IotaAccountProcessorState.INSTANCE.unregister()
|
138
|
+
deleted = 0
|
139
|
+
for (const processor of oldProcessors) {
|
140
|
+
if (processor.templateId === this.id) {
|
141
|
+
if (processor.config.network == options.network && processor.config.address === id) {
|
142
|
+
deleted++
|
143
|
+
continue
|
144
|
+
}
|
145
|
+
}
|
146
|
+
IotaAccountProcessorState.INSTANCE.addValue(processor)
|
147
|
+
}
|
148
|
+
|
149
|
+
if (deleted !== 1) {
|
150
|
+
throw new ServerError(
|
151
|
+
Status.INVALID_ARGUMENT,
|
152
|
+
`Failed to delete processor for template ${this.id}, ${sig}. deleted ${deleted} times`
|
153
|
+
)
|
154
|
+
}
|
155
|
+
|
156
|
+
console.log(`successfully unbind template ${sig}`)
|
157
|
+
|
158
|
+
ctx.update({
|
159
|
+
states: {
|
160
|
+
configUpdated: true
|
161
|
+
}
|
162
|
+
})
|
163
|
+
}
|
164
|
+
|
165
|
+
protected onInterval(
|
166
|
+
handler: HandlerType,
|
167
|
+
timeInterval: HandleInterval | undefined,
|
168
|
+
checkpointInterval: HandleInterval | undefined,
|
169
|
+
type: string | undefined,
|
170
|
+
fetchConfig: Partial<MoveAccountFetchConfig> | undefined
|
171
|
+
): this {
|
172
|
+
this.objectHandlers.push({
|
173
|
+
handlerName: getHandlerName(),
|
174
|
+
handler: handler,
|
175
|
+
timeIntervalInMinutes: timeInterval,
|
176
|
+
checkpointInterval: checkpointInterval,
|
177
|
+
type,
|
178
|
+
fetchConfig: { ...DEFAULT_ACCOUNT_FETCH_CONFIG, ...fetchConfig }
|
179
|
+
})
|
180
|
+
return this
|
181
|
+
}
|
182
|
+
|
183
|
+
public onTimeInterval(
|
184
|
+
handler: HandlerType,
|
185
|
+
timeIntervalInMinutes = 60,
|
186
|
+
backfillTimeIntervalInMinutes = 240,
|
187
|
+
type?: string,
|
188
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
189
|
+
): this {
|
190
|
+
return this.onInterval(
|
191
|
+
handler,
|
192
|
+
{
|
193
|
+
recentInterval: timeIntervalInMinutes,
|
194
|
+
backfillInterval: backfillTimeIntervalInMinutes
|
195
|
+
},
|
196
|
+
undefined,
|
197
|
+
type,
|
198
|
+
fetchConfig
|
199
|
+
)
|
200
|
+
}
|
201
|
+
|
202
|
+
public onCheckpointInterval(
|
203
|
+
handler: HandlerType,
|
204
|
+
checkpointInterval = 100000,
|
205
|
+
backfillCheckpointInterval = 400000,
|
206
|
+
type?: string,
|
207
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
208
|
+
): this {
|
209
|
+
return this.onInterval(
|
210
|
+
handler,
|
211
|
+
undefined,
|
212
|
+
{ recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },
|
213
|
+
type,
|
214
|
+
fetchConfig
|
215
|
+
)
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
class AddressTransactionHandler {
|
220
|
+
handler: (transaction: IotaTransactionBlockResponse, ctx: IotaContext) => void
|
221
|
+
filter?: TransactionFilter
|
222
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
223
|
+
}
|
224
|
+
|
225
|
+
export class IotaAddressProcessorTemplate extends IotaObjectOrAddressProcessorTemplate<
|
226
|
+
(objects: IotaMoveObject[], ctx: IotaAddressContext) => PromiseOrVoid,
|
227
|
+
IotaBindOptions,
|
228
|
+
IotaAddressProcessor
|
229
|
+
> {
|
230
|
+
private handlers: AddressTransactionHandler[] = []
|
231
|
+
|
232
|
+
createProcessor(options: IotaBindOptions): IotaAddressProcessor {
|
233
|
+
const p = IotaAddressProcessor.bind(options)
|
234
|
+
for (const handler of this.handlers) {
|
235
|
+
p.onTransactionBlock(handler.handler, handler.filter, handler.fetchConfig)
|
236
|
+
}
|
237
|
+
p.templateId = this.id
|
238
|
+
return p
|
239
|
+
}
|
240
|
+
|
241
|
+
onTransactionBlock(
|
242
|
+
handler: (transaction: IotaTransactionBlockResponse, ctx: IotaContext) => void,
|
243
|
+
filter?: TransactionFilter,
|
244
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
245
|
+
): this {
|
246
|
+
this.handlers.push({
|
247
|
+
handler,
|
248
|
+
filter,
|
249
|
+
fetchConfig
|
250
|
+
})
|
251
|
+
return this
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
export class IotaObjectProcessorTemplate extends IotaObjectOrAddressProcessorTemplate<
|
256
|
+
(self: IotaMoveObject, dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid,
|
257
|
+
IotaObjectBindOptions,
|
258
|
+
IotaObjectProcessor
|
259
|
+
> {
|
260
|
+
createProcessor(options: IotaObjectBindOptions): IotaObjectProcessor {
|
261
|
+
const p = IotaObjectProcessor.bind(options)
|
262
|
+
p.templateId = this.id
|
263
|
+
return p
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
export class IotaWrappedObjectProcessorTemplate extends IotaObjectOrAddressProcessorTemplate<
|
268
|
+
(dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid,
|
269
|
+
IotaObjectBindOptions,
|
270
|
+
IotaWrappedObjectProcessor
|
271
|
+
> {
|
272
|
+
createProcessor(options: IotaObjectBindOptions): IotaWrappedObjectProcessor {
|
273
|
+
const p = IotaWrappedObjectProcessor.bind(options)
|
274
|
+
p.templateId = this.id
|
275
|
+
return p
|
276
|
+
}
|
277
|
+
}
|
@@ -0,0 +1,386 @@
|
|
1
|
+
import {
|
2
|
+
Data_SuiCall,
|
3
|
+
Data_SuiObject,
|
4
|
+
Data_SuiObjectChange,
|
5
|
+
HandleInterval,
|
6
|
+
MoveAccountFetchConfig,
|
7
|
+
MoveFetchConfig,
|
8
|
+
MoveOwnerType,
|
9
|
+
ProcessResult
|
10
|
+
} from '@sentio/protos'
|
11
|
+
import { ListStateStorage } from '@sentio/runtime'
|
12
|
+
import { IotaNetwork } from './network.js'
|
13
|
+
import { IotaAddressContext, IotaContext, IotaObjectChangeContext, IotaObjectContext } from './context.js'
|
14
|
+
import { IotaMoveObject, IotaObjectChange, IotaTransactionBlockResponse } from '@iota/iota-sdk/client'
|
15
|
+
import { ALL_ADDRESS, PromiseOrVoid } from '../core/index.js'
|
16
|
+
import { configure, DEFAULT_FETCH_CONFIG, IndexConfigure, IotaBindOptions } from './iota-processor.js'
|
17
|
+
import { CallHandler, TransactionFilter, accountTypeString, ObjectChangeHandler } from '../move/index.js'
|
18
|
+
import { ServerError, Status } from 'nice-grpc'
|
19
|
+
import { TypeDescriptor } from '@typemove/move'
|
20
|
+
import { TypedIotaMoveObject } from './models.js'
|
21
|
+
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
22
|
+
|
23
|
+
export interface IotaObjectBindOptions {
|
24
|
+
objectId: string
|
25
|
+
network?: IotaNetwork
|
26
|
+
startCheckpoint?: bigint
|
27
|
+
endCheckpoint?: bigint
|
28
|
+
baseLabels?: { [key: string]: string }
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface IotaObjectTypeBindOptions<T> {
|
32
|
+
objectType: TypeDescriptor<T>
|
33
|
+
network?: IotaNetwork
|
34
|
+
startCheckpoint?: bigint
|
35
|
+
endCheckpoint?: bigint
|
36
|
+
baseLabels?: { [key: string]: string }
|
37
|
+
}
|
38
|
+
|
39
|
+
interface ObjectHandler {
|
40
|
+
type?: string
|
41
|
+
checkPointInterval?: HandleInterval
|
42
|
+
timeIntervalInMinutes?: HandleInterval
|
43
|
+
fetchConfig: MoveAccountFetchConfig
|
44
|
+
handler: (resource: Data_SuiObject) => Promise<ProcessResult>
|
45
|
+
handlerName: string
|
46
|
+
}
|
47
|
+
|
48
|
+
export const DEFAULT_ACCOUNT_FETCH_CONFIG: MoveAccountFetchConfig = {
|
49
|
+
owned: false
|
50
|
+
}
|
51
|
+
|
52
|
+
export class IotaAccountProcessorState extends ListStateStorage<IotaBaseObjectOrAddressProcessor<any>> {
|
53
|
+
static INSTANCE = new IotaAccountProcessorState()
|
54
|
+
}
|
55
|
+
|
56
|
+
export interface IotaInternalObjectsBindOptions extends IotaBindOptions {
|
57
|
+
ownerType: MoveOwnerType
|
58
|
+
}
|
59
|
+
|
60
|
+
export abstract class IotaBaseObjectOrAddressProcessor<HandlerType> {
|
61
|
+
config: IndexConfigure
|
62
|
+
ownerType: MoveOwnerType
|
63
|
+
templateId: number | undefined
|
64
|
+
|
65
|
+
objectHandlers: ObjectHandler[] = []
|
66
|
+
objectChangeHandlers: ObjectChangeHandler<Data_SuiObjectChange>[] = []
|
67
|
+
|
68
|
+
// static bind(options: IotaObjectsBindOptions): IotaBaseObjectsProcessor<any> {
|
69
|
+
// return new IotaBaseObjectsProcessor(options)
|
70
|
+
// }
|
71
|
+
|
72
|
+
protected constructor(options: IotaInternalObjectsBindOptions) {
|
73
|
+
if (options.ownerType === MoveOwnerType.TYPE) {
|
74
|
+
this.config = {
|
75
|
+
startCheckpoint: options.startCheckpoint || 0n,
|
76
|
+
endCheckpoint: options.endCheckpoint,
|
77
|
+
address: options.address === '*' ? '*' : accountTypeString(options.address),
|
78
|
+
network: options.network || IotaNetwork.MAIN_NET,
|
79
|
+
baseLabels: options.baseLabels
|
80
|
+
}
|
81
|
+
} else {
|
82
|
+
this.config = configure(options)
|
83
|
+
}
|
84
|
+
this.ownerType = options.ownerType
|
85
|
+
IotaAccountProcessorState.INSTANCE.addValue(this)
|
86
|
+
|
87
|
+
return proxyProcessor(this)
|
88
|
+
}
|
89
|
+
|
90
|
+
getChainId(): string {
|
91
|
+
return this.config.network
|
92
|
+
}
|
93
|
+
|
94
|
+
// protected abstract transformObjects(objects: IotaMoveObject[]): IotaMoveObject[]
|
95
|
+
|
96
|
+
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: IotaObjectContext): Promise<any>
|
97
|
+
|
98
|
+
public onInterval(
|
99
|
+
handler: HandlerType, //(resources: IotaMoveObject[], ctx: IotaObjectsContext) => PromiseOrVoid,
|
100
|
+
timeInterval: HandleInterval | undefined,
|
101
|
+
checkpointInterval: HandleInterval | undefined,
|
102
|
+
type: string | undefined,
|
103
|
+
fetchConfig: Partial<MoveAccountFetchConfig> | undefined,
|
104
|
+
handlerName = getHandlerName()
|
105
|
+
): this {
|
106
|
+
const processor = this
|
107
|
+
this.objectHandlers.push({
|
108
|
+
handlerName,
|
109
|
+
handler: async function (data) {
|
110
|
+
const ctx = new IotaObjectContext(
|
111
|
+
processor.config.network,
|
112
|
+
data.objectId,
|
113
|
+
data.objectVersion,
|
114
|
+
data.slot,
|
115
|
+
data.timestamp || new Date(0),
|
116
|
+
processor.config.baseLabels
|
117
|
+
)
|
118
|
+
await processor.doHandle(handler, data, ctx)
|
119
|
+
return ctx.stopAndGetResult()
|
120
|
+
},
|
121
|
+
timeIntervalInMinutes: timeInterval,
|
122
|
+
checkPointInterval: checkpointInterval,
|
123
|
+
type,
|
124
|
+
fetchConfig: { ...DEFAULT_ACCOUNT_FETCH_CONFIG, ...fetchConfig }
|
125
|
+
})
|
126
|
+
return this
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
abstract class IotaBaseObjectOrAddressProcessorInternal<
|
131
|
+
HandlerType
|
132
|
+
> extends IotaBaseObjectOrAddressProcessor<HandlerType> {
|
133
|
+
public onTimeInterval(
|
134
|
+
handler: HandlerType,
|
135
|
+
timeIntervalInMinutes = 60,
|
136
|
+
backfillTimeIntervalInMinutes = 240,
|
137
|
+
type?: string,
|
138
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
139
|
+
): this {
|
140
|
+
return this.onInterval(
|
141
|
+
handler,
|
142
|
+
{
|
143
|
+
recentInterval: timeIntervalInMinutes,
|
144
|
+
backfillInterval: backfillTimeIntervalInMinutes
|
145
|
+
},
|
146
|
+
undefined,
|
147
|
+
type,
|
148
|
+
fetchConfig
|
149
|
+
)
|
150
|
+
}
|
151
|
+
|
152
|
+
public onCheckpointInterval(
|
153
|
+
handler: HandlerType,
|
154
|
+
checkpointInterval = 100000,
|
155
|
+
backfillCheckpointInterval = 400000,
|
156
|
+
type?: string,
|
157
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
158
|
+
): this {
|
159
|
+
return this.onInterval(
|
160
|
+
handler,
|
161
|
+
undefined,
|
162
|
+
{ recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },
|
163
|
+
type,
|
164
|
+
fetchConfig
|
165
|
+
)
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
export class IotaAddressProcessor extends IotaBaseObjectOrAddressProcessorInternal<
|
170
|
+
(objects: IotaMoveObject[], ctx: IotaAddressContext) => PromiseOrVoid
|
171
|
+
> {
|
172
|
+
callHandlers: CallHandler<Data_SuiCall>[] = []
|
173
|
+
|
174
|
+
static bind(options: IotaBindOptions): IotaAddressProcessor {
|
175
|
+
return new IotaAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS })
|
176
|
+
}
|
177
|
+
|
178
|
+
protected async doHandle(
|
179
|
+
handler: (objects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid,
|
180
|
+
data: Data_SuiObject,
|
181
|
+
ctx: IotaObjectContext
|
182
|
+
) {
|
183
|
+
return handler(data.rawObjects.map((o) => JSON.parse(o)) as IotaMoveObject[], ctx)
|
184
|
+
}
|
185
|
+
|
186
|
+
onTransactionBlock(
|
187
|
+
handler: (transaction: IotaTransactionBlockResponse, ctx: IotaContext) => PromiseOrVoid,
|
188
|
+
filter?: TransactionFilter,
|
189
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
190
|
+
) {
|
191
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
192
|
+
const _filter: TransactionFilter = {
|
193
|
+
fromAndToAddress: {
|
194
|
+
from: '',
|
195
|
+
to: this.config.address
|
196
|
+
},
|
197
|
+
...filter
|
198
|
+
}
|
199
|
+
|
200
|
+
const processor = this
|
201
|
+
|
202
|
+
this.callHandlers.push({
|
203
|
+
handlerName: getHandlerName(),
|
204
|
+
handler: async function (data) {
|
205
|
+
if (!data.rawTransaction) {
|
206
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'transaction is null')
|
207
|
+
}
|
208
|
+
const tx = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
209
|
+
|
210
|
+
const ctx = new IotaContext(
|
211
|
+
'object',
|
212
|
+
processor.config.network,
|
213
|
+
processor.config.address,
|
214
|
+
data.timestamp || new Date(0),
|
215
|
+
data.slot,
|
216
|
+
tx,
|
217
|
+
0,
|
218
|
+
processor.config.baseLabels
|
219
|
+
)
|
220
|
+
if (tx) {
|
221
|
+
await handler(tx, ctx)
|
222
|
+
}
|
223
|
+
return ctx.stopAndGetResult()
|
224
|
+
},
|
225
|
+
filters: [{ ..._filter, function: '' }],
|
226
|
+
fetchConfig: _fetchConfig
|
227
|
+
})
|
228
|
+
return this
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
export class IotaObjectProcessor extends IotaBaseObjectOrAddressProcessorInternal<
|
233
|
+
(self: IotaMoveObject, dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid
|
234
|
+
> {
|
235
|
+
static bind(options: IotaObjectBindOptions): IotaObjectProcessor {
|
236
|
+
return new IotaObjectProcessor({
|
237
|
+
address: options.objectId,
|
238
|
+
network: options.network,
|
239
|
+
startCheckpoint: options.startCheckpoint,
|
240
|
+
endCheckpoint: options.endCheckpoint,
|
241
|
+
ownerType: MoveOwnerType.OBJECT,
|
242
|
+
baseLabels: options.baseLabels
|
243
|
+
})
|
244
|
+
}
|
245
|
+
|
246
|
+
protected async doHandle(
|
247
|
+
handler: (self: IotaMoveObject, dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid,
|
248
|
+
data: Data_SuiObject,
|
249
|
+
ctx: IotaObjectContext
|
250
|
+
) {
|
251
|
+
if (!data.rawSelf) {
|
252
|
+
console.log(`Iota object not existed in ${ctx.checkpoint}, please specific a start time`)
|
253
|
+
return
|
254
|
+
}
|
255
|
+
return handler(
|
256
|
+
JSON.parse(data.rawSelf) as IotaMoveObject,
|
257
|
+
data.rawObjects.map((o) => JSON.parse(o)) as IotaMoveObject[],
|
258
|
+
ctx
|
259
|
+
)
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
export class IotaObjectTypeProcessor<T> extends IotaBaseObjectOrAddressProcessor<
|
264
|
+
(self: TypedIotaMoveObject<T>, dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid
|
265
|
+
> {
|
266
|
+
objectType: TypeDescriptor<T>
|
267
|
+
|
268
|
+
static bind<T>(options: IotaObjectTypeBindOptions<T>): IotaObjectTypeProcessor<T> {
|
269
|
+
const processor = new IotaObjectTypeProcessor<T>({
|
270
|
+
address: ALL_ADDRESS, // current only support on all address
|
271
|
+
network: options.network,
|
272
|
+
startCheckpoint: options.startCheckpoint,
|
273
|
+
endCheckpoint: options.endCheckpoint,
|
274
|
+
ownerType: MoveOwnerType.TYPE,
|
275
|
+
baseLabels: options.baseLabels
|
276
|
+
})
|
277
|
+
processor.objectType = options.objectType
|
278
|
+
return processor
|
279
|
+
}
|
280
|
+
|
281
|
+
protected async doHandle(
|
282
|
+
handler: (
|
283
|
+
self: TypedIotaMoveObject<T>,
|
284
|
+
dynamicFieldObjects: IotaMoveObject[],
|
285
|
+
ctx: IotaObjectContext
|
286
|
+
) => PromiseOrVoid,
|
287
|
+
data: Data_SuiObject,
|
288
|
+
ctx: IotaObjectContext
|
289
|
+
) {
|
290
|
+
if (!data.rawSelf) {
|
291
|
+
console.log(`Iota object not existed in ${ctx.checkpoint}, please specific a start time`)
|
292
|
+
return
|
293
|
+
}
|
294
|
+
const object = await ctx.coder.filterAndDecodeObjects(this.objectType, [JSON.parse(data.rawSelf) as IotaMoveObject])
|
295
|
+
return handler(object[0], data.rawObjects.map((o) => JSON.parse(o)) as IotaMoveObject[], ctx)
|
296
|
+
}
|
297
|
+
|
298
|
+
public onObjectChange(handler: (changes: IotaObjectChange[], ctx: IotaObjectChangeContext) => PromiseOrVoid): this {
|
299
|
+
if (this.config.network === IotaNetwork.TEST_NET) {
|
300
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'object change not supported in testnet')
|
301
|
+
}
|
302
|
+
const processor = this
|
303
|
+
this.objectChangeHandlers.push({
|
304
|
+
handlerName: getHandlerName(),
|
305
|
+
handler: async function (data: Data_SuiObjectChange) {
|
306
|
+
const ctx = new IotaObjectChangeContext(
|
307
|
+
processor.config.network,
|
308
|
+
processor.config.address,
|
309
|
+
data.timestamp || new Date(0),
|
310
|
+
data.slot,
|
311
|
+
data.txDigest,
|
312
|
+
processor.config.baseLabels
|
313
|
+
)
|
314
|
+
await handler(data.rawChanges.map((r) => JSON.parse(r)) as IotaObjectChange[], ctx)
|
315
|
+
return ctx.stopAndGetResult()
|
316
|
+
},
|
317
|
+
type: this.objectType.getSignature()
|
318
|
+
})
|
319
|
+
|
320
|
+
return this
|
321
|
+
}
|
322
|
+
|
323
|
+
public onTimeInterval(
|
324
|
+
handler: (
|
325
|
+
self: TypedIotaMoveObject<T>,
|
326
|
+
dynamicFieldObjects: IotaMoveObject[],
|
327
|
+
ctx: IotaObjectContext
|
328
|
+
) => PromiseOrVoid,
|
329
|
+
timeIntervalInMinutes = 60,
|
330
|
+
backfillTimeIntervalInMinutes = 240,
|
331
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
332
|
+
): this {
|
333
|
+
return this.onInterval(
|
334
|
+
handler,
|
335
|
+
{
|
336
|
+
recentInterval: timeIntervalInMinutes,
|
337
|
+
backfillInterval: backfillTimeIntervalInMinutes
|
338
|
+
},
|
339
|
+
undefined,
|
340
|
+
this.objectType.getSignature(),
|
341
|
+
fetchConfig
|
342
|
+
)
|
343
|
+
}
|
344
|
+
|
345
|
+
public onCheckpointInterval(
|
346
|
+
handler: (
|
347
|
+
self: TypedIotaMoveObject<T>,
|
348
|
+
dynamicFieldObjects: IotaMoveObject[],
|
349
|
+
ctx: IotaObjectContext
|
350
|
+
) => PromiseOrVoid,
|
351
|
+
checkpointInterval = 100000,
|
352
|
+
backfillCheckpointInterval = 400000,
|
353
|
+
fetchConfig?: Partial<MoveAccountFetchConfig>
|
354
|
+
): this {
|
355
|
+
return this.onInterval(
|
356
|
+
handler,
|
357
|
+
undefined,
|
358
|
+
{ recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },
|
359
|
+
this.objectType.qname,
|
360
|
+
fetchConfig
|
361
|
+
)
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
export class IotaWrappedObjectProcessor extends IotaBaseObjectOrAddressProcessorInternal<
|
366
|
+
(dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid
|
367
|
+
> {
|
368
|
+
static bind(options: IotaObjectBindOptions): IotaWrappedObjectProcessor {
|
369
|
+
return new IotaWrappedObjectProcessor({
|
370
|
+
address: options.objectId,
|
371
|
+
network: options.network,
|
372
|
+
startCheckpoint: options.startCheckpoint,
|
373
|
+
endCheckpoint: options.endCheckpoint,
|
374
|
+
ownerType: MoveOwnerType.WRAPPED_OBJECT,
|
375
|
+
baseLabels: options.baseLabels
|
376
|
+
})
|
377
|
+
}
|
378
|
+
|
379
|
+
protected async doHandle(
|
380
|
+
handler: (dynamicFieldObjects: IotaMoveObject[], ctx: IotaObjectContext) => PromiseOrVoid,
|
381
|
+
data: Data_SuiObject,
|
382
|
+
ctx: IotaObjectContext
|
383
|
+
) {
|
384
|
+
return handler(data.rawObjects.map((o) => JSON.parse(o)) as IotaMoveObject[], ctx)
|
385
|
+
}
|
386
|
+
}
|