@sentio/sdk 2.60.0-rc.4 → 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/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/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 +20 -8
- 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/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,211 @@
|
|
1
|
+
import { USER_PROCESSOR } from '@sentio/runtime'
|
2
|
+
import {
|
3
|
+
AccountConfig,
|
4
|
+
ContractConfig,
|
5
|
+
HandlerType,
|
6
|
+
InitResponse,
|
7
|
+
MoveCallHandlerConfig,
|
8
|
+
MoveEventHandlerConfig,
|
9
|
+
MoveResourceChangeConfig,
|
10
|
+
ProcessConfigResponse,
|
11
|
+
StartRequest
|
12
|
+
} from '@sentio/protos'
|
13
|
+
|
14
|
+
import { PartitionHandlerManager } from '../core/index.js'
|
15
|
+
import { HandlerRegister } from '../core/handler-register.js'
|
16
|
+
|
17
|
+
import { IotaProcessorState } from './iota-processor.js'
|
18
|
+
import { IotaAccountProcessorState, IotaAddressProcessor } from './iota-object-processor.js'
|
19
|
+
import { initCoinList } from './ext/coin.js'
|
20
|
+
import { SuiChainId } from '@sentio/chain'
|
21
|
+
import {
|
22
|
+
IotaAccountProcessorTemplateState,
|
23
|
+
IotaObjectOrAddressProcessorTemplate
|
24
|
+
} from './iota-object-processor-template.js'
|
25
|
+
import { IotaNetwork } from './network.js'
|
26
|
+
import { IotaContext } from './context.js'
|
27
|
+
|
28
|
+
export class IotaPluginPart {
|
29
|
+
constructor(
|
30
|
+
private handlerRegister: HandlerRegister,
|
31
|
+
private partitionManager: PartitionHandlerManager
|
32
|
+
) {}
|
33
|
+
|
34
|
+
async start(request: StartRequest): Promise<void> {
|
35
|
+
await initCoinList()
|
36
|
+
|
37
|
+
console.log('total instances:', request.templateInstances.length)
|
38
|
+
const allowedChainIds = new Set<string>([SuiChainId.IOTA_MAINNET, SuiChainId.IOTA_TESTNET])
|
39
|
+
for (const instance of request.templateInstances) {
|
40
|
+
if (!allowedChainIds.has(instance.contract?.chainId || '')) {
|
41
|
+
continue
|
42
|
+
}
|
43
|
+
|
44
|
+
console.log('start template instance', instance.templateId)
|
45
|
+
const template: IotaObjectOrAddressProcessorTemplate<any, any, any> =
|
46
|
+
IotaAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]
|
47
|
+
|
48
|
+
template.bind(
|
49
|
+
{
|
50
|
+
address: instance.contract?.address || '',
|
51
|
+
objectId: instance.contract?.address || '',
|
52
|
+
network: <IotaNetwork>instance.contract?.chainId || IotaNetwork.MAIN_NET,
|
53
|
+
startCheckpoint: instance.startBlock || 0n,
|
54
|
+
endCheckpoint: instance.endBlock || 0n,
|
55
|
+
baseLabels: instance.baseLabels
|
56
|
+
},
|
57
|
+
NoopContext
|
58
|
+
)
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
async init(config: InitResponse) {
|
63
|
+
for (const state of [IotaProcessorState.INSTANCE, IotaAccountProcessorState.INSTANCE]) {
|
64
|
+
for (const suiProcessor of state.getValues()) {
|
65
|
+
config.chainIds.push(suiProcessor.config.network)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
async configure(config: ProcessConfigResponse, forChainId?: string) {
|
71
|
+
// this.handlerRegister.clear(forChainId as any)
|
72
|
+
|
73
|
+
for (const suiProcessor of IotaProcessorState.INSTANCE.getValues()) {
|
74
|
+
const chainId = suiProcessor.config.network
|
75
|
+
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
76
|
+
continue
|
77
|
+
}
|
78
|
+
const contractConfig = ContractConfig.fromPartial({
|
79
|
+
transactionConfig: [],
|
80
|
+
processorType: USER_PROCESSOR,
|
81
|
+
contract: {
|
82
|
+
name: suiProcessor.moduleName,
|
83
|
+
chainId: suiProcessor.config.network,
|
84
|
+
address: suiProcessor.config.address,
|
85
|
+
abi: ''
|
86
|
+
},
|
87
|
+
startBlock: suiProcessor.config.startCheckpoint,
|
88
|
+
endBlock: suiProcessor.config.endCheckpoint
|
89
|
+
})
|
90
|
+
for (const handler of suiProcessor.eventHandlers) {
|
91
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
92
|
+
this.partitionManager.registerPartitionHandler(HandlerType.SUI_EVENT, handlerId, handler.partitionHandler)
|
93
|
+
const eventHandlerConfig: MoveEventHandlerConfig = {
|
94
|
+
filters: handler.filters.map((f) => {
|
95
|
+
return {
|
96
|
+
type: f.type,
|
97
|
+
account: f.account || '',
|
98
|
+
eventAccount: f.eventAccount || ''
|
99
|
+
}
|
100
|
+
}),
|
101
|
+
fetchConfig: handler.fetchConfig,
|
102
|
+
handlerId,
|
103
|
+
handlerName: handler.handlerName
|
104
|
+
}
|
105
|
+
contractConfig.moveEventConfigs.push(eventHandlerConfig)
|
106
|
+
}
|
107
|
+
for (const handler of suiProcessor.callHandlers) {
|
108
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
109
|
+
this.partitionManager.registerPartitionHandler(HandlerType.SUI_CALL, handlerId, handler.partitionHandler)
|
110
|
+
const functionHandlerConfig: MoveCallHandlerConfig = {
|
111
|
+
filters: handler.filters.map((filter) => {
|
112
|
+
return {
|
113
|
+
function: filter.function,
|
114
|
+
typeArguments: filter.typeArguments || [],
|
115
|
+
withTypeArguments: !!filter.typeArguments,
|
116
|
+
includeFailed: filter.includeFailed || false,
|
117
|
+
publicKeyPrefix: filter.publicKeyPrefix || '',
|
118
|
+
fromAndToAddress: filter.fromAndToAddress
|
119
|
+
}
|
120
|
+
}),
|
121
|
+
fetchConfig: handler.fetchConfig,
|
122
|
+
handlerId,
|
123
|
+
handlerName: handler.handlerName
|
124
|
+
}
|
125
|
+
contractConfig.moveCallConfigs.push(functionHandlerConfig)
|
126
|
+
}
|
127
|
+
// deprecated, use objectType processor instead
|
128
|
+
for (const handler of suiProcessor.objectChangeHandlers) {
|
129
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
130
|
+
const objectChangeHandler: MoveResourceChangeConfig = {
|
131
|
+
type: handler.type,
|
132
|
+
handlerId,
|
133
|
+
handlerName: handler.handlerName,
|
134
|
+
includeDeleted: false
|
135
|
+
}
|
136
|
+
contractConfig.moveResourceChangeConfigs.push(objectChangeHandler)
|
137
|
+
}
|
138
|
+
config.contractConfigs.push(contractConfig)
|
139
|
+
}
|
140
|
+
|
141
|
+
for (const processor of IotaAccountProcessorState.INSTANCE.getValues()) {
|
142
|
+
const chainId = processor.getChainId()
|
143
|
+
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
144
|
+
continue
|
145
|
+
}
|
146
|
+
const accountConfig = AccountConfig.fromPartial({
|
147
|
+
address: processor.config.address,
|
148
|
+
chainId: processor.getChainId(),
|
149
|
+
startBlock: processor.config.startCheckpoint, // TODO maybe use another field
|
150
|
+
endBlock: processor.config.endCheckpoint
|
151
|
+
})
|
152
|
+
|
153
|
+
for (const handler of processor.objectChangeHandlers) {
|
154
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
155
|
+
const objectChangeHandler: MoveResourceChangeConfig = {
|
156
|
+
type: handler.type,
|
157
|
+
handlerId,
|
158
|
+
handlerName: handler.handlerName,
|
159
|
+
includeDeleted: false
|
160
|
+
}
|
161
|
+
accountConfig.moveResourceChangeConfigs.push(objectChangeHandler)
|
162
|
+
}
|
163
|
+
|
164
|
+
for (const handler of processor.objectHandlers) {
|
165
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
166
|
+
|
167
|
+
accountConfig.moveIntervalConfigs.push({
|
168
|
+
intervalConfig: {
|
169
|
+
handlerId: handlerId,
|
170
|
+
handlerName: handler.handlerName,
|
171
|
+
minutes: 0,
|
172
|
+
minutesInterval: handler.timeIntervalInMinutes,
|
173
|
+
slot: 0,
|
174
|
+
slotInterval: handler.checkPointInterval,
|
175
|
+
fetchConfig: undefined
|
176
|
+
},
|
177
|
+
type: handler.type || '',
|
178
|
+
ownerType: processor.ownerType,
|
179
|
+
resourceFetchConfig: handler.fetchConfig,
|
180
|
+
fetchConfig: undefined
|
181
|
+
})
|
182
|
+
}
|
183
|
+
|
184
|
+
if (processor instanceof IotaAddressProcessor) {
|
185
|
+
for (const handler of processor.callHandlers) {
|
186
|
+
const handlerId = this.handlerRegister.register(handler.handler, chainId)
|
187
|
+
const functionHandlerConfig: MoveCallHandlerConfig = {
|
188
|
+
filters: handler.filters.map((filter) => {
|
189
|
+
return {
|
190
|
+
function: filter.function,
|
191
|
+
typeArguments: filter.typeArguments || [],
|
192
|
+
withTypeArguments: !!filter.typeArguments,
|
193
|
+
includeFailed: filter.includeFailed || false,
|
194
|
+
publicKeyPrefix: filter.publicKeyPrefix || '',
|
195
|
+
fromAndToAddress: filter.fromAndToAddress
|
196
|
+
}
|
197
|
+
}),
|
198
|
+
fetchConfig: handler.fetchConfig,
|
199
|
+
handlerId,
|
200
|
+
handlerName: handler.handlerName
|
201
|
+
}
|
202
|
+
accountConfig.moveCallConfigs.push(functionHandlerConfig)
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
config.accountConfigs.push(accountConfig)
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
const NoopContext = new IotaContext('', SuiChainId.IOTA_MAINNET, '', new Date(), 0n, {} as any, 0, {})
|
@@ -0,0 +1,339 @@
|
|
1
|
+
import { Data_SuiCall, Data_SuiEvent, Data_SuiObjectChange, MoveFetchConfig } from '@sentio/protos'
|
2
|
+
import { ListStateStorage } from '@sentio/runtime'
|
3
|
+
import { IotaNetwork } from './network.js'
|
4
|
+
import { ServerError, Status } from 'nice-grpc'
|
5
|
+
import { IotaContext, IotaObjectChangeContext } from './context.js'
|
6
|
+
import {
|
7
|
+
MoveCallIotaTransaction,
|
8
|
+
IotaEvent,
|
9
|
+
IotaTransactionBlockResponse,
|
10
|
+
IotaObjectChange
|
11
|
+
} from '@iota/iota-sdk/client'
|
12
|
+
import {
|
13
|
+
accountAddressString,
|
14
|
+
CallHandler,
|
15
|
+
EventFilter,
|
16
|
+
EventHandler,
|
17
|
+
FunctionNameAndCallFilter,
|
18
|
+
ObjectChangeHandler,
|
19
|
+
SPLITTER,
|
20
|
+
TransactionFilter
|
21
|
+
} from '../move/index.js'
|
22
|
+
import { getMoveCalls } from './utils.js'
|
23
|
+
import { defaultMoveCoder, MoveCoder } from './index.js'
|
24
|
+
import { ALL_ADDRESS, Labels, PromiseOrVoid } from '../core/index.js'
|
25
|
+
import { Required } from 'utility-types'
|
26
|
+
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
27
|
+
import { HandlerOptions } from './models.js'
|
28
|
+
|
29
|
+
export const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
|
30
|
+
resourceChanges: false,
|
31
|
+
allEvents: true,
|
32
|
+
inputs: true
|
33
|
+
}
|
34
|
+
|
35
|
+
export type IndexConfigure = Required<IotaBindOptions, 'startCheckpoint' | 'network'>
|
36
|
+
|
37
|
+
export function configure(options: IotaBindOptions): IndexConfigure {
|
38
|
+
return {
|
39
|
+
startCheckpoint: options.startCheckpoint || 0n,
|
40
|
+
endCheckpoint: options.endCheckpoint,
|
41
|
+
address: options.address === ALL_ADDRESS ? ALL_ADDRESS : accountAddressString(options.address),
|
42
|
+
network: options.network || IotaNetwork.MAIN_NET,
|
43
|
+
baseLabels: options.baseLabels
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface IotaBindOptions {
|
48
|
+
address: string
|
49
|
+
network?: IotaNetwork
|
50
|
+
startCheckpoint?: bigint
|
51
|
+
endCheckpoint?: bigint
|
52
|
+
baseLabels?: Labels
|
53
|
+
}
|
54
|
+
|
55
|
+
export class IotaProcessorState extends ListStateStorage<IotaBaseProcessor> {
|
56
|
+
static INSTANCE = new IotaProcessorState()
|
57
|
+
}
|
58
|
+
|
59
|
+
export class IotaBaseProcessor {
|
60
|
+
readonly moduleName: string
|
61
|
+
config: IndexConfigure
|
62
|
+
|
63
|
+
eventHandlers: EventHandler<Data_SuiEvent>[] = []
|
64
|
+
callHandlers: CallHandler<Data_SuiCall>[] = []
|
65
|
+
objectChangeHandlers: ObjectChangeHandler<Data_SuiObjectChange>[] = []
|
66
|
+
|
67
|
+
coder: MoveCoder
|
68
|
+
|
69
|
+
constructor(name: string, options: IotaBindOptions) {
|
70
|
+
this.moduleName = name
|
71
|
+
this.config = configure(options)
|
72
|
+
IotaProcessorState.INSTANCE.addValue(this)
|
73
|
+
this.coder = defaultMoveCoder(this.config.network)
|
74
|
+
|
75
|
+
return proxyProcessor(this)
|
76
|
+
}
|
77
|
+
|
78
|
+
getChainId(): string {
|
79
|
+
return this.config.network
|
80
|
+
}
|
81
|
+
|
82
|
+
protected onMoveEvent(
|
83
|
+
handler: (event: IotaEvent, ctx: IotaContext) => PromiseOrVoid,
|
84
|
+
filter: EventFilter | EventFilter[],
|
85
|
+
handlerOptions?: HandlerOptions<MoveFetchConfig, IotaEvent>
|
86
|
+
): IotaBaseProcessor {
|
87
|
+
let _filters: EventFilter[] = []
|
88
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
|
89
|
+
|
90
|
+
if (Array.isArray(filter)) {
|
91
|
+
_filters = filter
|
92
|
+
} else {
|
93
|
+
_filters.push(filter)
|
94
|
+
}
|
95
|
+
|
96
|
+
// const address = this.config.address
|
97
|
+
// const moduleName = this.moduleName
|
98
|
+
|
99
|
+
const processor = this
|
100
|
+
|
101
|
+
this.eventHandlers.push({
|
102
|
+
handlerName: getHandlerName(),
|
103
|
+
handler: async function (data) {
|
104
|
+
if (!data.rawTransaction) {
|
105
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')
|
106
|
+
}
|
107
|
+
const txn = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
108
|
+
if (txn.events == null) {
|
109
|
+
txn.events = []
|
110
|
+
}
|
111
|
+
|
112
|
+
const evt = JSON.parse(data.rawEvent) as IotaEvent
|
113
|
+
const idx = Number(evt.id.eventSeq) || 0
|
114
|
+
|
115
|
+
const ctx = new IotaContext(
|
116
|
+
processor.moduleName,
|
117
|
+
processor.config.network,
|
118
|
+
processor.config.address,
|
119
|
+
data.timestamp || new Date(0),
|
120
|
+
data.slot,
|
121
|
+
txn,
|
122
|
+
idx,
|
123
|
+
processor.config.baseLabels
|
124
|
+
)
|
125
|
+
|
126
|
+
const decoded = await processor.coder.decodeEvent<any>(evt)
|
127
|
+
await handler(decoded || evt, ctx)
|
128
|
+
|
129
|
+
return ctx.stopAndGetResult()
|
130
|
+
},
|
131
|
+
filters: _filters,
|
132
|
+
fetchConfig: _fetchConfig,
|
133
|
+
partitionHandler: async (data: Data_SuiEvent): Promise<string | undefined> => {
|
134
|
+
const p = handlerOptions?.partitionKey
|
135
|
+
if (!p) return undefined
|
136
|
+
if (typeof p === 'function') {
|
137
|
+
const evt = JSON.parse(data.rawEvent) as IotaEvent
|
138
|
+
const decoded = await processor.coder.decodeEvent<any>(evt)
|
139
|
+
return p(decoded || evt)
|
140
|
+
}
|
141
|
+
return p
|
142
|
+
}
|
143
|
+
})
|
144
|
+
return this
|
145
|
+
}
|
146
|
+
|
147
|
+
protected onEntryFunctionCall(
|
148
|
+
handler: (call: MoveCallIotaTransaction, ctx: IotaContext) => PromiseOrVoid,
|
149
|
+
filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
|
150
|
+
handlerOptions?: HandlerOptions<MoveFetchConfig, MoveCallIotaTransaction>
|
151
|
+
): IotaBaseProcessor {
|
152
|
+
let _filters: FunctionNameAndCallFilter[] = []
|
153
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
|
154
|
+
|
155
|
+
if (Array.isArray(filter)) {
|
156
|
+
_filters = filter
|
157
|
+
} else {
|
158
|
+
_filters.push(filter)
|
159
|
+
}
|
160
|
+
|
161
|
+
const processor = this
|
162
|
+
const allFunctionType = new Set(_filters.map((f) => f.function))
|
163
|
+
|
164
|
+
this.callHandlers.push({
|
165
|
+
handlerName: getHandlerName(),
|
166
|
+
handler: async function (data) {
|
167
|
+
if (!data.rawTransaction) {
|
168
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')
|
169
|
+
}
|
170
|
+
const tx = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
171
|
+
|
172
|
+
const ctx = new IotaContext(
|
173
|
+
processor.moduleName,
|
174
|
+
processor.config.network,
|
175
|
+
processor.config.address,
|
176
|
+
data.timestamp || new Date(0),
|
177
|
+
data.slot,
|
178
|
+
tx,
|
179
|
+
0,
|
180
|
+
processor.config.baseLabels
|
181
|
+
)
|
182
|
+
if (tx) {
|
183
|
+
const calls: MoveCallIotaTransaction[] = getMoveCalls(tx)
|
184
|
+
const txKind = tx.transaction?.data?.transaction
|
185
|
+
if (!txKind) {
|
186
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')
|
187
|
+
}
|
188
|
+
|
189
|
+
// getProgrammableTransaction(txKind)
|
190
|
+
const programmableTx = txKind.kind === 'ProgrammableTransaction' ? txKind : undefined
|
191
|
+
|
192
|
+
// TODO potential pass index
|
193
|
+
for (const call of calls) {
|
194
|
+
const functionType = [call.module, call.function].join(SPLITTER)
|
195
|
+
if (!allFunctionType.has(functionType)) {
|
196
|
+
continue
|
197
|
+
}
|
198
|
+
|
199
|
+
// TODO maybe do in parallel
|
200
|
+
const decoded = await processor.coder.decodeFunctionPayload(call, programmableTx?.inputs || [])
|
201
|
+
await handler(decoded, ctx)
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return ctx.stopAndGetResult()
|
205
|
+
},
|
206
|
+
filters: _filters,
|
207
|
+
fetchConfig: _fetchConfig,
|
208
|
+
partitionHandler: async (data: Data_SuiCall): Promise<string | undefined> => {
|
209
|
+
const p = handlerOptions?.partitionKey
|
210
|
+
if (!p) return undefined
|
211
|
+
if (typeof p === 'function') {
|
212
|
+
const tx = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
213
|
+
const calls: MoveCallIotaTransaction[] = getMoveCalls(tx)
|
214
|
+
// For simplicity, use the first call for partitioning
|
215
|
+
if (calls.length > 0) {
|
216
|
+
return p(calls[0])
|
217
|
+
}
|
218
|
+
return undefined
|
219
|
+
}
|
220
|
+
return p
|
221
|
+
}
|
222
|
+
})
|
223
|
+
return this
|
224
|
+
}
|
225
|
+
|
226
|
+
onEvent(
|
227
|
+
handler: (event: IotaEvent, ctx: IotaContext) => void,
|
228
|
+
handlerOptions?: HandlerOptions<MoveFetchConfig, IotaEvent>
|
229
|
+
): this {
|
230
|
+
this.onMoveEvent(handler, { type: '' }, handlerOptions)
|
231
|
+
return this
|
232
|
+
}
|
233
|
+
|
234
|
+
onTransactionBlock(
|
235
|
+
handler: (transaction: IotaTransactionBlockResponse, ctx: IotaContext) => PromiseOrVoid,
|
236
|
+
filter?: TransactionFilter,
|
237
|
+
handlerOptions?: HandlerOptions<MoveFetchConfig, IotaTransactionBlockResponse>
|
238
|
+
): this {
|
239
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
|
240
|
+
|
241
|
+
const processor = this
|
242
|
+
|
243
|
+
this.callHandlers.push({
|
244
|
+
handlerName: getHandlerName(),
|
245
|
+
handler: async function (data) {
|
246
|
+
if (!data.rawTransaction) {
|
247
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'transaction is null')
|
248
|
+
}
|
249
|
+
const tx = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
250
|
+
|
251
|
+
const ctx = new IotaContext(
|
252
|
+
processor.moduleName,
|
253
|
+
processor.config.network,
|
254
|
+
processor.config.address,
|
255
|
+
data.timestamp || new Date(0),
|
256
|
+
data.slot,
|
257
|
+
tx,
|
258
|
+
0,
|
259
|
+
processor.config.baseLabels
|
260
|
+
)
|
261
|
+
if (tx) {
|
262
|
+
await handler(tx, ctx)
|
263
|
+
}
|
264
|
+
return ctx.stopAndGetResult()
|
265
|
+
},
|
266
|
+
filters: [{ ...filter, function: '' }],
|
267
|
+
fetchConfig: _fetchConfig,
|
268
|
+
partitionHandler: async (data: Data_SuiCall): Promise<string | undefined> => {
|
269
|
+
const p = handlerOptions?.partitionKey
|
270
|
+
if (!p) return undefined
|
271
|
+
if (typeof p === 'function') {
|
272
|
+
const tx = JSON.parse(data.rawTransaction) as IotaTransactionBlockResponse
|
273
|
+
return p(tx)
|
274
|
+
}
|
275
|
+
return p
|
276
|
+
}
|
277
|
+
})
|
278
|
+
return this
|
279
|
+
}
|
280
|
+
|
281
|
+
protected onObjectChange(
|
282
|
+
handler: (changes: IotaObjectChange[], ctx: IotaObjectChangeContext) => PromiseOrVoid,
|
283
|
+
type: string
|
284
|
+
): this {
|
285
|
+
if (this.config.network === IotaNetwork.TEST_NET) {
|
286
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'object change not supported in testnet')
|
287
|
+
}
|
288
|
+
const processor = this
|
289
|
+
this.objectChangeHandlers.push({
|
290
|
+
handlerName: getHandlerName(),
|
291
|
+
handler: async function (data: Data_SuiObjectChange) {
|
292
|
+
const ctx = new IotaObjectChangeContext(
|
293
|
+
processor.config.network,
|
294
|
+
processor.config.address,
|
295
|
+
data.timestamp || new Date(0),
|
296
|
+
data.slot,
|
297
|
+
data.txDigest,
|
298
|
+
processor.config.baseLabels
|
299
|
+
)
|
300
|
+
await handler(data.rawChanges.map((r) => JSON.parse(r)) as IotaObjectChange[], ctx)
|
301
|
+
return ctx.stopAndGetResult()
|
302
|
+
},
|
303
|
+
type
|
304
|
+
})
|
305
|
+
|
306
|
+
return this
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
export class IotaModulesProcessor extends IotaBaseProcessor {
|
311
|
+
static bind(options: IotaBindOptions): IotaModulesProcessor {
|
312
|
+
return new IotaModulesProcessor(ALL_ADDRESS, options)
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
export class IotaGlobalProcessor extends IotaBaseProcessor {
|
317
|
+
static bind(options: Omit<IotaBindOptions, 'address'>): IotaGlobalProcessor {
|
318
|
+
return new IotaGlobalProcessor(ALL_ADDRESS, { ...options, address: ALL_ADDRESS })
|
319
|
+
}
|
320
|
+
onTransactionBlock(
|
321
|
+
handler: (transaction: IotaTransactionBlockResponse, ctx: IotaContext) => void,
|
322
|
+
filter: TransactionFilter,
|
323
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
324
|
+
): this {
|
325
|
+
// TODO enable more strict check
|
326
|
+
// if (!filter.publicKeyPrefix || filter.publicKeyPrefix.length < 2) {
|
327
|
+
// throw new ServerError(Status.INVALID_ARGUMENT, 'restriction too low for global processor')
|
328
|
+
// }
|
329
|
+
return super.onTransactionBlock(handler, filter, fetchConfig)
|
330
|
+
}
|
331
|
+
|
332
|
+
// deprecated,, use object type processor
|
333
|
+
public onObjectChange(
|
334
|
+
handler: (changes: IotaObjectChange[], ctx: IotaObjectChangeContext) => void,
|
335
|
+
type: string
|
336
|
+
): this {
|
337
|
+
return super.onObjectChange(handler, type)
|
338
|
+
}
|
339
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { IotaEvent, MoveCallIotaTransaction, IotaMoveObject } from '@iota/iota-sdk/client'
|
2
|
+
import { DecodedStruct } from '@typemove/move'
|
3
|
+
|
4
|
+
export type TypedEventInstance<T> = DecodedStruct<IotaEvent, T>
|
5
|
+
export type TypedIotaMoveObject<T> = DecodedStruct<IotaMoveObject, T>
|
6
|
+
|
7
|
+
export type TypedFunctionPayload<T extends Array<any>> = MoveCallIotaTransaction & {
|
8
|
+
/**
|
9
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
10
|
+
*/
|
11
|
+
arguments_decoded: T
|
12
|
+
}
|
13
|
+
|
14
|
+
export type { PartitionHandler, HandlerOptions } from '../core/index.js'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { MoveCoder } from '@typemove/iota'
|
2
|
+
|
3
|
+
import { getClient, IotaNetwork } from './network.js'
|
4
|
+
|
5
|
+
const CODERS = new Map<IotaNetwork, MoveCoder>()
|
6
|
+
|
7
|
+
export function defaultMoveCoder(network: IotaNetwork = IotaNetwork.MAIN_NET): MoveCoder {
|
8
|
+
let coder = CODERS.get(network)
|
9
|
+
if (!coder) {
|
10
|
+
coder = new MoveCoder(getClient(network))
|
11
|
+
CODERS.set(network, coder)
|
12
|
+
}
|
13
|
+
|
14
|
+
return coder
|
15
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { SuiChainId } from '@sentio/chain'
|
2
|
+
import { Endpoints } from '@sentio/runtime'
|
3
|
+
// import { ServerError, Status } from 'nice-grpc'
|
4
|
+
import { IotaClient } from '@iota/iota-sdk/client'
|
5
|
+
|
6
|
+
export type IotaNetwork = SuiChainId
|
7
|
+
export const IotaNetwork = <const>{
|
8
|
+
MAIN_NET: SuiChainId.IOTA_MAINNET,
|
9
|
+
TEST_NET: SuiChainId.IOTA_TESTNET
|
10
|
+
}
|
11
|
+
|
12
|
+
export function getClient(network: IotaNetwork): IotaClient {
|
13
|
+
let chainServer = Endpoints.INSTANCE.chainServer.get(network)
|
14
|
+
if (!chainServer) {
|
15
|
+
chainServer = getRpcEndpoint(network)
|
16
|
+
// throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')
|
17
|
+
}
|
18
|
+
return new IotaClient({ url: chainServer })
|
19
|
+
}
|
20
|
+
|
21
|
+
export function getRpcEndpoint(network: IotaNetwork): string {
|
22
|
+
switch (network) {
|
23
|
+
case IotaNetwork.TEST_NET:
|
24
|
+
return 'https://api.testnet.iota.cafe/'
|
25
|
+
}
|
26
|
+
return 'https://api.mainnet.iota.cafe/'
|
27
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import {
|
2
|
+
IotaTransactionBlockResponse,
|
3
|
+
MoveCallIotaTransaction,
|
4
|
+
ProgrammableTransaction,
|
5
|
+
IotaTransaction
|
6
|
+
} from '@iota/iota-sdk/client'
|
7
|
+
import { accountTypeString } from '@typemove/move'
|
8
|
+
|
9
|
+
export function getMoveCalls(txBlock: IotaTransactionBlockResponse) {
|
10
|
+
const txKind = txBlock.transaction?.data.transaction
|
11
|
+
if (!txKind) {
|
12
|
+
return []
|
13
|
+
}
|
14
|
+
const programmableTx: ProgrammableTransaction | undefined =
|
15
|
+
txKind.kind === 'ProgrammableTransaction' ? txKind : undefined
|
16
|
+
if (!programmableTx) {
|
17
|
+
return []
|
18
|
+
}
|
19
|
+
|
20
|
+
return programmableTx.transactions.flatMap((tx: IotaTransaction) => {
|
21
|
+
if ('MoveCall' in tx) {
|
22
|
+
const call = tx.MoveCall as MoveCallIotaTransaction
|
23
|
+
call.package = accountTypeString(call.package)
|
24
|
+
|
25
|
+
return [call]
|
26
|
+
}
|
27
|
+
return []
|
28
|
+
})
|
29
|
+
}
|
30
|
+
|
31
|
+
// function isHex(value: string): boolean {
|
32
|
+
// return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
|
33
|
+
// }
|
34
|
+
//
|
35
|
+
// function getHexByteLength(value: string): number {
|
36
|
+
// return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
|
37
|
+
// }
|
38
|
+
//
|
39
|
+
// export function isValidIotaAddress(value: string): value is IotaAddress {
|
40
|
+
// return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH
|
41
|
+
// }
|
42
|
+
|
43
|
+
// export function validateAndNormalizeAddress(address: string): string {
|
44
|
+
// // if (isFrameworkAccount(address)) {
|
45
|
+
// // const n = parseInt(address, 16)
|
46
|
+
// // return `0x${n.toString(16)}`
|
47
|
+
// // }
|
48
|
+
// if (!isValidIotaAddress(address)) {
|
49
|
+
// throw Error('Not valid Address')
|
50
|
+
// }
|
51
|
+
// return normalizeIotaAddress(address)
|
52
|
+
// }
|
package/src/sui/network.ts
CHANGED
@@ -7,9 +7,6 @@ export type SuiNetwork = SuiChainId
|
|
7
7
|
export const SuiNetwork = <const>{
|
8
8
|
MAIN_NET: SuiChainId.SUI_MAINNET,
|
9
9
|
TEST_NET: SuiChainId.SUI_TESTNET
|
10
|
-
// DEV_NET: SuiChainId.SUI_DEVNET,
|
11
|
-
// MOVEMENT_MAIN_NET: SuiChainId.SUI_MOVEMENT_MAINNET,
|
12
|
-
// MOVEMENT_TEST_NET: SuiChainId.SUI_MOVEMENT_TESTNET
|
13
10
|
}
|
14
11
|
|
15
12
|
export function getClient(network: SuiNetwork): SuiClient {
|