@proto-kit/module 0.1.1-develop.190 → 0.1.1-develop.2024
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/dist/factories/MethodIdFactory.d.ts +6 -6
- package/dist/factories/MethodIdFactory.d.ts.map +1 -1
- package/dist/factories/MethodIdFactory.js +10 -34
- package/dist/factories/MethodIdFactory.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -0
- package/dist/messages/OutgoingMessage.d.ts +96 -0
- package/dist/messages/OutgoingMessage.d.ts.map +1 -0
- package/dist/messages/OutgoingMessage.js +68 -0
- package/dist/messages/OutgoingMessage.js.map +1 -0
- package/dist/messages/OutgoingMessages.d.ts +231 -0
- package/dist/messages/OutgoingMessages.d.ts.map +1 -0
- package/dist/messages/OutgoingMessages.js +66 -0
- package/dist/messages/OutgoingMessages.js.map +1 -0
- package/dist/method/MethodParameterEncoder.d.ts +26 -0
- package/dist/method/MethodParameterEncoder.d.ts.map +1 -0
- package/dist/method/MethodParameterEncoder.js +169 -0
- package/dist/method/MethodParameterEncoder.js.map +1 -0
- package/dist/method/runtimeMethod.d.ts +21 -5
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +69 -25
- package/dist/method/runtimeMethod.js.map +1 -0
- package/dist/module/decorator.js +1 -0
- package/dist/module/decorator.js.map +1 -0
- package/dist/runtime/MethodIdResolver.d.ts +10 -8
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +74 -33
- package/dist/runtime/MethodIdResolver.js.map +1 -0
- package/dist/runtime/Runtime.d.ts +20 -26
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +117 -62
- package/dist/runtime/Runtime.js.map +1 -0
- package/dist/runtime/RuntimeEnvironment.d.ts +10 -0
- package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -0
- package/dist/runtime/RuntimeEnvironment.js +2 -0
- package/dist/runtime/RuntimeEnvironment.js.map +1 -0
- package/dist/runtime/RuntimeModule.d.ts +18 -15
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.js +33 -8
- package/dist/runtime/RuntimeModule.js.map +1 -0
- package/dist/state/InMemoryStateService.d.ts +11 -10
- package/dist/state/InMemoryStateService.d.ts.map +1 -1
- package/dist/state/InMemoryStateService.js +11 -8
- package/dist/state/InMemoryStateService.js.map +1 -0
- package/dist/state/decorator.d.ts.map +1 -1
- package/dist/state/decorator.js +2 -4
- package/dist/state/decorator.js.map +1 -0
- package/dist/testing/TestingRuntime.d.ts +8 -0
- package/dist/testing/TestingRuntime.d.ts.map +1 -0
- package/dist/testing/TestingRuntime.js +31 -0
- package/dist/testing/TestingRuntime.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +10 -11
- package/src/factories/MethodIdFactory.ts +10 -17
- package/src/index.ts +4 -7
- package/src/messages/OutgoingMessages.ts +122 -0
- package/src/method/MethodParameterEncoder.ts +262 -0
- package/src/method/runtimeMethod.ts +130 -33
- package/src/runtime/MethodIdResolver.ts +83 -46
- package/src/runtime/Runtime.ts +193 -100
- package/src/runtime/RuntimeEnvironment.ts +16 -0
- package/src/runtime/RuntimeModule.ts +62 -30
- package/src/state/InMemoryStateService.ts +14 -18
- package/test/Runtime.test.ts +68 -42
- package/test/TestingRuntime.ts +43 -0
- package/test/messages/message.test.ts +42 -0
- package/test/method/MethodParameterEncoder.test.ts +124 -0
- package/test/method/runtimeMethod-fail.test.ts +53 -0
- package/{src/method/decorator.test.ts → test/method/runtimeMethod.test.ts} +3 -3
- package/test/modules/Admin.ts +4 -4
- package/test/modules/Balances.test.ts +92 -78
- package/test/modules/Balances.ts +15 -17
- package/test/modules/{methodId.test.ts → MethodIdResolver.test.ts} +24 -36
- package/test/modules/State.test.ts +81 -0
- package/test/runtimeMethod.test.ts +192 -20
- package/test/tsconfig.json +7 -0
- package/tsconfig.json +2 -2
- package/LICENSE.md +0 -201
- package/dist/method/MethodParameterDecoder.d.ts +0 -22
- package/dist/method/MethodParameterDecoder.d.ts.map +0 -1
- package/dist/method/MethodParameterDecoder.js +0 -33
- package/dist/method/RuntimeMethodExecutionContext.d.ts +0 -57
- package/dist/method/RuntimeMethodExecutionContext.d.ts.map +0 -1
- package/dist/method/RuntimeMethodExecutionContext.js +0 -92
- package/dist/method/assert.d.ts +0 -12
- package/dist/method/assert.d.ts.map +0 -1
- package/dist/method/assert.js +0 -23
- package/dist/state/State.d.ts +0 -65
- package/dist/state/State.d.ts.map +0 -1
- package/dist/state/State.js +0 -114
- package/dist/state/StateMap.d.ts +0 -37
- package/dist/state/StateMap.d.ts.map +0 -1
- package/dist/state/StateMap.js +0 -56
- package/dist/state/StateServiceProvider.d.ts +0 -10
- package/dist/state/StateServiceProvider.d.ts.map +0 -1
- package/dist/state/StateServiceProvider.js +0 -34
- package/src/method/MethodParameterDecoder.ts +0 -68
- package/src/method/RuntimeMethodExecutionContext.ts +0 -111
- package/src/method/assert.test.ts +0 -49
- package/src/method/assert.ts +0 -27
- package/src/state/State.ts +0 -154
- package/src/state/StateMap.ts +0 -69
- package/src/state/StateServiceProvider.ts +0 -24
- package/src/state/decorator.ts +0 -65
- package/test/state/MerkleTree.test.ts +0 -95
- package/test/state/MockAsyncMerkleStore.ts +0 -28
- package/test/transaction.test.ts +0 -82
- package/tsconfig.test.json +0 -9
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bool, Field, FlexibleProvablePure, Poseidon } from "o1js";
|
|
2
2
|
import { container } from "tsyringe";
|
|
3
3
|
import {
|
|
4
|
-
StateTransition,
|
|
5
|
-
DefaultProvableHashList,
|
|
6
4
|
ProvableStateTransition,
|
|
7
5
|
MethodPublicOutput,
|
|
6
|
+
RuntimeMethodExecutionContext,
|
|
7
|
+
StateTransitionReductionList,
|
|
8
|
+
DefaultProvableHashList,
|
|
8
9
|
} from "@proto-kit/protocol";
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
DecoratedMethod,
|
|
12
|
+
toProver,
|
|
13
|
+
ZkProgrammable,
|
|
14
|
+
ArgumentTypes,
|
|
15
|
+
} from "@proto-kit/common";
|
|
10
16
|
|
|
11
17
|
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
12
18
|
|
|
13
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
MethodParameterEncoder,
|
|
21
|
+
checkArgsProvable,
|
|
22
|
+
} from "./MethodParameterEncoder";
|
|
14
23
|
|
|
15
24
|
const errors = {
|
|
16
25
|
runtimeNotProvided: (name: string) =>
|
|
17
26
|
new Error(`Runtime was not provided for module: ${name}`),
|
|
18
27
|
|
|
19
|
-
|
|
28
|
+
runtimeNameNotSet: () => new Error("Runtime name was not set"),
|
|
29
|
+
|
|
30
|
+
fieldNotConstant: (name: string) =>
|
|
20
31
|
new Error(
|
|
21
|
-
|
|
32
|
+
`In-circuit field ${name} not a constant, this is likely a framework bug`
|
|
22
33
|
),
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
export function toStateTransitionsHash(
|
|
26
|
-
|
|
27
|
-
stateTransitions: StateTransition<any>[]
|
|
37
|
+
stateTransitions: { toProvable: () => ProvableStateTransition }[]
|
|
28
38
|
) {
|
|
29
|
-
const stateTransitionsHashList = new
|
|
39
|
+
const stateTransitionsHashList = new StateTransitionReductionList(
|
|
30
40
|
ProvableStateTransition
|
|
31
41
|
);
|
|
32
42
|
|
|
@@ -40,39 +50,102 @@ export function toStateTransitionsHash(
|
|
|
40
50
|
.toField();
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
export function toEventsHash(
|
|
54
|
+
events: {
|
|
55
|
+
eventType: FlexibleProvablePure<any>;
|
|
56
|
+
event: any;
|
|
57
|
+
eventName: string;
|
|
58
|
+
condition: Bool;
|
|
59
|
+
}[]
|
|
60
|
+
) {
|
|
61
|
+
return events.reduce((acc, event) => {
|
|
62
|
+
const hashList = new DefaultProvableHashList(event.eventType, acc);
|
|
63
|
+
hashList.pushIf(event.event, event.condition);
|
|
64
|
+
return hashList.commitment;
|
|
65
|
+
}, Field(0));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
|
|
69
|
+
export type AsyncWrappedMethod = (
|
|
70
|
+
...args: ArgumentTypes
|
|
71
|
+
) => Promise<MethodPublicOutput>;
|
|
45
72
|
|
|
46
73
|
export function toWrappedMethod(
|
|
47
74
|
this: RuntimeModule<unknown>,
|
|
48
75
|
methodName: string,
|
|
49
|
-
moduleMethod: (...args:
|
|
50
|
-
|
|
76
|
+
moduleMethod: (...args: ArgumentTypes) => Promise<any>,
|
|
77
|
+
options: {
|
|
78
|
+
invocationType: RuntimeMethodInvocationType;
|
|
79
|
+
}
|
|
80
|
+
): AsyncWrappedMethod {
|
|
51
81
|
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
|
|
52
82
|
RuntimeMethodExecutionContext
|
|
53
83
|
);
|
|
54
84
|
|
|
55
|
-
const wrappedMethod:
|
|
56
|
-
|
|
85
|
+
const wrappedMethod: AsyncWrappedMethod = async (
|
|
86
|
+
...args
|
|
87
|
+
): Promise<MethodPublicOutput> => {
|
|
88
|
+
await Reflect.apply(moduleMethod, this, args);
|
|
57
89
|
const {
|
|
58
|
-
result: { stateTransitions, status },
|
|
59
|
-
input,
|
|
90
|
+
result: { stateTransitions, status, events },
|
|
60
91
|
} = executionContext.current();
|
|
61
92
|
|
|
62
93
|
const stateTransitionsHash = toStateTransitionsHash(stateTransitions);
|
|
94
|
+
const eventsHash = toEventsHash(events);
|
|
63
95
|
|
|
64
|
-
|
|
65
|
-
|
|
96
|
+
const { name, parent: runtime } = this;
|
|
97
|
+
|
|
98
|
+
if (name === undefined) {
|
|
99
|
+
throw errors.runtimeNameNotSet();
|
|
100
|
+
}
|
|
101
|
+
if (runtime === undefined) {
|
|
102
|
+
throw errors.runtimeNotProvided(name);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { transaction, networkState } = executionContext.witnessInput();
|
|
106
|
+
const { methodIdResolver } = runtime;
|
|
107
|
+
|
|
108
|
+
// Assert that the given transaction has the correct methodId
|
|
109
|
+
const thisMethodId = Field(methodIdResolver.getMethodId(name, methodName));
|
|
110
|
+
if (!thisMethodId.isConstant()) {
|
|
111
|
+
throw errors.fieldNotConstant("methodId");
|
|
66
112
|
}
|
|
67
113
|
|
|
68
|
-
|
|
69
|
-
|
|
114
|
+
transaction.methodId.assertEquals(
|
|
115
|
+
thisMethodId,
|
|
116
|
+
"Runtimemethod called with wrong methodId on the transaction object"
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Use the type info obtained previously to convert
|
|
121
|
+
* the args passed to fields
|
|
122
|
+
*/
|
|
123
|
+
const { fields } = MethodParameterEncoder.fromMethod(
|
|
124
|
+
this,
|
|
125
|
+
methodName
|
|
126
|
+
).encode(args);
|
|
127
|
+
|
|
128
|
+
// Assert that the argsHash that has been signed matches the given arguments
|
|
129
|
+
const argsHash = Poseidon.hash(fields);
|
|
130
|
+
|
|
131
|
+
transaction.argsHash.assertEquals(
|
|
132
|
+
argsHash,
|
|
133
|
+
"argsHash and therefore arguments of transaction and runtime call does not match"
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const isMessage = Bool(options.invocationType === "INCOMING_MESSAGE");
|
|
137
|
+
transaction.assertTransactionType(Bool(isMessage));
|
|
138
|
+
|
|
139
|
+
const transactionHash = transaction.hash();
|
|
140
|
+
const networkStateHash = networkState.hash();
|
|
70
141
|
|
|
71
142
|
return new MethodPublicOutput({
|
|
72
143
|
stateTransitionsHash,
|
|
73
144
|
status,
|
|
74
145
|
transactionHash,
|
|
75
146
|
networkStateHash,
|
|
147
|
+
isMessage,
|
|
148
|
+
eventsHash,
|
|
76
149
|
});
|
|
77
150
|
};
|
|
78
151
|
|
|
@@ -93,6 +166,7 @@ export function combineMethodName(
|
|
|
93
166
|
|
|
94
167
|
export const runtimeMethodMetadataKey = "yab-method";
|
|
95
168
|
export const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
|
|
169
|
+
export const runtimeMethodTypeMetadataKey = "proto-kit-runtime-method-type";
|
|
96
170
|
|
|
97
171
|
/**
|
|
98
172
|
* Checks the metadata of the provided runtime module and its method,
|
|
@@ -111,12 +185,17 @@ export function isRuntimeMethod(
|
|
|
111
185
|
);
|
|
112
186
|
}
|
|
113
187
|
|
|
114
|
-
export
|
|
188
|
+
export type RuntimeMethodInvocationType = "SIGNATURE" | "INCOMING_MESSAGE";
|
|
189
|
+
|
|
190
|
+
function runtimeMethodInternal(options: {
|
|
191
|
+
invocationType: RuntimeMethodInvocationType;
|
|
192
|
+
}) {
|
|
115
193
|
return (
|
|
116
194
|
target: RuntimeModule<unknown>,
|
|
117
195
|
methodName: string,
|
|
118
|
-
descriptor:
|
|
196
|
+
descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>
|
|
119
197
|
) => {
|
|
198
|
+
checkArgsProvable(target, methodName);
|
|
120
199
|
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
|
|
121
200
|
RuntimeMethodExecutionContext
|
|
122
201
|
);
|
|
@@ -135,14 +214,21 @@ export function runtimeMethod() {
|
|
|
135
214
|
|
|
136
215
|
Reflect.defineMetadata(runtimeMethodMetadataKey, true, target, methodName);
|
|
137
216
|
|
|
217
|
+
Reflect.defineMetadata(
|
|
218
|
+
runtimeMethodTypeMetadataKey,
|
|
219
|
+
options.invocationType,
|
|
220
|
+
target,
|
|
221
|
+
methodName
|
|
222
|
+
);
|
|
223
|
+
|
|
138
224
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
139
225
|
const simulatedMethod = descriptor.value as DecoratedMethod;
|
|
140
226
|
|
|
141
|
-
descriptor.value = function value(
|
|
227
|
+
descriptor.value = async function value(
|
|
142
228
|
this: RuntimeModule<unknown>,
|
|
143
|
-
...args:
|
|
229
|
+
...args: ArgumentTypes
|
|
144
230
|
) {
|
|
145
|
-
const constructorName = this.
|
|
231
|
+
const constructorName = this.name!;
|
|
146
232
|
|
|
147
233
|
/**
|
|
148
234
|
* If its a top level method call, wrap it into a wrapped method,
|
|
@@ -154,6 +240,7 @@ export function runtimeMethod() {
|
|
|
154
240
|
const simulatedWrappedMethod = Reflect.apply(toWrappedMethod, this, [
|
|
155
241
|
methodName,
|
|
156
242
|
simulatedMethod,
|
|
243
|
+
options,
|
|
157
244
|
]);
|
|
158
245
|
|
|
159
246
|
/**
|
|
@@ -161,7 +248,7 @@ export function runtimeMethod() {
|
|
|
161
248
|
* RuntimeMethodExecutionContext state, meaning it enters and exits
|
|
162
249
|
* the context properly.
|
|
163
250
|
*/
|
|
164
|
-
|
|
251
|
+
|
|
165
252
|
async function prover(this: ZkProgrammable<any, any>) {
|
|
166
253
|
executionContext.beforeMethod(constructorName, methodName, args);
|
|
167
254
|
const innerProver = toProver(
|
|
@@ -170,7 +257,6 @@ export function runtimeMethod() {
|
|
|
170
257
|
false,
|
|
171
258
|
...args
|
|
172
259
|
).bind(this);
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
174
260
|
let result: Awaited<ReturnType<typeof innerProver>>;
|
|
175
261
|
try {
|
|
176
262
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -185,16 +271,15 @@ export function runtimeMethod() {
|
|
|
185
271
|
executionContext.beforeMethod(constructorName, methodName, args);
|
|
186
272
|
|
|
187
273
|
if (executionContext.isTopLevel) {
|
|
188
|
-
if (!this.
|
|
274
|
+
if (!this.parent) {
|
|
189
275
|
throw errors.runtimeNotProvided(constructorName);
|
|
190
276
|
}
|
|
191
|
-
executionContext.setProver(prover.bind(this.
|
|
277
|
+
executionContext.setProver(prover.bind(this.parent.zkProgrammable));
|
|
192
278
|
}
|
|
193
279
|
|
|
194
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
195
280
|
let result: unknown;
|
|
196
281
|
try {
|
|
197
|
-
result = Reflect.apply(simulatedMethod, this, args);
|
|
282
|
+
result = await Reflect.apply(simulatedMethod, this, args);
|
|
198
283
|
} finally {
|
|
199
284
|
executionContext.afterMethod();
|
|
200
285
|
}
|
|
@@ -203,3 +288,15 @@ export function runtimeMethod() {
|
|
|
203
288
|
};
|
|
204
289
|
};
|
|
205
290
|
}
|
|
291
|
+
|
|
292
|
+
export function runtimeMessage() {
|
|
293
|
+
return runtimeMethodInternal({
|
|
294
|
+
invocationType: "INCOMING_MESSAGE",
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function runtimeMethod() {
|
|
299
|
+
return runtimeMethodInternal({
|
|
300
|
+
invocationType: "SIGNATURE",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
@@ -1,71 +1,108 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filterNonUndefined } from "@proto-kit/common";
|
|
2
|
+
import { stringToField, RuntimeMethodIdMapping } from "@proto-kit/protocol";
|
|
3
|
+
import { Poseidon } from "o1js";
|
|
4
|
+
import { inject, injectable } from "tsyringe";
|
|
2
5
|
|
|
3
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
RuntimeMethodInvocationType,
|
|
8
|
+
runtimeMethodTypeMetadataKey,
|
|
9
|
+
} from "../method/runtimeMethod";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
7
|
-
const modulus = 2n ** (offset - 1n);
|
|
11
|
+
import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* [0
|
|
13
|
-
* ...hash(stringToField(moduleName))[0..128],
|
|
14
|
-
* ...hash(stringToField(methodName))[0..128]
|
|
15
|
-
* ]
|
|
14
|
+
* Please see `getMethodId` to learn more about
|
|
15
|
+
* methodId encoding
|
|
16
16
|
*/
|
|
17
|
+
@injectable()
|
|
17
18
|
export class MethodIdResolver {
|
|
18
|
-
private readonly dictionary: {
|
|
19
|
+
private readonly dictionary: {
|
|
20
|
+
[key: string]: { moduleName: string; methodName: string };
|
|
21
|
+
} = {};
|
|
19
22
|
|
|
20
23
|
public constructor(
|
|
21
|
-
private readonly runtime: Runtime<RuntimeModulesRecord
|
|
22
|
-
private readonly modules: RuntimeModulesRecord
|
|
24
|
+
@inject("Runtime") private readonly runtime: Runtime<RuntimeModulesRecord>
|
|
23
25
|
) {
|
|
24
|
-
this.dictionary = runtime.runtimeModuleNames.reduce<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
26
|
+
this.dictionary = runtime.runtimeModuleNames.reduce<
|
|
27
|
+
Record<string, { moduleName: string; methodName: string }>
|
|
28
|
+
>((dict, moduleName) => {
|
|
29
|
+
this.runtime.assertIsValidModuleName(moduleName);
|
|
30
|
+
|
|
31
|
+
runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
|
|
32
|
+
dict[this.getMethodId(moduleName, methodName).toString()] = {
|
|
33
|
+
moduleName,
|
|
34
|
+
methodName,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return dict;
|
|
39
|
+
}, {});
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The purpose of this method is to provide a dictionary where
|
|
44
|
+
* we can look up properties like methodId and invocationType
|
|
45
|
+
* for each runtimeMethod using their module name and method name
|
|
46
|
+
*/
|
|
47
|
+
public methodIdMap(): RuntimeMethodIdMapping {
|
|
48
|
+
const methodIdResolver =
|
|
49
|
+
this.runtime.dependencyContainer.resolve<MethodIdResolver>(
|
|
50
|
+
"MethodIdResolver"
|
|
51
|
+
);
|
|
44
52
|
|
|
45
|
-
const
|
|
53
|
+
const rawMappings = this.runtime.moduleNames.flatMap((moduleName) => {
|
|
54
|
+
const module = this.runtime.resolve(moduleName);
|
|
55
|
+
return module.runtimeMethodNames.map((method) => {
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
57
|
+
const type = Reflect.getMetadata(
|
|
58
|
+
runtimeMethodTypeMetadataKey,
|
|
59
|
+
module,
|
|
60
|
+
method
|
|
61
|
+
) as RuntimeMethodInvocationType | undefined;
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
if (type !== undefined) {
|
|
64
|
+
return {
|
|
65
|
+
name: `${moduleName}.${method}`,
|
|
66
|
+
methodId: methodIdResolver.getMethodId(moduleName, method),
|
|
67
|
+
type,
|
|
68
|
+
} as const;
|
|
69
|
+
}
|
|
53
70
|
|
|
54
|
-
|
|
71
|
+
return undefined;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
55
74
|
|
|
56
|
-
|
|
75
|
+
return rawMappings
|
|
76
|
+
.filter(filterNonUndefined)
|
|
77
|
+
.reduce<RuntimeMethodIdMapping>((acc, entry) => {
|
|
78
|
+
acc[entry.name] = {
|
|
79
|
+
methodId: entry.methodId,
|
|
80
|
+
type: entry.type,
|
|
81
|
+
};
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getMethodNameFromId(methodId: bigint): [string, string] | undefined {
|
|
87
|
+
const methodPath = this.dictionary[methodId.toString()];
|
|
88
|
+
|
|
89
|
+
if (methodPath === undefined) {
|
|
57
90
|
return undefined;
|
|
58
91
|
}
|
|
59
92
|
|
|
93
|
+
const { moduleName, methodName } = methodPath;
|
|
94
|
+
|
|
95
|
+
this.runtime.assertIsValidModuleName(moduleName);
|
|
96
|
+
|
|
60
97
|
return [moduleName, methodName];
|
|
61
98
|
}
|
|
62
99
|
|
|
63
100
|
public getMethodId(moduleName: string, methodName: string): bigint {
|
|
64
|
-
this.runtime.assertIsValidModuleName(
|
|
101
|
+
this.runtime.assertIsValidModuleName(moduleName);
|
|
65
102
|
|
|
66
|
-
return (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
103
|
+
return Poseidon.hash([
|
|
104
|
+
stringToField(moduleName),
|
|
105
|
+
stringToField(methodName),
|
|
106
|
+
]).toBigInt();
|
|
70
107
|
}
|
|
71
108
|
}
|