wao 0.9.0 → 0.9.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/cjs/aoconnect-base.js +1332 -0
- package/cjs/aoconnect-web.js +15 -1317
- package/cjs/aoconnect.js +15 -1317
- package/cjs/ar-base.js +683 -0
- package/cjs/armem-base.js +438 -0
- package/cjs/armem-web.js +25 -409
- package/cjs/armem.js +30 -402
- package/cjs/bao.js +248 -0
- package/cjs/lfdb.js +165 -0
- package/cjs/tao.js +10 -222
- package/cjs/tar.js +8 -655
- package/cjs/wao.js +10 -222
- package/cjs/war.js +8 -655
- package/esm/aoconnect-base.js +482 -0
- package/esm/aoconnect-web.js +6 -482
- package/esm/aoconnect.js +6 -483
- package/esm/ar-base.js +215 -0
- package/esm/armem-base.js +172 -0
- package/esm/armem-web.js +9 -169
- package/esm/armem.js +7 -163
- package/esm/bao.js +125 -0
- package/esm/lfdb.js +68 -0
- package/esm/tao.js +4 -121
- package/esm/tar.js +3 -209
- package/esm/wao.js +4 -121
- package/esm/war.js +3 -209
- package/esm/web.js +0 -1
- package/package.json +2 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import _Arweave from "arweave"
|
|
2
|
+
const Arweave = _Arweave.default ?? _Arweave
|
|
3
|
+
|
|
4
|
+
import { last } from "ramda"
|
|
5
|
+
import { buildTags, tags } from "./utils.js"
|
|
6
|
+
|
|
7
|
+
export default class ArMemBase {
|
|
8
|
+
constructor({ MU_URL, CU_URL, SU_URL, GATEWAY_URL, scheduler, cache } = {}) {
|
|
9
|
+
this.__type__ = "mem"
|
|
10
|
+
this.isInit = false
|
|
11
|
+
this.keyInit = false
|
|
12
|
+
this.keys = {}
|
|
13
|
+
this.arweave = Arweave.init()
|
|
14
|
+
this.arweave.transactions.getTransactionAnchor = () => this.getAnchor()
|
|
15
|
+
this.arweave.transactions.getPrice = () => 0
|
|
16
|
+
this.scheduler = scheduler
|
|
17
|
+
this.SU_URL = SU_URL
|
|
18
|
+
}
|
|
19
|
+
getAnchor() {
|
|
20
|
+
return this.blocks.length === 0
|
|
21
|
+
? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
22
|
+
: last(this.blockmap[last(this.blocks)].txs)
|
|
23
|
+
}
|
|
24
|
+
async get(key, field) {
|
|
25
|
+
await this.init()
|
|
26
|
+
if (!field) return this[key]
|
|
27
|
+
return this[key]?.[field]
|
|
28
|
+
}
|
|
29
|
+
async set(val, key, field) {
|
|
30
|
+
await this.init()
|
|
31
|
+
if (!field) {
|
|
32
|
+
this[key] = val
|
|
33
|
+
if (this.db) await this.db.put(`${key}`, this[key])
|
|
34
|
+
} else {
|
|
35
|
+
this[key] ??= {}
|
|
36
|
+
this[key][field] = val
|
|
37
|
+
if (this.db) await this.db.put(`${key}.${field}`, this[key][field])
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
initSync() {
|
|
41
|
+
this.addrmap = {}
|
|
42
|
+
this.txs = {}
|
|
43
|
+
this.jwks = {}
|
|
44
|
+
this.blocks = []
|
|
45
|
+
this.blockmap = {}
|
|
46
|
+
this.env = {}
|
|
47
|
+
this.modules = {
|
|
48
|
+
aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
49
|
+
aos1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
50
|
+
sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
51
|
+
}
|
|
52
|
+
this.modmap = {}
|
|
53
|
+
this.msgs = {}
|
|
54
|
+
this.wasms = {
|
|
55
|
+
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
56
|
+
file: "aos2_0_1",
|
|
57
|
+
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
58
|
+
},
|
|
59
|
+
cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo: {
|
|
60
|
+
file: "aos_1",
|
|
61
|
+
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
62
|
+
},
|
|
63
|
+
ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw: {
|
|
64
|
+
file: "sqlite",
|
|
65
|
+
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
let txs = []
|
|
69
|
+
for (const k in this.modules) {
|
|
70
|
+
const key = this.modules[k]
|
|
71
|
+
txs.push(key)
|
|
72
|
+
this.txs[key] = {
|
|
73
|
+
id: key,
|
|
74
|
+
block: 0,
|
|
75
|
+
tags: buildTags(null, {
|
|
76
|
+
"Data-Protocol": "ao",
|
|
77
|
+
Variant: "ao.TN.1",
|
|
78
|
+
Type: "Module",
|
|
79
|
+
"Module-Format": "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
80
|
+
"Input-Encoding": "JSON-V1",
|
|
81
|
+
"Output-Encoding": "JSON-V1",
|
|
82
|
+
"Memory-Limit": "1-gb",
|
|
83
|
+
"Compute-Limit": "9000000000000",
|
|
84
|
+
Extension: "WeaveDrive",
|
|
85
|
+
}),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (this.scheduler && this.SU_URL) {
|
|
89
|
+
const key = this.scheduler
|
|
90
|
+
txs.push(key)
|
|
91
|
+
this.addrmap[this.scheduler] = { address: this.scheduler }
|
|
92
|
+
this.txs[key] = {
|
|
93
|
+
id: key,
|
|
94
|
+
block: 0,
|
|
95
|
+
owner: this.scheduler,
|
|
96
|
+
tags: buildTags(null, {
|
|
97
|
+
"Data-Protocol": "ao",
|
|
98
|
+
Variant: "ao.TN.1",
|
|
99
|
+
Type: "Scheduler-Location",
|
|
100
|
+
Url: this.SU_URL,
|
|
101
|
+
"Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10,
|
|
102
|
+
}),
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.blockmap["0"] = {
|
|
106
|
+
txs,
|
|
107
|
+
timestamp: Date.now(),
|
|
108
|
+
height: 0,
|
|
109
|
+
previous: "",
|
|
110
|
+
id: "0",
|
|
111
|
+
}
|
|
112
|
+
this.blocks.push("0")
|
|
113
|
+
this.height = 1
|
|
114
|
+
}
|
|
115
|
+
async putAll(key) {
|
|
116
|
+
for (let k in this[key]) await this.set(this[key][k], key, k)
|
|
117
|
+
}
|
|
118
|
+
async init() {
|
|
119
|
+
if (this.isInit) return
|
|
120
|
+
this.isInit = true
|
|
121
|
+
if (this.db) {
|
|
122
|
+
for (const v of ["height", "blocks"]) this[v] = await this.get(v)
|
|
123
|
+
for (const v of [
|
|
124
|
+
"txs",
|
|
125
|
+
"jwks",
|
|
126
|
+
"env",
|
|
127
|
+
"modules",
|
|
128
|
+
"wasms",
|
|
129
|
+
"addrmap",
|
|
130
|
+
"blockmap",
|
|
131
|
+
"modmap",
|
|
132
|
+
"msgs",
|
|
133
|
+
]) {
|
|
134
|
+
this[v] ??= {}
|
|
135
|
+
const items = await this.db.getKeys({ start: v, end: v + "a" })
|
|
136
|
+
for (const v2 of items || []) {
|
|
137
|
+
const key = v2.split(".")[0]
|
|
138
|
+
const field = v2.split(".")[1]
|
|
139
|
+
if (key === v) this[v][field] = await this.db.get(v2)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
for (const v of ["height", "blocks"]) await this.set(this[v], v)
|
|
144
|
+
for (const v of ["modules", "wasms", "addrmap", "blockmap"]) {
|
|
145
|
+
await this.putAll(v)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async getWasm(module) {
|
|
150
|
+
let mod = module ?? this.modules.aos2_0_1
|
|
151
|
+
if (!mod) throw Error("module not found")
|
|
152
|
+
let format = null
|
|
153
|
+
let _wasm = await this.wasms[mod]
|
|
154
|
+
let wasm = _wasm?.data
|
|
155
|
+
if (!wasm) {
|
|
156
|
+
if (_wasm?.file) {
|
|
157
|
+
wasm = await this._getWasm(this.wasms[mod].file)
|
|
158
|
+
format = _wasm.format
|
|
159
|
+
} else {
|
|
160
|
+
const tx = await this.get("txs", mod)
|
|
161
|
+
if (tx) {
|
|
162
|
+
wasm = Buffer.from(tx.data, "base64")
|
|
163
|
+
format = tags(tx.tags)["Module-Format"]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
format = _wasm.format
|
|
168
|
+
}
|
|
169
|
+
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
170
|
+
return { format, mod, wasm }
|
|
171
|
+
}
|
|
172
|
+
}
|
package/esm/armem-web.js
CHANGED
|
@@ -1,174 +1,14 @@
|
|
|
1
|
-
import _Arweave from "arweave"
|
|
2
|
-
import { last } from "ramda"
|
|
3
|
-
import { tags, buildTags, dirname } from "./utils.js"
|
|
4
|
-
const Arweave = _Arweave.default ?? _Arweave
|
|
5
|
-
//import { readFileSync } from "fs"
|
|
6
|
-
//import { resolve } from "path"
|
|
7
1
|
import wdb from "./lua/weavedb-lite.js"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.arweave.transactions.getPrice = () => 0
|
|
16
|
-
this.scheduler = scheduler
|
|
17
|
-
this.SU_URL = SU_URL
|
|
2
|
+
import Base from "./armem-base.js"
|
|
3
|
+
import db from "./lfdb.js"
|
|
4
|
+
|
|
5
|
+
export default class ArMem extends Base {
|
|
6
|
+
constructor(args = {}) {
|
|
7
|
+
super(args)
|
|
8
|
+
this.db = db(this)
|
|
18
9
|
this.initSync()
|
|
19
10
|
}
|
|
20
|
-
async
|
|
21
|
-
|
|
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 = Buffer.from(wdb, "base64")
|
|
64
|
-
format = _wasm.format
|
|
65
|
-
} else {
|
|
66
|
-
const tx = await this.get("txs", mod)
|
|
67
|
-
if (tx) {
|
|
68
|
-
wasm = Buffer.from(tx.data, "base64")
|
|
69
|
-
format = tags(tx.tags)["Module-Format"]
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
format = _wasm.format
|
|
74
|
-
}
|
|
75
|
-
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
76
|
-
return { format, mod, wasm }
|
|
77
|
-
}
|
|
78
|
-
initSync() {
|
|
79
|
-
this.addrmap = {}
|
|
80
|
-
this.txs = {}
|
|
81
|
-
this.jwks = {}
|
|
82
|
-
this.blocks = []
|
|
83
|
-
this.blockmap = {}
|
|
84
|
-
this.env = {}
|
|
85
|
-
this.modules = {
|
|
86
|
-
aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
87
|
-
aos1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
88
|
-
sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
89
|
-
}
|
|
90
|
-
this.modmap = {}
|
|
91
|
-
this.msgs = {}
|
|
92
|
-
this.wasms = {
|
|
93
|
-
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
94
|
-
file: "aos2_0_1",
|
|
95
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
96
|
-
},
|
|
97
|
-
cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo: {
|
|
98
|
-
file: "aos_1",
|
|
99
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
100
|
-
},
|
|
101
|
-
ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw: {
|
|
102
|
-
file: "sqlite",
|
|
103
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
let txs = []
|
|
107
|
-
for (const k in this.modules) {
|
|
108
|
-
const key = this.modules[k]
|
|
109
|
-
txs.push(key)
|
|
110
|
-
this.txs[key] = {
|
|
111
|
-
id: key,
|
|
112
|
-
block: 0,
|
|
113
|
-
tags: buildTags(null, {
|
|
114
|
-
"Data-Protocol": "ao",
|
|
115
|
-
Variant: "ao.TN.1",
|
|
116
|
-
Type: "Module",
|
|
117
|
-
"Module-Format": "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
118
|
-
"Input-Encoding": "JSON-V1",
|
|
119
|
-
"Output-Encoding": "JSON-V1",
|
|
120
|
-
"Memory-Limit": "1-gb",
|
|
121
|
-
"Compute-Limit": "9000000000000",
|
|
122
|
-
Extension: "WeaveDrive",
|
|
123
|
-
}),
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (this.scheduler && this.SU_URL) {
|
|
127
|
-
const key = this.scheduler
|
|
128
|
-
txs.push(key)
|
|
129
|
-
this.addrmap[this.scheduler] = { address: this.scheduler }
|
|
130
|
-
this.txs[key] = {
|
|
131
|
-
id: key,
|
|
132
|
-
block: 0,
|
|
133
|
-
owner: this.scheduler,
|
|
134
|
-
tags: buildTags(null, {
|
|
135
|
-
"Data-Protocol": "ao",
|
|
136
|
-
Variant: "ao.TN.1",
|
|
137
|
-
Type: "Scheduler-Location",
|
|
138
|
-
Url: this.SU_URL,
|
|
139
|
-
"Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10,
|
|
140
|
-
}),
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
this.blockmap["0"] = {
|
|
144
|
-
txs,
|
|
145
|
-
timestamp: Date.now(),
|
|
146
|
-
height: 0,
|
|
147
|
-
previous: "",
|
|
148
|
-
id: "0",
|
|
149
|
-
}
|
|
150
|
-
this.blocks.push("0")
|
|
151
|
-
this.height = 1
|
|
152
|
-
}
|
|
153
|
-
getAnchor() {
|
|
154
|
-
return this.blocks.length === 0
|
|
155
|
-
? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
156
|
-
: last(this.blockmap[last(this.blocks)].txs)
|
|
157
|
-
}
|
|
158
|
-
async get(key, field) {
|
|
159
|
-
await this.init()
|
|
160
|
-
if (!field) return this[key]
|
|
161
|
-
return this[key]?.[field]
|
|
162
|
-
}
|
|
163
|
-
async set(val, key, field) {
|
|
164
|
-
await this.init()
|
|
165
|
-
if (!field) {
|
|
166
|
-
this[key] = val
|
|
167
|
-
if (this.db) await this.db.put(`${key}`, this[key])
|
|
168
|
-
} else {
|
|
169
|
-
this[key] ??= {}
|
|
170
|
-
this[key][field] = val
|
|
171
|
-
if (this.db) await this.db.put(`${key}.${field}`, this[key][field])
|
|
172
|
-
}
|
|
11
|
+
async _getWasm(file) {
|
|
12
|
+
return Buffer.from(wdb, "base64")
|
|
173
13
|
}
|
|
174
14
|
}
|
package/esm/armem.js
CHANGED
|
@@ -4,173 +4,17 @@ import { tags, buildTags, dirname } from "./utils.js"
|
|
|
4
4
|
import { open } from "lmdb"
|
|
5
5
|
import { readFileSync } from "fs"
|
|
6
6
|
import { resolve } from "path"
|
|
7
|
+
import Base from "./armem-base.js"
|
|
7
8
|
|
|
8
|
-
export default class ArMem {
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export default class ArMem extends Base {
|
|
10
|
+
constructor(args = {}) {
|
|
11
|
+
const { cache } = args
|
|
12
|
+
super(args)
|
|
12
13
|
if (cache) this.db = open({ path: cache, compression: true })
|
|
13
|
-
this.arweave = Arweave.init()
|
|
14
|
-
this.arweave.transactions.getTransactionAnchor = () => this.getAnchor()
|
|
15
|
-
this.arweave.transactions.getPrice = () => 0
|
|
16
|
-
this.scheduler = scheduler
|
|
17
|
-
this.SU_URL = SU_URL
|
|
18
14
|
this.initSync()
|
|
19
15
|
}
|
|
20
|
-
async
|
|
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")
|
|
16
|
+
async _getWasm(file) {
|
|
57
17
|
const __dirname = await dirname()
|
|
58
|
-
|
|
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() {
|
|
81
|
-
this.addrmap = {}
|
|
82
|
-
this.txs = {}
|
|
83
|
-
this.jwks = {}
|
|
84
|
-
this.blocks = []
|
|
85
|
-
this.blockmap = {}
|
|
86
|
-
this.env = {}
|
|
87
|
-
this.modules = {
|
|
88
|
-
aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
|
89
|
-
aos1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
|
|
90
|
-
sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw",
|
|
91
|
-
}
|
|
92
|
-
this.modmap = {}
|
|
93
|
-
this.msgs = {}
|
|
94
|
-
this.wasms = {
|
|
95
|
-
"Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
|
|
96
|
-
file: "aos2_0_1",
|
|
97
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
98
|
-
},
|
|
99
|
-
cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo: {
|
|
100
|
-
file: "aos_1",
|
|
101
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
102
|
-
},
|
|
103
|
-
ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw: {
|
|
104
|
-
file: "sqlite",
|
|
105
|
-
format: "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
let txs = []
|
|
109
|
-
for (const k in this.modules) {
|
|
110
|
-
const key = this.modules[k]
|
|
111
|
-
txs.push(key)
|
|
112
|
-
this.txs[key] = {
|
|
113
|
-
id: key,
|
|
114
|
-
block: 0,
|
|
115
|
-
tags: buildTags(null, {
|
|
116
|
-
"Data-Protocol": "ao",
|
|
117
|
-
Variant: "ao.TN.1",
|
|
118
|
-
Type: "Module",
|
|
119
|
-
"Module-Format": "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
120
|
-
"Input-Encoding": "JSON-V1",
|
|
121
|
-
"Output-Encoding": "JSON-V1",
|
|
122
|
-
"Memory-Limit": "1-gb",
|
|
123
|
-
"Compute-Limit": "9000000000000",
|
|
124
|
-
Extension: "WeaveDrive",
|
|
125
|
-
}),
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (this.scheduler && this.SU_URL) {
|
|
129
|
-
const key = this.scheduler
|
|
130
|
-
txs.push(key)
|
|
131
|
-
this.addrmap[this.scheduler] = { address: this.scheduler }
|
|
132
|
-
this.txs[key] = {
|
|
133
|
-
id: key,
|
|
134
|
-
block: 0,
|
|
135
|
-
owner: this.scheduler,
|
|
136
|
-
tags: buildTags(null, {
|
|
137
|
-
"Data-Protocol": "ao",
|
|
138
|
-
Variant: "ao.TN.1",
|
|
139
|
-
Type: "Scheduler-Location",
|
|
140
|
-
Url: this.SU_URL,
|
|
141
|
-
"Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10,
|
|
142
|
-
}),
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
this.blockmap["0"] = {
|
|
146
|
-
txs,
|
|
147
|
-
timestamp: Date.now(),
|
|
148
|
-
height: 0,
|
|
149
|
-
previous: "",
|
|
150
|
-
id: "0",
|
|
151
|
-
}
|
|
152
|
-
this.blocks.push("0")
|
|
153
|
-
this.height = 1
|
|
154
|
-
}
|
|
155
|
-
getAnchor() {
|
|
156
|
-
return this.blocks.length === 0
|
|
157
|
-
? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
158
|
-
: last(this.blockmap[last(this.blocks)].txs)
|
|
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
|
-
}
|
|
18
|
+
return readFileSync(resolve(__dirname, `lua/${file}.wasm`))
|
|
175
19
|
}
|
|
176
20
|
}
|
package/esm/bao.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import MAO from "./ao.js"
|
|
2
|
+
import { createDataItemSigner } from "@permaweb/aoconnect"
|
|
3
|
+
import { srcs, buildTags } from "./utils.js"
|
|
4
|
+
import { mergeLeft, is, map } from "ramda"
|
|
5
|
+
|
|
6
|
+
let log = `
|
|
7
|
+
local json = require("json")
|
|
8
|
+
ao = ao or {}
|
|
9
|
+
|
|
10
|
+
function ao.log(...)
|
|
11
|
+
local args = {...}
|
|
12
|
+
local txt = json.encode(args)
|
|
13
|
+
if type(ao.outbox.Output) == 'string' then
|
|
14
|
+
ao.outbox.Output = {ao.outbox.Output}
|
|
15
|
+
end
|
|
16
|
+
table.insert(ao.outbox.Output, txt)
|
|
17
|
+
ao.outbox.Logs = ao.outbox.Logs or {}
|
|
18
|
+
table.insert(ao.outbox.Logs, txt)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
function ao.result(result)
|
|
22
|
+
if ao.outbox.Error or result.Error then
|
|
23
|
+
return { Error = result.Error or ao.outbox.Error, Output = ao.outbox.Logs }
|
|
24
|
+
end
|
|
25
|
+
return {
|
|
26
|
+
Output = ao.outbox.Logs or result.Output or ao.outbox.Output,
|
|
27
|
+
Messages = ao.outbox.Messages,
|
|
28
|
+
Spawns = ao.outbox.Spawns,
|
|
29
|
+
Assignments = ao.outbox.Assignments,
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
const renderLogs = logs => {
|
|
35
|
+
if (is(Array, logs) && logs.length > 0) {
|
|
36
|
+
for (const v of logs) {
|
|
37
|
+
let l = v
|
|
38
|
+
try {
|
|
39
|
+
const p = JSON.parse(v)
|
|
40
|
+
if (JSON.stringify(p) === v) l = p
|
|
41
|
+
console.log(...l)
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.log(l)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class AO extends MAO {
|
|
50
|
+
constructor(opt = {}) {
|
|
51
|
+
super({ ...opt, in_memory: true })
|
|
52
|
+
this.in_memory = true
|
|
53
|
+
const {
|
|
54
|
+
modules,
|
|
55
|
+
results,
|
|
56
|
+
assign,
|
|
57
|
+
result,
|
|
58
|
+
message,
|
|
59
|
+
spawn,
|
|
60
|
+
dryrun,
|
|
61
|
+
monitor,
|
|
62
|
+
unmonitor,
|
|
63
|
+
mem,
|
|
64
|
+
} = opt.connect(opt.mem, {
|
|
65
|
+
extensions: opt.extensions,
|
|
66
|
+
cache: opt.cache,
|
|
67
|
+
reset: opt.reset,
|
|
68
|
+
})
|
|
69
|
+
this.assign = assign
|
|
70
|
+
this.result = async (...opt) => {
|
|
71
|
+
const res = await result(...opt)
|
|
72
|
+
renderLogs(res.Output)
|
|
73
|
+
return res
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.results = results
|
|
77
|
+
this.message = message
|
|
78
|
+
this.spawn = async (...opt) => {
|
|
79
|
+
const res = await spawn(...opt)
|
|
80
|
+
await this.load({ data: log, pid: res })
|
|
81
|
+
return res
|
|
82
|
+
}
|
|
83
|
+
this.dryrun = async (...opt) => {
|
|
84
|
+
const res = await dryrun(...opt)
|
|
85
|
+
renderLogs(res.Output)
|
|
86
|
+
return res
|
|
87
|
+
}
|
|
88
|
+
this.monitor = monitor
|
|
89
|
+
this.unmonitor = unmonitor
|
|
90
|
+
this.mem = mem
|
|
91
|
+
this.ar = new opt.AR({ mem })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async init(jwk) {
|
|
95
|
+
if (!jwk && this.acc[0]) jwk = this.acc[0].jwk
|
|
96
|
+
await this.ar.init(jwk)
|
|
97
|
+
return this
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async postModule({ data, tags = {}, jwk }) {
|
|
101
|
+
let err = null
|
|
102
|
+
;({ jwk, err } = await this.ar.checkWallet({ jwk }))
|
|
103
|
+
if (err) return { err }
|
|
104
|
+
const t = mergeLeft(tags, {
|
|
105
|
+
"Data-Protocol": "ao",
|
|
106
|
+
Variant: "ao.TN.1",
|
|
107
|
+
Type: "Module",
|
|
108
|
+
"Module-Format": "wasm64-unknown-emscripten-draft_2024_02_15",
|
|
109
|
+
"Input-Encoding": "JSON-V1",
|
|
110
|
+
"Output-Encoding": "JSON-V1",
|
|
111
|
+
"Memory-Limit": "1-gb",
|
|
112
|
+
"Compute-Limit": "9000000000000",
|
|
113
|
+
})
|
|
114
|
+
const signer = createDataItemSigner(jwk)
|
|
115
|
+
const { id, owner, item } = await this.ar.dataitem({
|
|
116
|
+
tags: t,
|
|
117
|
+
data,
|
|
118
|
+
signer,
|
|
119
|
+
})
|
|
120
|
+
await this.ar.postItems(item, jwk)
|
|
121
|
+
return { id }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default AO
|