@xyo-network/react-sentinel 2.65.4 → 2.65.5

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.
Files changed (102) hide show
  1. package/dist/browser/components/Card/Card.d.cts +10 -0
  2. package/dist/browser/components/Card/Card.d.cts.map +1 -0
  3. package/dist/browser/components/Card/Card.d.mts +10 -0
  4. package/dist/browser/components/Card/Card.d.mts.map +1 -0
  5. package/dist/browser/components/Card/Card.d.ts +10 -0
  6. package/dist/browser/components/Card/Card.d.ts.map +1 -0
  7. package/dist/browser/components/Card/CardActions.d.cts +9 -0
  8. package/dist/browser/components/Card/CardActions.d.cts.map +1 -0
  9. package/dist/browser/components/Card/CardActions.d.mts +9 -0
  10. package/dist/browser/components/Card/CardActions.d.mts.map +1 -0
  11. package/dist/browser/components/Card/CardActions.d.ts +9 -0
  12. package/dist/browser/components/Card/CardActions.d.ts.map +1 -0
  13. package/dist/browser/components/Card/CardContent.d.cts +10 -0
  14. package/dist/browser/components/Card/CardContent.d.cts.map +1 -0
  15. package/dist/browser/components/Card/CardContent.d.mts +10 -0
  16. package/dist/browser/components/Card/CardContent.d.mts.map +1 -0
  17. package/dist/browser/components/Card/CardContent.d.ts +10 -0
  18. package/dist/browser/components/Card/CardContent.d.ts.map +1 -0
  19. package/dist/browser/components/Card/CardHeader.d.cts +6 -0
  20. package/dist/browser/components/Card/CardHeader.d.cts.map +1 -0
  21. package/dist/browser/components/Card/CardHeader.d.mts +6 -0
  22. package/dist/browser/components/Card/CardHeader.d.mts.map +1 -0
  23. package/dist/browser/components/Card/CardHeader.d.ts +6 -0
  24. package/dist/browser/components/Card/CardHeader.d.ts.map +1 -0
  25. package/dist/browser/components/Card/index.d.cts +4 -0
  26. package/dist/browser/components/Card/index.d.cts.map +1 -0
  27. package/dist/browser/components/Card/index.d.mts +4 -0
  28. package/dist/browser/components/Card/index.d.mts.map +1 -0
  29. package/dist/browser/components/Card/index.d.ts +4 -0
  30. package/dist/browser/components/Card/index.d.ts.map +1 -0
  31. package/dist/browser/components/index.d.cts +2 -0
  32. package/dist/browser/components/index.d.cts.map +1 -0
  33. package/dist/browser/components/index.d.mts +2 -0
  34. package/dist/browser/components/index.d.mts.map +1 -0
  35. package/dist/browser/components/index.d.ts +2 -0
  36. package/dist/browser/components/index.d.ts.map +1 -0
  37. package/dist/browser/index.cjs +71 -9
  38. package/dist/browser/index.cjs.map +1 -1
  39. package/dist/browser/index.d.cts +1 -0
  40. package/dist/browser/index.d.cts.map +1 -1
  41. package/dist/browser/index.d.mts +1 -0
  42. package/dist/browser/index.d.mts.map +1 -1
  43. package/dist/browser/index.d.ts +1 -0
  44. package/dist/browser/index.d.ts.map +1 -1
  45. package/dist/browser/index.js +60 -8
  46. package/dist/browser/index.js.map +1 -1
  47. package/dist/node/components/Card/Card.d.cts +10 -0
  48. package/dist/node/components/Card/Card.d.cts.map +1 -0
  49. package/dist/node/components/Card/Card.d.mts +10 -0
  50. package/dist/node/components/Card/Card.d.mts.map +1 -0
  51. package/dist/node/components/Card/Card.d.ts +10 -0
  52. package/dist/node/components/Card/Card.d.ts.map +1 -0
  53. package/dist/node/components/Card/CardActions.d.cts +9 -0
  54. package/dist/node/components/Card/CardActions.d.cts.map +1 -0
  55. package/dist/node/components/Card/CardActions.d.mts +9 -0
  56. package/dist/node/components/Card/CardActions.d.mts.map +1 -0
  57. package/dist/node/components/Card/CardActions.d.ts +9 -0
  58. package/dist/node/components/Card/CardActions.d.ts.map +1 -0
  59. package/dist/node/components/Card/CardContent.d.cts +10 -0
  60. package/dist/node/components/Card/CardContent.d.cts.map +1 -0
  61. package/dist/node/components/Card/CardContent.d.mts +10 -0
  62. package/dist/node/components/Card/CardContent.d.mts.map +1 -0
  63. package/dist/node/components/Card/CardContent.d.ts +10 -0
  64. package/dist/node/components/Card/CardContent.d.ts.map +1 -0
  65. package/dist/node/components/Card/CardHeader.d.cts +6 -0
  66. package/dist/node/components/Card/CardHeader.d.cts.map +1 -0
  67. package/dist/node/components/Card/CardHeader.d.mts +6 -0
  68. package/dist/node/components/Card/CardHeader.d.mts.map +1 -0
  69. package/dist/node/components/Card/CardHeader.d.ts +6 -0
  70. package/dist/node/components/Card/CardHeader.d.ts.map +1 -0
  71. package/dist/node/components/Card/index.d.cts +4 -0
  72. package/dist/node/components/Card/index.d.cts.map +1 -0
  73. package/dist/node/components/Card/index.d.mts +4 -0
  74. package/dist/node/components/Card/index.d.mts.map +1 -0
  75. package/dist/node/components/Card/index.d.ts +4 -0
  76. package/dist/node/components/Card/index.d.ts.map +1 -0
  77. package/dist/node/components/index.d.cts +2 -0
  78. package/dist/node/components/index.d.cts.map +1 -0
  79. package/dist/node/components/index.d.mts +2 -0
  80. package/dist/node/components/index.d.mts.map +1 -0
  81. package/dist/node/components/index.d.ts +2 -0
  82. package/dist/node/components/index.d.ts.map +1 -0
  83. package/dist/node/index.cjs +74 -9
  84. package/dist/node/index.cjs.map +1 -1
  85. package/dist/node/index.d.cts +1 -0
  86. package/dist/node/index.d.cts.map +1 -1
  87. package/dist/node/index.d.mts +1 -0
  88. package/dist/node/index.d.mts.map +1 -1
  89. package/dist/node/index.d.ts +1 -0
  90. package/dist/node/index.d.ts.map +1 -1
  91. package/dist/node/index.js +60 -8
  92. package/dist/node/index.js.map +1 -1
  93. package/package.json +14 -11
  94. package/src/components/Card/Card.stories.tsx +152 -0
  95. package/src/components/Card/Card.tsx +32 -0
  96. package/src/components/Card/CardActions.tsx +19 -0
  97. package/src/components/Card/CardContent.tsx +23 -0
  98. package/src/components/Card/CardHeader.tsx +7 -0
  99. package/src/components/Card/NftSentinel.json +214 -0
  100. package/src/components/Card/index.ts +3 -0
  101. package/src/components/index.ts +1 -0
  102. package/src/index.ts +1 -0
@@ -1,3 +1,52 @@
1
+ // src/components/Card/Card.tsx
2
+ import { Card } from "@mui/material";
3
+ import { usePromise } from "@xylabs/react-promise";
4
+ import { useState } from "react";
5
+
6
+ // src/components/Card/CardActions.tsx
7
+ import { ButtonEx } from "@xylabs/react-button";
8
+ import { ModuleCardActions } from "@xyo-network/react-module";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var SentinelCardActions = ({ onReport, module, ...props }) => {
11
+ return /* @__PURE__ */ jsx(ModuleCardActions, { module, ...props, children: /* @__PURE__ */ jsx(ButtonEx, { onClick: () => onReport == null ? void 0 : onReport(module), size: "small", variant: "outlined", children: "Report" }) });
12
+ };
13
+
14
+ // src/components/Card/CardContent.tsx
15
+ import { FlexGrowRow } from "@xylabs/react-flexbox";
16
+ import { ModuleCardContent } from "@xyo-network/react-module";
17
+ import JsonView from "react-json-view";
18
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
19
+ var SentinelCardContent = ({ children, report, module, ...props }) => {
20
+ return /* @__PURE__ */ jsx2(ModuleCardContent, { module, ...props, children: /* @__PURE__ */ jsxs(FlexGrowRow, { flexWrap: "wrap", justifyContent: "start", gap: 2, children: [
21
+ report ? /* @__PURE__ */ jsx2(JsonView, { src: report }) : null,
22
+ children
23
+ ] }) });
24
+ };
25
+
26
+ // src/components/Card/CardHeader.tsx
27
+ import { ModuleCardHeader } from "@xyo-network/react-module";
28
+ import { jsx as jsx3 } from "react/jsx-runtime";
29
+ var SentinelCardHeader = ({ title, module, ...props }) => {
30
+ return /* @__PURE__ */ jsx3(ModuleCardHeader, { module, title: title ?? (module == null ? void 0 : module.config.name) ?? "Sentinel", ...props });
31
+ };
32
+
33
+ // src/components/Card/Card.tsx
34
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
35
+ var SentinelCard = ({ children, inPayloads, module, ...props }) => {
36
+ const [retry, setRetry] = useState(-1);
37
+ const [report] = usePromise(async () => {
38
+ if (retry >= 0) {
39
+ return await (module == null ? void 0 : module.report(inPayloads));
40
+ }
41
+ }, [module, retry, inPayloads]);
42
+ return /* @__PURE__ */ jsxs2(Card, { ...props, children: [
43
+ /* @__PURE__ */ jsx4(SentinelCardHeader, { module }),
44
+ /* @__PURE__ */ jsx4(SentinelCardContent, { module, report }),
45
+ children,
46
+ /* @__PURE__ */ jsx4(SentinelCardActions, { module, onReport: () => setRetry(retry + 1) })
47
+ ] });
48
+ };
49
+
1
50
  // src/contexts/Context.ts
2
51
  import { createContextEx } from "@xyo-network/react-shared";
3
52
  var SentinelContext = createContextEx();
@@ -6,7 +55,7 @@ var SentinelContext = createContextEx();
6
55
  import { useAsyncEffect } from "@xylabs/react-async-effect";
7
56
  import { useWitnessesFromNode } from "@xyo-network/react-witness";
8
57
  import { MemorySentinel, SentinelConfigSchema } from "@xyo-network/sentinel";
9
- import { useEffect, useState } from "react";
58
+ import { useEffect, useState as useState2 } from "react";
10
59
 
11
60
  // src/contexts/State.ts
12
61
  var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
@@ -19,13 +68,13 @@ var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
19
68
  })(SentinelReportStatus || {});
20
69
 
21
70
  // src/contexts/Provider.tsx
22
- import { jsx } from "react/jsx-runtime";
71
+ import { jsx as jsx5 } from "react/jsx-runtime";
23
72
  var SentinelProvider = ({ account, archivist, children, filter, name, required = false }) => {
24
- const [sentinel, setSentinel] = useState();
25
- const [history, setHistory] = useState();
26
- const [progress, setProgress] = useState({});
27
- const [status, setStatus] = useState("idle" /* Idle */);
28
- const [reportingErrors, setReportingErrors] = useState();
73
+ const [sentinel, setSentinel] = useState2();
74
+ const [history, setHistory] = useState2();
75
+ const [progress, setProgress] = useState2({});
76
+ const [status, setStatus] = useState2("idle" /* Idle */);
77
+ const [reportingErrors, setReportingErrors] = useState2();
29
78
  const [witnesses] = useWitnessesFromNode(filter);
30
79
  useAsyncEffect(
31
80
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -107,7 +156,7 @@ var SentinelProvider = ({ account, archivist, children, filter, name, required =
107
156
  useEffect(() => {
108
157
  setHistory(sentinel == null ? void 0 : sentinel.history);
109
158
  }, [sentinel]);
110
- return !required || sentinel ? /* @__PURE__ */ jsx(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
159
+ return !required || sentinel ? /* @__PURE__ */ jsx5(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
111
160
  };
112
161
 
113
162
  // src/contexts/use.ts
@@ -155,6 +204,9 @@ var useSentinelsFromNode = (filter, config) => {
155
204
  }
156
205
  };
157
206
  export {
207
+ SentinelCard,
208
+ SentinelCardContent,
209
+ SentinelCardHeader,
158
210
  SentinelContext,
159
211
  SentinelProvider,
160
212
  SentinelReportStatus,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contexts/Context.ts","../../src/contexts/Provider.tsx","../../src/contexts/State.ts","../../src/contexts/use.ts","../../src/hooks/node/useSentinelFromNode.tsx","../../src/hooks/node/useSentinelsFromNode.tsx"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { AccountInstance } from '@xyo-network/account-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleFilter } from '@xyo-network/module'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel, SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel'\nimport { WitnessInstance } from '@xyo-network/witness'\nimport { useEffect, useState } from 'react'\n\nimport { SentinelContext } from './Context'\nimport { SentinelReportProgress, SentinelReportStatus } from './State'\n\nexport interface SentinelProviderProps {\n /** Account used by the sentinel for signing */\n account: AccountInstance\n /** @deprecated - sentinel no longer uses archive but relies on an archivist */\n archive?: string\n archivist?: string\n filter?: ModuleFilter\n name?: string\n required?: boolean\n witnesses?: WitnessInstance[]\n}\n\nexport const SentinelProvider: React.FC<WithChildren<SentinelProviderProps>> = ({ account, archivist, children, filter, name, required = false }) => {\n const [sentinel, setSentinel] = useState<MemorySentinel>()\n const [history, setHistory] = useState<BoundWitness[]>()\n const [progress, setProgress] = useState<SentinelReportProgress>({})\n const [status, setStatus] = useState(SentinelReportStatus.Idle)\n const [reportingErrors, setReportingErrors] = useState<Error[]>()\n const [witnesses] = useWitnessesFromNode(filter)\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const sentinel = await MemorySentinel.create({\n account,\n config: {\n archivists: archivist ? [archivist] : undefined,\n name,\n\n schema: SentinelConfigSchema,\n synchronous: true,\n tasks: witnesses?.map((module) => ({ module: module.address })),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module, outPayloads }) => {\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses: progress.witnesses,\n })\n setStatus(outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed)\n setReportingErrors([Error(`Witness failed [${module?.config?.name ?? module.address}]`)])\n }\n }),\n )\n offCallbacks.push(\n sentinel.on('reportStart', () => {\n if (mounted()) {\n setProgress({ archivists: {}, witnesses: {} })\n setStatus(SentinelReportStatus.Started)\n }\n }),\n )\n witnesses?.forEach((witness) => {\n offCallbacks.push(\n witness.on('observeEnd', ({ module, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n })\n setSentinel(sentinel as MemorySentinel)\n return () => {\n //unsubscribe from events\n offCallbacks.forEach((callback) => {\n callback()\n })\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [account, archivist, witnesses],\n )\n\n useEffect(() => {\n setHistory(sentinel?.history as BoundWitness[])\n }, [sentinel])\n\n return !required || sentinel ? (\n <SentinelContext.Provider value={{ history, progress, provided: true, reportingErrors, sentinel, status }}>{children}</SentinelContext.Provider>\n ) : null\n}\n","import { ArchivistModule } from '@xyo-network/archivist'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel'\nimport { WitnessModule } from '@xyo-network/witness'\n\nexport enum SentinelReportStatus {\n Idle = 'idle',\n Queued = 'queued',\n Started = 'started',\n Succeeded = 'succeeded',\n Failed = 'failed',\n}\n\nexport interface SentinelWitnessReportProgress {\n status: SentinelReportStatus\n witness: WitnessModule\n}\n\nexport interface SentinelArchivistApiReportProgress {\n archivist: ArchivistModule\n status: SentinelReportStatus\n}\n\nexport interface SentinelReportProgress {\n archivists?: Record<string, SentinelArchivistApiReportProgress>\n witnesses?: Record<string, SentinelWitnessReportProgress>\n}\n\nexport interface SentinelContextState {\n history?: BoundWitness[]\n progress?: SentinelReportProgress\n reportingErrors?: Error[]\n sentinel?: SentinelModule\n status?: SentinelReportStatus\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContext } from './Context'\n\nexport const useSentinelContext = () => {\n const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, 'Sentinel')\n return { history, progress, reportingErrors, sentinel, status }\n}\n","import { ModuleFromNodeConfig, useModuleFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance | undefined, Error | undefined] => {\n const [module, error] = useModuleFromNode(nameOrAddressOrInstance, config)\n const instance = asSentinelInstance(module)\n if (module && !instance) {\n const error = Error(`Resolved module is not a SentinelInstance [${module.config?.schema}:${module.config?.name}:${module.address}]`)\n console.error(error.message)\n return [undefined, error]\n }\n return [instance, error]\n}\n","import { ModuleFilter } from '@xyo-network/module-model'\nimport { ModuleFromNodeConfig, useModulesFromNode } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance[] | null | undefined, Error | undefined] => {\n const [modules, error] = useModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n if (modules) {\n return [\n modules.reduce<SentinelInstance[]>((prev, module) => {\n if (isSentinelInstance(module)) {\n prev.push(module)\n }\n return prev\n }, []),\n undefined,\n ]\n } else {\n return [modules, error]\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,kBAAkB,gBAAsC;;;ACJrE,SAAS,sBAAsB;AAK/B,SAAS,4BAA4B;AACrC,SAAS,gBAAgC,4BAA4B;AAErE,SAAS,WAAW,gBAAgB;;;ACH7B,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,YAAS;AACT,EAAAA,sBAAA,aAAU;AACV,EAAAA,sBAAA,eAAY;AACZ,EAAAA,sBAAA,YAAS;AALC,SAAAA;AAAA,GAAA;;;ADgHR;AA5FG,IAAM,mBAAkE,CAAC,EAAE,SAAS,WAAW,UAAU,QAAQ,MAAM,WAAW,MAAM,MAAM;AACnJ,QAAM,CAAC,UAAU,WAAW,IAAI,SAAyB;AACzD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyB;AACvD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAiC,CAAC,CAAC;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,0BAAkC;AAC9D,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAkB;AAChE,QAAM,CAAC,SAAS,IAAI,qBAAqB,MAAM;AAE/C;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,YAAMC,YAAW,MAAM,eAAe,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QAAWA,MAAK;AAAA,EAC1B;AACA,SAAO,CAAC,UAAU,KAAK;AACzB;;;ACdA,SAA+B,0BAA0B;AACzD,SAAS,0BAA4C;AAE9C,IAAM,uBAAuB,CAClC,QACA,WAC+D;AAC/D,QAAM,CAAC,SAAS,KAAK,IAAI,mBAAmB,QAAQ,MAAM;AAC1D,MAAI,OAAO;AACT,WAAO,CAAC,MAAM,KAAK;AAAA,EACrB;AACA,MAAI,SAAS;AACX,WAAO;AAAA,MACL,QAAQ,OAA2B,CAAC,MAAM,WAAW;AACnD,YAAI,mBAAmB,MAAM,GAAG;AAC9B,eAAK,KAAK,MAAM;AAAA,QAClB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,MACL;AAAA,IACF;AAAA,EACF,OAAO;AACL,WAAO,CAAC,SAAS,KAAK;AAAA,EACxB;AACF;","names":["SentinelReportStatus","sentinel","witnesses","error"]}
1
+ {"version":3,"sources":["../../src/components/Card/Card.tsx","../../src/components/Card/CardActions.tsx","../../src/components/Card/CardContent.tsx","../../src/components/Card/CardHeader.tsx","../../src/contexts/Context.ts","../../src/contexts/Provider.tsx","../../src/contexts/State.ts","../../src/contexts/use.ts","../../src/hooks/node/useSentinelFromNode.tsx","../../src/hooks/node/useSentinelsFromNode.tsx"],"sourcesContent":["import { Card, CardProps } from '@mui/material'\nimport { usePromise } from '@xylabs/react-promise'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport { useState } from 'react'\n\nimport { SentinelCardActions } from './CardActions'\nimport { SentinelCardContent } from './CardContent'\nimport { SentinelCardHeader } from './CardHeader'\n\nexport type SentinelCardProps = CardProps &\n ModuleRenderProps<SentinelInstance> & {\n inPayloads?: Payload[]\n }\n\nexport const SentinelCard: React.FC<SentinelCardProps> = ({ children, inPayloads, module, ...props }) => {\n const [retry, setRetry] = useState(-1)\n const [report] = usePromise(async () => {\n if (retry >= 0) {\n return await module?.report(inPayloads)\n }\n }, [module, retry, inPayloads])\n return (\n <Card {...props}>\n <SentinelCardHeader module={module} />\n <SentinelCardContent module={module} report={report} />\n {children}\n <SentinelCardActions module={module} onReport={() => setRetry(retry + 1)} />\n </Card>\n )\n}\n","import { CardActionsProps } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleCardActions, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel'\n\nexport type SentinelCardActionsProps = ModuleRenderProps<SentinelInstance> &\n CardActionsProps & {\n onReport?: (module?: SentinelInstance) => void\n }\n\nexport const SentinelCardActions: React.FC<SentinelCardActionsProps> = ({ onReport, module, ...props }) => {\n return (\n <ModuleCardActions module={module} {...props}>\n <ButtonEx onClick={() => onReport?.(module)} size={'small'} variant={'outlined'}>\n Report\n </ButtonEx>\n </ModuleCardActions>\n )\n}\n","import { CardContentProps } from '@mui/material'\nimport { FlexGrowRow } from '@xylabs/react-flexbox'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleCardContent, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport React from 'react'\nimport JsonView from 'react-json-view'\n\nexport type SentinelCardContentProps = ModuleRenderProps<SentinelInstance> &\n CardContentProps & {\n report?: Payload[]\n }\n\nexport const SentinelCardContent: React.FC<SentinelCardContentProps> = ({ children, report, module, ...props }) => {\n return (\n <ModuleCardContent module={module} {...props}>\n <FlexGrowRow flexWrap=\"wrap\" justifyContent=\"start\" gap={2}>\n {report ? <JsonView src={report} /> : null}\n {children}\n </FlexGrowRow>\n </ModuleCardContent>\n )\n}\n","import { CardHeaderProps } from '@mui/material'\nimport { ModuleCardHeader, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const SentinelCardHeader: React.FC<ModuleRenderProps<SentinelInstance> & CardHeaderProps> = ({ title, module, ...props }) => {\n return <ModuleCardHeader module={module} title={title ?? module?.config.name ?? 'Sentinel'} {...props} />\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { AccountInstance } from '@xyo-network/account-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleFilter } from '@xyo-network/module'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel, SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel'\nimport { WitnessInstance } from '@xyo-network/witness'\nimport { useEffect, useState } from 'react'\n\nimport { SentinelContext } from './Context'\nimport { SentinelReportProgress, SentinelReportStatus } from './State'\n\nexport interface SentinelProviderProps {\n /** Account used by the sentinel for signing */\n account: AccountInstance\n /** @deprecated - sentinel no longer uses archive but relies on an archivist */\n archive?: string\n archivist?: string\n filter?: ModuleFilter\n name?: string\n required?: boolean\n witnesses?: WitnessInstance[]\n}\n\nexport const SentinelProvider: React.FC<WithChildren<SentinelProviderProps>> = ({ account, archivist, children, filter, name, required = false }) => {\n const [sentinel, setSentinel] = useState<MemorySentinel>()\n const [history, setHistory] = useState<BoundWitness[]>()\n const [progress, setProgress] = useState<SentinelReportProgress>({})\n const [status, setStatus] = useState(SentinelReportStatus.Idle)\n const [reportingErrors, setReportingErrors] = useState<Error[]>()\n const [witnesses] = useWitnessesFromNode(filter)\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const sentinel = await MemorySentinel.create({\n account,\n config: {\n archivists: archivist ? [archivist] : undefined,\n name,\n\n schema: SentinelConfigSchema,\n synchronous: true,\n tasks: witnesses?.map((module) => ({ module: module.address })),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module, outPayloads }) => {\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses: progress.witnesses,\n })\n setStatus(outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed)\n setReportingErrors([Error(`Witness failed [${module?.config?.name ?? module.address}]`)])\n }\n }),\n )\n offCallbacks.push(\n sentinel.on('reportStart', () => {\n if (mounted()) {\n setProgress({ archivists: {}, witnesses: {} })\n setStatus(SentinelReportStatus.Started)\n }\n }),\n )\n witnesses?.forEach((witness) => {\n offCallbacks.push(\n witness.on('observeEnd', ({ module, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n })\n setSentinel(sentinel as MemorySentinel)\n return () => {\n //unsubscribe from events\n offCallbacks.forEach((callback) => {\n callback()\n })\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [account, archivist, witnesses],\n )\n\n useEffect(() => {\n setHistory(sentinel?.history as BoundWitness[])\n }, [sentinel])\n\n return !required || sentinel ? (\n <SentinelContext.Provider value={{ history, progress, provided: true, reportingErrors, sentinel, status }}>{children}</SentinelContext.Provider>\n ) : null\n}\n","import { ArchivistModule } from '@xyo-network/archivist'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel'\nimport { WitnessModule } from '@xyo-network/witness'\n\nexport enum SentinelReportStatus {\n Idle = 'idle',\n Queued = 'queued',\n Started = 'started',\n Succeeded = 'succeeded',\n Failed = 'failed',\n}\n\nexport interface SentinelWitnessReportProgress {\n status: SentinelReportStatus\n witness: WitnessModule\n}\n\nexport interface SentinelArchivistApiReportProgress {\n archivist: ArchivistModule\n status: SentinelReportStatus\n}\n\nexport interface SentinelReportProgress {\n archivists?: Record<string, SentinelArchivistApiReportProgress>\n witnesses?: Record<string, SentinelWitnessReportProgress>\n}\n\nexport interface SentinelContextState {\n history?: BoundWitness[]\n progress?: SentinelReportProgress\n reportingErrors?: Error[]\n sentinel?: SentinelModule\n status?: SentinelReportStatus\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContext } from './Context'\n\nexport const useSentinelContext = () => {\n const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, 'Sentinel')\n return { history, progress, reportingErrors, sentinel, status }\n}\n","import { ModuleFromNodeConfig, useModuleFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance | undefined, Error | undefined] => {\n const [module, error] = useModuleFromNode(nameOrAddressOrInstance, config)\n const instance = asSentinelInstance(module)\n if (module && !instance) {\n const error = Error(`Resolved module is not a SentinelInstance [${module.config?.schema}:${module.config?.name}:${module.address}]`)\n console.error(error.message)\n return [undefined, error]\n }\n return [instance, error]\n}\n","import { ModuleFilter } from '@xyo-network/module-model'\nimport { ModuleFromNodeConfig, useModulesFromNode } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance[] | null | undefined, Error | undefined] => {\n const [modules, error] = useModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n if (modules) {\n return [\n modules.reduce<SentinelInstance[]>((prev, module) => {\n if (isSentinelInstance(module)) {\n prev.push(module)\n }\n return prev\n }, []),\n undefined,\n ]\n } else {\n return [modules, error]\n }\n}\n"],"mappings":";AAAA,SAAS,YAAuB;AA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MAAM,KAAK;AAAA,EACrB;AACA,MAAI,SAAS;AACX,WAAO;AAAA,MACL,QAAQ,OAA2B,CAAC,MAAM,WAAW;AACnD,YAAI,mBAAmB,MAAM,GAAG;AAC9B,eAAK,KAAK,MAAM;AAAA,QAClB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,MACL;AAAA,IACF;AAAA,EACF,OAAO;AACL,WAAO,CAAC,SAAS,KAAK;AAAA,EACxB;AACF;","names":["jsx","jsx","jsx","jsxs","useState","SentinelReportStatus","jsx","useState","sentinel","witnesses","error"]}
package/package.json CHANGED
@@ -12,20 +12,23 @@
12
12
  "dependencies": {
13
13
  "@xylabs/react-async-effect": "^3.0.21",
14
14
  "@xylabs/react-shared": "^3.0.21",
15
- "@xyo-network/account-model": "^2.77.7",
16
- "@xyo-network/archivist": "^2.77.7",
17
- "@xyo-network/boundwitness-model": "^2.77.7",
18
- "@xyo-network/module": "^2.77.7",
19
- "@xyo-network/module-model": "^2.77.7",
20
- "@xyo-network/react-node": "~2.65.4",
21
- "@xyo-network/react-shared": "~2.65.4",
22
- "@xyo-network/react-witness": "~2.65.4",
23
- "@xyo-network/sentinel": "^2.77.7",
24
- "@xyo-network/witness": "^2.77.7"
15
+ "@xyo-network/account-model": "^2.77.19",
16
+ "@xyo-network/archivist": "^2.77.19",
17
+ "@xyo-network/boundwitness-model": "^2.77.19",
18
+ "@xyo-network/module": "^2.77.19",
19
+ "@xyo-network/module-model": "^2.77.19",
20
+ "@xyo-network/react-node": "~2.65.5",
21
+ "@xyo-network/react-shared": "~2.65.5",
22
+ "@xyo-network/react-witness": "~2.65.5",
23
+ "@xyo-network/sentinel": "^2.77.19",
24
+ "@xyo-network/witness": "^2.77.19"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@xylabs/ts-scripts-yarn3": "^3.1.13",
28
28
  "@xylabs/tsconfig-react": "^3.1.13",
29
+ "@xyo-network/crypto-contract-function-read-plugin": "^2.77.19",
30
+ "@xyo-network/open-zeppelin-typechain": "^2.2.11",
31
+ "ethers": "^5.7.2",
29
32
  "typescript": "^5.2.2"
30
33
  },
31
34
  "peerDependencies": {
@@ -86,6 +89,6 @@
86
89
  },
87
90
  "sideEffects": false,
88
91
  "types": "dist/browser/index.d.ts",
89
- "version": "2.65.4",
92
+ "version": "2.65.5",
90
93
  "type": "module"
91
94
  }
@@ -0,0 +1,152 @@
1
+ import { InfuraProvider } from '@ethersproject/providers'
2
+ import { Meta, StoryFn } from '@storybook/react'
3
+ import { FlexCol } from '@xylabs/react-flexbox'
4
+ import { usePromise } from '@xylabs/react-promise'
5
+ import { HDWallet } from '@xyo-network/account'
6
+ import { CryptoContractFunctionCallSchema } from '@xyo-network/crypto-contract-function-read-payload-plugin'
7
+ import { CryptoContractDiviner, CryptoContractFunctionReadWitness } from '@xyo-network/crypto-contract-function-read-plugin'
8
+ import { ManifestPayload, ManifestWrapper } from '@xyo-network/manifest'
9
+ import { ModuleFactory, ModuleFactoryLocator } from '@xyo-network/module-model'
10
+ import { ERC721__factory, ERC721Enumerable__factory, ERC1155__factory } from '@xyo-network/open-zeppelin-typechain'
11
+ import { Payload } from '@xyo-network/payload-model'
12
+ import { asSentinelInstance, ReportEndEventArgs } from '@xyo-network/sentinel'
13
+ import { useState } from 'react'
14
+ import JsonView from 'react-json-view'
15
+
16
+ import { SentinelCard } from './Card'
17
+ import NftSentinelManifest from './NftSentinel.json'
18
+
19
+ const loadFromManifest = async () => {
20
+ const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
21
+ const wallet = await HDWallet.fromMnemonic(mnemonic)
22
+ const provider = new InfuraProvider('homestead', {
23
+ projectId: process.env.STORYBOOK_INFURA_PROJECT_ID,
24
+ projectSecret: process.env.STORYBOOK_INFURA_PROJECT_SECRET,
25
+ })
26
+
27
+ const locator = new ModuleFactoryLocator()
28
+ locator.register(CryptoContractDiviner)
29
+
30
+ locator.register(
31
+ new ModuleFactory(CryptoContractFunctionReadWitness, {
32
+ factory: (address: string) => ERC721__factory.connect(address, provider),
33
+ }),
34
+ { 'network.xyo.crypto.contract.interface': 'Erc721' },
35
+ )
36
+
37
+ locator.register(
38
+ new ModuleFactory(CryptoContractFunctionReadWitness, {
39
+ factory: (address: string) => ERC721Enumerable__factory.connect(address, provider),
40
+ }),
41
+ { 'network.xyo.crypto.contract.interface': 'Erc721Enumerable' },
42
+ )
43
+
44
+ locator.register(
45
+ new ModuleFactory(CryptoContractFunctionReadWitness, {
46
+ factory: (address: string) => ERC1155__factory.connect(address, provider),
47
+ }),
48
+ { 'network.xyo.crypto.contract.interface': 'Erc1155' },
49
+ )
50
+
51
+ const manifest = new ManifestWrapper(NftSentinelManifest as ManifestPayload, wallet, locator)
52
+ const node = await manifest.loadNodeFromIndex(0)
53
+ console.log(`node: ${(await node.resolve()).length}`)
54
+ return node
55
+ }
56
+
57
+ const StorybookEntry = {
58
+ component: SentinelCard,
59
+ parameters: {
60
+ docs: {
61
+ page: null,
62
+ },
63
+ },
64
+ title: 'modules/sentinel/SentinelCard',
65
+ } as Meta<typeof SentinelCard>
66
+
67
+ const NftSentinelTemplate: StoryFn<typeof SentinelCard> = () => {
68
+ const [node] = usePromise(async () => await loadFromManifest(), [])
69
+ const [sentinel] = usePromise(async () => {
70
+ if (node) {
71
+ const sentinel = asSentinelInstance(await node.resolve('NftInfoSentinel'))
72
+ sentinel?.on('reportEnd', (args) => {
73
+ const { inPayloads, outPayloads } = args as ReportEndEventArgs
74
+ console.log(`inPayloads: ${inPayloads?.length}`)
75
+ console.log(`outPayloads: ${outPayloads?.length}`)
76
+ })
77
+ return sentinel
78
+ }
79
+ }, [node])
80
+
81
+ const inPayloads = [
82
+ {
83
+ address: '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea', //Random ERC721
84
+ schema: CryptoContractFunctionCallSchema,
85
+ },
86
+ ]
87
+
88
+ return (
89
+ <FlexCol gap={2}>
90
+ <SentinelCard module={sentinel} inPayloads={inPayloads} />
91
+ </FlexCol>
92
+ )
93
+ }
94
+
95
+ const NftSentinelCard = NftSentinelTemplate.bind({})
96
+
97
+ const NftTokensSentinelTemplate: StoryFn<typeof SentinelCard> = () => {
98
+ const [node] = usePromise(async () => await loadFromManifest(), [])
99
+ const [tokens, setTokens] = useState<Payload[]>()
100
+
101
+ const [tokensSentinel] = usePromise(async () => {
102
+ if (node) {
103
+ const sentinel = asSentinelInstance(await node.resolve('NftTokenInfoSentinel'))
104
+ sentinel?.on('reportEnd', (args) => {
105
+ const { inPayloads, outPayloads } = args as ReportEndEventArgs
106
+ console.log(`tokensSentinelInPayloads: ${inPayloads?.length}`)
107
+ console.log(`tokensSentinelOutPayloads: ${outPayloads?.length}`)
108
+ console.log(`tokens: ${JSON.stringify(outPayloads, null, 2)}`)
109
+ })
110
+ return sentinel
111
+ }
112
+ }, [node])
113
+
114
+ const [contractSentinel] = usePromise(async () => {
115
+ if (node) {
116
+ const sentinel = asSentinelInstance(await node.resolve('NftInfoSentinel'))
117
+ sentinel?.on('reportEnd', async (args) => {
118
+ const { inPayloads, outPayloads } = args as ReportEndEventArgs
119
+ console.log(`inPayloads: ${inPayloads?.length}`)
120
+ console.log(`outPayloads: ${outPayloads?.length}`)
121
+ const calls = Array(1000).map((_, index) => ({
122
+ address: '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea', //Random ERC721
123
+ params: [index],
124
+ schema: CryptoContractFunctionCallSchema,
125
+ }))
126
+ await tokensSentinel?.report(calls)
127
+ })
128
+ return sentinel
129
+ }
130
+ }, [node, tokensSentinel])
131
+
132
+ const inPayloads = [
133
+ {
134
+ address: '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea', //Random ERC721
135
+ schema: CryptoContractFunctionCallSchema,
136
+ },
137
+ ]
138
+
139
+ return (
140
+ <FlexCol gap={2}>
141
+ <SentinelCard module={contractSentinel} inPayloads={inPayloads} />
142
+ {/*tokens ? <JsonView src={tokens} /> : null*/}
143
+ </FlexCol>
144
+ )
145
+ }
146
+
147
+ const NftTokensSentinelCard = NftTokensSentinelTemplate.bind({})
148
+
149
+ export { NftSentinelCard, NftTokensSentinelCard }
150
+
151
+ // eslint-disable-next-line import/no-default-export
152
+ export default StorybookEntry
@@ -0,0 +1,32 @@
1
+ import { Card, CardProps } from '@mui/material'
2
+ import { usePromise } from '@xylabs/react-promise'
3
+ import { Payload } from '@xyo-network/payload-model'
4
+ import { ModuleRenderProps } from '@xyo-network/react-module'
5
+ import { SentinelInstance } from '@xyo-network/sentinel-model'
6
+ import { useState } from 'react'
7
+
8
+ import { SentinelCardActions } from './CardActions'
9
+ import { SentinelCardContent } from './CardContent'
10
+ import { SentinelCardHeader } from './CardHeader'
11
+
12
+ export type SentinelCardProps = CardProps &
13
+ ModuleRenderProps<SentinelInstance> & {
14
+ inPayloads?: Payload[]
15
+ }
16
+
17
+ export const SentinelCard: React.FC<SentinelCardProps> = ({ children, inPayloads, module, ...props }) => {
18
+ const [retry, setRetry] = useState(-1)
19
+ const [report] = usePromise(async () => {
20
+ if (retry >= 0) {
21
+ return await module?.report(inPayloads)
22
+ }
23
+ }, [module, retry, inPayloads])
24
+ return (
25
+ <Card {...props}>
26
+ <SentinelCardHeader module={module} />
27
+ <SentinelCardContent module={module} report={report} />
28
+ {children}
29
+ <SentinelCardActions module={module} onReport={() => setRetry(retry + 1)} />
30
+ </Card>
31
+ )
32
+ }
@@ -0,0 +1,19 @@
1
+ import { CardActionsProps } from '@mui/material'
2
+ import { ButtonEx } from '@xylabs/react-button'
3
+ import { ModuleCardActions, ModuleRenderProps } from '@xyo-network/react-module'
4
+ import { SentinelInstance } from '@xyo-network/sentinel'
5
+
6
+ export type SentinelCardActionsProps = ModuleRenderProps<SentinelInstance> &
7
+ CardActionsProps & {
8
+ onReport?: (module?: SentinelInstance) => void
9
+ }
10
+
11
+ export const SentinelCardActions: React.FC<SentinelCardActionsProps> = ({ onReport, module, ...props }) => {
12
+ return (
13
+ <ModuleCardActions module={module} {...props}>
14
+ <ButtonEx onClick={() => onReport?.(module)} size={'small'} variant={'outlined'}>
15
+ Report
16
+ </ButtonEx>
17
+ </ModuleCardActions>
18
+ )
19
+ }
@@ -0,0 +1,23 @@
1
+ import { CardContentProps } from '@mui/material'
2
+ import { FlexGrowRow } from '@xylabs/react-flexbox'
3
+ import { Payload } from '@xyo-network/payload-model'
4
+ import { ModuleCardContent, ModuleRenderProps } from '@xyo-network/react-module'
5
+ import { SentinelInstance } from '@xyo-network/sentinel-model'
6
+ import React from 'react'
7
+ import JsonView from 'react-json-view'
8
+
9
+ export type SentinelCardContentProps = ModuleRenderProps<SentinelInstance> &
10
+ CardContentProps & {
11
+ report?: Payload[]
12
+ }
13
+
14
+ export const SentinelCardContent: React.FC<SentinelCardContentProps> = ({ children, report, module, ...props }) => {
15
+ return (
16
+ <ModuleCardContent module={module} {...props}>
17
+ <FlexGrowRow flexWrap="wrap" justifyContent="start" gap={2}>
18
+ {report ? <JsonView src={report} /> : null}
19
+ {children}
20
+ </FlexGrowRow>
21
+ </ModuleCardContent>
22
+ )
23
+ }
@@ -0,0 +1,7 @@
1
+ import { CardHeaderProps } from '@mui/material'
2
+ import { ModuleCardHeader, ModuleRenderProps } from '@xyo-network/react-module'
3
+ import { SentinelInstance } from '@xyo-network/sentinel-model'
4
+
5
+ export const SentinelCardHeader: React.FC<ModuleRenderProps<SentinelInstance> & CardHeaderProps> = ({ title, module, ...props }) => {
6
+ return <ModuleCardHeader module={module} title={title ?? module?.config.name ?? 'Sentinel'} {...props} />
7
+ }
@@ -0,0 +1,214 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/a5a229a767e3998e13cce8160fd1c2b027317424/packages/manifest/src/schema.json",
3
+ "nodes": [
4
+ {
5
+ "config": {
6
+ "accountPath": "m/44'/60'/1'/0'/0'",
7
+ "name": "NftInfoNode",
8
+ "schema": "network.xyo.node.config"
9
+ },
10
+ "modules": {
11
+ "public": [
12
+ {
13
+ "config": {
14
+ "accountPath": "m/44'/60'/1'/1'/0'",
15
+ "call": {
16
+ "functionName": "name",
17
+ "params": []
18
+ },
19
+ "labels": {
20
+ "network.xyo.crypto.contract.interface": "Erc721"
21
+ },
22
+ "language": "javascript",
23
+ "name": "Erc721NameWitness",
24
+ "schema": "network.xyo.crypto.contract.function.read.config"
25
+ }
26
+ },
27
+ {
28
+ "config": {
29
+ "accountPath": "m/44'/60'/1'/1'/1'",
30
+ "call": {
31
+ "functionName": "symbol",
32
+ "params": []
33
+ },
34
+ "labels": {
35
+ "network.xyo.crypto.contract.interface": "Erc721"
36
+ },
37
+ "language": "javascript",
38
+ "name": "Erc721SymbolWitness",
39
+ "schema": "network.xyo.crypto.contract.function.read.config"
40
+ }
41
+ },
42
+ {
43
+ "config": {
44
+ "accountPath": "m/44'/60'/1'/1'/2'",
45
+ "call": {
46
+ "functionName": "totalSupply",
47
+ "params": []
48
+ },
49
+ "labels": {
50
+ "network.xyo.crypto.contract.interface": "Erc721Enumerable"
51
+ },
52
+ "language": "javascript",
53
+ "name": "Erc721TotalSupplyWitness",
54
+ "schema": "network.xyo.crypto.contract.function.read.config"
55
+ }
56
+ },
57
+ {
58
+ "config": {
59
+ "accountPath": "m/44'/60'/1'/1'/3'",
60
+ "call": {
61
+ "functionName": "tokenURI"
62
+ },
63
+ "labels": {
64
+ "network.xyo.crypto.contract.interface": "Erc721"
65
+ },
66
+ "language": "javascript",
67
+ "name": "Erc721TokenURIWitness",
68
+ "schema": "network.xyo.crypto.contract.function.read.config"
69
+ }
70
+ },
71
+ {
72
+ "config": {
73
+ "accountPath": "m/44'/60'/1'/1'/4'",
74
+ "call": {
75
+ "functionName": "ownerOf"
76
+ },
77
+ "labels": {
78
+ "network.xyo.crypto.contract.interface": "Erc721"
79
+ },
80
+ "language": "javascript",
81
+ "name": "Erc721OwnerOfWitness",
82
+ "schema": "network.xyo.crypto.contract.function.read.config"
83
+ }
84
+ },
85
+ {
86
+ "config": {
87
+ "accountPath": "m/44'/60'/1'/1'/5'",
88
+ "call": {
89
+ "functionName": "uri",
90
+ "params": []
91
+ },
92
+ "labels": {
93
+ "network.xyo.crypto.contract.interface": "Erc1155"
94
+ },
95
+ "language": "javascript",
96
+ "name": "Erc1155UriWitness",
97
+ "schema": "network.xyo.crypto.contract.function.read.config"
98
+ }
99
+ },
100
+ {
101
+ "config": {
102
+ "accountPath": "m/44'/60'/1'/2'/0'",
103
+ "language": "javascript",
104
+ "name": "Erc721ContractInfoDiviner",
105
+ "schema": "network.xyo.crypto.contract.diviner.config"
106
+ }
107
+ },
108
+ {
109
+ "config": {
110
+ "accountPath": "m/44'/60'/1'/2'/1'",
111
+ "language": "javascript",
112
+ "name": "Erc1155ContractInfoDiviner",
113
+ "schema": "network.xyo.crypto.contract.diviner.config"
114
+ }
115
+ },
116
+ {
117
+ "config": {
118
+ "accountPath": "m/44'/60'/1'/2'/2'",
119
+ "language": "javascript",
120
+ "name": "Erc721TokenContractInfoDiviner",
121
+ "schema": "network.xyo.crypto.contract.diviner.config"
122
+ }
123
+ },
124
+ {
125
+ "config": {
126
+ "accountPath": "m/44'/60'/1'/2'/3'",
127
+ "language": "javascript",
128
+ "name": "Erc1155TokenContractInfoDiviner",
129
+ "schema": "network.xyo.crypto.contract.diviner.config"
130
+ }
131
+ },
132
+ {
133
+ "config": {
134
+ "accountPath": "m/44'/60'/1'/3'/0'",
135
+ "language": "javascript",
136
+ "name": "NftInfoSentinel",
137
+ "schema": "network.xyo.sentinel.config",
138
+ "synchronous": "true",
139
+ "tasks": [
140
+ {
141
+ "input": true,
142
+ "module": "Erc721NameWitness"
143
+ },
144
+ {
145
+ "input": true,
146
+ "module": "Erc721SymbolWitness"
147
+ },
148
+ {
149
+ "input": true,
150
+ "module": "Erc721TotalSupplyWitness"
151
+ },
152
+ {
153
+ "input": true,
154
+ "module": "Erc1155UriWitness"
155
+ },
156
+ {
157
+ "input": [
158
+ "Erc721NameWitness",
159
+ "Erc721SymbolWitness",
160
+ "Erc721TotalSupplyWitness"
161
+ ],
162
+ "module": "Erc721ContractInfoDiviner"
163
+ },
164
+ {
165
+ "input": [
166
+ "Erc1155UriWitness"
167
+ ],
168
+ "module": "Erc1155ContractInfoDiviner"
169
+ }
170
+ ]
171
+ }
172
+ },
173
+ {
174
+ "config": {
175
+ "accountPath": "m/44'/60'/1'/3'/1'",
176
+ "language": "javascript",
177
+ "name": "NftTokenInfoSentinel",
178
+ "schema": "network.xyo.sentinel.config",
179
+ "synchronous": "true",
180
+ "tasks": [
181
+ {
182
+ "input": true,
183
+ "module": "Erc721TokenURIWitness"
184
+ },
185
+ {
186
+ "input": true,
187
+ "module": "Erc721OwnerOfWitness"
188
+ },
189
+ {
190
+ "input": true,
191
+ "module": "Erc1155UriWitness"
192
+ },
193
+ {
194
+ "input": [
195
+ "Erc721TokenURIWitness",
196
+ "Erc721OwnerOfWitness"
197
+ ],
198
+ "module": "Erc721TokenContractInfoDiviner"
199
+ },
200
+ {
201
+ "input": [
202
+ "Erc1155UriWitness"
203
+ ],
204
+ "module": "Erc1155TokenContractInfoDiviner"
205
+ }
206
+ ]
207
+ }
208
+ }
209
+ ]
210
+ }
211
+ }
212
+ ],
213
+ "schema": "network.xyo.manifest"
214
+ }