@xyo-network/diviner-address-chain-memory 2.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/cjs/MemoryDiviner.js +48 -0
- package/dist/cjs/MemoryDiviner.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +10738 -0
- package/dist/esm/MemoryDiviner.js +38 -0
- package/dist/esm/MemoryDiviner.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/MemoryDiviner.d.ts +13 -0
- package/dist/types/MemoryDiviner.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +63 -0
- package/src/MemoryDiviner.ts +52 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert';
|
|
2
|
+
import { ArchivistGetQuerySchema } from '@xyo-network/archivist-model';
|
|
3
|
+
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
|
|
4
|
+
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper';
|
|
5
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract';
|
|
6
|
+
import { AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model';
|
|
7
|
+
export class MemoryAddressChainDiviner extends AddressChainDiviner {
|
|
8
|
+
static configSchema = AddressChainDivinerConfigSchema;
|
|
9
|
+
get queryAddress() {
|
|
10
|
+
return assertEx(this.config.address, 'Missing address');
|
|
11
|
+
}
|
|
12
|
+
async divine(payloads) {
|
|
13
|
+
const result = [];
|
|
14
|
+
assertEx(!payloads?.length, 'MemoryAddressChainDiviner.divine does not allow payloads to be sent');
|
|
15
|
+
const archivists = (await this.resolve({ query: [[ArchivistGetQuerySchema]] }))?.map((archivist) => ArchivistWrapper.wrap(archivist, this.account)) ?? [];
|
|
16
|
+
let currentHash = assertEx(this.config.startHash, 'Missing startHash');
|
|
17
|
+
while (currentHash && result.length < (this.config.maxResults ?? 1000)) {
|
|
18
|
+
const bwPayload = await this.archivistFindHash(archivists, currentHash);
|
|
19
|
+
const bw = BoundWitnessWrapper.parse(bwPayload);
|
|
20
|
+
if (bw) {
|
|
21
|
+
result.push(bw);
|
|
22
|
+
currentHash = bw.prev(this.queryAddress);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
async archivistFindHash(archivists, hash) {
|
|
28
|
+
let index = 0;
|
|
29
|
+
if (archivists[index]) {
|
|
30
|
+
const result = (await archivists[index].get([hash])).pop();
|
|
31
|
+
if (result) {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
index++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=MemoryDiviner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.js","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,EAA6B,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;AASrH,MAAM,OAAO,yBAEX,SAAQ,mBAA4B;IACpC,MAAM,CAAU,YAAY,GAAG,+BAA+B,CAAA;IAE9D,IAAI,YAAY;QACd,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;IAC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AC1E,IAAI,MAAM,EAAE;gBACV,OAAO,MAAM,CAAA;aACd;YACD,KAAK,EAAE,CAAA;SACR;IACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract';
|
|
2
|
+
import { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model';
|
|
3
|
+
import { DivinerParams } from '@xyo-network/diviner-model';
|
|
4
|
+
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
5
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
6
|
+
export type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>;
|
|
7
|
+
export declare class MemoryAddressChainDiviner<TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams> extends AddressChainDiviner<TParams> {
|
|
8
|
+
static configSchema: "network.xyo.diviner.address.chain.config";
|
|
9
|
+
get queryAddress(): string;
|
|
10
|
+
divine(payloads?: Payload[]): Promise<Payload[]>;
|
|
11
|
+
private archivistFindHash;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=MemoryDiviner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAmC,MAAM,0CAA0C,CAAA;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIpD,MAAM,MAAM,+BAA+B,GAAG,aAAa,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAA;AAEvG,qBAAa,yBAAyB,CACpC,OAAO,SAAS,+BAA+B,GAAG,+BAA+B,CACjF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IACpC,OAAgB,YAAY,6CAAkC;IAE9D,IAAI,YAAY,WAEf;IAEK,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YAiBxC,iBAAiB;CAUhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/diviner-address-chain-memory",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xylabs/assert": "^2.7.6",
|
|
14
|
+
"@xyo-network/archivist-model": "^2.56.0",
|
|
15
|
+
"@xyo-network/archivist-wrapper": "^2.56.0",
|
|
16
|
+
"@xyo-network/boundwitness-model": "^2.56.0",
|
|
17
|
+
"@xyo-network/boundwitness-wrapper": "^2.56.0",
|
|
18
|
+
"@xyo-network/diviner-address-chain-abstract": "^2.56.0",
|
|
19
|
+
"@xyo-network/diviner-address-chain-model": "^2.56.0",
|
|
20
|
+
"@xyo-network/diviner-model": "^2.56.0",
|
|
21
|
+
"@xyo-network/module-model": "^2.56.0",
|
|
22
|
+
"@xyo-network/payload-model": "^2.56.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^2.16.5",
|
|
26
|
+
"@xylabs/tsconfig": "^2.16.5",
|
|
27
|
+
"typescript": "^4.9.5"
|
|
28
|
+
},
|
|
29
|
+
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
30
|
+
"browser": "dist/esm/index.js",
|
|
31
|
+
"docs": "dist/docs.json",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"node": {
|
|
35
|
+
"import": "./dist/esm/index.js",
|
|
36
|
+
"require": "./dist/cjs/index.js"
|
|
37
|
+
},
|
|
38
|
+
"browser": {
|
|
39
|
+
"import": "./dist/esm/index.js",
|
|
40
|
+
"require": "./dist/cjs/index.js"
|
|
41
|
+
},
|
|
42
|
+
"default": "./dist/esm/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./dist/docs.json": {
|
|
45
|
+
"default": "./dist/docs.json"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"main": "dist/cjs/index.js",
|
|
50
|
+
"module": "dist/esm/index.js",
|
|
51
|
+
"homepage": "https://xyo.network",
|
|
52
|
+
"license": "LGPL-3.0",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"types": "dist/types/index.d.ts",
|
|
62
|
+
"version": "2.56.0"
|
|
63
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { ArchivistGetQuerySchema } from '@xyo-network/archivist-model'
|
|
3
|
+
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
4
|
+
import { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
|
+
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
6
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'
|
|
7
|
+
import { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'
|
|
8
|
+
import { DivinerParams } from '@xyo-network/diviner-model'
|
|
9
|
+
import { AnyConfigSchema } from '@xyo-network/module-model'
|
|
10
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
11
|
+
|
|
12
|
+
// This diviner returns the most recent boundwitness signed by the address that can be found
|
|
13
|
+
// if multiple broken chains are found, all the heads are returned
|
|
14
|
+
export type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>
|
|
15
|
+
|
|
16
|
+
export class MemoryAddressChainDiviner<
|
|
17
|
+
TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,
|
|
18
|
+
> extends AddressChainDiviner<TParams> {
|
|
19
|
+
static override configSchema = AddressChainDivinerConfigSchema
|
|
20
|
+
|
|
21
|
+
get queryAddress() {
|
|
22
|
+
return assertEx(this.config.address, 'Missing address')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async divine(payloads?: Payload[]): Promise<Payload[]> {
|
|
26
|
+
const result: Payload[] = []
|
|
27
|
+
assertEx(!payloads?.length, 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')
|
|
28
|
+
const archivists =
|
|
29
|
+
(await this.resolve({ query: [[ArchivistGetQuerySchema]] }))?.map((archivist) => ArchivistWrapper.wrap(archivist, this.account)) ?? []
|
|
30
|
+
let currentHash: string | null = assertEx(this.config.startHash, 'Missing startHash')
|
|
31
|
+
while (currentHash && result.length < (this.config.maxResults ?? 1000)) {
|
|
32
|
+
const bwPayload: BoundWitness | undefined = await this.archivistFindHash(archivists, currentHash)
|
|
33
|
+
const bw: BoundWitnessWrapper | undefined = BoundWitnessWrapper.parse(bwPayload)
|
|
34
|
+
if (bw) {
|
|
35
|
+
result.push(bw)
|
|
36
|
+
currentHash = bw.prev(this.queryAddress)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private async archivistFindHash(archivists: ArchivistWrapper[], hash: string): Promise<BoundWitness | undefined> {
|
|
43
|
+
let index = 0
|
|
44
|
+
if (archivists[index]) {
|
|
45
|
+
const result = (await archivists[index].get([hash])).pop() as BoundWitness
|
|
46
|
+
if (result) {
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
index++
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MemoryDiviner'
|