wao 0.4.0 → 0.4.1
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 +6 -1
- package/cjs/aoconnect.js +7 -3
- package/cjs/ar.js +38 -64
- package/cjs/armem.js +3 -1
- package/cjs/tar.js +112 -111
- package/cjs/tgql.js +733 -0
- package/cjs/utils.js +1 -7
- package/esm/ao.js +4 -1
- package/esm/aoconnect.js +3 -2
- package/esm/ar.js +7 -23
- package/esm/armem.js +5 -1
- package/esm/gql.js +1 -0
- package/esm/tar.js +34 -26
- package/esm/tgql.js +282 -0
- package/esm/utils.js +0 -14
- package/package.json +1 -1
package/cjs/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isData = exports.isCheckComplete = exports.getTagVal = exports.getTag = exports.dirname = exports.checkTag = exports.buildTags = exports.action = void 0;
|
|
7
7
|
exports.isJSON = isJSON;
|
|
8
|
-
exports.wait = exports.validAddress = exports.udl = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.
|
|
8
|
+
exports.wait = exports.validAddress = exports.udl = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.mergeOut = exports.mergeChecks = exports.ltags = exports.jsonToStr = exports.isRegExp = exports.isOutComplete = exports.isLocalhost = void 0;
|
|
9
9
|
var _ramda = require("ramda");
|
|
10
10
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
11
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -207,12 +207,6 @@ var isData = exports.isData = function isData(data, res) {
|
|
|
207
207
|
}
|
|
208
208
|
return false;
|
|
209
209
|
};
|
|
210
|
-
var query = exports.query = function query(txid) {
|
|
211
|
-
return "query {\n transactions(ids: [\"".concat(txid, "\"]) {\n edges { node { id tags { name value } owner { address } } }\n }\n}");
|
|
212
|
-
};
|
|
213
|
-
var queries = exports.queries = function queries(to) {
|
|
214
|
-
return "query {\n transactions (recipients: [\"".concat(to, "\"]){\n edges { node { id recipient tags { name value } owner { address } } }\n }\n}");
|
|
215
|
-
};
|
|
216
210
|
var isLocalhost = exports.isLocalhost = function isLocalhost(v) {
|
|
217
211
|
return (0, _ramda.includes)(v, ["localhost", "127.0.0.1"]);
|
|
218
212
|
};
|
package/esm/ao.js
CHANGED
|
@@ -384,7 +384,10 @@ class AO {
|
|
|
384
384
|
let ex = exRef(ref, txs)
|
|
385
385
|
if (!ex) {
|
|
386
386
|
if (!this.in_memory) await wait(1000)
|
|
387
|
-
txs = await this.ar.txs(
|
|
387
|
+
txs = await this.ar.gql.txs({
|
|
388
|
+
recipient: pid,
|
|
389
|
+
fields: ["id", "recipient", "tags", { owner: ["address"] }],
|
|
390
|
+
})
|
|
388
391
|
ex = exRef(ref, txs)
|
|
389
392
|
}
|
|
390
393
|
if (ex) return txs
|
package/esm/aoconnect.js
CHANGED
|
@@ -214,6 +214,7 @@ export const connect = mem => {
|
|
|
214
214
|
data: _opt.data,
|
|
215
215
|
signer: _opt.signer,
|
|
216
216
|
tags: tags(_opt.tags),
|
|
217
|
+
target: opt.process,
|
|
217
218
|
})
|
|
218
219
|
await ar.postItem(item, su.jwk)
|
|
219
220
|
try {
|
|
@@ -265,8 +266,8 @@ export const connect = mem => {
|
|
|
265
266
|
data: opt.data,
|
|
266
267
|
signer: opt.signer,
|
|
267
268
|
tags: tags(opt.tags),
|
|
269
|
+
target: opt.process,
|
|
268
270
|
})
|
|
269
|
-
|
|
270
271
|
await ar.postItem(item, su.jwk)
|
|
271
272
|
try {
|
|
272
273
|
const msg = genMsg(
|
|
@@ -372,7 +373,7 @@ export const connect = mem => {
|
|
|
372
373
|
},
|
|
373
374
|
dryrun: async opt => {
|
|
374
375
|
const p = mem.env[opt.process]
|
|
375
|
-
const { id, owner } = await ar.dataitem(opt)
|
|
376
|
+
const { id, owner } = await ar.dataitem({ ...opt, target: opt.process })
|
|
376
377
|
try {
|
|
377
378
|
const msg = genMsg(p, opt.data ?? "", opt.tags, owner, mu.addr, true)
|
|
378
379
|
const _env = genEnv({
|
package/esm/ar.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import Arweave from "arweave"
|
|
2
2
|
import { ArweaveSigner, bundleAndSignData, createData } from "arbundles"
|
|
3
|
-
import { buildTags, tag,
|
|
3
|
+
import { buildTags, tag, isLocalhost } from "./utils.js"
|
|
4
4
|
import { is } from "ramda"
|
|
5
|
+
import GQL from "./gql.js"
|
|
5
6
|
|
|
6
7
|
class AR {
|
|
7
8
|
constructor({ host, port = 443, protocol } = {}) {
|
|
8
9
|
this.__type__ = "ar"
|
|
9
10
|
let _arweave = { host, port, protocol }
|
|
10
11
|
if (!_arweave.host)
|
|
11
|
-
_arweave.host = port === 443 ? "arweave.net" : "
|
|
12
|
+
_arweave.host = port === 443 ? "arweave.net" : "localhost"
|
|
12
13
|
if (!_arweave.protocol)
|
|
13
14
|
_arweave.protocol = isLocalhost(_arweave.host) ? "http" : "https"
|
|
14
15
|
if (!_arweave.port) _arweave.port = isLocalhost(_arweave.host) ? 1984 : 443
|
|
@@ -16,6 +17,9 @@ class AR {
|
|
|
16
17
|
this.host = _arweave.host
|
|
17
18
|
this.protocol = _arweave.protocol
|
|
18
19
|
this.arweave = Arweave.init(_arweave)
|
|
20
|
+
this.gql = new GQL({
|
|
21
|
+
url: `${_arweave.protocol}://${_arweave.host}:${_arweave.port}/graphql`,
|
|
22
|
+
})
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
isArConnect(jwk) {
|
|
@@ -211,27 +215,7 @@ class AR {
|
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
async tx(txid) {
|
|
214
|
-
|
|
215
|
-
`${this.protocol}://${this.host}:${this.port}/graphql`,
|
|
216
|
-
{
|
|
217
|
-
method: "POST",
|
|
218
|
-
headers: { "Content-Type": "application/json" },
|
|
219
|
-
body: JSON.stringify({ query: query(txid) }),
|
|
220
|
-
},
|
|
221
|
-
).then(r => r.json())
|
|
222
|
-
return json.data.transactions.edges.map(v => v.node)[0] ?? null
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async txs(to) {
|
|
226
|
-
const json = await fetch(
|
|
227
|
-
`${this.protocol}://${this.host}:${this.port}/graphql`,
|
|
228
|
-
{
|
|
229
|
-
method: "POST",
|
|
230
|
-
headers: { "Content-Type": "application/json" },
|
|
231
|
-
body: JSON.stringify({ query: queries(to) }),
|
|
232
|
-
},
|
|
233
|
-
).then(r => r.json())
|
|
234
|
-
return json.data.transactions.edges.map(v => v.node)
|
|
218
|
+
return (await this.gql.txs({ id: txid }))[0] ?? null
|
|
235
219
|
}
|
|
236
220
|
|
|
237
221
|
async data(txid, string = false) {
|
package/esm/armem.js
CHANGED
|
@@ -6,12 +6,16 @@ export default class ArMem {
|
|
|
6
6
|
this.__type__ = "mem"
|
|
7
7
|
this.arweave = Arweave.init()
|
|
8
8
|
this.arweave.transactions.getTransactionAnchor = () => {
|
|
9
|
-
return this.blocks.length === 0
|
|
9
|
+
return this.blocks.length === 0
|
|
10
|
+
? ""
|
|
11
|
+
: last(this.blockmap[last(this.blocks)].txs)
|
|
10
12
|
}
|
|
11
13
|
this.arweave.transactions.getPrice = () => 0
|
|
12
14
|
this.txs = {}
|
|
15
|
+
this.jwks = {}
|
|
13
16
|
this.height = 0
|
|
14
17
|
this.blocks = []
|
|
18
|
+
this.blockmap = {}
|
|
15
19
|
this.env = {}
|
|
16
20
|
this.modules = {
|
|
17
21
|
aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
|
package/esm/gql.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { includes, map, is, isNil, last, clone } from "ramda"
|
|
2
|
+
|
|
2
3
|
const full = `id anchor signature recipient owner { address key } fee { winston ar } quantity { winston ar } data { size type } tags { name value } block { id timestamp height previous } parent { id }`
|
|
3
4
|
const full_blocks = `id timestamp height previous`
|
|
4
5
|
|
package/esm/tar.js
CHANGED
|
@@ -3,25 +3,20 @@ import { buildTags } from "./utils.js"
|
|
|
3
3
|
import { DataItem } from "warp-arbundles"
|
|
4
4
|
import base64url from "base64url"
|
|
5
5
|
import ArMem from "./armem.js"
|
|
6
|
-
|
|
6
|
+
import GQL from "./tgql.js"
|
|
7
|
+
import { last } from "ramda"
|
|
7
8
|
class AR extends MAR {
|
|
8
9
|
constructor(opt = {}) {
|
|
9
10
|
super({ ...opt, in_memory: true })
|
|
10
11
|
this.in_memory = true
|
|
11
12
|
this.mem = opt.mem ?? new ArMem()
|
|
13
|
+
this.gql = new GQL({ mem: this.mem })
|
|
14
|
+
this.arweave = this.mem.arweave
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
async
|
|
15
|
-
let _txs = []
|
|
16
|
-
for (let v of this.mem.env[pid].txs) {
|
|
17
|
-
_txs.push({ tags: v.tags, id: v.id })
|
|
18
|
-
}
|
|
19
|
-
return _txs
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async dataitem({ data = "1984", tags = {}, signer }) {
|
|
17
|
+
async dataitem({ target = "", data = "1984", tags = {}, signer }) {
|
|
23
18
|
const _tags = buildTags(tags)
|
|
24
|
-
const item = await signer({ data, tags: _tags })
|
|
19
|
+
const item = await signer({ data, tags: _tags, target })
|
|
25
20
|
const di = new DataItem(item.raw)
|
|
26
21
|
const raw_owner = di.rawOwner
|
|
27
22
|
const hashBuffer = Buffer.from(
|
|
@@ -35,18 +30,16 @@ class AR extends MAR {
|
|
|
35
30
|
let tx = await this.arweave.createTransaction({ data: data })
|
|
36
31
|
let _tags = buildTags(null, tags)
|
|
37
32
|
for (const v of _tags) tx.addTag(v.name, v.value)
|
|
38
|
-
this.mem.height += 1
|
|
39
33
|
return await this.postTx(tx, jwk, {
|
|
40
|
-
|
|
34
|
+
recipient: "",
|
|
41
35
|
tags: _tags,
|
|
42
36
|
data,
|
|
37
|
+
owner: await this.arweave.wallets.jwkToAddress(jwk),
|
|
43
38
|
})
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
async postItem(item, jwk) {
|
|
47
|
-
const tx = await this.mem.arweave.createTransaction({
|
|
48
|
-
data: item.raw,
|
|
49
|
-
})
|
|
42
|
+
const tx = await this.mem.arweave.createTransaction({ data: item.raw }, jwk)
|
|
50
43
|
tx.addTag("Bundle-Format", "binary")
|
|
51
44
|
tx.addTag("Bundle-Version", "2.0.0")
|
|
52
45
|
const di = new DataItem(item.raw)
|
|
@@ -55,34 +48,49 @@ class AR extends MAR {
|
|
|
55
48
|
await crypto.subtle.digest("SHA-256", rowner),
|
|
56
49
|
)
|
|
57
50
|
const owner = base64url.encode(hashBuffer)
|
|
58
|
-
this.mem.height += 1
|
|
59
51
|
let data = di.data
|
|
60
52
|
try {
|
|
61
53
|
data = base64url.decode(di.data)
|
|
62
54
|
} catch (e) {}
|
|
63
|
-
|
|
55
|
+
let _item = {
|
|
56
|
+
recipient: di.target,
|
|
64
57
|
id: item.id,
|
|
65
58
|
item: di,
|
|
66
59
|
owner,
|
|
67
|
-
height: this.mem.height,
|
|
68
60
|
tags: di.tags,
|
|
69
61
|
data,
|
|
70
62
|
}
|
|
71
|
-
this.mem.
|
|
72
|
-
return await this.postTx(tx, jwk)
|
|
63
|
+
this.mem.txs[item.id] = _item
|
|
64
|
+
return await this.postTx(tx, jwk, _item)
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
async postTx(tx, jwk, item) {
|
|
76
68
|
let [res, err] = [null, null]
|
|
77
69
|
await this.mem.arweave.transactions.sign(tx, jwk)
|
|
78
70
|
if (item) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
this.mem.height += 1
|
|
72
|
+
|
|
73
|
+
const block = {
|
|
74
|
+
id: tx.id,
|
|
75
|
+
timestamp: Date.now(),
|
|
76
|
+
height: this.mem.height,
|
|
77
|
+
previous: last(this.mem.blocks) ?? "",
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!item.id) {
|
|
81
|
+
item.id = tx.id
|
|
82
|
+
this.mem.txs[item.id] = item
|
|
83
|
+
this.mem.txs[item.id].parent = { id: block.id }
|
|
84
|
+
} else {
|
|
85
|
+
this.mem.txs[item.id].parent = { id: "" }
|
|
86
|
+
}
|
|
87
|
+
block.txs = [item.id]
|
|
88
|
+
this.mem.txs[item.id].block = block.id
|
|
89
|
+
this.mem.txs[item.id].parent = { id: block.id }
|
|
90
|
+
this.mem.blocks.push(block.id)
|
|
91
|
+
this.mem.blockmap[block.id] = block
|
|
82
92
|
}
|
|
83
93
|
res = { id: tx.id, status: 200, statusText: "200" }
|
|
84
|
-
//res = await this.arweave.transactions.post(tx)
|
|
85
|
-
//if (res.status !== 200) err = res.statusText
|
|
86
94
|
return { res, err, id: tx.id }
|
|
87
95
|
}
|
|
88
96
|
|
package/esm/tgql.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { reverse, includes, map, is, isNil, last, clone, pick } from "ramda"
|
|
2
|
+
|
|
3
|
+
const subs = {
|
|
4
|
+
owner: ["address", "key"],
|
|
5
|
+
fee: ["winston", "ar"],
|
|
6
|
+
quantity: ["winston", "ar"],
|
|
7
|
+
data: ["size", "type"],
|
|
8
|
+
tags: ["name", "value"],
|
|
9
|
+
block: ["id", "timestamp", "height", "previous"],
|
|
10
|
+
parent: ["id"],
|
|
11
|
+
}
|
|
12
|
+
const field = (key, val = true) => {
|
|
13
|
+
if (includes(key, ["id", "anchor", "signature", "recipient"])) {
|
|
14
|
+
return { key }
|
|
15
|
+
} else if (subs[key]) {
|
|
16
|
+
let _subs = []
|
|
17
|
+
if (val === true) val = subs[key]
|
|
18
|
+
else if (is(Object, val) && !is(Array, val)) {
|
|
19
|
+
let _val = []
|
|
20
|
+
let isTrue = false
|
|
21
|
+
let isFalse = false
|
|
22
|
+
for (const k in val)
|
|
23
|
+
if (val[k] === true) isTrue = true
|
|
24
|
+
else if (val[k] === false) isFalse = true
|
|
25
|
+
if (!isTrue && isFalse) {
|
|
26
|
+
for (const k of subs[key]) if (val[k] !== false) _val.push(k)
|
|
27
|
+
} else {
|
|
28
|
+
for (const k in val) if (val[k] === true) _val.push(k)
|
|
29
|
+
}
|
|
30
|
+
val = _val
|
|
31
|
+
} else if (!is(Array, val)) val = subs[key]
|
|
32
|
+
for (const v2 of val) {
|
|
33
|
+
if (is(String, v2) && includes(v2, subs[key])) _subs.push(v2)
|
|
34
|
+
}
|
|
35
|
+
if (_subs.length === 0) return null
|
|
36
|
+
return { key, subs: _subs }
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const field_blocks = (key, val = true) => {
|
|
42
|
+
if (includes(key, ["id", "timestamp", "height", "previous"])) {
|
|
43
|
+
return { key }
|
|
44
|
+
}
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class GQL {
|
|
49
|
+
constructor({ mem }) {
|
|
50
|
+
this.mem = mem
|
|
51
|
+
}
|
|
52
|
+
async txs(opt = {}) {
|
|
53
|
+
let block_max = null
|
|
54
|
+
let block_min = null
|
|
55
|
+
let _block = {}
|
|
56
|
+
if (is(Number, opt.block)) {
|
|
57
|
+
_block = { min: opt.block, max: opt.block }
|
|
58
|
+
} else if (is(Array, opt.block) && opt.block.length > 0) {
|
|
59
|
+
_block = {}
|
|
60
|
+
if (!isNil(opt.block[0])) _block.min = opt.block[0]
|
|
61
|
+
if (!isNil(opt.block[1])) _block.max = opt.block[1]
|
|
62
|
+
}
|
|
63
|
+
let first = opt.first ?? 20
|
|
64
|
+
let tags = []
|
|
65
|
+
for (const k in opt.tags ?? {}) {
|
|
66
|
+
if (is(String, opt.tags[k])) {
|
|
67
|
+
tags.push({ name: k, values: [opt.tags[k]] })
|
|
68
|
+
} else if (is(Array, opt.tags[k])) {
|
|
69
|
+
tags.push({ name: k, values: opt.tags[k] })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let recipients = null
|
|
73
|
+
if (is(Array, opt.recipients)) recipients = opt.recipients
|
|
74
|
+
else if (is(String, opt.recipient)) recipients = [opt.recipient]
|
|
75
|
+
|
|
76
|
+
let owners = null
|
|
77
|
+
if (is(Array, opt.owners)) owners = opt.owners
|
|
78
|
+
else if (is(String, opt.owner)) owners = [opt.owner]
|
|
79
|
+
|
|
80
|
+
let ids = null
|
|
81
|
+
if (is(Array, opt.ids)) ids = opt.ids
|
|
82
|
+
else if (is(String, opt.id)) ids = [opt.id]
|
|
83
|
+
|
|
84
|
+
let data = []
|
|
85
|
+
let blocks = this.mem.blocks
|
|
86
|
+
if (opt.asc !== true) blocks = reverse(blocks)
|
|
87
|
+
let count = 0
|
|
88
|
+
let after = false
|
|
89
|
+
for (const v of blocks) {
|
|
90
|
+
const block = clone(this.mem.blockmap[v])
|
|
91
|
+
if (!isNil(_block.min) && block.height < _block.min) continue
|
|
92
|
+
if (!isNil(_block.max) && block.height > _block.max) continue
|
|
93
|
+
let txs = block.txs
|
|
94
|
+
if (opt.asc !== true) txs = reverse(txs)
|
|
95
|
+
for (const v2 of txs) {
|
|
96
|
+
if (!isNil(opt.after) && opt.after === v2) {
|
|
97
|
+
after = true
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
if (!isNil(opt.after) && count === 0 && !after) continue
|
|
101
|
+
let tx = this.mem.txs[v2]
|
|
102
|
+
if (!isNil(ids) && ids.length > 0) {
|
|
103
|
+
if (!includes(tx.id, ids)) continue
|
|
104
|
+
}
|
|
105
|
+
if (!isNil(owners) && owners.length > 0) {
|
|
106
|
+
if (!includes(tx.owner, owners)) continue
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!isNil(recipients) && recipients.length > 0) {
|
|
110
|
+
if (!includes(tx.recipient, recipients)) continue
|
|
111
|
+
}
|
|
112
|
+
let tag_unmatch = false
|
|
113
|
+
for (const v of tags) {
|
|
114
|
+
let ex = false
|
|
115
|
+
for (const v2 of tx.tags) {
|
|
116
|
+
if (v2.name === v.name && includes(v2.value, v.values)) {
|
|
117
|
+
ex = true
|
|
118
|
+
break
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!ex) {
|
|
122
|
+
tag_unmatch = true
|
|
123
|
+
break
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (tag_unmatch) continue
|
|
127
|
+
let _tx = {
|
|
128
|
+
cursor: tx.id,
|
|
129
|
+
...tx,
|
|
130
|
+
block: pick(["id", "timestamp", "height", "previous"], block),
|
|
131
|
+
anchor: tx.anchor ?? "",
|
|
132
|
+
signature: tx.signature ?? "",
|
|
133
|
+
owner: { address: tx.owner, key: "" },
|
|
134
|
+
fee: { ar: 0, winston: 0 },
|
|
135
|
+
quantity: { ar: 0, winston: 0 },
|
|
136
|
+
data: { size: 0, type: "" },
|
|
137
|
+
}
|
|
138
|
+
if (!isNil(opt.fields)) {
|
|
139
|
+
let _tx2 = { cursor: tx.id }
|
|
140
|
+
let fields = []
|
|
141
|
+
if (is(Array, opt.fields) && opt.fields.length > 0) {
|
|
142
|
+
for (const v of opt.fields) {
|
|
143
|
+
if (is(String, v)) {
|
|
144
|
+
const fld = field(v)
|
|
145
|
+
if (fld) fields.push(fld)
|
|
146
|
+
} else if (is(Object, v) && !is(Array, v)) {
|
|
147
|
+
for (const k in v) {
|
|
148
|
+
const fld = field(k, v[k])
|
|
149
|
+
if (fld) fields.push(fld)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} else if (is(Object, opt.fields) && !is(Array, opt.fields)) {
|
|
154
|
+
for (const k in opt.fields) {
|
|
155
|
+
const fld = field(k, opt.fields[k])
|
|
156
|
+
if (fld) fields.push(fld)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const f of fields) {
|
|
160
|
+
if (isNil(f.subs)) {
|
|
161
|
+
_tx2[f.key] = _tx[f.key] ?? ""
|
|
162
|
+
} else {
|
|
163
|
+
let subs = {}
|
|
164
|
+
_tx2[f.key] = {}
|
|
165
|
+
if (is(Array, _tx[f.key])) {
|
|
166
|
+
_tx2[f.key] = map(pick(f.subs))(_tx[f.key])
|
|
167
|
+
} else {
|
|
168
|
+
for (const f2 of f.subs) {
|
|
169
|
+
_tx2[f.key][f2] = _tx[f.key][f2] ?? ""
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
_tx = _tx2
|
|
175
|
+
}
|
|
176
|
+
data.push(_tx)
|
|
177
|
+
count += 1
|
|
178
|
+
if (count >= first) break
|
|
179
|
+
}
|
|
180
|
+
if (count >= first) break
|
|
181
|
+
}
|
|
182
|
+
if (opt.next === true) {
|
|
183
|
+
let cursor = null
|
|
184
|
+
if (data.length > 0) cursor = last(data).cursor
|
|
185
|
+
const next = !cursor
|
|
186
|
+
? null
|
|
187
|
+
: async () => {
|
|
188
|
+
let _opt = clone(opt)
|
|
189
|
+
_opt.after = cursor
|
|
190
|
+
return await this.txs(_opt)
|
|
191
|
+
}
|
|
192
|
+
return { data, next }
|
|
193
|
+
} else {
|
|
194
|
+
return data
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async blocks(opt = {}) {
|
|
198
|
+
let block_max = null
|
|
199
|
+
let block_min = null
|
|
200
|
+
let _block = {}
|
|
201
|
+
if (is(Number, opt.block)) {
|
|
202
|
+
_block = { min: opt.block, max: opt.block }
|
|
203
|
+
} else if (is(Array, opt.block) && opt.block.length > 0) {
|
|
204
|
+
_block = {}
|
|
205
|
+
if (!isNil(opt.block[0])) _block.min = opt.block[0]
|
|
206
|
+
if (!isNil(opt.block[1])) _block.max = opt.block[1]
|
|
207
|
+
}
|
|
208
|
+
let first = opt.first ?? 20
|
|
209
|
+
|
|
210
|
+
let ids = null
|
|
211
|
+
if (is(Array, opt.ids)) ids = opt.ids
|
|
212
|
+
else if (is(String, opt.id)) ids = [opt.id]
|
|
213
|
+
|
|
214
|
+
let data = []
|
|
215
|
+
let blocks = this.mem.blocks
|
|
216
|
+
if (opt.asc !== true) blocks = reverse(blocks)
|
|
217
|
+
let count = 0
|
|
218
|
+
let after = false
|
|
219
|
+
for (const v of blocks) {
|
|
220
|
+
let block = clone({ ...this.mem.blockmap[v], cursor: v })
|
|
221
|
+
delete block.txs
|
|
222
|
+
if (!isNil(_block.min) && block.height < _block.min) continue
|
|
223
|
+
if (!isNil(_block.max) && block.height > _block.max) continue
|
|
224
|
+
if (!isNil(ids) && ids.length > 0) if (!includes(v.id, ids)) continue
|
|
225
|
+
if (!isNil(opt.fields)) {
|
|
226
|
+
let block2 = { cursor: block.id }
|
|
227
|
+
let fields = []
|
|
228
|
+
if (is(Array, opt.fields) && opt.fields.length > 0) {
|
|
229
|
+
for (const v of opt.fields) {
|
|
230
|
+
if (is(String, v)) {
|
|
231
|
+
const fld = field_blocks(v)
|
|
232
|
+
if (fld) fields.push(fld)
|
|
233
|
+
} else if (is(Object, v) && !is(Array, v)) {
|
|
234
|
+
for (const k in v) {
|
|
235
|
+
const fld = field_blocks(k, v[k])
|
|
236
|
+
if (fld) fields.push(fld)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} else if (is(Object, opt.fields) && !is(Array, opt.fields)) {
|
|
241
|
+
for (const k in opt.fields) {
|
|
242
|
+
const fld = field_blocks(k, opt.fields[k])
|
|
243
|
+
if (fld) fields.push(fld)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const f of fields) {
|
|
247
|
+
if (isNil(f.subs)) {
|
|
248
|
+
block2[f.key] = block[f.key] ?? ""
|
|
249
|
+
} else {
|
|
250
|
+
let subs = {}
|
|
251
|
+
block2[f.key] = {}
|
|
252
|
+
if (is(Array, block[f.key])) {
|
|
253
|
+
block2[f.key] = map(pick(f.subs))(block[f.key])
|
|
254
|
+
} else {
|
|
255
|
+
for (const f2 of f.subs) {
|
|
256
|
+
block2[f.key][f2] = block[f.key][f2] ?? ""
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
block = block2
|
|
262
|
+
}
|
|
263
|
+
data.push(block)
|
|
264
|
+
count += 1
|
|
265
|
+
if (count >= first) break
|
|
266
|
+
}
|
|
267
|
+
if (opt.next === true) {
|
|
268
|
+
let cursor = null
|
|
269
|
+
if (data.length > 0) cursor = last(data).cursor
|
|
270
|
+
const next = !cursor
|
|
271
|
+
? null
|
|
272
|
+
: async () => {
|
|
273
|
+
let _opt = clone(opt)
|
|
274
|
+
_opt.after = cursor
|
|
275
|
+
return await this.txs(_opt)
|
|
276
|
+
}
|
|
277
|
+
return { data, next }
|
|
278
|
+
} else {
|
|
279
|
+
return data
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
package/esm/utils.js
CHANGED
|
@@ -91,18 +91,6 @@ const isData = (data, res) => {
|
|
|
91
91
|
return false
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const query = txid => `query {
|
|
95
|
-
transactions(ids: ["${txid}"]) {
|
|
96
|
-
edges { node { id tags { name value } owner { address } } }
|
|
97
|
-
}
|
|
98
|
-
}`
|
|
99
|
-
|
|
100
|
-
const queries = to => `query {
|
|
101
|
-
transactions (recipients: ["${to}"]){
|
|
102
|
-
edges { node { id recipient tags { name value } owner { address } } }
|
|
103
|
-
}
|
|
104
|
-
}`
|
|
105
|
-
|
|
106
94
|
const isLocalhost = v => includes(v, ["localhost", "127.0.0.1"])
|
|
107
95
|
|
|
108
96
|
const udl = ({ payment, access, derivations, commercial, training }) => {
|
|
@@ -315,8 +303,6 @@ export {
|
|
|
315
303
|
srcs,
|
|
316
304
|
getTagVal,
|
|
317
305
|
isData,
|
|
318
|
-
query,
|
|
319
|
-
queries,
|
|
320
306
|
getTag,
|
|
321
307
|
tagEq,
|
|
322
308
|
searchTag,
|