@hazae41/bobine 0.0.19 → 0.0.20
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/README.md +7 -1
- package/out/libs/metering/mod.js +134 -34
- package/out/mod.d.ts +1 -1
- package/out/mod.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
A blockchain in your garage
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
|
|
6
|
+
deno install -gf -A npm:@hazae41/bobine
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
[**🌐 Website**](https://bobine.tech/) • [**📦 NPM**](https://www.npmjs.com/package/@hazae41/bobine)
|
|
@@ -23,6 +23,12 @@ npm install -g @hazae41/bobine
|
|
|
23
23
|
|
|
24
24
|
### Running the server
|
|
25
25
|
|
|
26
|
+
Install Deno
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install -g deno
|
|
30
|
+
```
|
|
31
|
+
|
|
26
32
|
Install the binary with Deno
|
|
27
33
|
|
|
28
34
|
```bash
|
package/out/libs/metering/mod.js
CHANGED
|
@@ -1,57 +1,157 @@
|
|
|
1
|
+
// deno-lint-ignore-file prefer-const
|
|
1
2
|
import * as Wasm from "@hazae41/wasm";
|
|
2
3
|
export function meter(module, from, name) {
|
|
3
4
|
let wtype = module.body.sections.find(section => section.kind === Wasm.TypeSection.kind);
|
|
5
|
+
let wimport = module.body.sections.find(section => section.kind === Wasm.ImportSection.kind);
|
|
6
|
+
let wexport = module.body.sections.find(section => section.kind === Wasm.ExportSection.kind);
|
|
7
|
+
let wcode = module.body.sections.find(section => section.kind === Wasm.CodeSection.kind);
|
|
8
|
+
let welem = module.body.sections.find(section => section.kind === Wasm.ElementSection.kind);
|
|
9
|
+
let wstart = module.body.sections.find(section => section.kind === Wasm.StartSection.kind);
|
|
4
10
|
if (wtype == null) {
|
|
5
11
|
wtype = new Wasm.TypeSection([]);
|
|
6
12
|
module.body.sections.unshift(wtype);
|
|
7
13
|
}
|
|
8
|
-
let wimport = module.body.sections.find(section => section.kind === Wasm.ImportSection.kind);
|
|
9
14
|
if (wimport == null) {
|
|
10
15
|
wimport = new Wasm.ImportSection([]);
|
|
11
16
|
const before = module.body.sections.findLastIndex(section => section.kind < Wasm.ImportSection.kind);
|
|
12
17
|
module.body.sections.splice(before + 1, 0, wimport);
|
|
13
18
|
}
|
|
14
|
-
let wexport = module.body.sections.find(section => section.kind === Wasm.ExportSection.kind);
|
|
15
|
-
if (wexport == null) {
|
|
16
|
-
wexport = new Wasm.ExportSection([]);
|
|
17
|
-
const before = module.body.sections.findLastIndex(section => section.kind < Wasm.ExportSection.kind);
|
|
18
|
-
module.body.sections.splice(before + 1, 0, wexport);
|
|
19
|
-
}
|
|
20
|
-
let wcode = module.body.sections.find(section => section.kind === Wasm.CodeSection.kind);
|
|
21
|
-
if (wcode == null) {
|
|
22
|
-
wcode = new Wasm.CodeSection([]);
|
|
23
|
-
const before = module.body.sections.findLastIndex(section => section.kind < Wasm.CodeSection.kind);
|
|
24
|
-
module.body.sections.splice(before + 1, 0, wcode);
|
|
25
|
-
}
|
|
26
|
-
const wstart = module.body.sections.find(section => section.kind === Wasm.StartSection.kind);
|
|
27
19
|
wtype.descriptors.push({ prefix: Wasm.TypeSection.FuncType.kind, subtypes: [], body: new Wasm.TypeSection.FuncType([0x7f], []) });
|
|
28
20
|
wimport.descriptors.unshift({ from: new TextEncoder().encode(from), name: new TextEncoder().encode(name), body: new Wasm.ImportSection.FunctionImport(wtype.descriptors.length - 1) });
|
|
29
21
|
if (wstart != null)
|
|
30
22
|
wstart.funcidx++;
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
if (welem != null) {
|
|
24
|
+
for (const segment of welem.segments) {
|
|
25
|
+
switch (segment.flag) {
|
|
26
|
+
case 0: {
|
|
27
|
+
for (let i = 0; i < segment.funcidxs.length; i++) {
|
|
28
|
+
segment.funcidxs[i]++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
for (const instruction of segment.instructions) {
|
|
32
|
+
if (![0xd2].includes(instruction.opcode))
|
|
33
|
+
continue;
|
|
34
|
+
instruction.params[0].value++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 1: {
|
|
40
|
+
for (const element of segment.elements) {
|
|
41
|
+
for (const instruction of element) {
|
|
42
|
+
if (![0xd2].includes(instruction.opcode))
|
|
43
|
+
continue;
|
|
44
|
+
instruction.params[0].value++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 2: {
|
|
52
|
+
for (const instruction of segment.instructions) {
|
|
53
|
+
if (![0xd2].includes(instruction.opcode))
|
|
54
|
+
continue;
|
|
55
|
+
instruction.params[0].value++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
for (const element of segment.elements) {
|
|
59
|
+
for (const instruction of element) {
|
|
60
|
+
if (![0xd2].includes(instruction.opcode))
|
|
61
|
+
continue;
|
|
62
|
+
instruction.params[0].value++;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 3: {
|
|
70
|
+
for (const element of segment.elements) {
|
|
71
|
+
for (const instruction of element) {
|
|
72
|
+
if (![0xd2].includes(instruction.opcode))
|
|
73
|
+
continue;
|
|
74
|
+
instruction.params[0].value++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case 4: {
|
|
82
|
+
for (let i = 0; i < segment.funcidxs.length; i++) {
|
|
83
|
+
segment.funcidxs[i]++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const instruction of segment.instructions) {
|
|
87
|
+
if (![0xd2].includes(instruction.opcode))
|
|
88
|
+
continue;
|
|
89
|
+
instruction.params[0].value++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 5: {
|
|
95
|
+
for (let i = 0; i < segment.funcidxs.length; i++) {
|
|
96
|
+
segment.funcidxs[i]++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 6: {
|
|
102
|
+
for (let i = 0; i < segment.funcidxs.length; i++) {
|
|
103
|
+
segment.funcidxs[i]++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
for (const instruction of segment.instructions) {
|
|
107
|
+
if (![0xd2].includes(instruction.opcode))
|
|
108
|
+
continue;
|
|
109
|
+
instruction.params[0].value++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 7: {
|
|
115
|
+
for (let i = 0; i < segment.funcidxs.length; i++) {
|
|
116
|
+
segment.funcidxs[i]++;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
43
121
|
}
|
|
44
|
-
|
|
45
|
-
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (wcode != null) {
|
|
126
|
+
for (const body of wcode.bodies) {
|
|
127
|
+
const instructions = new Array();
|
|
128
|
+
const subinstructions = new Array();
|
|
129
|
+
for (const instruction of body.instructions) {
|
|
130
|
+
if ([0x10, 0x12, 0xd2].includes(instruction.opcode))
|
|
131
|
+
instruction.params[0].value++;
|
|
132
|
+
if ([0x03, 0x04, 0x05, 0x0B, 0x0c, 0x0D, 0x0E, 0x0F, 0xd5, 0xd6].includes(instruction.opcode)) {
|
|
133
|
+
subinstructions.push(instruction);
|
|
134
|
+
instructions.push(new Wasm.Instruction(0x41, [new Wasm.LEB128.I32(subinstructions.length)]));
|
|
135
|
+
instructions.push(new Wasm.Instruction(0x10, [new Wasm.LEB128.U32(0)]));
|
|
136
|
+
instructions.push(...subinstructions);
|
|
137
|
+
subinstructions.length = 0;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
subinstructions.push(instruction);
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
46
143
|
}
|
|
144
|
+
instructions.push(...subinstructions);
|
|
145
|
+
body.instructions = instructions;
|
|
146
|
+
continue;
|
|
47
147
|
}
|
|
48
|
-
instructions.push(...subinstructions);
|
|
49
|
-
body.instructions = instructions;
|
|
50
|
-
continue;
|
|
51
148
|
}
|
|
52
|
-
|
|
53
|
-
|
|
149
|
+
if (wexport != null) {
|
|
150
|
+
for (const descriptor of wexport.descriptors) {
|
|
151
|
+
if (descriptor.kind !== 0x00)
|
|
152
|
+
continue;
|
|
153
|
+
descriptor.xidx++;
|
|
54
154
|
continue;
|
|
55
|
-
|
|
155
|
+
}
|
|
56
156
|
}
|
|
57
157
|
}
|
package/out/mod.d.ts
CHANGED
package/out/mod.js
CHANGED