@proto-kit/module 0.1.1-develop.339 → 0.1.1-develop.455
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 -5
- package/dist/factories/MethodIdFactory.d.ts.map +1 -1
- package/dist/factories/MethodIdFactory.js +8 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/MethodIdResolver.d.ts +1 -2
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +10 -6
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +3 -5
- package/dist/runtime/RuntimeModule.d.ts +2 -2
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/factories/MethodIdFactory.ts +8 -17
- package/src/index.ts +1 -0
- package/src/runtime/MethodIdResolver.ts +12 -5
- package/src/runtime/Runtime.ts +5 -6
- package/src/runtime/RuntimeModule.ts +4 -2
- package/test/state/MerkleTree.test.ts +0 -95
- package/test/state/MockAsyncMerkleStore.ts +0 -29
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DependencyFactory } from "@proto-kit/common";
|
|
2
2
|
import { MethodIdResolver } from "../runtime/MethodIdResolver";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export declare class MethodIdFactory implements DependencyFactory {
|
|
4
|
+
dependencies(): {
|
|
5
|
+
methodIdResolver: {
|
|
6
|
+
useClass: typeof MethodIdResolver;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=MethodIdFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodIdFactory.d.ts","sourceRoot":"","sources":["../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"MethodIdFactory.d.ts","sourceRoot":"","sources":["../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,qBAAa,eAAgB,YAAW,iBAAiB;IAChD,YAAY;;;;;CAOpB"}
|
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { dependency, dependencyFactory, DependencyFactory } from "@proto-kit/common";
|
|
14
|
-
import { inject } from "tsyringe";
|
|
15
1
|
import { MethodIdResolver } from "../runtime/MethodIdResolver";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
export class MethodIdFactory {
|
|
3
|
+
dependencies() {
|
|
4
|
+
return {
|
|
5
|
+
methodIdResolver: {
|
|
6
|
+
useClass: MethodIdResolver,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
return new MethodIdResolver(this.runtime, this.runtime.definition.modules);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
__decorate([
|
|
26
|
-
dependency(),
|
|
27
|
-
__metadata("design:type", Function),
|
|
28
|
-
__metadata("design:paramtypes", []),
|
|
29
|
-
__metadata("design:returntype", MethodIdResolver)
|
|
30
|
-
], MethodIdFactory.prototype, "methodIdResolver", null);
|
|
31
|
-
MethodIdFactory = __decorate([
|
|
32
|
-
dependencyFactory(),
|
|
33
|
-
__param(0, inject("Runtime")),
|
|
34
|
-
__metadata("design:paramtypes", [Function])
|
|
35
|
-
], MethodIdFactory);
|
|
36
|
-
export { MethodIdFactory };
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./method/runtimeMethod";
|
|
2
2
|
export * from "./module/decorator";
|
|
3
3
|
export * from "./runtime/RuntimeModule";
|
|
4
|
+
export * from "./runtime/RuntimeEnvironment";
|
|
4
5
|
export * from "./runtime/Runtime";
|
|
5
6
|
export * from "./state/InMemoryStateService";
|
|
6
7
|
export * from "./state/decorator";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./method/runtimeMethod";
|
|
2
2
|
export * from "./module/decorator";
|
|
3
3
|
export * from "./runtime/RuntimeModule";
|
|
4
|
+
export * from "./runtime/RuntimeEnvironment";
|
|
4
5
|
export * from "./runtime/Runtime";
|
|
5
6
|
export * from "./state/InMemoryStateService";
|
|
6
7
|
export * from "./state/decorator";
|
|
@@ -5,9 +5,8 @@ import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class MethodIdResolver {
|
|
7
7
|
private readonly runtime;
|
|
8
|
-
private readonly modules;
|
|
9
8
|
private readonly dictionary;
|
|
10
|
-
constructor(runtime: Runtime<RuntimeModulesRecord
|
|
9
|
+
constructor(runtime: Runtime<RuntimeModulesRecord>);
|
|
11
10
|
getMethodNameFromId(methodId: bigint): [string, string] | undefined;
|
|
12
11
|
getMethodId(moduleName: string, methodName: string): bigint;
|
|
13
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBACa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBACa,gBAAgB;IAMN,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAEpB;gBAG+B,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAoBrE,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAiBnE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAWnE"}
|
|
@@ -7,18 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
10
13
|
import { stringToField } from "@proto-kit/protocol";
|
|
11
14
|
import { Poseidon } from "o1js";
|
|
12
|
-
import { injectable } from "tsyringe";
|
|
15
|
+
import { inject, injectable } from "tsyringe";
|
|
13
16
|
/**
|
|
14
17
|
* Please see `getMethodId` to learn more about
|
|
15
18
|
* methodId encoding
|
|
16
19
|
*/
|
|
17
20
|
let MethodIdResolver = class MethodIdResolver {
|
|
18
|
-
constructor(runtime
|
|
21
|
+
constructor(runtime) {
|
|
19
22
|
this.runtime = runtime;
|
|
20
|
-
this.modules = modules;
|
|
21
23
|
this.dictionary = {};
|
|
24
|
+
const { modules } = runtime.definition;
|
|
22
25
|
this.dictionary = runtime.runtimeModuleNames.reduce((dict, moduleName) => {
|
|
23
26
|
this.runtime.assertIsValidModuleName(modules, moduleName);
|
|
24
27
|
runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
|
|
@@ -36,11 +39,11 @@ let MethodIdResolver = class MethodIdResolver {
|
|
|
36
39
|
return undefined;
|
|
37
40
|
}
|
|
38
41
|
const { moduleName, methodName } = methodPath;
|
|
39
|
-
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
42
|
+
this.runtime.assertIsValidModuleName(this.runtime.definition.modules, moduleName);
|
|
40
43
|
return [moduleName, methodName];
|
|
41
44
|
}
|
|
42
45
|
getMethodId(moduleName, methodName) {
|
|
43
|
-
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
46
|
+
this.runtime.assertIsValidModuleName(this.runtime.definition.modules, moduleName);
|
|
44
47
|
return Poseidon.hash([
|
|
45
48
|
stringToField(moduleName),
|
|
46
49
|
stringToField(methodName),
|
|
@@ -49,6 +52,7 @@ let MethodIdResolver = class MethodIdResolver {
|
|
|
49
52
|
};
|
|
50
53
|
MethodIdResolver = __decorate([
|
|
51
54
|
injectable(),
|
|
52
|
-
|
|
55
|
+
__param(0, inject("Runtime")),
|
|
56
|
+
__metadata("design:paramtypes", [Function])
|
|
53
57
|
], MethodIdResolver);
|
|
54
58
|
export { MethodIdResolver };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EAEd,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EAEd,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAU7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CACnC,CAAC;AAOF;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,oBAAoB;IACrE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,qBAAa,qBAAqB,CAChC,OAAO,SAAS,oBAAoB,CACpC,SAAQ,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAE3B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;gBAAzB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAInD,IAAW,QAAQ,iCAElB;IAEM,gBAAgB,IAAI,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;CAgHzE;AAED;;;GAGG;AACH,qBACa,OAAO,CAAC,OAAO,SAAS,oBAAoB,CACvD,SAAQ,eAAe,CAAC,OAAO,CAC/B,YAAW,kBAAkB;WAEf,IAAI,CAAC,OAAO,SAAS,oBAAoB,EACrD,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACrC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IASxB,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;IAEpD,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAEvC,cAAc,EAAE,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IAErE;;;;OAIG;gBACgB,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAQlD,MAAM,CAAC,sBAAsB,EAAE,sBAAsB;IAM5D,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAItD;IAED,IAAW,YAAY,IAAI,YAAY,CAEtC;IAED,IAAW,gBAAgB,IAAI,gBAAgB,CAE9C;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,mBAAmB,CAEpD;IAED;;;OAGG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,GACf,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,SAAS;IAuBhD;;;;;;OAMG;IACI,cAAc,CACnB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAQ9D;;OAEG;IACH,IAAW,kBAAkB,aAE5B;CACF"}
|
package/dist/runtime/Runtime.js
CHANGED
|
@@ -117,7 +117,7 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
117
117
|
// TODO Remove after changing DFs to type-based approach
|
|
118
118
|
create(childContainerProvider) {
|
|
119
119
|
super.create(childContainerProvider);
|
|
120
|
-
this.
|
|
120
|
+
this.useDependencyFactory(this.container.resolve(MethodIdFactory));
|
|
121
121
|
}
|
|
122
122
|
get appChain() {
|
|
123
123
|
return this.container.resolve("AreProofsEnabled");
|
|
@@ -142,14 +142,12 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
142
142
|
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
|
|
143
143
|
*/
|
|
144
144
|
getMethodById(methodId) {
|
|
145
|
-
const methodDescriptor = this.
|
|
146
|
-
.resolve("MethodIdResolver")
|
|
147
|
-
.getMethodNameFromId(methodId);
|
|
145
|
+
const methodDescriptor = this.methodIdResolver.getMethodNameFromId(methodId);
|
|
148
146
|
if (methodDescriptor === undefined) {
|
|
149
147
|
return undefined;
|
|
150
148
|
}
|
|
151
149
|
const [moduleName, methodName] = methodDescriptor;
|
|
152
|
-
this.
|
|
150
|
+
this.assertIsValidModuleName(this.definition.modules, moduleName);
|
|
153
151
|
const module = this.resolve(moduleName);
|
|
154
152
|
// eslint-disable-next-line max-len
|
|
155
153
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions,@typescript-eslint/no-unsafe-member-access
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ConfigurableModule, Presets } from "@proto-kit/common";
|
|
1
|
+
import { ConfigurableModule, NoConfig, Presets } from "@proto-kit/common";
|
|
2
2
|
import { NetworkState, RuntimeTransaction } from "@proto-kit/protocol";
|
|
3
3
|
import { RuntimeEnvironment } from "./RuntimeEnvironment";
|
|
4
4
|
/**
|
|
5
5
|
* Base class for runtime modules providing the necessary utilities.
|
|
6
6
|
*/
|
|
7
|
-
export declare class RuntimeModule<Config> extends ConfigurableModule<Config> {
|
|
7
|
+
export declare class RuntimeModule<Config = NoConfig> extends ConfigurableModule<Config> {
|
|
8
8
|
static presets: Presets<unknown>;
|
|
9
9
|
/**
|
|
10
10
|
* Holds all method names that are callable throw transactions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EACL,YAAY,EACZ,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM1D;;GAEG;AACH,qBACa,aAAa,CACxB,MAAM,GAAG,QAAQ,CACjB,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IAClC,OAAc,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAE7C;;OAEG;IACH,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAM;IAElD;;;;OAIG;IACI,eAAe,UAAQ;IAEvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,kBAAkB,CAAC;;IAYpC,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@proto-kit/module",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.1.1-develop.
|
|
5
|
+
"version": "0.1.1-develop.455+b020c57",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"o1js": "0.13.1",
|
|
32
32
|
"tsyringe": "^4.7.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "b020c5717e414d3a02a842cfbe1ac19a62584dbd"
|
|
35
35
|
}
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
dependency, dependencyFactory,
|
|
3
|
-
DependencyFactory
|
|
4
|
-
} from "@proto-kit/common";
|
|
5
|
-
import { inject, injectable } from "tsyringe";
|
|
1
|
+
import { DependencyFactory, DependencyRecord } from "@proto-kit/common";
|
|
6
2
|
|
|
7
3
|
import { MethodIdResolver } from "../runtime/MethodIdResolver";
|
|
8
|
-
import type { Runtime, RuntimeModulesRecord } from "../runtime/Runtime";
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@dependency()
|
|
19
|
-
public methodIdResolver(): MethodIdResolver {
|
|
20
|
-
return new MethodIdResolver(this.runtime, this.runtime.definition.modules);
|
|
5
|
+
export class MethodIdFactory implements DependencyFactory {
|
|
6
|
+
public dependencies() {
|
|
7
|
+
return {
|
|
8
|
+
methodIdResolver: {
|
|
9
|
+
useClass: MethodIdResolver,
|
|
10
|
+
},
|
|
11
|
+
} satisfies DependencyRecord;
|
|
21
12
|
}
|
|
22
13
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./method/runtimeMethod";
|
|
2
2
|
export * from "./module/decorator";
|
|
3
3
|
export * from "./runtime/RuntimeModule";
|
|
4
|
+
export * from "./runtime/RuntimeEnvironment";
|
|
4
5
|
export * from "./runtime/Runtime";
|
|
5
6
|
export * from "./state/InMemoryStateService";
|
|
6
7
|
export * from "./state/decorator";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringToField } from "@proto-kit/protocol";
|
|
2
2
|
import { Poseidon } from "o1js";
|
|
3
|
-
import { injectable } from "tsyringe";
|
|
3
|
+
import { inject, injectable } from "tsyringe";
|
|
4
4
|
|
|
5
5
|
import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
6
6
|
|
|
@@ -15,9 +15,10 @@ export class MethodIdResolver {
|
|
|
15
15
|
} = {};
|
|
16
16
|
|
|
17
17
|
public constructor(
|
|
18
|
-
private readonly runtime: Runtime<RuntimeModulesRecord
|
|
19
|
-
private readonly modules: RuntimeModulesRecord
|
|
18
|
+
@inject("Runtime") private readonly runtime: Runtime<RuntimeModulesRecord>
|
|
20
19
|
) {
|
|
20
|
+
const { modules } = runtime.definition;
|
|
21
|
+
|
|
21
22
|
this.dictionary = runtime.runtimeModuleNames.reduce<
|
|
22
23
|
Record<string, { moduleName: string; methodName: string }>
|
|
23
24
|
>((dict, moduleName) => {
|
|
@@ -43,13 +44,19 @@ export class MethodIdResolver {
|
|
|
43
44
|
|
|
44
45
|
const { moduleName, methodName } = methodPath;
|
|
45
46
|
|
|
46
|
-
this.runtime.assertIsValidModuleName(
|
|
47
|
+
this.runtime.assertIsValidModuleName(
|
|
48
|
+
this.runtime.definition.modules,
|
|
49
|
+
moduleName
|
|
50
|
+
);
|
|
47
51
|
|
|
48
52
|
return [moduleName, methodName];
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
public getMethodId(moduleName: string, methodName: string): bigint {
|
|
52
|
-
this.runtime.assertIsValidModuleName(
|
|
56
|
+
this.runtime.assertIsValidModuleName(
|
|
57
|
+
this.runtime.definition.modules,
|
|
58
|
+
moduleName
|
|
59
|
+
);
|
|
53
60
|
|
|
54
61
|
return Poseidon.hash([
|
|
55
62
|
stringToField(moduleName),
|
package/src/runtime/Runtime.ts
CHANGED
|
@@ -26,11 +26,11 @@ import {
|
|
|
26
26
|
toWrappedMethod,
|
|
27
27
|
WrappedMethod,
|
|
28
28
|
} from "../method/runtimeMethod";
|
|
29
|
+
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
29
30
|
|
|
30
31
|
import { RuntimeModule } from "./RuntimeModule";
|
|
31
32
|
import { MethodIdResolver } from "./MethodIdResolver";
|
|
32
33
|
import { RuntimeEnvironment } from "./RuntimeEnvironment";
|
|
33
|
-
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Record of modules accepted by the Runtime module container.
|
|
@@ -223,7 +223,7 @@ export class Runtime<Modules extends RuntimeModulesRecord>
|
|
|
223
223
|
public create(childContainerProvider: ChildContainerProvider) {
|
|
224
224
|
super.create(childContainerProvider);
|
|
225
225
|
|
|
226
|
-
this.
|
|
226
|
+
this.useDependencyFactory(this.container.resolve(MethodIdFactory));
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
public get appChain(): AreProofsEnabled | undefined {
|
|
@@ -258,16 +258,15 @@ export class Runtime<Modules extends RuntimeModulesRecord>
|
|
|
258
258
|
public getMethodById(
|
|
259
259
|
methodId: bigint
|
|
260
260
|
): ((...args: unknown[]) => unknown) | undefined {
|
|
261
|
-
const methodDescriptor =
|
|
262
|
-
.
|
|
263
|
-
.getMethodNameFromId(methodId);
|
|
261
|
+
const methodDescriptor =
|
|
262
|
+
this.methodIdResolver.getMethodNameFromId(methodId);
|
|
264
263
|
|
|
265
264
|
if (methodDescriptor === undefined) {
|
|
266
265
|
return undefined;
|
|
267
266
|
}
|
|
268
267
|
const [moduleName, methodName] = methodDescriptor;
|
|
269
268
|
|
|
270
|
-
this.
|
|
269
|
+
this.assertIsValidModuleName(this.definition.modules, moduleName);
|
|
271
270
|
const module = this.resolve(moduleName);
|
|
272
271
|
|
|
273
272
|
// eslint-disable-next-line max-len
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigurableModule, Presets } from "@proto-kit/common";
|
|
1
|
+
import { ConfigurableModule, NoConfig, Presets } from "@proto-kit/common";
|
|
2
2
|
import { container, injectable } from "tsyringe";
|
|
3
3
|
import {
|
|
4
4
|
NetworkState,
|
|
@@ -25,7 +25,9 @@ const errors = {
|
|
|
25
25
|
* Base class for runtime modules providing the necessary utilities.
|
|
26
26
|
*/
|
|
27
27
|
@injectable()
|
|
28
|
-
export class RuntimeModule<
|
|
28
|
+
export class RuntimeModule<
|
|
29
|
+
Config = NoConfig
|
|
30
|
+
> extends ConfigurableModule<Config> {
|
|
29
31
|
public static presets: Presets<unknown> = {};
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CachedMerkleTreeStore,
|
|
3
|
-
InMemoryMerkleTreeStorage,
|
|
4
|
-
RollupMerkleTree,
|
|
5
|
-
} from "@proto-kit/protocol";
|
|
6
|
-
import { MockAsyncMerkleTreeStore } from "./MockAsyncMerkleStore";
|
|
7
|
-
import { beforeEach } from "@jest/globals";
|
|
8
|
-
import { Field, Poseidon } from "o1js";
|
|
9
|
-
import { log } from "@proto-kit/common";
|
|
10
|
-
|
|
11
|
-
describe("cachedMerkleTree", () => {
|
|
12
|
-
let store: MockAsyncMerkleTreeStore;
|
|
13
|
-
let syncStore: InMemoryMerkleTreeStorage;
|
|
14
|
-
let tree: RollupMerkleTree;
|
|
15
|
-
|
|
16
|
-
let cached: CachedMerkleTreeStore;
|
|
17
|
-
let cachedTree: RollupMerkleTree;
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
log.setLevel("DEBUG");
|
|
21
|
-
|
|
22
|
-
store = new MockAsyncMerkleTreeStore();
|
|
23
|
-
syncStore = store.store;
|
|
24
|
-
tree = new RollupMerkleTree(syncStore);
|
|
25
|
-
|
|
26
|
-
tree.setLeaf(1n, Field(10));
|
|
27
|
-
tree.setLeaf(3n, Field(30));
|
|
28
|
-
tree.setLeaf(5n, Field(50));
|
|
29
|
-
|
|
30
|
-
cached = new CachedMerkleTreeStore(store);
|
|
31
|
-
await cached.preloadKey(1n);
|
|
32
|
-
await cached.preloadKey(3n);
|
|
33
|
-
await cached.preloadKey(5n);
|
|
34
|
-
cachedTree = new RollupMerkleTree(cached);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should have the same root", async () => {
|
|
38
|
-
expect(cached.getNode(1n, 0)).toBe(10n);
|
|
39
|
-
expect(cached.getNode(3n, 0)).toBe(30n);
|
|
40
|
-
expect(cached.getNode(5n, 0)).toBe(50n);
|
|
41
|
-
expect(syncStore.getNode(5n, 0)).toBe(50n);
|
|
42
|
-
|
|
43
|
-
expect(cached.getNode(0n, 1)).toBe(
|
|
44
|
-
Poseidon.hash([Field(0), Field(10)]).toBigInt()
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(cached.getNode(0n, 254)).toBe(await store.getNode(0n, 254));
|
|
48
|
-
expect(cached.getNode(0n, 254)).toBe(syncStore.getNode(0n, 254));
|
|
49
|
-
|
|
50
|
-
expect(cachedTree.getRoot().toBigInt()).toBe(tree.getRoot().toBigInt());
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should load the correct root when only loading a subset of keys", async () => {
|
|
54
|
-
await cached.preloadKey(3n);
|
|
55
|
-
|
|
56
|
-
const correctRoot = tree.getRoot();
|
|
57
|
-
expect(cachedTree.getRoot().toBigInt()).toBe(correctRoot.toBigInt());
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should generate correct witnesses when only loading a subset of keys", async () => {
|
|
61
|
-
await cached.preloadKey(5n);
|
|
62
|
-
|
|
63
|
-
const correctRoot = tree.getRoot();
|
|
64
|
-
const witness = tree.getWitness(5n);
|
|
65
|
-
expect(witness.calculateRoot(Field(50)).toBigInt()).toBe(
|
|
66
|
-
correctRoot.toBigInt()
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should generate correct witnesses after merging", async () => {
|
|
71
|
-
expect(cachedTree.getRoot().toBigInt()).toBe(tree.getRoot().toBigInt());
|
|
72
|
-
|
|
73
|
-
await cached.preloadKey(5n);
|
|
74
|
-
cachedTree.setLeaf(5n, Field(100));
|
|
75
|
-
|
|
76
|
-
const correctRoot = cachedTree.getRoot();
|
|
77
|
-
|
|
78
|
-
await cached.mergeIntoParent();
|
|
79
|
-
|
|
80
|
-
const cached2 = new CachedMerkleTreeStore(store);
|
|
81
|
-
await cached2.preloadKey(1n);
|
|
82
|
-
await cached2.preloadKey(3n);
|
|
83
|
-
await cached2.preloadKey(5n);
|
|
84
|
-
expect(cached2.getNode(1n, 0)).toBe(10n);
|
|
85
|
-
expect(cached2.getNode(3n, 0)).toBe(30n);
|
|
86
|
-
expect(cached2.getNode(5n, 0)).toBe(100n);
|
|
87
|
-
const tree2 = new RollupMerkleTree(cached2);
|
|
88
|
-
|
|
89
|
-
const witness = tree2.getWitness(3n);
|
|
90
|
-
|
|
91
|
-
expect(witness.calculateRoot(Field(30)).toBigInt()).toBe(
|
|
92
|
-
correctRoot.toBigInt()
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AsyncMerkleTreeStore, InMemoryMerkleTreeStorage } from "@proto-kit/protocol";
|
|
2
|
-
import { noop } from "@proto-kit/common";
|
|
3
|
-
|
|
4
|
-
export class MockAsyncMerkleTreeStore implements AsyncMerkleTreeStore {
|
|
5
|
-
public readonly store = new InMemoryMerkleTreeStorage();
|
|
6
|
-
|
|
7
|
-
public commit(): void {
|
|
8
|
-
noop();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public openTransaction(): void {
|
|
12
|
-
noop();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public async getNodeAsync(
|
|
16
|
-
key: bigint,
|
|
17
|
-
level: number
|
|
18
|
-
): Promise<bigint | undefined> {
|
|
19
|
-
return this.store.getNode(key, level);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public async setNodeAsync(
|
|
23
|
-
key: bigint,
|
|
24
|
-
level: number,
|
|
25
|
-
value: bigint
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
this.store.setNode(key, level, value);
|
|
28
|
-
}
|
|
29
|
-
}
|