@sentio/sdk 2.1.6-rc.1 → 2.2.0-rc.2
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/aptos-plugin.js +5 -13
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +5 -28
- package/lib/aptos/aptos-processor.js +4 -14
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +116 -115
- package/lib/aptos/builtin/0x1.js +0 -1
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +28 -27
- package/lib/aptos/builtin/0x3.js +0 -1
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +5 -5
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/index.d.ts +0 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/tests/types/reserved.d.ts +21 -20
- package/lib/aptos/tests/types/reserved.js +0 -1
- package/lib/aptos/tests/types/reserved.js.map +1 -1
- package/lib/aptos/tests/types/soffl3.d.ts +37 -36
- package/lib/aptos/tests/types/soffl3.js +0 -1
- package/lib/aptos/tests/types/soffl3.js.map +1 -1
- package/lib/aptos/tests/types/souffle.d.ts +21 -20
- package/lib/aptos/tests/types/souffle.js +0 -1
- package/lib/aptos/tests/types/souffle.js.map +1 -1
- package/lib/core/chain.d.ts +3 -2
- package/lib/core/chain.js +3 -2
- package/lib/core/chain.js.map +1 -1
- package/lib/core/index.d.ts +0 -2
- package/lib/core/index.js +0 -2
- package/lib/core/index.js.map +1 -1
- package/lib/eth/context.d.ts +0 -7
- package/lib/eth/context.js +0 -24
- package/lib/eth/context.js.map +1 -1
- package/lib/eth/eth-plugin.js +4 -14
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/move/index.d.ts +25 -0
- package/lib/move/index.js +11 -0
- package/lib/move/index.js.map +1 -0
- package/lib/solana/solana-plugin.js +3 -10
- package/lib/solana/solana-plugin.js.map +1 -1
- package/lib/sui/context.d.ts +13 -0
- package/lib/sui/context.js +33 -0
- package/lib/sui/context.js.map +1 -0
- package/lib/sui/index.d.ts +2 -0
- package/lib/sui/index.js +3 -0
- package/lib/sui/index.js.map +1 -0
- package/lib/sui/models.d.ts +8 -0
- package/lib/sui/models.js +25 -0
- package/lib/sui/models.js.map +1 -0
- package/lib/sui/network.d.ts +11 -0
- package/lib/sui/network.js +26 -0
- package/lib/sui/network.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +12 -0
- package/lib/sui/sui-plugin.js +96 -0
- package/lib/sui/sui-plugin.js.map +1 -0
- package/lib/sui/sui-processor.d.ts +29 -0
- package/lib/sui/sui-processor.js +120 -0
- package/lib/sui/sui-processor.js.map +1 -0
- package/lib/sui/tests/sui.test.d.ts +1 -0
- package/lib/sui/tests/sui.test.js.map +1 -0
- package/lib/testing/test-processor-server.d.ts +1 -0
- package/lib/testing/test-processor-server.js +3 -0
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +14 -7
- package/src/aptos/aptos-plugin.ts +8 -16
- package/src/aptos/aptos-processor.ts +8 -46
- package/src/aptos/builtin/0x1.ts +115 -115
- package/src/aptos/builtin/0x3.ts +27 -27
- package/src/aptos/codegen/codegen.ts +5 -5
- package/src/aptos/index.ts +0 -1
- package/src/aptos/tests/types/reserved.ts +20 -20
- package/src/aptos/tests/types/soffl3.ts +36 -36
- package/src/aptos/tests/types/souffle.ts +20 -20
- package/src/core/chain.ts +4 -3
- package/src/core/index.ts +0 -3
- package/src/eth/context.ts +0 -26
- package/src/eth/eth-plugin.ts +3 -13
- package/src/move/index.ts +33 -0
- package/src/solana/solana-plugin.ts +2 -9
- package/src/sui/abis/0x1.json +2067 -0
- package/src/sui/abis/0x2.json +15598 -0
- package/src/sui/context.ts +43 -0
- package/src/sui/index.ts +3 -0
- package/src/sui/models.ts +38 -0
- package/src/sui/network.ts +28 -0
- package/src/sui/sui-plugin.ts +122 -0
- package/src/sui/sui-processor.ts +159 -0
- package/src/testing/test-processor-server.ts +4 -0
- package/lib/core/sui-plugin.d.ts +0 -8
- package/lib/core/sui-plugin.js +0 -42
- package/lib/core/sui-plugin.js.map +0 -1
- package/lib/core/sui-processor.d.ts +0 -25
- package/lib/core/sui-processor.js +0 -43
- package/lib/core/sui-processor.js.map +0 -1
- package/src/aptos/codegen/tsconfig.json +0 -8
- package/src/core/sui-plugin.ts +0 -48
- package/src/core/sui-processor.ts +0 -58
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RecordMetaData } from '@sentio/protos'
|
|
2
|
+
import { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'
|
|
3
|
+
import { SuiNetwork, getChainId } from './network.js'
|
|
4
|
+
import { SuiTransactionResponse } from '@mysten/sui.js'
|
|
5
|
+
|
|
6
|
+
export class SuiContext extends BaseContext {
|
|
7
|
+
address: string
|
|
8
|
+
network: SuiNetwork
|
|
9
|
+
moduleName: string
|
|
10
|
+
timestamp: number
|
|
11
|
+
transaction: SuiTransactionResponse
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
moduleName: string,
|
|
15
|
+
network: SuiNetwork,
|
|
16
|
+
address: string,
|
|
17
|
+
version: number,
|
|
18
|
+
transaction?: SuiTransactionResponse
|
|
19
|
+
) {
|
|
20
|
+
super()
|
|
21
|
+
this.address = address
|
|
22
|
+
this.network = network
|
|
23
|
+
this.moduleName = moduleName
|
|
24
|
+
this.timestamp = version
|
|
25
|
+
if (transaction) {
|
|
26
|
+
this.transaction = transaction
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getMetaData(name: string, labels: Labels): RecordMetaData {
|
|
31
|
+
return {
|
|
32
|
+
address: this.address,
|
|
33
|
+
contractName: this.moduleName,
|
|
34
|
+
blockNumber: BigInt(this.timestamp),
|
|
35
|
+
transactionIndex: 0,
|
|
36
|
+
transactionHash: this.transaction?.certificate.transactionDigest || '', // TODO
|
|
37
|
+
logIndex: 0,
|
|
38
|
+
chainId: getChainId(this.network),
|
|
39
|
+
name: name,
|
|
40
|
+
labels: normalizeLabels(labels),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/sui/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MoveEvent } from '@mysten/sui.js'
|
|
2
|
+
|
|
3
|
+
// export type MoveEvent = MoveEvent & {
|
|
4
|
+
// }
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
export type TypedEventInstance<T> = MoveEvent & {
|
|
8
|
+
/**
|
|
9
|
+
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
10
|
+
*/
|
|
11
|
+
fields_decoded: T
|
|
12
|
+
|
|
13
|
+
type_arguments: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
// // Don't use intermediate type to make IDE happier
|
|
18
|
+
// export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
19
|
+
// /**
|
|
20
|
+
// * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
21
|
+
// */
|
|
22
|
+
// arguments_decoded: T
|
|
23
|
+
// }
|
|
24
|
+
//
|
|
25
|
+
// export type TypedMoveResource<T> = MoveResource & {
|
|
26
|
+
// data_decoded: T
|
|
27
|
+
// type_arguments: string[]
|
|
28
|
+
// }
|
|
29
|
+
//
|
|
30
|
+
// export interface StructWithTag {
|
|
31
|
+
// type: string
|
|
32
|
+
// data: any
|
|
33
|
+
// }
|
|
34
|
+
//
|
|
35
|
+
// export interface StructWithType<T> extends StructWithTag {
|
|
36
|
+
// data_decoded: T
|
|
37
|
+
// type_arguments: string[]
|
|
38
|
+
// }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CHAIN_IDS, getChainName } from '../core/chain.js'
|
|
2
|
+
|
|
3
|
+
export enum SuiNetwork {
|
|
4
|
+
MAIN_NET = 1,
|
|
5
|
+
TEST_NET = 2,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getChainId(network: SuiNetwork): string {
|
|
9
|
+
switch (network) {
|
|
10
|
+
case SuiNetwork.TEST_NET:
|
|
11
|
+
return CHAIN_IDS.SUI_TESTNET
|
|
12
|
+
}
|
|
13
|
+
return CHAIN_IDS.SUI_MAINNET
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getSuiChainName(network: SuiNetwork): string {
|
|
17
|
+
switch (network) {
|
|
18
|
+
case SuiNetwork.TEST_NET:
|
|
19
|
+
return getChainName(CHAIN_IDS.SUI_TESTNET)
|
|
20
|
+
}
|
|
21
|
+
return getChainName(CHAIN_IDS.SUI_MAINNET)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class SuiBindOptions {
|
|
25
|
+
address: string
|
|
26
|
+
network?: SuiNetwork = SuiNetwork.MAIN_NET
|
|
27
|
+
startVersion?: bigint | number
|
|
28
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
|
2
|
+
import {
|
|
3
|
+
ContractConfig,
|
|
4
|
+
Data_SuiCall,
|
|
5
|
+
Data_SuiEvent,
|
|
6
|
+
DataBinding,
|
|
7
|
+
HandlerType,
|
|
8
|
+
MoveCallHandlerConfig,
|
|
9
|
+
MoveEventHandlerConfig,
|
|
10
|
+
ProcessConfigResponse,
|
|
11
|
+
ProcessResult,
|
|
12
|
+
} from '@sentio/protos'
|
|
13
|
+
|
|
14
|
+
import { ServerError, Status } from 'nice-grpc'
|
|
15
|
+
|
|
16
|
+
import { SuiProcessorState } from './sui-processor.js'
|
|
17
|
+
import { getChainId } from './network.js'
|
|
18
|
+
|
|
19
|
+
export class SuiPlugin extends Plugin {
|
|
20
|
+
name: string = 'SuiPlugin'
|
|
21
|
+
|
|
22
|
+
private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []
|
|
23
|
+
private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []
|
|
24
|
+
|
|
25
|
+
async configure(config: ProcessConfigResponse) {
|
|
26
|
+
for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
|
|
27
|
+
const contractConfig = ContractConfig.fromPartial({
|
|
28
|
+
transactionConfig: [],
|
|
29
|
+
processorType: USER_PROCESSOR,
|
|
30
|
+
contract: {
|
|
31
|
+
name: suiProcessor.moduleName,
|
|
32
|
+
chainId: getChainId(suiProcessor.config.network),
|
|
33
|
+
address: suiProcessor.config.address,
|
|
34
|
+
abi: '',
|
|
35
|
+
},
|
|
36
|
+
startBlock: BigInt(suiProcessor.config.startTimestamp),
|
|
37
|
+
})
|
|
38
|
+
for (const handler of suiProcessor.eventHandlers) {
|
|
39
|
+
const handlerId = this.suiEventHandlers.push(handler.handler) - 1
|
|
40
|
+
const eventHandlerConfig: MoveEventHandlerConfig = {
|
|
41
|
+
filters: handler.filters.map((f) => {
|
|
42
|
+
return {
|
|
43
|
+
type: f.type,
|
|
44
|
+
account: f.account || '',
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
47
|
+
fetchConfig: handler.fetchConfig,
|
|
48
|
+
handlerId,
|
|
49
|
+
}
|
|
50
|
+
contractConfig.moveEventConfigs.push(eventHandlerConfig)
|
|
51
|
+
}
|
|
52
|
+
for (const handler of suiProcessor.callHandlers) {
|
|
53
|
+
const handlerId = this.suiCallHandlers.push(handler.handler) - 1
|
|
54
|
+
const functionHandlerConfig: MoveCallHandlerConfig = {
|
|
55
|
+
filters: handler.filters.map((filter) => {
|
|
56
|
+
return {
|
|
57
|
+
function: filter.function,
|
|
58
|
+
typeArguments: filter.typeArguments || [],
|
|
59
|
+
withTypeArguments: !!filter.typeArguments,
|
|
60
|
+
includeFailed: filter.includeFailed || false,
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
fetchConfig: handler.fetchConfig,
|
|
64
|
+
handlerId,
|
|
65
|
+
}
|
|
66
|
+
contractConfig.moveCallConfigs.push(functionHandlerConfig)
|
|
67
|
+
}
|
|
68
|
+
config.contractConfigs.push(contractConfig)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]
|
|
73
|
+
|
|
74
|
+
async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {
|
|
75
|
+
if (!binding.data?.suiEvent) {
|
|
76
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
|
77
|
+
}
|
|
78
|
+
const promises: Promise<ProcessResult>[] = []
|
|
79
|
+
const event = binding.data.suiEvent
|
|
80
|
+
|
|
81
|
+
for (const handlerId of binding.handlerIds) {
|
|
82
|
+
promises.push(
|
|
83
|
+
this.suiEventHandlers[handlerId](event).catch((e) => {
|
|
84
|
+
throw new ServerError(
|
|
85
|
+
Status.INTERNAL,
|
|
86
|
+
'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
|
|
87
|
+
)
|
|
88
|
+
})
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
return mergeProcessResults(await Promise.all(promises))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {
|
|
95
|
+
if (!binding.data?.suiCall) {
|
|
96
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Call can't be empty")
|
|
97
|
+
}
|
|
98
|
+
const call = binding.data.suiCall
|
|
99
|
+
|
|
100
|
+
const promises: Promise<ProcessResult>[] = []
|
|
101
|
+
for (const handlerId of binding.handlerIds) {
|
|
102
|
+
const promise = this.suiCallHandlers[handlerId](call).catch((e) => {
|
|
103
|
+
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
|
|
104
|
+
})
|
|
105
|
+
promises.push(promise)
|
|
106
|
+
}
|
|
107
|
+
return mergeProcessResults(await Promise.all(promises))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
processBinding(request: DataBinding): Promise<ProcessResult> {
|
|
111
|
+
switch (request.handlerType) {
|
|
112
|
+
case HandlerType.SUI_EVENT:
|
|
113
|
+
return this.processSuiEvent(request)
|
|
114
|
+
case HandlerType.SUI_CALL:
|
|
115
|
+
return this.processSuiFunctionCall(request)
|
|
116
|
+
default:
|
|
117
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
PluginManager.INSTANCE.register(new SuiPlugin())
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { MoveFetchConfig } from '@sentio/protos'
|
|
2
|
+
import { ListStateStorage } from '@sentio/runtime'
|
|
3
|
+
import { SuiNetwork, getChainId } from './network.js'
|
|
4
|
+
import { ServerError, Status } from 'nice-grpc'
|
|
5
|
+
import { SuiContext } from './context.js'
|
|
6
|
+
import { MoveEvent, SuiTransactionResponse, getMoveCallTransaction, MoveCall } from '@mysten/sui.js'
|
|
7
|
+
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
|
|
8
|
+
|
|
9
|
+
export class IndexConfigure {
|
|
10
|
+
address: string
|
|
11
|
+
network: SuiNetwork
|
|
12
|
+
startTimestamp: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class SuiBindOptions {
|
|
16
|
+
address: string
|
|
17
|
+
network?: SuiNetwork
|
|
18
|
+
startTimestamp?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
|
|
22
|
+
static INSTANCE = new SuiProcessorState()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class SuiBaseProcessor {
|
|
26
|
+
readonly moduleName: string
|
|
27
|
+
config: IndexConfigure
|
|
28
|
+
|
|
29
|
+
eventHandlers: EventHandler[] = []
|
|
30
|
+
callHandlers: CallHandler[] = []
|
|
31
|
+
|
|
32
|
+
constructor(name: string, options: SuiBindOptions) {
|
|
33
|
+
this.config = configure(options)
|
|
34
|
+
SuiProcessorState.INSTANCE.addValue(this)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getChainId(): string {
|
|
38
|
+
return getChainId(this.config.network)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public onMoveEvent(
|
|
42
|
+
handler: (event: MoveEvent, ctx: SuiContext) => void,
|
|
43
|
+
filter: EventFilter | EventFilter[],
|
|
44
|
+
fetchConfig?: MoveFetchConfig
|
|
45
|
+
): SuiBaseProcessor {
|
|
46
|
+
let _filters: EventFilter[] = []
|
|
47
|
+
const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})
|
|
48
|
+
|
|
49
|
+
if (Array.isArray(filter)) {
|
|
50
|
+
_filters = filter
|
|
51
|
+
} else {
|
|
52
|
+
_filters.push(filter)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// const address = this.config.address
|
|
56
|
+
// const moduleName = this.moduleName
|
|
57
|
+
|
|
58
|
+
const processor = this
|
|
59
|
+
|
|
60
|
+
this.eventHandlers.push({
|
|
61
|
+
handler: async function (data) {
|
|
62
|
+
if (!data.transaction) {
|
|
63
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')
|
|
64
|
+
}
|
|
65
|
+
const txn = data.transaction as SuiTransactionResponse
|
|
66
|
+
if (!txn.effects.events || !txn.effects.events.length) {
|
|
67
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ctx = new SuiContext(
|
|
71
|
+
processor.moduleName,
|
|
72
|
+
processor.config.network,
|
|
73
|
+
processor.config.address,
|
|
74
|
+
txn.timestamp_ms || 0,
|
|
75
|
+
txn
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const events = txn.effects.events
|
|
79
|
+
txn.effects.events = []
|
|
80
|
+
for (const evt of events) {
|
|
81
|
+
if ('moveEvent' in evt) {
|
|
82
|
+
const eventInstance = evt.moveEvent as MoveEvent
|
|
83
|
+
const decoded = eventInstance // TODO
|
|
84
|
+
// const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)
|
|
85
|
+
await handler(decoded || eventInstance, ctx)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return ctx.getProcessResult()
|
|
90
|
+
},
|
|
91
|
+
filters: _filters,
|
|
92
|
+
fetchConfig: _fetchConfig,
|
|
93
|
+
})
|
|
94
|
+
return this
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public onEntryFunctionCall(
|
|
98
|
+
handler: (call: MoveCall, ctx: SuiContext) => void,
|
|
99
|
+
filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
|
|
100
|
+
fetchConfig?: MoveFetchConfig
|
|
101
|
+
): SuiBaseProcessor {
|
|
102
|
+
let _filters: FunctionNameAndCallFilter[] = []
|
|
103
|
+
const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(filter)) {
|
|
106
|
+
_filters = filter
|
|
107
|
+
} else {
|
|
108
|
+
_filters.push(filter)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// const address = this.config.address
|
|
112
|
+
// const moduleName = this.moduleName
|
|
113
|
+
const processor = this
|
|
114
|
+
|
|
115
|
+
this.callHandlers.push({
|
|
116
|
+
handler: async function (data) {
|
|
117
|
+
if (!data.transaction) {
|
|
118
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')
|
|
119
|
+
}
|
|
120
|
+
const tx = data.transaction as SuiTransactionResponse
|
|
121
|
+
|
|
122
|
+
const ctx = new SuiContext(
|
|
123
|
+
processor.moduleName,
|
|
124
|
+
processor.config.network,
|
|
125
|
+
processor.config.address,
|
|
126
|
+
tx.timestamp_ms || 0,
|
|
127
|
+
tx
|
|
128
|
+
)
|
|
129
|
+
if (tx) {
|
|
130
|
+
const calls: MoveCall[] = tx.certificate.data.transactions.flatMap((tx) => {
|
|
131
|
+
const call = getMoveCallTransaction(tx)
|
|
132
|
+
if (call) {
|
|
133
|
+
return [call]
|
|
134
|
+
}
|
|
135
|
+
return []
|
|
136
|
+
})
|
|
137
|
+
if (calls.length !== 1) {
|
|
138
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)
|
|
139
|
+
}
|
|
140
|
+
const payload = calls[0]
|
|
141
|
+
const decoded = payload // MOVE_CODER.decodeFunctionPayload(payload)
|
|
142
|
+
await handler(decoded, ctx)
|
|
143
|
+
}
|
|
144
|
+
return ctx.getProcessResult()
|
|
145
|
+
},
|
|
146
|
+
filters: _filters,
|
|
147
|
+
fetchConfig: _fetchConfig,
|
|
148
|
+
})
|
|
149
|
+
return this
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function configure(options: SuiBindOptions): IndexConfigure {
|
|
154
|
+
return {
|
|
155
|
+
startTimestamp: options.startTimestamp || 0,
|
|
156
|
+
address: options.address,
|
|
157
|
+
network: options.network || SuiNetwork.MAIN_NET,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -310,6 +310,10 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
310
310
|
return this.service.processBindings(request, context)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
+
processBinding(request: DataBinding, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
314
|
+
return this.service.processBindings({ bindings: [request] }, context)
|
|
315
|
+
}
|
|
316
|
+
|
|
313
317
|
processBindingsStream(request: AsyncIterable<DataBinding>, context: CallContext) {
|
|
314
318
|
return this.service.processBindingsStream(request, context)
|
|
315
319
|
}
|
package/lib/core/sui-plugin.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@sentio/runtime';
|
|
2
|
-
import { DataBinding, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
|
|
3
|
-
export declare class SuiPlugin extends Plugin {
|
|
4
|
-
name: string;
|
|
5
|
-
configure(config: ProcessConfigResponse): Promise<void>;
|
|
6
|
-
supportedHandlers: never[];
|
|
7
|
-
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
8
|
-
}
|
package/lib/core/sui-plugin.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
|
|
2
|
-
import { HandlerType } from '@sentio/protos';
|
|
3
|
-
import { ServerError, Status } from 'nice-grpc';
|
|
4
|
-
import { CHAIN_IDS } from './chain.js';
|
|
5
|
-
import { SuiProcessorState } from './sui-processor.js';
|
|
6
|
-
export class SuiPlugin extends Plugin {
|
|
7
|
-
name = 'SuiPlugin';
|
|
8
|
-
async configure(config) {
|
|
9
|
-
for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
|
|
10
|
-
const contractConfig = {
|
|
11
|
-
transactionConfig: [],
|
|
12
|
-
processorType: USER_PROCESSOR,
|
|
13
|
-
contract: {
|
|
14
|
-
name: 'sui contract',
|
|
15
|
-
chainId: CHAIN_IDS.SUI_DEVNET,
|
|
16
|
-
address: suiProcessor.address,
|
|
17
|
-
abi: '',
|
|
18
|
-
},
|
|
19
|
-
logConfigs: [],
|
|
20
|
-
intervalConfigs: [],
|
|
21
|
-
traceConfigs: [],
|
|
22
|
-
startBlock: suiProcessor.config.startSeqNumber,
|
|
23
|
-
endBlock: 0n,
|
|
24
|
-
instructionConfig: undefined,
|
|
25
|
-
aptosEventConfigs: [],
|
|
26
|
-
aptosCallConfigs: [],
|
|
27
|
-
};
|
|
28
|
-
config.contractConfigs.push(contractConfig);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
supportedHandlers = [];
|
|
32
|
-
processBinding(request) {
|
|
33
|
-
switch (request.handlerType) {
|
|
34
|
-
case HandlerType.SUI_TRANSACTION:
|
|
35
|
-
// return this.processSolInstruction(request)
|
|
36
|
-
default:
|
|
37
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
PluginManager.INSTANCE.register(new SuiPlugin());
|
|
42
|
-
//# sourceMappingURL=sui-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/core/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAA+B,WAAW,EAAwC,MAAM,gBAAgB,CAAA;AAE/G,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEtD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAE1B,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAmB;gBACrC,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,SAAS,CAAC,UAAU;oBAC7B,OAAO,EAAE,YAAY,CAAC,OAAO;oBAC7B,GAAG,EAAE,EAAE;iBACR;gBACD,UAAU,EAAE,EAAE;gBACd,eAAe,EAAE,EAAE;gBACnB,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,cAAc;gBAC9C,QAAQ,EAAE,EAAE;gBACZ,iBAAiB,EAAE,SAAS;gBAC5B,iBAAiB,EAAE,EAAE;gBACrB,gBAAgB,EAAE,EAAE;aACrB,CAAA;YACD,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC5C;IACH,CAAC;IAED,iBAAiB,GAAG,EAAE,CAAA;IAEtB,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW,CAAC,eAAe,CAAC;YACjC,6CAA6C;YAC7C;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { CHAIN_IDS } from './chain.js'\nimport { SuiProcessorState } from './sui-processor.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n async configure(config: ProcessConfigResponse) {\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig: ContractConfig = {\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: 'sui contract',\n chainId: CHAIN_IDS.SUI_DEVNET,\n address: suiProcessor.address,\n abi: '',\n },\n logConfigs: [],\n intervalConfigs: [],\n traceConfigs: [],\n startBlock: suiProcessor.config.startSeqNumber,\n endBlock: 0n,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n config.contractConfigs.push(contractConfig)\n }\n }\n\n supportedHandlers = []\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_TRANSACTION:\n // return this.processSolInstruction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SuiContext } from '../eth/context.js';
|
|
2
|
-
import { ProcessResult } from '@sentio/protos';
|
|
3
|
-
import { ListStateStorage } from '@sentio/runtime';
|
|
4
|
-
type IndexConfigure = {
|
|
5
|
-
startSeqNumber: bigint;
|
|
6
|
-
endSeqNumber?: bigint;
|
|
7
|
-
};
|
|
8
|
-
export declare class SuiBindOptions {
|
|
9
|
-
address: string;
|
|
10
|
-
startBlock?: bigint | number;
|
|
11
|
-
}
|
|
12
|
-
export declare class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
|
|
13
|
-
static INSTANCE: SuiProcessorState;
|
|
14
|
-
}
|
|
15
|
-
export declare class SuiBaseProcessor {
|
|
16
|
-
transactionHanlder: (transaction: any, ctx: SuiContext) => void;
|
|
17
|
-
address: string;
|
|
18
|
-
config: IndexConfigure;
|
|
19
|
-
constructor(name: string, options: SuiBindOptions);
|
|
20
|
-
onTransaction(handler: (transaction: any, ctx: SuiContext) => void): this;
|
|
21
|
-
handleTransaction(txn: any, slot: bigint): ProcessResult | null;
|
|
22
|
-
startSlot(startSlot: bigint | number): this;
|
|
23
|
-
endBlock(endBlock: bigint | number): this;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { SuiContext } from '../eth/context.js';
|
|
2
|
-
import { ListStateStorage } from '@sentio/runtime';
|
|
3
|
-
export class SuiBindOptions {
|
|
4
|
-
address;
|
|
5
|
-
// network?: Networkish = 1
|
|
6
|
-
// name?: string
|
|
7
|
-
startBlock;
|
|
8
|
-
}
|
|
9
|
-
export class SuiProcessorState extends ListStateStorage {
|
|
10
|
-
static INSTANCE = new SuiProcessorState();
|
|
11
|
-
}
|
|
12
|
-
export class SuiBaseProcessor {
|
|
13
|
-
transactionHanlder;
|
|
14
|
-
address;
|
|
15
|
-
config = { startSeqNumber: 0n };
|
|
16
|
-
constructor(name, options) {
|
|
17
|
-
this.address = options.address;
|
|
18
|
-
if (options.startBlock) {
|
|
19
|
-
this.startSlot(options.startBlock);
|
|
20
|
-
}
|
|
21
|
-
SuiProcessorState.INSTANCE.addValue(this);
|
|
22
|
-
}
|
|
23
|
-
onTransaction(handler) {
|
|
24
|
-
this.transactionHanlder = handler;
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
handleTransaction(txn, slot) {
|
|
28
|
-
const ctx = new SuiContext(this.address, slot);
|
|
29
|
-
if (txn) {
|
|
30
|
-
this.transactionHanlder(txn, ctx);
|
|
31
|
-
}
|
|
32
|
-
return ctx.getProcessResult();
|
|
33
|
-
}
|
|
34
|
-
startSlot(startSlot) {
|
|
35
|
-
this.config.startSeqNumber = BigInt(startSlot);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
endBlock(endBlock) {
|
|
39
|
-
this.config.endSeqNumber = BigInt(endBlock);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=sui-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAkB;CAE7B;AAED,MAAM,OAAO,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAA;IAE/C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAY;QAC7C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAyB;QACvC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { SuiContext } from '../eth/context.js'\nimport { ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\n\ntype IndexConfigure = {\n startSeqNumber: bigint\n endSeqNumber?: bigint\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: bigint | number\n // endBlock?: Long | number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: 0n }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: bigint): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: bigint | number) {\n this.config.startSeqNumber = BigInt(startSlot)\n return this\n }\n\n public endBlock(endBlock: bigint | number) {\n this.config.endSeqNumber = BigInt(endBlock)\n return this\n }\n}\n"]}
|
package/src/core/sui-plugin.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
|
2
|
-
import { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'
|
|
3
|
-
|
|
4
|
-
import { ServerError, Status } from 'nice-grpc'
|
|
5
|
-
|
|
6
|
-
import { CHAIN_IDS } from './chain.js'
|
|
7
|
-
import { SuiProcessorState } from './sui-processor.js'
|
|
8
|
-
|
|
9
|
-
export class SuiPlugin extends Plugin {
|
|
10
|
-
name: string = 'SuiPlugin'
|
|
11
|
-
|
|
12
|
-
async configure(config: ProcessConfigResponse) {
|
|
13
|
-
for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
|
|
14
|
-
const contractConfig: ContractConfig = {
|
|
15
|
-
transactionConfig: [],
|
|
16
|
-
processorType: USER_PROCESSOR,
|
|
17
|
-
contract: {
|
|
18
|
-
name: 'sui contract',
|
|
19
|
-
chainId: CHAIN_IDS.SUI_DEVNET,
|
|
20
|
-
address: suiProcessor.address,
|
|
21
|
-
abi: '',
|
|
22
|
-
},
|
|
23
|
-
logConfigs: [],
|
|
24
|
-
intervalConfigs: [],
|
|
25
|
-
traceConfigs: [],
|
|
26
|
-
startBlock: suiProcessor.config.startSeqNumber,
|
|
27
|
-
endBlock: 0n,
|
|
28
|
-
instructionConfig: undefined,
|
|
29
|
-
aptosEventConfigs: [],
|
|
30
|
-
aptosCallConfigs: [],
|
|
31
|
-
}
|
|
32
|
-
config.contractConfigs.push(contractConfig)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
supportedHandlers = []
|
|
37
|
-
|
|
38
|
-
processBinding(request: DataBinding): Promise<ProcessResult> {
|
|
39
|
-
switch (request.handlerType) {
|
|
40
|
-
case HandlerType.SUI_TRANSACTION:
|
|
41
|
-
// return this.processSolInstruction(request)
|
|
42
|
-
default:
|
|
43
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
PluginManager.INSTANCE.register(new SuiPlugin())
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SuiContext } from '../eth/context.js'
|
|
2
|
-
import { ProcessResult } from '@sentio/protos'
|
|
3
|
-
import { ListStateStorage } from '@sentio/runtime'
|
|
4
|
-
|
|
5
|
-
type IndexConfigure = {
|
|
6
|
-
startSeqNumber: bigint
|
|
7
|
-
endSeqNumber?: bigint
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class SuiBindOptions {
|
|
11
|
-
address: string
|
|
12
|
-
// network?: Networkish = 1
|
|
13
|
-
// name?: string
|
|
14
|
-
startBlock?: bigint | number
|
|
15
|
-
// endBlock?: Long | number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
|
|
19
|
-
static INSTANCE = new SuiProcessorState()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class SuiBaseProcessor {
|
|
23
|
-
public transactionHanlder: (transaction: any, ctx: SuiContext) => void
|
|
24
|
-
address: string
|
|
25
|
-
config: IndexConfigure = { startSeqNumber: 0n }
|
|
26
|
-
|
|
27
|
-
constructor(name: string, options: SuiBindOptions) {
|
|
28
|
-
this.address = options.address
|
|
29
|
-
if (options.startBlock) {
|
|
30
|
-
this.startSlot(options.startBlock)
|
|
31
|
-
}
|
|
32
|
-
SuiProcessorState.INSTANCE.addValue(this)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {
|
|
36
|
-
this.transactionHanlder = handler
|
|
37
|
-
return this
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public handleTransaction(txn: any, slot: bigint): ProcessResult | null {
|
|
41
|
-
const ctx = new SuiContext(this.address, slot)
|
|
42
|
-
|
|
43
|
-
if (txn) {
|
|
44
|
-
this.transactionHanlder(txn, ctx)
|
|
45
|
-
}
|
|
46
|
-
return ctx.getProcessResult()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public startSlot(startSlot: bigint | number) {
|
|
50
|
-
this.config.startSeqNumber = BigInt(startSlot)
|
|
51
|
-
return this
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public endBlock(endBlock: bigint | number) {
|
|
55
|
-
this.config.endSeqNumber = BigInt(endBlock)
|
|
56
|
-
return this
|
|
57
|
-
}
|
|
58
|
-
}
|