@xyo-network/diviner 2.44.1 → 2.45.0-rc.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/dist/cjs/AddressHistory/MemoryAddressHistoryDiviner.js +46 -30
- package/dist/cjs/AddressHistory/MemoryAddressHistoryDiviner.js.map +1 -1
- package/dist/cjs/Payload/Archivist/Diviner.js +6 -10
- package/dist/cjs/Payload/Archivist/Diviner.js.map +1 -1
- package/dist/docs.json +10184 -9835
- package/dist/esm/AddressHistory/MemoryAddressHistoryDiviner.js +40 -29
- package/dist/esm/AddressHistory/MemoryAddressHistoryDiviner.js.map +1 -1
- package/dist/esm/Payload/Archivist/Diviner.js +5 -7
- package/dist/esm/Payload/Archivist/Diviner.js.map +1 -1
- package/dist/types/AddressHistory/MemoryAddressHistoryDiviner.d.ts +14 -2
- package/dist/types/AddressHistory/MemoryAddressHistoryDiviner.d.ts.map +1 -1
- package/dist/types/Payload/Archivist/Diviner.d.ts +1 -2
- package/dist/types/Payload/Archivist/Diviner.d.ts.map +1 -1
- package/package.json +17 -16
- package/src/AddressHistory/MemoryAddressHistoryDiviner.ts +60 -31
- package/src/Payload/Archivist/Diviner.ts +5 -8
|
@@ -4,44 +4,55 @@ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
|
|
|
4
4
|
import { XyoBoundWitnessSchema } from '@xyo-network/boundwitness-model';
|
|
5
5
|
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper';
|
|
6
6
|
import { AbstractDiviner } from '../AbstractDiviner';
|
|
7
|
-
|
|
7
|
+
export const MemoryAddressHistoryDivinerConfigSchema = 'network.xyo.diviner.address.history.memory.config';
|
|
8
|
+
// This diviner returns the most recent boundwitness signed by the address that can be found
|
|
9
|
+
// if multiple broken chains are found, all the heads are returned
|
|
8
10
|
export class MemoryAddressHistoryDiviner extends AbstractDiviner {
|
|
11
|
+
static configSchema = MemoryAddressHistoryDivinerConfigSchema;
|
|
12
|
+
static async create(params) {
|
|
13
|
+
return (await super.create(params));
|
|
14
|
+
}
|
|
9
15
|
async divine(payloads) {
|
|
10
|
-
|
|
11
|
-
// TODO: Support multiple queries
|
|
12
|
-
if (!query)
|
|
13
|
-
return [];
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
-
const { address } = query;
|
|
16
|
-
const assertedAddress = assertEx(address);
|
|
17
|
-
//only supporting single address at this point
|
|
18
|
-
const singleAddress = assertEx((Array.isArray(assertedAddress) ? assertedAddress : [assertedAddress]).shift());
|
|
16
|
+
assertEx(!payloads, 'MemoryAddressHistoryDiviner.divine does not allow payloads to be sent');
|
|
19
17
|
const archivists = (await this.resolver?.resolve({ query: [[ArchivistGetQuerySchema]] }))?.map((archivist) => new ArchivistWrapper(archivist)) ?? [];
|
|
20
18
|
const bwLists = (await Promise.all(archivists.map((archivist) => {
|
|
19
|
+
//Todo: add address to filter
|
|
21
20
|
return archivist.find({ limit: 10000, schema: XyoBoundWitnessSchema });
|
|
22
21
|
}))).flat();
|
|
23
|
-
const bwRecords =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const wrapper = new BoundWitnessWrapper(bw);
|
|
28
|
-
bwRecords[wrapper.hash] = [wrapper];
|
|
29
|
-
return bwRecords;
|
|
30
|
-
}, bwRecords);
|
|
31
|
-
return Object.values(this.buildAddressLists(singleAddress, bwRecords)).flat();
|
|
22
|
+
const bwRecords = this.buildWrapperRecords(bwLists);
|
|
23
|
+
const chains = Object.values(this.buildAddressChains(this.config.address, bwRecords));
|
|
24
|
+
//return the heads of each chain (get the last bw on each chain)
|
|
25
|
+
return chains.map((chain) => assertEx(chain.pop()));
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
Object.entries(bwRecords).
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
buildAddressChains(address, bwRecords) {
|
|
28
|
+
const arrayedResult = Object.entries(bwRecords).reduce((prev, [key, value]) => {
|
|
29
|
+
prev[key] = [value];
|
|
30
|
+
return prev;
|
|
31
|
+
}, {});
|
|
32
|
+
return Object.entries(bwRecords).reduce((prev, [key, value]) => {
|
|
33
|
+
//check if key is still there (may have been deleted as prevHash)
|
|
34
|
+
if (prev[key]) {
|
|
35
|
+
const previousHash = value.prev(address);
|
|
36
|
+
if (previousHash) {
|
|
37
|
+
//if we have the previousHash, move this bw to its chain
|
|
38
|
+
if (prev[previousHash]) {
|
|
39
|
+
prev[key].push(...prev[previousHash]);
|
|
40
|
+
delete prev[previousHash];
|
|
41
|
+
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
return prev;
|
|
45
|
+
}, arrayedResult);
|
|
46
|
+
}
|
|
47
|
+
//build object with hashes as keys and wrappers as values
|
|
48
|
+
buildWrapperRecords(lists) {
|
|
49
|
+
return lists
|
|
50
|
+
.filter((bw) => bw.addresses.includes(this.config.address))
|
|
51
|
+
.reduce((bwRecords, bw) => {
|
|
52
|
+
const wrapper = new BoundWitnessWrapper(bw);
|
|
53
|
+
bwRecords[wrapper.hash] = wrapper;
|
|
54
|
+
return bwRecords;
|
|
55
|
+
}, {});
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
//# sourceMappingURL=MemoryAddressHistoryDiviner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryAddressHistoryDiviner.js","sourceRoot":"","sources":["../../../src/AddressHistory/MemoryAddressHistoryDiviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,m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AI,CAAC,YAAY,CAAC,CAAA;qBAC1B;iBACF;aACF;YACD,OAAO,IAAI,CAAA;QACb,CAAC,EAAE,aAAa,CAAC,CAAA;IACnB,CAAC;IAED,yDAAyD;IACjD,mBAAmB,CAAC,KAAwB;QAClD,OAAO,KAAK;aACT,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC1D,MAAM,CAAsC,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE;YAC7D,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAA;YAC3C,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAA;YACjC,OAAO,SAAS,CAAA;QAClB,CAAC,EAAE,EAAE,CAAC,CAAA;IACV,CAAC"}
|
|
@@ -8,14 +8,13 @@ import { AbstractPayloadDiviner } from '../AbstractPayloadDiviner';
|
|
|
8
8
|
import { XyoHuriSchema } from '../XyoHuriPayload';
|
|
9
9
|
export class ArchivistPayloadDiviner extends AbstractPayloadDiviner {
|
|
10
10
|
static configSchema;
|
|
11
|
-
archivist;
|
|
12
11
|
static async create(params) {
|
|
13
12
|
return (await super.create(params));
|
|
14
13
|
}
|
|
15
14
|
async divine(payloads) {
|
|
16
15
|
const huriPayloads = assertEx(payloads?.filter((payload) => payload?.schema === XyoHuriSchema), `no huri payloads provided: ${JSON.stringify(payloads, null, 2)}`);
|
|
17
16
|
const hashes = huriPayloads.map((huriPayload) => huriPayload.huri.map((huri) => new Huri(huri).hash)).flat();
|
|
18
|
-
const activeArchivist = this.archivist;
|
|
17
|
+
const activeArchivist = await this.archivist();
|
|
19
18
|
if (activeArchivist) {
|
|
20
19
|
const queryPayload = PayloadWrapper.parse({ hashes, schema: ArchivistGetQuerySchema });
|
|
21
20
|
const query = await this.bindQuery(queryPayload);
|
|
@@ -26,18 +25,17 @@ export class ArchivistPayloadDiviner extends AbstractPayloadDiviner {
|
|
|
26
25
|
queries() {
|
|
27
26
|
return [XyoDivinerDivineQuerySchema, ...super.queries()];
|
|
28
27
|
}
|
|
29
|
-
async
|
|
30
|
-
await super.start();
|
|
28
|
+
async archivist() {
|
|
31
29
|
const configArchivistAddress = this.config?.archivist;
|
|
32
30
|
if (configArchivistAddress) {
|
|
33
31
|
const resolvedArchivist = configArchivistAddress
|
|
34
|
-
? (this.
|
|
32
|
+
? (await this.resolve({ address: [configArchivistAddress] })).shift() ?? null
|
|
35
33
|
: null;
|
|
36
34
|
if (resolvedArchivist) {
|
|
37
|
-
|
|
35
|
+
return resolvedArchivist ? new ArchivistWrapper(resolvedArchivist) : null;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
|
-
return
|
|
38
|
+
return null;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
//# sourceMappingURL=Diviner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.js","sourceRoot":"","sources":["../../../../src/Payload/Archivist/Diviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAqB,uBAAuB,EAAoB,MAAM,wBAAwB,CAAA;AACrG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAkB,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjE,MAAM,OAAO,uBAAwB,SAAQ,sBAAwD;IACnG,MAAM,CAAU,YAAY,CAAwC;
|
|
1
|
+
{"version":3,"file":"Diviner.js","sourceRoot":"","sources":["../../../../src/Pay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AE;YACnB,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAA;YACzG,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;YAChD,OAAO,CAAC,MAAM,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;SAC5D;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IAEQ,OAAO;QACd,OAAO,CAAC,2BAA2B,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAC1D,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,EAAE,SAAS,CAAA;QACrD,IAAI,sBAAsB,EAAE;YAC1B,MAAM,iBAAiB,GAA4B,sBAAsB;gBACvE,CAAC,CAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAmC,CAAC,KAAK,EAAE,IAAI,IAAI;gBAChH,CAAC,CAAC,IAAI,CAAA;YACR,IAAI,iBAAiB,EAAE;gBACrB,OAAO,iBAAiB,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;aAC1E;SACF;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { XyoBoundWitness } from '@xyo-network/boundwitness-model';
|
|
2
|
+
import { DivinerConfig } from '@xyo-network/diviner-model';
|
|
3
|
+
import { ModuleParams } from '@xyo-network/module';
|
|
1
4
|
import { XyoPayload } from '@xyo-network/payload-model';
|
|
2
5
|
import { AbstractDiviner } from '../AbstractDiviner';
|
|
3
6
|
import { AddressHistoryDiviner } from './AddressHistoryDiviner';
|
|
4
|
-
export
|
|
7
|
+
export type MemoryAddressHistoryDivinerConfigSchema = 'network.xyo.diviner.address.history.memory.config';
|
|
8
|
+
export declare const MemoryAddressHistoryDivinerConfigSchema = "network.xyo.diviner.address.history.memory.config";
|
|
9
|
+
export type MemoryAddressHistoryDivinerConfig = DivinerConfig<XyoBoundWitness, {
|
|
10
|
+
address: string;
|
|
11
|
+
schema: MemoryAddressHistoryDivinerConfigSchema;
|
|
12
|
+
}>;
|
|
13
|
+
export declare class MemoryAddressHistoryDiviner extends AbstractDiviner<MemoryAddressHistoryDivinerConfig> implements AddressHistoryDiviner {
|
|
14
|
+
static configSchema: string;
|
|
15
|
+
static create(params?: Partial<ModuleParams<MemoryAddressHistoryDivinerConfig>>): Promise<MemoryAddressHistoryDiviner>;
|
|
5
16
|
divine(payloads?: XyoPayload[]): Promise<XyoPayload[]>;
|
|
6
|
-
private
|
|
17
|
+
private buildAddressChains;
|
|
18
|
+
private buildWrapperRecords;
|
|
7
19
|
}
|
|
8
20
|
//# sourceMappingURL=MemoryAddressHistoryDiviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryAddressHistoryDiviner.d.ts","sourceRoot":"","sources":["../../../src/AddressHistory/MemoryAddressHistoryDiviner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryAddressHistoryDiviner.d.ts","sourceRoot":"","sources":["../../../src/AddressHistory/MemoryAddressHistoryDiviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAyB,MAAM,iCAAiC,CAAA;AAExF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,MAAM,uCAAuC,GAAG,mDAAmD,CAAA;AACzG,eAAO,MAAM,uCAAuC,sDAAsD,CAAA;AAE1G,MAAM,MAAM,iCAAiC,GAAG,aAAa,CAC3D,eAAe,EACf;IACE,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,uCAAuC,CAAA;CAChD,CACF,CAAA;AAKD,qBAAa,2BAA4B,SAAQ,eAAe,CAAC,iCAAiC,CAAE,YAAW,qBAAqB;IAClI,OAAgB,YAAY,SAA0C;WAEhD,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,iCAAiC,CAAC,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAI/H,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAqB5D,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,mBAAmB;CAS5B"}
|
|
@@ -5,10 +5,9 @@ import { AbstractPayloadDiviner } from '../AbstractPayloadDiviner';
|
|
|
5
5
|
import { XyoArchivistPayloadDivinerConfig, XyoArchivistPayloadDivinerConfigSchema } from './Config';
|
|
6
6
|
export declare class ArchivistPayloadDiviner extends AbstractPayloadDiviner<XyoArchivistPayloadDivinerConfig> {
|
|
7
7
|
static configSchema: XyoArchivistPayloadDivinerConfigSchema;
|
|
8
|
-
protected archivist?: PayloadArchivist | null;
|
|
9
8
|
static create(params?: ModuleParams<XyoArchivistPayloadDivinerConfig>): Promise<ArchivistPayloadDiviner>;
|
|
10
9
|
divine(payloads?: XyoPayload[]): Promise<XyoPayload[]>;
|
|
11
10
|
queries(): string[];
|
|
12
|
-
protected
|
|
11
|
+
protected archivist(): Promise<PayloadArchivist | null>;
|
|
13
12
|
}
|
|
14
13
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../../src/Payload/Archivist/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAA8C,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAIrG,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,gCAAgC,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AAEnG,qBAAa,uBAAwB,SAAQ,sBAAsB,CAAC,gCAAgC,CAAC;IACnG,OAAgB,YAAY,EAAE,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../../src/Payload/Archivist/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAA8C,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAIrG,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,gCAAgC,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AAEnG,qBAAa,uBAAwB,SAAQ,sBAAsB,CAAC,gCAAgC,CAAC;IACnG,OAAgB,YAAY,EAAE,sCAAsC,CAAA;WAE9C,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,gCAAgC,CAAC,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAI1G,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAe1D,OAAO;cAIA,SAAS,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;CAY9D"}
|
package/package.json
CHANGED
|
@@ -12,25 +12,25 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.7.1",
|
|
14
14
|
"@xylabs/promise": "^2.7.1",
|
|
15
|
-
"@xyo-network/account": "^2.
|
|
16
|
-
"@xyo-network/archivist": "^2.
|
|
17
|
-
"@xyo-network/archivist-wrapper": "^2.
|
|
18
|
-
"@xyo-network/boundwitness-model": "^2.
|
|
19
|
-
"@xyo-network/boundwitness-wrapper": "^2.
|
|
20
|
-
"@xyo-network/diviner-model": "^2.
|
|
21
|
-
"@xyo-network/diviner-wrapper": "^2.
|
|
22
|
-
"@xyo-network/huri": "^2.
|
|
23
|
-
"@xyo-network/module": "^2.
|
|
24
|
-
"@xyo-network/module-model": "^2.
|
|
25
|
-
"@xyo-network/payload-model": "^2.
|
|
26
|
-
"@xyo-network/payload-wrapper": "^2.
|
|
27
|
-
"@xyo-network/promise": "^2.
|
|
15
|
+
"@xyo-network/account": "^2.45.0-rc.1",
|
|
16
|
+
"@xyo-network/archivist": "^2.45.0-rc.1",
|
|
17
|
+
"@xyo-network/archivist-wrapper": "^2.45.0-rc.1",
|
|
18
|
+
"@xyo-network/boundwitness-model": "^2.45.0-rc.1",
|
|
19
|
+
"@xyo-network/boundwitness-wrapper": "^2.45.0-rc.1",
|
|
20
|
+
"@xyo-network/diviner-model": "^2.45.0-rc.1",
|
|
21
|
+
"@xyo-network/diviner-wrapper": "^2.45.0-rc.1",
|
|
22
|
+
"@xyo-network/huri": "^2.45.0-rc.1",
|
|
23
|
+
"@xyo-network/module": "^2.45.0-rc.1",
|
|
24
|
+
"@xyo-network/module-model": "^2.45.0-rc.1",
|
|
25
|
+
"@xyo-network/payload-model": "^2.45.0-rc.1",
|
|
26
|
+
"@xyo-network/payload-wrapper": "^2.45.0-rc.1",
|
|
27
|
+
"@xyo-network/promise": "^2.45.0-rc.1",
|
|
28
28
|
"lodash": "^4.17.21"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/lodash": "^4.14.191",
|
|
32
|
-
"@xylabs/ts-scripts-yarn3": "^2.14.
|
|
33
|
-
"@xylabs/tsconfig": "^2.14.
|
|
32
|
+
"@xylabs/ts-scripts-yarn3": "^2.14.15",
|
|
33
|
+
"@xylabs/tsconfig": "^2.14.15",
|
|
34
34
|
"typescript": "^4.9.5"
|
|
35
35
|
},
|
|
36
36
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -66,5 +66,6 @@
|
|
|
66
66
|
},
|
|
67
67
|
"sideEffects": false,
|
|
68
68
|
"types": "dist/types/index.d.ts",
|
|
69
|
-
"version": "2.
|
|
69
|
+
"version": "2.45.0-rc.1",
|
|
70
|
+
"stableVersion": "2.44.1"
|
|
70
71
|
}
|
|
@@ -3,55 +3,84 @@ import { ArchivistGetQuerySchema } from '@xyo-network/archivist'
|
|
|
3
3
|
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
4
4
|
import { XyoBoundWitness, XyoBoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
5
5
|
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
6
|
+
import { DivinerConfig } from '@xyo-network/diviner-model'
|
|
7
|
+
import { ModuleParams } from '@xyo-network/module'
|
|
6
8
|
import { XyoPayload } from '@xyo-network/payload-model'
|
|
7
9
|
|
|
8
10
|
import { AbstractDiviner } from '../AbstractDiviner'
|
|
9
|
-
import { AddressHistoryDiviner
|
|
11
|
+
import { AddressHistoryDiviner } from './AddressHistoryDiviner'
|
|
10
12
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export type MemoryAddressHistoryDivinerConfigSchema = 'network.xyo.diviner.address.history.memory.config'
|
|
14
|
+
export const MemoryAddressHistoryDivinerConfigSchema = 'network.xyo.diviner.address.history.memory.config'
|
|
15
|
+
|
|
16
|
+
export type MemoryAddressHistoryDivinerConfig = DivinerConfig<
|
|
17
|
+
XyoBoundWitness,
|
|
18
|
+
{
|
|
19
|
+
address: string
|
|
20
|
+
schema: MemoryAddressHistoryDivinerConfigSchema
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
// This diviner returns the most recent boundwitness signed by the address that can be found
|
|
25
|
+
// if multiple broken chains are found, all the heads are returned
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
export class MemoryAddressHistoryDiviner extends AbstractDiviner<MemoryAddressHistoryDivinerConfig> implements AddressHistoryDiviner {
|
|
28
|
+
static override configSchema = MemoryAddressHistoryDivinerConfigSchema
|
|
22
29
|
|
|
30
|
+
static override async create(params?: Partial<ModuleParams<MemoryAddressHistoryDivinerConfig>>): Promise<MemoryAddressHistoryDiviner> {
|
|
31
|
+
return (await super.create(params)) as MemoryAddressHistoryDiviner
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async divine(payloads?: XyoPayload[]): Promise<XyoPayload[]> {
|
|
35
|
+
assertEx(!payloads, 'MemoryAddressHistoryDiviner.divine does not allow payloads to be sent')
|
|
23
36
|
const archivists =
|
|
24
37
|
(await this.resolver?.resolve({ query: [[ArchivistGetQuerySchema]] }))?.map((archivist) => new ArchivistWrapper(archivist)) ?? []
|
|
25
38
|
const bwLists = (
|
|
26
39
|
await Promise.all(
|
|
27
40
|
archivists.map((archivist) => {
|
|
28
|
-
|
|
41
|
+
//Todo: add address to filter
|
|
42
|
+
return archivist.find<XyoBoundWitness>({ limit: 10000, schema: XyoBoundWitnessSchema })
|
|
29
43
|
}),
|
|
30
44
|
)
|
|
31
45
|
).flat()
|
|
32
|
-
const bwRecords: Record<string, BoundWitnessWrapper[]> = {}
|
|
33
|
-
bwLists
|
|
34
|
-
.filter((bw) => bw.addresses.includes(singleAddress))
|
|
35
|
-
.reduce((bwRecords, bw) => {
|
|
36
|
-
const wrapper = new BoundWitnessWrapper(bw)
|
|
37
|
-
bwRecords[wrapper.hash] = [wrapper]
|
|
38
|
-
return bwRecords
|
|
39
|
-
}, bwRecords)
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
const bwRecords = this.buildWrapperRecords(bwLists)
|
|
48
|
+
|
|
49
|
+
const chains = Object.values(this.buildAddressChains(this.config.address, bwRecords))
|
|
50
|
+
|
|
51
|
+
//return the heads of each chain (get the last bw on each chain)
|
|
52
|
+
return chains.map((chain) => assertEx(chain.pop()))
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
private
|
|
45
|
-
Object.entries(bwRecords).
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
private buildAddressChains(address: string, bwRecords: Record<string, BoundWitnessWrapper>): Record<string, BoundWitnessWrapper[]> {
|
|
56
|
+
const arrayedResult = Object.entries(bwRecords).reduce<Record<string, BoundWitnessWrapper[]>>((prev, [key, value]) => {
|
|
57
|
+
prev[key] = [value]
|
|
58
|
+
return prev
|
|
59
|
+
}, {})
|
|
60
|
+
return Object.entries(bwRecords).reduce<Record<string, BoundWitnessWrapper[]>>((prev, [key, value]) => {
|
|
61
|
+
//check if key is still there (may have been deleted as prevHash)
|
|
62
|
+
if (prev[key]) {
|
|
63
|
+
const previousHash = value.prev(address)
|
|
64
|
+
if (previousHash) {
|
|
65
|
+
//if we have the previousHash, move this bw to its chain
|
|
66
|
+
if (prev[previousHash]) {
|
|
67
|
+
prev[key].push(...prev[previousHash])
|
|
68
|
+
delete prev[previousHash]
|
|
69
|
+
}
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
return prev
|
|
73
|
+
}, arrayedResult)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//build object with hashes as keys and wrappers as values
|
|
77
|
+
private buildWrapperRecords(lists: XyoBoundWitness[]) {
|
|
78
|
+
return lists
|
|
79
|
+
.filter((bw) => bw.addresses.includes(this.config.address))
|
|
80
|
+
.reduce<Record<string, BoundWitnessWrapper>>((bwRecords, bw) => {
|
|
81
|
+
const wrapper = new BoundWitnessWrapper(bw)
|
|
82
|
+
bwRecords[wrapper.hash] = wrapper
|
|
83
|
+
return bwRecords
|
|
84
|
+
}, {})
|
|
56
85
|
}
|
|
57
86
|
}
|
|
@@ -14,8 +14,6 @@ import { XyoArchivistPayloadDivinerConfig, XyoArchivistPayloadDivinerConfigSchem
|
|
|
14
14
|
export class ArchivistPayloadDiviner extends AbstractPayloadDiviner<XyoArchivistPayloadDivinerConfig> {
|
|
15
15
|
static override configSchema: XyoArchivistPayloadDivinerConfigSchema
|
|
16
16
|
|
|
17
|
-
protected archivist?: PayloadArchivist | null
|
|
18
|
-
|
|
19
17
|
static override async create(params?: ModuleParams<XyoArchivistPayloadDivinerConfig>): Promise<ArchivistPayloadDiviner> {
|
|
20
18
|
return (await super.create(params)) as ArchivistPayloadDiviner
|
|
21
19
|
}
|
|
@@ -26,7 +24,7 @@ export class ArchivistPayloadDiviner extends AbstractPayloadDiviner<XyoArchivist
|
|
|
26
24
|
`no huri payloads provided: ${JSON.stringify(payloads, null, 2)}`,
|
|
27
25
|
)
|
|
28
26
|
const hashes = huriPayloads.map((huriPayload) => huriPayload.huri.map((huri) => new Huri(huri).hash)).flat()
|
|
29
|
-
const activeArchivist = this.archivist
|
|
27
|
+
const activeArchivist = await this.archivist()
|
|
30
28
|
if (activeArchivist) {
|
|
31
29
|
const queryPayload = PayloadWrapper.parse<ArchivistGetQuery>({ hashes, schema: ArchivistGetQuerySchema })
|
|
32
30
|
const query = await this.bindQuery(queryPayload)
|
|
@@ -39,17 +37,16 @@ export class ArchivistPayloadDiviner extends AbstractPayloadDiviner<XyoArchivist
|
|
|
39
37
|
return [XyoDivinerDivineQuerySchema, ...super.queries()]
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
protected
|
|
43
|
-
await super.start()
|
|
40
|
+
protected async archivist(): Promise<PayloadArchivist | null> {
|
|
44
41
|
const configArchivistAddress = this.config?.archivist
|
|
45
42
|
if (configArchivistAddress) {
|
|
46
43
|
const resolvedArchivist: PayloadArchivist | null = configArchivistAddress
|
|
47
|
-
? (this.
|
|
44
|
+
? ((await this.resolve({ address: [configArchivistAddress] })) as unknown as PayloadArchivist[]).shift() ?? null
|
|
48
45
|
: null
|
|
49
46
|
if (resolvedArchivist) {
|
|
50
|
-
|
|
47
|
+
return resolvedArchivist ? new ArchivistWrapper(resolvedArchivist) : null
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
|
-
return
|
|
50
|
+
return null
|
|
54
51
|
}
|
|
55
52
|
}
|