@xyo-network/diviner-address-chain-memory 2.84.2 → 2.84.3
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/node/index.cjs +72 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.js +13 -40
- package/dist/node/index.js.map +1 -1
- package/package.json +23 -23
- package/dist/node/index.mjs +0 -45
- package/dist/node/index.mjs.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
MemoryAddressChainDiviner: () => MemoryAddressChainDiviner
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/MemoryDiviner.ts
|
|
28
|
+
var import_assert = require("@xylabs/assert");
|
|
29
|
+
var import_boundwitness_wrapper = require("@xyo-network/boundwitness-wrapper");
|
|
30
|
+
var import_diviner_address_chain_abstract = require("@xyo-network/diviner-address-chain-abstract");
|
|
31
|
+
var import_diviner_address_chain_model = require("@xyo-network/diviner-address-chain-model");
|
|
32
|
+
var MemoryAddressChainDiviner = class extends import_diviner_address_chain_abstract.AddressChainDiviner {
|
|
33
|
+
static configSchemas = [import_diviner_address_chain_model.AddressChainDivinerConfigSchema];
|
|
34
|
+
get queryAddress() {
|
|
35
|
+
return (0, import_assert.assertEx)(this.config.address, "Missing address");
|
|
36
|
+
}
|
|
37
|
+
async divineHandler(payloads) {
|
|
38
|
+
const result = [];
|
|
39
|
+
(0, import_assert.assertEx)(!(payloads == null ? void 0 : payloads.length), "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
40
|
+
try {
|
|
41
|
+
const archivistIn = await this.readArchivist();
|
|
42
|
+
const archivist = (0, import_assert.assertEx)(archivistIn, "Unable to resolve archivist");
|
|
43
|
+
let currentHash = (0, import_assert.assertEx)(this.config.startHash, "Missing startHash");
|
|
44
|
+
while (currentHash && result.length < (this.config.maxResults ?? 1e3)) {
|
|
45
|
+
const bwPayload = await this.archivistFindHash([archivist], currentHash);
|
|
46
|
+
const bwWrapper = import_boundwitness_wrapper.BoundWitnessWrapper.tryParse(bwPayload);
|
|
47
|
+
if (bwWrapper) {
|
|
48
|
+
result.push(bwWrapper.payload());
|
|
49
|
+
currentHash = bwWrapper.prev(this.queryAddress);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (ex) {
|
|
53
|
+
console.log(ex);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
async archivistFindHash(archivists, hash) {
|
|
58
|
+
let index = 0;
|
|
59
|
+
if (archivists[index]) {
|
|
60
|
+
const result = (await archivists[index].get([hash])).pop();
|
|
61
|
+
if (result) {
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
index++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
MemoryAddressChainDiviner
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override configSchemas = [AddressChainDivinerConfigSchema]\n\n get queryAddress() {\n return assertEx(this.config.address, 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.readArchivist()\n const archivist = assertEx(archivistIn, 'Unable to resolve archivist')\n let currentHash: string | null = assertEx(this.config.startHash, 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload())\n currentHash = bwWrapper.prev(this.queryAddress)\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: string): Promise<BoundWitness | undefined> {\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).pop() as BoundWitness\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AAGzB,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAM,4BAAN,cAEG,0DAA6B;AAAA,EACrC,OAAgB,gBAAgB,CAAC,kEAA+B;AAAA,EAEhE,IAAI,eAAe;AACjB,eAAO,wBAAS,KAAK,OAAO,SAAS,iBAAiB;AAAA,EACxD;AAAA,EAEA,MAAyB,cAAc,UAA0C;AAC/E,UAAM,SAAoB,CAAC;AAC3B,gCAAS,EAAC,qCAAU,SAAQ,qEAAqE;AACjG,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,cAAc;AAC7C,YAAM,gBAAY,wBAAS,aAAa,6BAA6B;AACrE,UAAI,kBAA6B,wBAAS,KAAK,OAAO,WAAW,mBAAmB;AACpF,aAAO,eAAe,OAAO,UAAU,KAAK,OAAO,cAAc,MAAO;AACtE,cAAM,YAAsC,MAAM,KAAK,kBAAkB,CAAC,SAAS,GAAG,WAAW;AACjG,cAAM,YAA6C,gDAAoB,SAAS,SAAS;AACzF,YAAI,WAAW;AACb,iBAAO,KAAK,UAAU,QAAQ,CAAC;AAC/B,wBAAc,UAAU,KAAK,KAAK,YAAY;AAAA,QAChD;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,cAAQ,IAAI,EAAE;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,kBAAkB,YAAiC,MAAiD;AAChH,QAAI,QAAQ;AACZ,QAAI,WAAW,KAAK,GAAG;AACrB,YAAM,UAAU,MAAM,WAAW,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;AACzD,UAAI,QAAQ;AACV,eAAO;AAAA,MACT;AACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,49 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
MemoryAddressChainDiviner: () => MemoryAddressChainDiviner
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
1
|
// src/MemoryDiviner.ts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var MemoryAddressChainDiviner = class extends
|
|
33
|
-
static configSchemas = [
|
|
2
|
+
import { assertEx } from "@xylabs/assert";
|
|
3
|
+
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
4
|
+
import { AddressChainDiviner } from "@xyo-network/diviner-address-chain-abstract";
|
|
5
|
+
import { AddressChainDivinerConfigSchema } from "@xyo-network/diviner-address-chain-model";
|
|
6
|
+
var MemoryAddressChainDiviner = class extends AddressChainDiviner {
|
|
7
|
+
static configSchemas = [AddressChainDivinerConfigSchema];
|
|
34
8
|
get queryAddress() {
|
|
35
|
-
return
|
|
9
|
+
return assertEx(this.config.address, "Missing address");
|
|
36
10
|
}
|
|
37
11
|
async divineHandler(payloads) {
|
|
38
12
|
const result = [];
|
|
39
|
-
|
|
13
|
+
assertEx(!(payloads == null ? void 0 : payloads.length), "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
40
14
|
try {
|
|
41
15
|
const archivistIn = await this.readArchivist();
|
|
42
|
-
const archivist =
|
|
43
|
-
let currentHash =
|
|
16
|
+
const archivist = assertEx(archivistIn, "Unable to resolve archivist");
|
|
17
|
+
let currentHash = assertEx(this.config.startHash, "Missing startHash");
|
|
44
18
|
while (currentHash && result.length < (this.config.maxResults ?? 1e3)) {
|
|
45
19
|
const bwPayload = await this.archivistFindHash([archivist], currentHash);
|
|
46
|
-
const bwWrapper =
|
|
20
|
+
const bwWrapper = BoundWitnessWrapper.tryParse(bwPayload);
|
|
47
21
|
if (bwWrapper) {
|
|
48
22
|
result.push(bwWrapper.payload());
|
|
49
23
|
currentHash = bwWrapper.prev(this.queryAddress);
|
|
@@ -65,8 +39,7 @@ var MemoryAddressChainDiviner = class extends import_diviner_address_chain_abstr
|
|
|
65
39
|
}
|
|
66
40
|
}
|
|
67
41
|
};
|
|
68
|
-
|
|
69
|
-
0 && (module.exports = {
|
|
42
|
+
export {
|
|
70
43
|
MemoryAddressChainDiviner
|
|
71
|
-
}
|
|
44
|
+
};
|
|
72
45
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override configSchemas = [AddressChainDivinerConfigSchema]\n\n get queryAddress() {\n return assertEx(this.config.address, 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.readArchivist()\n const archivist = assertEx(archivistIn, 'Unable to resolve archivist')\n let currentHash: string | null = assertEx(this.config.startHash, 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload())\n currentHash = bwWrapper.prev(this.queryAddress)\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: string): Promise<BoundWitness | undefined> {\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).pop() as BoundWitness\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAoC,uCAAuC;AASpE,IAAM,4BAAN,cAEG,oBAA6B;AAAA,EACrC,OAAgB,gBAAgB,CAAC,+BAA+B;AAAA,EAEhE,IAAI,eAAe;AACjB,WAAO,SAAS,KAAK,OAAO,SAAS,iBAAiB;AAAA,EACxD;AAAA,EAEA,MAAyB,cAAc,UAA0C;AAC/E,UAAM,SAAoB,CAAC;AAC3B,aAAS,EAAC,qCAAU,SAAQ,qEAAqE;AACjG,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,cAAc;AAC7C,YAAM,YAAY,SAAS,aAAa,6BAA6B;AACrE,UAAI,cAA6B,SAAS,KAAK,OAAO,WAAW,mBAAmB;AACpF,aAAO,eAAe,OAAO,UAAU,KAAK,OAAO,cAAc,MAAO;AACtE,cAAM,YAAsC,MAAM,KAAK,kBAAkB,CAAC,SAAS,GAAG,WAAW;AACjG,cAAM,YAA6C,oBAAoB,SAAS,SAAS;AACzF,YAAI,WAAW;AACb,iBAAO,KAAK,UAAU,QAAQ,CAAC;AAC/B,wBAAc,UAAU,KAAK,KAAK,YAAY;AAAA,QAChD;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,cAAQ,IAAI,EAAE;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,kBAAkB,YAAiC,MAAiD;AAChH,QAAI,QAAQ;AACZ,QAAI,WAAW,KAAK,GAAG;AACrB,YAAM,UAAU,MAAM,WAAW,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;AACzD,UAAI,QAAQ;AACV,eAAO;AAAA,MACT;AACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -11,28 +11,27 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
|
-
"@xyo-network/archivist-model": "~2.84.
|
|
15
|
-
"@xyo-network/boundwitness-model": "~2.84.
|
|
16
|
-
"@xyo-network/boundwitness-wrapper": "~2.84.
|
|
17
|
-
"@xyo-network/diviner-address-chain-abstract": "~2.84.
|
|
18
|
-
"@xyo-network/diviner-address-chain-model": "~2.84.
|
|
19
|
-
"@xyo-network/diviner-model": "~2.84.
|
|
20
|
-
"@xyo-network/module-model": "~2.84.
|
|
21
|
-
"@xyo-network/payload-model": "~2.84.
|
|
14
|
+
"@xyo-network/archivist-model": "~2.84.3",
|
|
15
|
+
"@xyo-network/boundwitness-model": "~2.84.3",
|
|
16
|
+
"@xyo-network/boundwitness-wrapper": "~2.84.3",
|
|
17
|
+
"@xyo-network/diviner-address-chain-abstract": "~2.84.3",
|
|
18
|
+
"@xyo-network/diviner-address-chain-model": "~2.84.3",
|
|
19
|
+
"@xyo-network/diviner-model": "~2.84.3",
|
|
20
|
+
"@xyo-network/module-model": "~2.84.3",
|
|
21
|
+
"@xyo-network/payload-model": "~2.84.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@xylabs/ts-scripts-yarn3": "^3.2.
|
|
25
|
-
"@xylabs/tsconfig": "^3.2.
|
|
26
|
-
"@xyo-network/account": "~2.84.
|
|
27
|
-
"@xyo-network/archivist": "~2.84.
|
|
28
|
-
"@xyo-network/archivist-wrapper": "~2.84.
|
|
29
|
-
"@xyo-network/node-memory": "~2.84.
|
|
30
|
-
"@xyo-network/node-model": "~2.84.
|
|
31
|
-
"@xyo-network/payload-wrapper": "~2.84.
|
|
24
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.19",
|
|
25
|
+
"@xylabs/tsconfig": "^3.2.19",
|
|
26
|
+
"@xyo-network/account": "~2.84.3",
|
|
27
|
+
"@xyo-network/archivist": "~2.84.3",
|
|
28
|
+
"@xyo-network/archivist-wrapper": "~2.84.3",
|
|
29
|
+
"@xyo-network/node-memory": "~2.84.3",
|
|
30
|
+
"@xyo-network/node-model": "~2.84.3",
|
|
31
|
+
"@xyo-network/payload-wrapper": "~2.84.3",
|
|
32
32
|
"typescript": "^5.3.3"
|
|
33
33
|
},
|
|
34
34
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
35
|
-
"docs": "dist/docs.json",
|
|
36
35
|
"types": "dist/node/index.d.ts",
|
|
37
36
|
"exports": {
|
|
38
37
|
".": {
|
|
@@ -48,19 +47,19 @@
|
|
|
48
47
|
},
|
|
49
48
|
"node": {
|
|
50
49
|
"require": {
|
|
51
|
-
"types": "./dist/node/index.d.
|
|
52
|
-
"default": "./dist/node/index.
|
|
50
|
+
"types": "./dist/node/index.d.cts",
|
|
51
|
+
"default": "./dist/node/index.cjs"
|
|
53
52
|
},
|
|
54
53
|
"import": {
|
|
55
54
|
"types": "./dist/node/index.d.mts",
|
|
56
|
-
"default": "./dist/node/index.
|
|
55
|
+
"default": "./dist/node/index.js"
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
"./package.json": "./package.json"
|
|
61
60
|
},
|
|
62
|
-
"main": "dist/node/index.
|
|
63
|
-
"module": "dist/node/index.
|
|
61
|
+
"main": "dist/node/index.cjs",
|
|
62
|
+
"module": "dist/node/index.js",
|
|
64
63
|
"homepage": "https://xyo.network",
|
|
65
64
|
"license": "LGPL-3.0-only",
|
|
66
65
|
"publishConfig": {
|
|
@@ -71,5 +70,6 @@
|
|
|
71
70
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
72
71
|
},
|
|
73
72
|
"sideEffects": false,
|
|
74
|
-
"version": "2.84.
|
|
73
|
+
"version": "2.84.3",
|
|
74
|
+
"type": "module"
|
|
75
75
|
}
|
package/dist/node/index.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/MemoryDiviner.ts
|
|
2
|
-
import { assertEx } from "@xylabs/assert";
|
|
3
|
-
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
4
|
-
import { AddressChainDiviner } from "@xyo-network/diviner-address-chain-abstract";
|
|
5
|
-
import { AddressChainDivinerConfigSchema } from "@xyo-network/diviner-address-chain-model";
|
|
6
|
-
var MemoryAddressChainDiviner = class extends AddressChainDiviner {
|
|
7
|
-
static configSchemas = [AddressChainDivinerConfigSchema];
|
|
8
|
-
get queryAddress() {
|
|
9
|
-
return assertEx(this.config.address, "Missing address");
|
|
10
|
-
}
|
|
11
|
-
async divineHandler(payloads) {
|
|
12
|
-
const result = [];
|
|
13
|
-
assertEx(!(payloads == null ? void 0 : payloads.length), "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
14
|
-
try {
|
|
15
|
-
const archivistIn = await this.readArchivist();
|
|
16
|
-
const archivist = assertEx(archivistIn, "Unable to resolve archivist");
|
|
17
|
-
let currentHash = assertEx(this.config.startHash, "Missing startHash");
|
|
18
|
-
while (currentHash && result.length < (this.config.maxResults ?? 1e3)) {
|
|
19
|
-
const bwPayload = await this.archivistFindHash([archivist], currentHash);
|
|
20
|
-
const bwWrapper = BoundWitnessWrapper.tryParse(bwPayload);
|
|
21
|
-
if (bwWrapper) {
|
|
22
|
-
result.push(bwWrapper.payload());
|
|
23
|
-
currentHash = bwWrapper.prev(this.queryAddress);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
} catch (ex) {
|
|
27
|
-
console.log(ex);
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
async archivistFindHash(archivists, hash) {
|
|
32
|
-
let index = 0;
|
|
33
|
-
if (archivists[index]) {
|
|
34
|
-
const result = (await archivists[index].get([hash])).pop();
|
|
35
|
-
if (result) {
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
index++;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
export {
|
|
43
|
-
MemoryAddressChainDiviner
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override configSchemas = [AddressChainDivinerConfigSchema]\n\n get queryAddress() {\n return assertEx(this.config.address, 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.readArchivist()\n const archivist = assertEx(archivistIn, 'Unable to resolve archivist')\n let currentHash: string | null = assertEx(this.config.startHash, 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload())\n currentHash = bwWrapper.prev(this.queryAddress)\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: string): Promise<BoundWitness | undefined> {\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).pop() as BoundWitness\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAoC,uCAAuC;AASpE,IAAM,4BAAN,cAEG,oBAA6B;AAAA,EACrC,OAAgB,gBAAgB,CAAC,+BAA+B;AAAA,EAEhE,IAAI,eAAe;AACjB,WAAO,SAAS,KAAK,OAAO,SAAS,iBAAiB;AAAA,EACxD;AAAA,EAEA,MAAyB,cAAc,UAA0C;AAC/E,UAAM,SAAoB,CAAC;AAC3B,aAAS,EAAC,qCAAU,SAAQ,qEAAqE;AACjG,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,cAAc;AAC7C,YAAM,YAAY,SAAS,aAAa,6BAA6B;AACrE,UAAI,cAA6B,SAAS,KAAK,OAAO,WAAW,mBAAmB;AACpF,aAAO,eAAe,OAAO,UAAU,KAAK,OAAO,cAAc,MAAO;AACtE,cAAM,YAAsC,MAAM,KAAK,kBAAkB,CAAC,SAAS,GAAG,WAAW;AACjG,cAAM,YAA6C,oBAAoB,SAAS,SAAS;AACzF,YAAI,WAAW;AACb,iBAAO,KAAK,UAAU,QAAQ,CAAC;AAC/B,wBAAc,UAAU,KAAK,KAAK,YAAY;AAAA,QAChD;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,cAAQ,IAAI,EAAE;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,kBAAkB,YAAiC,MAAiD;AAChH,QAAI,QAAQ;AACZ,QAAI,WAAW,KAAK,GAAG;AACrB,YAAM,UAAU,MAAM,WAAW,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;AACzD,UAAI,QAAQ;AACV,eAAO;AAAA,MACT;AACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|