wao 0.7.1 → 0.8.0
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/cjs/ao.js +8 -3
- package/cjs/aoconnect.js +570 -365
- package/cjs/armem.js +399 -73
- package/cjs/run.js +19 -3
- package/cjs/server.js +4 -2
- package/cjs/tao.js +3 -1
- package/cjs/tar.js +185 -103
- package/esm/ao.js +4 -1
- package/esm/aoconnect.js +60 -54
- package/esm/armem.js +94 -7
- package/esm/run.js +15 -4
- package/esm/server.js +3 -2
- package/esm/tao.js +5 -1
- package/esm/tar.js +31 -25
- package/package.json +3 -3
- package/esm/.cache/opt.json +0 -1
package/esm/aoconnect.js
CHANGED
|
@@ -23,12 +23,12 @@ import { scheduler, mu, su, cu, acc } from "./test.js"
|
|
|
23
23
|
import { is, clone, fromPairs, map, mergeLeft, isNil } from "ramda"
|
|
24
24
|
import AR from "./tar.js"
|
|
25
25
|
|
|
26
|
-
export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
26
|
+
export const connect = (mem, { cache, log = false, extensions = {} } = {}) => {
|
|
27
27
|
const isMem = mem?.__type__ === "mem"
|
|
28
28
|
if (!isMem) {
|
|
29
|
-
let args = {}
|
|
29
|
+
let args = { cache }
|
|
30
30
|
if (mem?.SU_URL) {
|
|
31
|
-
args = mem
|
|
31
|
+
args = mergeLeft(mem, args)
|
|
32
32
|
args.scheduler = scheduler
|
|
33
33
|
}
|
|
34
34
|
mem = new ArMem(args)
|
|
@@ -56,14 +56,14 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
56
56
|
return output
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const genMsg = (Id, p, data, Tags, from, Owner, dry = false) => {
|
|
59
|
+
const genMsg = async (Id, p, data, Tags, from, Owner, dry = false) => {
|
|
60
60
|
if (!dry) p.height += 1
|
|
61
61
|
return {
|
|
62
62
|
Id,
|
|
63
63
|
Target: p.id,
|
|
64
64
|
Owner,
|
|
65
65
|
Data: data?.length ? data : "",
|
|
66
|
-
"Block-Height": mem.height.toString(),
|
|
66
|
+
"Block-Height": (await mem.get("height")).toString(),
|
|
67
67
|
Timestamp: Date.now().toString(),
|
|
68
68
|
Module: p.module,
|
|
69
69
|
From: from,
|
|
@@ -94,31 +94,10 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
94
94
|
},
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
98
97
|
const spawn = async (opt = {}) => {
|
|
99
98
|
if (!opt.module) throw Error("module missing")
|
|
100
99
|
if (!opt.scheduler) throw Error("scheduler missing")
|
|
101
|
-
|
|
102
|
-
let _module = null
|
|
103
|
-
const __dirname = await dirname()
|
|
104
|
-
let format = null
|
|
105
|
-
let wasm = mem.wasms[mod]?.data
|
|
106
|
-
if (!wasm) {
|
|
107
|
-
if (mem.wasms[mod]?.file) {
|
|
108
|
-
wasm = readFileSync(
|
|
109
|
-
resolve(__dirname, `lua/${mem.wasms[mod].file}.wasm`),
|
|
110
|
-
)
|
|
111
|
-
format = mem.wasms[mod].format
|
|
112
|
-
} else if (mem.txs[mod]) {
|
|
113
|
-
wasm = Buffer.from(mem.txs[mod].data, "base64")
|
|
114
|
-
format = tags(mem.txs[mod].tags)["Module-Format"]
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
format = mem.wasms[mod].format
|
|
118
|
-
}
|
|
119
|
-
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
120
|
-
|
|
121
|
-
if (!mod) throw Error("module not found")
|
|
100
|
+
const { mod, wasm, format } = await mem.getWasm(opt.module, mem)
|
|
122
101
|
opt.tags = buildTags(
|
|
123
102
|
null,
|
|
124
103
|
mergeLeft(tags(opt.tags ?? []), {
|
|
@@ -132,7 +111,6 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
132
111
|
}),
|
|
133
112
|
)
|
|
134
113
|
let ex = false
|
|
135
|
-
opt.tags ??= []
|
|
136
114
|
for (let v of opt.tags) if (v.name === "Type") ex = true
|
|
137
115
|
if (!ex) opt.tags.push({ name: "Type", value: "Process" })
|
|
138
116
|
const {
|
|
@@ -151,24 +129,28 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
151
129
|
await ar.postItems(item, su.jwk)
|
|
152
130
|
const now = Date.now
|
|
153
131
|
const t = tags(opt.tags)
|
|
154
|
-
const
|
|
132
|
+
const ext = t.Extension || "WeaveDrive"
|
|
133
|
+
const wdrive = extensions[ext]
|
|
155
134
|
let handle = null
|
|
156
135
|
try {
|
|
157
136
|
handle = await AoLoader(wasm, {
|
|
158
137
|
format,
|
|
159
138
|
WeaveDrive: wdrive,
|
|
160
139
|
spawn: item,
|
|
161
|
-
module: mem.txs
|
|
140
|
+
module: await mem.get("txs", mod),
|
|
162
141
|
})
|
|
163
142
|
} catch (e) {}
|
|
164
143
|
if (!handle) return null
|
|
144
|
+
let _module = null
|
|
165
145
|
_module = { handle, id: mod }
|
|
166
146
|
Date.now = now
|
|
167
|
-
|
|
168
147
|
const _tags = tags(opt.tags)
|
|
169
148
|
let res = null
|
|
170
|
-
let memory = null
|
|
149
|
+
let memory = opt.memory ?? null
|
|
171
150
|
let p = {
|
|
151
|
+
extension: ext,
|
|
152
|
+
item: item?.binary,
|
|
153
|
+
format,
|
|
172
154
|
id: id,
|
|
173
155
|
epochs: [],
|
|
174
156
|
handle: _module.handle,
|
|
@@ -182,18 +164,19 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
182
164
|
txs: [],
|
|
183
165
|
opt,
|
|
184
166
|
}
|
|
185
|
-
if (
|
|
167
|
+
if (memory) {
|
|
168
|
+
// forking...
|
|
169
|
+
} else if (_tags["On-Boot"] || true) {
|
|
186
170
|
let data = ""
|
|
187
171
|
if (_tags["On-Boot"] === "Data") data = opt.data ?? ""
|
|
188
|
-
else data = mem.msgs
|
|
189
|
-
let msg = genMsg(id, p, data, opt.tags, owner, mu.addr, true)
|
|
172
|
+
else data = (await mem.get("msgs", _tags["On-Boot"]))?.data ?? ""
|
|
173
|
+
let msg = await genMsg(id, p, data, opt.tags, owner, mu.addr, true)
|
|
190
174
|
const _env = genEnv({
|
|
191
175
|
pid: p.id,
|
|
192
176
|
owner: p.owner,
|
|
193
177
|
module: p.module,
|
|
194
178
|
auth: mu.addr,
|
|
195
179
|
})
|
|
196
|
-
const _t = tags(msg.Tags)
|
|
197
180
|
res = await _module.handle(null, msg, _env)
|
|
198
181
|
p.memory = res.Memory
|
|
199
182
|
delete res.Memory
|
|
@@ -201,8 +184,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
201
184
|
} else {
|
|
202
185
|
p.height += 1
|
|
203
186
|
}
|
|
204
|
-
mem.msgs
|
|
205
|
-
mem.env[id] = p
|
|
187
|
+
await mem.set(opt, "msgs", id)
|
|
206
188
|
if (_tags["Cron-Interval"]) {
|
|
207
189
|
let [num, unit] = _tags["Cron-Interval"].split("-")
|
|
208
190
|
let int = 0
|
|
@@ -235,9 +217,10 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
235
217
|
cronTags.push({ name: k.replace(/Cron-Tag-/, ""), value: _tags[k] })
|
|
236
218
|
}
|
|
237
219
|
}
|
|
238
|
-
|
|
239
|
-
|
|
220
|
+
p.cronTags = cronTags
|
|
221
|
+
p.span = int
|
|
240
222
|
}
|
|
223
|
+
await mem.set(p, "env", id)
|
|
241
224
|
return id
|
|
242
225
|
}
|
|
243
226
|
|
|
@@ -251,9 +234,9 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
251
234
|
}
|
|
252
235
|
|
|
253
236
|
const assign = async opt => {
|
|
254
|
-
const p = mem.env
|
|
237
|
+
const p = await mem.get("env", opt.process)
|
|
255
238
|
if (!p) return null
|
|
256
|
-
let _opt = mem.msgs
|
|
239
|
+
let _opt = await mem.get("msgs", opt.message)
|
|
257
240
|
let hash = genHashChain(p.hash, opt.message)
|
|
258
241
|
p.hash = hash
|
|
259
242
|
opt.tags = buildTags(
|
|
@@ -266,7 +249,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
266
249
|
Variant: "ao.TN.1",
|
|
267
250
|
SDK: "aoconnect",
|
|
268
251
|
Type: "Assignment",
|
|
269
|
-
"Block-Height": mem.height,
|
|
252
|
+
"Block-Height": await mem.get("height"),
|
|
270
253
|
Process: opt.process,
|
|
271
254
|
Message: opt.message,
|
|
272
255
|
"Hash-Chain": hash,
|
|
@@ -304,22 +287,34 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
304
287
|
}
|
|
305
288
|
}
|
|
306
289
|
// check: is owner=mu.addr right?
|
|
307
|
-
const msg = genMsg(opt.message, p, data, _tags, from, mu.addr)
|
|
290
|
+
const msg = await genMsg(opt.message, p, data, _tags, from, mu.addr)
|
|
308
291
|
const _env = genEnv({
|
|
309
292
|
pid: p.id,
|
|
310
293
|
owner: p.owner,
|
|
311
294
|
module: p.module,
|
|
312
295
|
auth: mu.addr,
|
|
313
296
|
})
|
|
297
|
+
if (!p.handle) {
|
|
298
|
+
const { format, mod, wasm } = await mem.getWasm(p.modulea)
|
|
299
|
+
const wdrive = extensions[p.extention]
|
|
300
|
+
p.handle = await AoLoader(wasm, {
|
|
301
|
+
format,
|
|
302
|
+
WeaveDrive: wdrive,
|
|
303
|
+
spawn: new DataItem(p.item),
|
|
304
|
+
module: await mem.get("txs", mod),
|
|
305
|
+
})
|
|
306
|
+
mem.env[opt.process].handle = p.handle
|
|
307
|
+
}
|
|
314
308
|
const res = await p.handle(p.memory, msg, _env)
|
|
315
309
|
p.memory = res.Memory
|
|
316
310
|
delete res.Memory
|
|
317
311
|
p.res[opt.message] = res
|
|
318
312
|
p.results.push(opt.message)
|
|
319
313
|
p.txs.unshift({ id, ...opt })
|
|
320
|
-
mem.
|
|
314
|
+
await mem.set(p, "env", opt.process)
|
|
315
|
+
await mem.set(_opt, "msgs", opt.message)
|
|
321
316
|
for (const v of res.Messages ?? []) {
|
|
322
|
-
if (mem.env
|
|
317
|
+
if (await mem.get("env", v.Target)) {
|
|
323
318
|
await message({
|
|
324
319
|
process: v.Target,
|
|
325
320
|
tags: v.Tags,
|
|
@@ -359,7 +354,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
359
354
|
}
|
|
360
355
|
|
|
361
356
|
const message = async opt => {
|
|
362
|
-
const p = mem.env
|
|
357
|
+
const p = await mem.get("env", opt.process)
|
|
363
358
|
if (!p) return null
|
|
364
359
|
let ex = false
|
|
365
360
|
let id = opt?.item?.id ?? ""
|
|
@@ -383,7 +378,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
383
378
|
target: opt.process,
|
|
384
379
|
}))
|
|
385
380
|
}
|
|
386
|
-
mem.msgs
|
|
381
|
+
await mem.set(opt, "msgs", id)
|
|
387
382
|
await assign({
|
|
388
383
|
message_item: item,
|
|
389
384
|
message: id,
|
|
@@ -397,14 +392,14 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
397
392
|
return {
|
|
398
393
|
message,
|
|
399
394
|
unmonitor: async opt => {
|
|
400
|
-
const p = mem.env
|
|
395
|
+
const p = await mem.get("env", opt.process)
|
|
401
396
|
try {
|
|
402
397
|
clearInterval(p.cron)
|
|
403
398
|
p.cron = null
|
|
404
399
|
} catch (e) {}
|
|
405
400
|
},
|
|
406
401
|
monitor: async opt => {
|
|
407
|
-
const p = mem.env
|
|
402
|
+
const p = await mem.get("env", opt.process)
|
|
408
403
|
if (isNil(p.cron)) {
|
|
409
404
|
p.cron = setInterval(async () => {
|
|
410
405
|
await message({
|
|
@@ -419,9 +414,9 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
419
414
|
spawn,
|
|
420
415
|
assign,
|
|
421
416
|
ar,
|
|
422
|
-
result: async opt => mem.env
|
|
417
|
+
result: async opt => (await mem.get("env", opt.process)).res[opt.message],
|
|
423
418
|
results: async opt => {
|
|
424
|
-
const p = mem.env
|
|
419
|
+
const p = await mem.get("env", opt.process)
|
|
425
420
|
let results = []
|
|
426
421
|
const limit = opt.limit ?? 25
|
|
427
422
|
if (opt.sort === "DESC") {
|
|
@@ -438,7 +433,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
438
433
|
return { edges: results }
|
|
439
434
|
},
|
|
440
435
|
dryrun: async opt => {
|
|
441
|
-
const p = mem.env
|
|
436
|
+
const p = await mem.get("env", opt.process)
|
|
442
437
|
if (!p) return null
|
|
443
438
|
let id = opt.id ?? ""
|
|
444
439
|
let owner = opt.owner ?? ""
|
|
@@ -446,7 +441,7 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
446
441
|
;({ id, owner } = await ar.dataitem({ ...opt, target: opt.process }))
|
|
447
442
|
}
|
|
448
443
|
try {
|
|
449
|
-
const msg = genMsg(
|
|
444
|
+
const msg = await genMsg(
|
|
450
445
|
id,
|
|
451
446
|
p,
|
|
452
447
|
opt.data ?? "",
|
|
@@ -469,6 +464,17 @@ export const connect = (mem, { log = false, extensions = {} } = {}) => {
|
|
|
469
464
|
shared: memory.shared || false,
|
|
470
465
|
})
|
|
471
466
|
}
|
|
467
|
+
if (!p.handle) {
|
|
468
|
+
const { format, mod, wasm } = await mem.getWasm(p.modulea)
|
|
469
|
+
const wdrive = extensions[p.extention]
|
|
470
|
+
p.handle = await AoLoader(wasm, {
|
|
471
|
+
format,
|
|
472
|
+
WeaveDrive: wdrive,
|
|
473
|
+
spawn: new DataItem(p.item),
|
|
474
|
+
module: await mem.get("txs", mod),
|
|
475
|
+
})
|
|
476
|
+
mem.env[opt.process].handle = p.handle
|
|
477
|
+
}
|
|
472
478
|
const res = await p.handle(p.memory, msg, _env)
|
|
473
479
|
return res
|
|
474
480
|
} catch (e) {
|
package/esm/armem.js
CHANGED
|
@@ -1,12 +1,83 @@
|
|
|
1
1
|
import Arweave from "arweave"
|
|
2
2
|
import { last } from "ramda"
|
|
3
|
-
import { buildTags } from "./utils.js"
|
|
3
|
+
import { tags, buildTags, dirname } from "./utils.js"
|
|
4
|
+
import { open } from "lmdb"
|
|
5
|
+
import { readFileSync } from "fs"
|
|
6
|
+
import { resolve } from "path"
|
|
7
|
+
|
|
4
8
|
export default class ArMem {
|
|
5
|
-
constructor({ MU_URL, CU_URL, SU_URL, GATEWAY_URL, scheduler } = {}) {
|
|
9
|
+
constructor({ MU_URL, CU_URL, SU_URL, GATEWAY_URL, scheduler, cache } = {}) {
|
|
6
10
|
this.__type__ = "mem"
|
|
11
|
+
this.isInit = false
|
|
12
|
+
if (cache) this.db = open({ path: cache, compression: true })
|
|
7
13
|
this.arweave = Arweave.init()
|
|
8
14
|
this.arweave.transactions.getTransactionAnchor = () => this.getAnchor()
|
|
9
15
|
this.arweave.transactions.getPrice = () => 0
|
|
16
|
+
this.scheduler = scheduler
|
|
17
|
+
this.SU_URL = SU_URL
|
|
18
|
+
this.initSync()
|
|
19
|
+
}
|
|
20
|
+
async putAll(key) {
|
|
21
|
+
for (let k in this[key]) await this.set(this[key][k], key, k)
|
|
22
|
+
}
|
|
23
|
+
async init() {
|
|
24
|
+
if (this.isInit) return
|
|
25
|
+
this.isInit = true
|
|
26
|
+
if (this.db) {
|
|
27
|
+
for (const v of ["height", "blocks"]) this[v] = await this.get(v)
|
|
28
|
+
for (const v of [
|
|
29
|
+
"txs",
|
|
30
|
+
"jwks",
|
|
31
|
+
"env",
|
|
32
|
+
"modules",
|
|
33
|
+
"wasms",
|
|
34
|
+
"addrmap",
|
|
35
|
+
"blockmap",
|
|
36
|
+
"modmap",
|
|
37
|
+
"msgs",
|
|
38
|
+
]) {
|
|
39
|
+
this[v] ??= {}
|
|
40
|
+
const items = await this.db.getKeys({ start: v, end: v + "a" })
|
|
41
|
+
for (const v2 of items) {
|
|
42
|
+
const key = v2.split(".")[0]
|
|
43
|
+
const field = v2.split(".")[1]
|
|
44
|
+
if (key === v) this[v][field] = await this.db.get(v2)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
for (const v of ["height", "blocks"]) await this.set(this[v], v)
|
|
49
|
+
for (const v of ["modules", "wasms", "addrmap", "blockmap"]) {
|
|
50
|
+
await this.putAll(v)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async getWasm(module) {
|
|
55
|
+
let mod = module ?? this.modules.aos2_0_1
|
|
56
|
+
if (!mod) throw Error("module not found")
|
|
57
|
+
const __dirname = await dirname()
|
|
58
|
+
let format = null
|
|
59
|
+
let _wasm = await this.wasms[mod]
|
|
60
|
+
let wasm = _wasm?.data
|
|
61
|
+
if (!wasm) {
|
|
62
|
+
if (_wasm?.file) {
|
|
63
|
+
wasm = readFileSync(
|
|
64
|
+
resolve(__dirname, `lua/${this.wasms[mod].file}.wasm`),
|
|
65
|
+
)
|
|
66
|
+
format = _wasm.format
|
|
67
|
+
} else {
|
|
68
|
+
const tx = await this.get("txs", mod)
|
|
69
|
+
if (tx) {
|
|
70
|
+
wasm = Buffer.from(tx.data, "base64")
|
|
71
|
+
format = tags(tx.tags)["Module-Format"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
format = _wasm.format
|
|
76
|
+
}
|
|
77
|
+
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
78
|
+
return { format, mod, wasm }
|
|
79
|
+
}
|
|
80
|
+
initSync() {
|
|
10
81
|
this.addrmap = {}
|
|
11
82
|
this.txs = {}
|
|
12
83
|
this.jwks = {}
|
|
@@ -54,19 +125,19 @@ export default class ArMem {
|
|
|
54
125
|
}),
|
|
55
126
|
}
|
|
56
127
|
}
|
|
57
|
-
if (scheduler && SU_URL) {
|
|
58
|
-
const key = scheduler
|
|
128
|
+
if (this.scheduler && this.SU_URL) {
|
|
129
|
+
const key = this.scheduler
|
|
59
130
|
txs.push(key)
|
|
60
|
-
this.addrmap[scheduler] = { address: scheduler }
|
|
131
|
+
this.addrmap[this.scheduler] = { address: this.scheduler }
|
|
61
132
|
this.txs[key] = {
|
|
62
133
|
id: key,
|
|
63
134
|
block: 0,
|
|
64
|
-
owner: scheduler,
|
|
135
|
+
owner: this.scheduler,
|
|
65
136
|
tags: buildTags(null, {
|
|
66
137
|
"Data-Protocol": "ao",
|
|
67
138
|
Variant: "ao.TN.1",
|
|
68
139
|
Type: "Scheduler-Location",
|
|
69
|
-
Url: SU_URL,
|
|
140
|
+
Url: this.SU_URL,
|
|
70
141
|
"Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10,
|
|
71
142
|
}),
|
|
72
143
|
}
|
|
@@ -86,4 +157,20 @@ export default class ArMem {
|
|
|
86
157
|
? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
87
158
|
: last(this.blockmap[last(this.blocks)].txs)
|
|
88
159
|
}
|
|
160
|
+
async get(key, field) {
|
|
161
|
+
await this.init()
|
|
162
|
+
if (!field) return this[key]
|
|
163
|
+
return this[key]?.[field]
|
|
164
|
+
}
|
|
165
|
+
async set(val, key, field) {
|
|
166
|
+
await this.init()
|
|
167
|
+
if (!field) {
|
|
168
|
+
this[key] = val
|
|
169
|
+
if (this.db) await this.db.put(`${key}`, this[key])
|
|
170
|
+
} else {
|
|
171
|
+
this[key] ??= {}
|
|
172
|
+
this[key][field] = val
|
|
173
|
+
if (this.db) await this.db.put(`${key}.${field}`, this[key][field])
|
|
174
|
+
}
|
|
175
|
+
}
|
|
89
176
|
}
|
package/esm/run.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --experimental-wasm-memory64
|
|
2
2
|
import yargs from "yargs"
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { resolve } from "path"
|
|
4
|
+
import { unlinkSync } from "fs"
|
|
5
5
|
import Server from "./server.js"
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
let {
|
|
7
|
+
reset = false,
|
|
8
|
+
memory = false,
|
|
9
|
+
port = 4000,
|
|
10
|
+
db = ".cache",
|
|
11
|
+
} = yargs(process.argv.slice(2)).argv
|
|
12
|
+
db = memory ? null : resolve(process.cwd(), db)
|
|
13
|
+
if (reset) {
|
|
14
|
+
try {
|
|
15
|
+
unlinkSync(db)
|
|
16
|
+
} catch (e) {}
|
|
17
|
+
}
|
|
18
|
+
const main = async () => new Server({ log: true, port, db })
|
|
8
19
|
|
|
9
20
|
main()
|
package/esm/server.js
CHANGED
|
@@ -16,6 +16,7 @@ class Server {
|
|
|
16
16
|
cu = 4004,
|
|
17
17
|
aoconnect,
|
|
18
18
|
log = false,
|
|
19
|
+
db,
|
|
19
20
|
port,
|
|
20
21
|
} = {}) {
|
|
21
22
|
if (port) {
|
|
@@ -35,7 +36,7 @@ class Server {
|
|
|
35
36
|
mem,
|
|
36
37
|
monitor,
|
|
37
38
|
unmonitor,
|
|
38
|
-
} = connect(aoconnect, { log })
|
|
39
|
+
} = connect(aoconnect, { log, cache: db })
|
|
39
40
|
this.monitor = monitor
|
|
40
41
|
this.unmonitor = unmonitor
|
|
41
42
|
this.spawn = spawn
|
|
@@ -288,7 +289,7 @@ class Server {
|
|
|
288
289
|
v.close(() => {
|
|
289
290
|
count += 1
|
|
290
291
|
if (count >= 4) {
|
|
291
|
-
console.log("servers closed!"
|
|
292
|
+
console.log("servers closed!")
|
|
292
293
|
res()
|
|
293
294
|
}
|
|
294
295
|
})
|
package/esm/tao.js
CHANGED
|
@@ -64,7 +64,11 @@ class AO extends MAO {
|
|
|
64
64
|
monitor,
|
|
65
65
|
unmonitor,
|
|
66
66
|
mem,
|
|
67
|
-
} = connect(opt.mem, {
|
|
67
|
+
} = connect(opt.mem, {
|
|
68
|
+
extensions: opt.extensions,
|
|
69
|
+
cache: opt.cache,
|
|
70
|
+
reset: opt.reset,
|
|
71
|
+
})
|
|
68
72
|
this.module = mem.modules.aos2_0_1
|
|
69
73
|
this.assign = assign
|
|
70
74
|
this.result = async (...opt) => {
|
package/esm/tar.js
CHANGED
|
@@ -8,6 +8,7 @@ import base64url from "base64url"
|
|
|
8
8
|
import ArMem from "./armem.js"
|
|
9
9
|
import GQL from "./tgql.js"
|
|
10
10
|
import { last, is, includes, isNil } from "ramda"
|
|
11
|
+
|
|
11
12
|
class AR extends MAR {
|
|
12
13
|
constructor(opt = {}) {
|
|
13
14
|
super({ ...opt, in_memory: true })
|
|
@@ -60,11 +61,8 @@ class AR extends MAR {
|
|
|
60
61
|
for (const t of di.tags)
|
|
61
62
|
if (t.name === "Content-Type") data_type = t.value
|
|
62
63
|
const owner = await this.owner(di)
|
|
63
|
-
this.mem.
|
|
64
|
+
await this.mem.set({ key: di.owner, address: owner }, "addrmap", owner)
|
|
64
65
|
let data = di.data
|
|
65
|
-
try {
|
|
66
|
-
//data = base64url.decode(di.data)
|
|
67
|
-
} catch (e) {}
|
|
68
66
|
let _item = {
|
|
69
67
|
_data: { size: data_size, type: data_type },
|
|
70
68
|
anchor: di.anchor,
|
|
@@ -76,7 +74,7 @@ class AR extends MAR {
|
|
|
76
74
|
tags: di.tags,
|
|
77
75
|
data,
|
|
78
76
|
}
|
|
79
|
-
this.mem.txs
|
|
77
|
+
await this.mem.set(_item, "txs", await di.id)
|
|
80
78
|
_items.push(_item)
|
|
81
79
|
}
|
|
82
80
|
const bundle = await bundleAndSignData(items, new ArweaveSigner(jwk))
|
|
@@ -96,21 +94,22 @@ class AR extends MAR {
|
|
|
96
94
|
|
|
97
95
|
let res = null
|
|
98
96
|
if (!tx.id) await this.mem.arweave.transactions.sign(tx, jwk)
|
|
99
|
-
this.mem.height
|
|
97
|
+
let height = (await this.mem.get("height")) + 1
|
|
98
|
+
await this.mem.set(height, "height")
|
|
100
99
|
let block = {
|
|
101
100
|
id: tx.id,
|
|
102
101
|
timestamp: Date.now(),
|
|
103
|
-
height
|
|
104
|
-
previous: last(this.mem.blocks) ?? "",
|
|
102
|
+
height,
|
|
103
|
+
previous: last(await this.mem.get("blocks")) ?? "",
|
|
105
104
|
txs: [],
|
|
106
105
|
}
|
|
107
106
|
let msg = null
|
|
108
107
|
if (items) {
|
|
109
108
|
for (const item of items) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
let _txs = item
|
|
110
|
+
_txs.parent = { id: tx.id }
|
|
111
|
+
_txs.bundledIn = { id: tx.id }
|
|
112
|
+
_txs.anchor = ""
|
|
114
113
|
const _tags = t(item.tags)
|
|
115
114
|
if (
|
|
116
115
|
includes(_tags.Type, [
|
|
@@ -129,9 +128,9 @@ class AR extends MAR {
|
|
|
129
128
|
for (const v of item.item.tags) {
|
|
130
129
|
if (v.name === "Content-Type") data_type = v.value
|
|
131
130
|
}
|
|
132
|
-
//this.mem.txs[tx.id]._data = { size: tx.data_size, type: data_type }
|
|
133
131
|
block.txs.push(item.id)
|
|
134
|
-
|
|
132
|
+
_txs.block = block.id
|
|
133
|
+
await this.mem.set(_txs, "txs", item.id)
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
let _tags = []
|
|
@@ -143,22 +142,29 @@ class AR extends MAR {
|
|
|
143
142
|
}
|
|
144
143
|
const __tags = t(_tags)
|
|
145
144
|
if (__tags.Type === "Module") {
|
|
146
|
-
this.mem.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
await this.mem.set(
|
|
146
|
+
{
|
|
147
|
+
data: Buffer.from(tx.data, "base64"),
|
|
148
|
+
format: __tags["Module-Format"],
|
|
149
|
+
},
|
|
150
|
+
"wasms",
|
|
151
|
+
tx.id,
|
|
152
|
+
)
|
|
150
153
|
}
|
|
151
154
|
tx.tags = _tags
|
|
152
155
|
tx.owner = await this.arweave.wallets.jwkToAddress({ n: tx.owner })
|
|
153
|
-
|
|
156
|
+
let _txs = tx
|
|
154
157
|
block.txs.push(tx.id)
|
|
155
|
-
|
|
156
|
-
this.mem.
|
|
157
|
-
this.mem.
|
|
158
|
+
_txs.block = block.id
|
|
159
|
+
await this.mem.set(_txs, "txs", tx.id)
|
|
160
|
+
let blocks = await this.mem.get("blocks")
|
|
161
|
+
blocks.push(block.id)
|
|
162
|
+
await this.mem.set(blocks, "blocks")
|
|
163
|
+
await this.mem.set(block, "blockmap", block.id)
|
|
158
164
|
|
|
159
165
|
if (jwk) {
|
|
160
166
|
const owner = await this.arweave.wallets.jwkToAddress(jwk)
|
|
161
|
-
this.mem.
|
|
167
|
+
await this.mem.set({ address: owner, key: jwk.n }, "addrmap", owner)
|
|
162
168
|
}
|
|
163
169
|
res = { id: tx.id, status: 200, statusText: "200" }
|
|
164
170
|
if (this.log) {
|
|
@@ -174,7 +180,7 @@ class AR extends MAR {
|
|
|
174
180
|
}
|
|
175
181
|
|
|
176
182
|
async tx(id) {
|
|
177
|
-
return this.mem.txs
|
|
183
|
+
return await this.mem.get("txs", id)
|
|
178
184
|
}
|
|
179
185
|
|
|
180
186
|
async data(id, _string, log) {
|
|
@@ -184,7 +190,7 @@ class AR extends MAR {
|
|
|
184
190
|
if (!isNil(_string.decode)) decode = _string.decode
|
|
185
191
|
if (!isNil(_string.string)) string = _string.string
|
|
186
192
|
}
|
|
187
|
-
let tx = this.mem.txs
|
|
193
|
+
let tx = await this.mem.get("txs", id)
|
|
188
194
|
let _data = tx?.data ?? null
|
|
189
195
|
if (tx?.format === 2 && _data) {
|
|
190
196
|
_data = Buffer.from(_data, "base64")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wao",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
"import": "./esm/test.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
"author": "",
|
|
22
|
-
"license": "MIT",
|
|
23
21
|
"dependencies": {
|
|
24
22
|
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
|
|
25
23
|
"@permaweb/ao-loader": "^0.0.44",
|
|
@@ -31,6 +29,8 @@
|
|
|
31
29
|
"cors": "^2.8.5",
|
|
32
30
|
"express": "^4.21.2",
|
|
33
31
|
"graphql": "^16.10.0",
|
|
32
|
+
"lmdb": "^3.2.2",
|
|
33
|
+
"pm2": "^5.4.3",
|
|
34
34
|
"ramda": "^0.30.1",
|
|
35
35
|
"yargs": "^17.7.2"
|
|
36
36
|
},
|
package/esm/.cache/opt.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"ar":{"port":4000},"jwk":{"kty":"RSA","n":"tBba3N1KKiDvu4TnAd_lhYDBXs0QrLH4Hgd6mHTeovFvZDLZHlNukT9SXeHx1_58hQWtcIPvS6F9tASdpMREKMVkG9hb6nMXtUCkTJE7PURvqeJf5VGJt9rUBtYaaJ_8eVJ3w98_RqUR0k0rYsYcJqiFFYaSFG2mIbyP7lBSUifF0dsOI1j1IRlvhZ02BOD7LJpwycX-fsXq7DAbpC6ywkuQ0EU830f3DefhfCQRRreZiKKNHRVvKhe9Z8LTjtMWHcAotg5-lLWLVUT1fO5tUnVwcJ_fGGFtLC1RGjryGg2ZOykktpDuALvZrZd3psIGQPnpuF75QYTVSbiadCK_JOelt8xcwIUphYAeWJQ6BNBmA8afPvVhS6rma0zp30ChXLQJEgtRWm9FpI-DQaM9PPcDlupsDFmmBtZGj0fLSTcpf00i0gpoDVJWcBVrd5aBiks0rRNUWRgWHadWBfBskUCrA1DG99seZOKKL9qLIknK3c6cTO068JegbwAW51eEH-etaoAvZ5mmyIB7LHKEomOQjeobek5_7OChwA66cS882gbFc3CfX0QdQRWWrNJ84hm3_xgHG6VjQOWNTh751WrVe4PnlLPvqKt8u2It4ZIlBxri7JklRxLL4Y1xkuV1a3gKllLVWizULPFN8Dms_7hjGSk1N3UUV3Bv_oxlRTk","e":"AQAB","d":"BQo4tAKraMdrZIhhI9yXIoFw2ybXbYXWuq-dGJ3FfbKB2nOD2QUe7Iixobf8Wf4HKeMRSggfNWYlGIy8HrILC3sOt936I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zuEvdmxZk9HWRRaPiKCif3uJfZtJ3_4WxpFvw-IYY3p8m3nt9qdU8EPhiZBEKdYdyAkHN6bIN9GbpUpUbEwYJXTCtqOgG4nuiWl8HWijk7QgcEO1gRG-pt4HzzFTa01BBIxdbelBii35uUoUVzco3dntUghotXOMGeCg"},"ao":{"module":"nrwqdbTzLYTALBkzLv9HwmF97b0eoGvlT3YwfJnyOjY","scheduler":"FKtGpY1kBbr8hBIocph3nMvadgBSQtQBTYnlAJetrDU","aoconnect":{"MU_URL":"http://localhost:4002","CU_URL":"http://localhost:4004","GATEWAY_URL":"http://localhost:4000"},"ar":{"port":4000},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s"},"ao2":{"module":"9Xx6YzV2-giIaD8b9HTewr0FxRjugwm5FCuaQU-kJvI","scheduler":"FKtGpY1kBbr8hBIocph3nMvadgBSQtQBTYnlAJetrDU","aoconnect":{"MU_URL":"http://localhost:4002","CU_URL":"http://localhost:4004","GATEWAY_URL":"http://localhost:4000"},"ar":{"port":4000},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s"},"authority":"7WspynohDWhx3_Q37pzHmDGStf2T_p8ghdk_XTSUm8s","targets":{"profile":false,"note":false,"asset":false},"modules":{"aos2":"9Xx6YzV2-giIaD8b9HTewr0FxRjugwm5FCuaQU-kJvI","aos1":"MSCReWoRQ3w3JmPvbsTvPFnJrdzPym0F61cdBGEsBgs","sqlite":"nrwqdbTzLYTALBkzLv9HwmF97b0eoGvlT3YwfJnyOjY"}}
|