@xyo-network/crypto-contract-function-read-plugin 2.83.0 → 2.84.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/browser/{CryptoContractDiviner.d.cts → Diviner/Diviner.d.cts} +3 -16
- package/dist/browser/Diviner/Diviner.d.cts.map +1 -0
- package/dist/browser/{CryptoContractDiviner.d.ts → Diviner/Diviner.d.mts} +3 -16
- package/dist/browser/Diviner/Diviner.d.mts.map +1 -0
- package/dist/browser/{CryptoContractDiviner.d.mts → Diviner/Diviner.d.ts} +3 -16
- package/dist/browser/Diviner/Diviner.d.ts.map +1 -0
- package/dist/browser/Diviner/index.d.cts +1 -1
- package/dist/browser/Diviner/index.d.cts.map +1 -1
- package/dist/browser/Diviner/index.d.mts +1 -1
- package/dist/browser/Diviner/index.d.mts.map +1 -1
- package/dist/browser/Diviner/index.d.ts +1 -1
- package/dist/browser/Diviner/index.d.ts.map +1 -1
- package/dist/browser/Plugin.d.cts +611 -5
- package/dist/browser/Plugin.d.cts.map +1 -1
- package/dist/browser/Plugin.d.mts +611 -5
- package/dist/browser/Plugin.d.mts.map +1 -1
- package/dist/browser/Plugin.d.ts +611 -5
- package/dist/browser/Plugin.d.ts.map +1 -1
- package/dist/browser/index.cjs +4 -7
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -1
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +5 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/node/{CryptoContractDiviner.d.cts → Diviner/Diviner.d.cts} +3 -16
- package/dist/node/Diviner/Diviner.d.cts.map +1 -0
- package/dist/node/Diviner/Diviner.d.mts +15 -0
- package/dist/node/Diviner/Diviner.d.mts.map +1 -0
- package/dist/node/Diviner/Diviner.d.ts +15 -0
- package/dist/node/Diviner/Diviner.d.ts.map +1 -0
- package/dist/node/Diviner/index.d.cts +1 -1
- package/dist/node/Diviner/index.d.cts.map +1 -1
- package/dist/node/Diviner/index.d.mts +1 -1
- package/dist/node/Diviner/index.d.mts.map +1 -1
- package/dist/node/Diviner/index.d.ts +1 -1
- package/dist/node/Diviner/index.d.ts.map +1 -1
- package/dist/node/Plugin.d.cts +611 -5
- package/dist/node/Plugin.d.cts.map +1 -1
- package/dist/node/Plugin.d.mts +611 -5
- package/dist/node/Plugin.d.mts.map +1 -1
- package/dist/node/Plugin.d.ts +611 -5
- package/dist/node/Plugin.d.ts.map +1 -1
- package/dist/node/index.cjs +171 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +1 -1
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +45 -69
- package/dist/node/index.js.map +1 -1
- package/package.json +30 -23
- package/src/{CryptoContractDiviner.ts → Diviner/Diviner.ts} +6 -21
- package/src/Diviner/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/spec/Contract.Sentinel.Erc1155.Index.json +191 -0
- package/src/spec/Contract.Sentinel.Erc721.Index.json +191 -0
- package/src/spec/Contract.Sentinel.Node.json +233 -0
- package/dist/browser/CryptoContractDiviner.d.cts.map +0 -1
- package/dist/browser/CryptoContractDiviner.d.mts.map +0 -1
- package/dist/browser/CryptoContractDiviner.d.ts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.cts +0 -6
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.cts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.mts +0 -6
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.mts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.ts +0 -6
- package/dist/browser/Diviner/CryptoContractIndexingDiviner.d.ts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.cts +0 -19
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.cts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.mts +0 -19
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.mts.map +0 -1
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.ts +0 -19
- package/dist/browser/Diviner/CryptoContractIndexingDivinerLabels.d.ts.map +0 -1
- package/dist/node/CryptoContractDiviner.d.cts.map +0 -1
- package/dist/node/CryptoContractDiviner.d.mts +0 -28
- package/dist/node/CryptoContractDiviner.d.mts.map +0 -1
- package/dist/node/CryptoContractDiviner.d.ts +0 -28
- package/dist/node/CryptoContractDiviner.d.ts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.cts +0 -6
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.cts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.mts +0 -6
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.mts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.ts +0 -6
- package/dist/node/Diviner/CryptoContractIndexingDiviner.d.ts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.cts +0 -19
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.cts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.mts +0 -19
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.mts.map +0 -1
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.ts +0 -19
- package/dist/node/Diviner/CryptoContractIndexingDivinerLabels.d.ts.map +0 -1
- package/dist/node/index.mjs +0 -152
- package/dist/node/index.mjs.map +0 -1
- package/src/Diviner/CryptoContractIndexingDiviner.ts +0 -7
- package/src/Diviner/CryptoContractIndexingDivinerLabels.ts +0 -26
- /package/src/{Erc721Sentinel.json → spec/Erc721Sentinel.json} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAA;AAE7D,eAAO,MAAM,uCAAuC
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAA;AAE7D,eAAO,MAAM,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASjD,CAAA"}
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
CryptoContractDiviner: () => CryptoContractDiviner,
|
|
24
|
+
CryptoContractFunctionReadWitness: () => CryptoContractFunctionReadWitness,
|
|
25
|
+
CryptoContractFunctionReadWitnessPlugin: () => CryptoContractFunctionReadWitnessPlugin,
|
|
26
|
+
default: () => src_default
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
|
|
30
|
+
// src/Plugin.ts
|
|
31
|
+
var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
|
|
32
|
+
var import_payload_model2 = require("@xyo-network/payload-model");
|
|
33
|
+
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
34
|
+
|
|
35
|
+
// src/Witness.ts
|
|
36
|
+
var import_assert = require("@xylabs/assert");
|
|
37
|
+
var import_abstract_witness = require("@xyo-network/abstract-witness");
|
|
38
|
+
var import_crypto_contract_function_read_payload_plugin = require("@xyo-network/crypto-contract-function-read-payload-plugin");
|
|
39
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
40
|
+
var import_ethers = require("ethers");
|
|
41
|
+
var CryptoContractFunctionReadWitness = class extends import_abstract_witness.AbstractWitness {
|
|
42
|
+
static configSchemas = [import_crypto_contract_function_read_payload_plugin.CryptoContractFunctionReadWitnessConfigSchema];
|
|
43
|
+
get abi() {
|
|
44
|
+
return (0, import_assert.assertEx)(this.config.abi, "Missing abi");
|
|
45
|
+
}
|
|
46
|
+
async observeHandler(inPayloads = []) {
|
|
47
|
+
await this.started("throw");
|
|
48
|
+
try {
|
|
49
|
+
const observations = await Promise.all(
|
|
50
|
+
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(import_crypto_contract_function_read_payload_plugin.CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {
|
|
51
|
+
const { providers } = this.params;
|
|
52
|
+
const provider = providers[Date.now() % providers.length];
|
|
53
|
+
const validatedAddress = (0, import_assert.assertEx)(address ?? this.config.address, "Missing address");
|
|
54
|
+
const validatedFunctionName = (0, import_assert.assertEx)(functionName ?? this.config.functionName, "Missing address");
|
|
55
|
+
const mergedArgs = [...args ?? this.config.args ?? []];
|
|
56
|
+
const contract = new import_ethers.Contract(validatedAddress, this.abi, provider);
|
|
57
|
+
try {
|
|
58
|
+
const result = await contract[validatedFunctionName](...mergedArgs);
|
|
59
|
+
const transformedResult = typeof result === "bigint" ? result.toString(16) : result;
|
|
60
|
+
const observation = {
|
|
61
|
+
address: validatedAddress,
|
|
62
|
+
args: mergedArgs,
|
|
63
|
+
chainId: Number((await provider.getNetwork()).chainId),
|
|
64
|
+
functionName: validatedFunctionName,
|
|
65
|
+
result: transformedResult,
|
|
66
|
+
schema: import_crypto_contract_function_read_payload_plugin.CryptoContractFunctionCallResultSchema
|
|
67
|
+
};
|
|
68
|
+
return observation;
|
|
69
|
+
} catch (ex) {
|
|
70
|
+
const error = ex;
|
|
71
|
+
console.log(`Error [${this.config.name}]: ${error.code}`);
|
|
72
|
+
const observation = {
|
|
73
|
+
address: validatedAddress,
|
|
74
|
+
args: mergedArgs,
|
|
75
|
+
chainId: Number((await provider.getNetwork()).chainId),
|
|
76
|
+
error: error.code,
|
|
77
|
+
functionName: validatedFunctionName,
|
|
78
|
+
schema: import_crypto_contract_function_read_payload_plugin.CryptoContractFunctionCallResultSchema
|
|
79
|
+
};
|
|
80
|
+
return observation;
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
return observations;
|
|
85
|
+
} catch (ex) {
|
|
86
|
+
const error = ex;
|
|
87
|
+
console.log(`Error [${this.config.name}]: ${error.message}`);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/Plugin.ts
|
|
94
|
+
var CryptoContractFunctionReadWitnessPlugin = () => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)(
|
|
95
|
+
{ required: { [import_crypto_nft_payload_plugin.NftSchema]: 1 }, schema: import_payload_model2.PayloadSetSchema },
|
|
96
|
+
{
|
|
97
|
+
witness: async (params) => {
|
|
98
|
+
const result = await CryptoContractFunctionReadWitness.create(params);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// src/Diviner/Diviner.ts
|
|
105
|
+
var import_assert2 = require("@xylabs/assert");
|
|
106
|
+
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
107
|
+
var import_crypto_contract_function_read_payload_plugin2 = require("@xyo-network/crypto-contract-function-read-payload-plugin");
|
|
108
|
+
var import_payload_model3 = require("@xyo-network/payload-model");
|
|
109
|
+
var CryptoContractDiviner = class _CryptoContractDiviner extends import_abstract_diviner.AbstractDiviner {
|
|
110
|
+
static configSchemas = [import_crypto_contract_function_read_payload_plugin2.CryptoContractDivinerConfigSchema];
|
|
111
|
+
static labels = import_crypto_contract_function_read_payload_plugin2.CryptoContractDivinerLabels;
|
|
112
|
+
static findCallResult(address, functionName, payloads) {
|
|
113
|
+
var _a;
|
|
114
|
+
const foundPayload = payloads.find((payload) => payload.functionName === functionName && payload.address === address);
|
|
115
|
+
return (_a = (0, import_crypto_contract_function_read_payload_plugin2.asCryptoContractFunctionCallSuccess)(foundPayload)) == null ? void 0 : _a.result;
|
|
116
|
+
}
|
|
117
|
+
static matchingExistingField(objs, field) {
|
|
118
|
+
var _a;
|
|
119
|
+
const expectedValue = (_a = objs.at(0)) == null ? void 0 : _a[field];
|
|
120
|
+
const didNotMatch = objs.reduce((prev, obj) => {
|
|
121
|
+
return prev || obj[field] !== expectedValue;
|
|
122
|
+
}, false);
|
|
123
|
+
return didNotMatch ? void 0 : expectedValue;
|
|
124
|
+
}
|
|
125
|
+
contractInfoRequiredFields(callResults) {
|
|
126
|
+
return {
|
|
127
|
+
address: (0, import_assert2.assertEx)(_CryptoContractDiviner.matchingExistingField(callResults, "address"), "Mismatched address"),
|
|
128
|
+
chainId: (0, import_assert2.assertEx)(_CryptoContractDiviner.matchingExistingField(callResults, "chainId"), "Mismatched chainId"),
|
|
129
|
+
schema: import_crypto_contract_function_read_payload_plugin2.ContractInfoSchema
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async divineHandler(inPayloads = []) {
|
|
133
|
+
const callResults = inPayloads.filter((0, import_payload_model3.isPayloadOfSchemaType)(import_crypto_contract_function_read_payload_plugin2.CryptoContractFunctionCallResultSchema));
|
|
134
|
+
const addresses = Object.keys(
|
|
135
|
+
callResults.reduce((prev, result2) => {
|
|
136
|
+
if (result2.address) {
|
|
137
|
+
prev[result2.address] = true;
|
|
138
|
+
}
|
|
139
|
+
return prev;
|
|
140
|
+
}, {})
|
|
141
|
+
);
|
|
142
|
+
const result = await Promise.all(
|
|
143
|
+
addresses.map(async (address) => {
|
|
144
|
+
const foundCallResults = callResults.filter((callResult) => callResult.address === address);
|
|
145
|
+
const info = {
|
|
146
|
+
...{ results: await this.reduceResults(foundCallResults) },
|
|
147
|
+
...this.contractInfoRequiredFields(foundCallResults)
|
|
148
|
+
};
|
|
149
|
+
return info;
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
reduceResults(callResults) {
|
|
155
|
+
return callResults.reduce((prev, callResult) => {
|
|
156
|
+
var _a;
|
|
157
|
+
prev[callResult.functionName] = (_a = (0, import_crypto_contract_function_read_payload_plugin2.asCryptoContractFunctionCallSuccess)(callResult)) == null ? void 0 : _a.result;
|
|
158
|
+
return prev;
|
|
159
|
+
}, {});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/index.ts
|
|
164
|
+
var src_default = CryptoContractFunctionReadWitnessPlugin;
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
CryptoContractDiviner,
|
|
168
|
+
CryptoContractFunctionReadWitness,
|
|
169
|
+
CryptoContractFunctionReadWitnessPlugin
|
|
170
|
+
});
|
|
171
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Witness.ts","../../src/Diviner/Diviner.ts"],"sourcesContent":["import { CryptoContractFunctionReadWitnessPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './Witness'\n\nexport { CryptoContractFunctionReadWitnessPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default CryptoContractFunctionReadWitnessPlugin\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { CryptoContractFunctionReadWitness } from './Witness'\n\nexport const CryptoContractFunctionReadWitnessPlugin = () =>\n createPayloadSetWitnessPlugin<CryptoContractFunctionReadWitness>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await CryptoContractFunctionReadWitness.create(params)\n return result\n },\n },\n )\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport {\n CryptoContractFunctionCall,\n CryptoContractFunctionCallFailure,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n CryptoContractFunctionCallSchema,\n CryptoContractFunctionCallSuccess,\n CryptoContractFunctionReadWitnessConfig,\n CryptoContractFunctionReadWitnessConfigSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { Contract, Provider } from 'ethers'\n\nexport type CryptoContractFunctionReadWitnessParams = WitnessParams<\n AnyConfigSchema<CryptoContractFunctionReadWitnessConfig>,\n {\n providers: Provider[]\n }\n>\n\nexport class CryptoContractFunctionReadWitness<\n TParams extends CryptoContractFunctionReadWitnessParams = CryptoContractFunctionReadWitnessParams,\n> extends AbstractWitness<TParams, CryptoContractFunctionCall, CryptoContractFunctionCallResult> {\n static override configSchemas = [CryptoContractFunctionReadWitnessConfigSchema]\n\n get abi() {\n return assertEx(this.config.abi, 'Missing abi')\n }\n\n protected override async observeHandler(inPayloads: CryptoContractFunctionCall[] = []): Promise<CryptoContractFunctionCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {\n const { providers } = this.params\n const provider = providers[Date.now() % providers.length] //pick a random provider\n const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')\n const validatedFunctionName = assertEx(functionName ?? this.config.functionName, 'Missing address')\n const mergedArgs = [...(args ?? this.config.args ?? [])]\n\n const contract = new Contract(validatedAddress, this.abi, provider)\n try {\n const result = await contract[validatedFunctionName](...mergedArgs)\n const transformedResult = typeof result === 'bigint' ? result.toString(16) : result\n const observation: CryptoContractFunctionCallSuccess = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n functionName: validatedFunctionName,\n result: transformedResult,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n } catch (ex) {\n const error = ex as Error & { code: string }\n console.log(`Error [${this.config.name}]: ${error.code}`)\n const observation: CryptoContractFunctionCallFailure = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n error: error.code,\n functionName: validatedFunctionName,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n }\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\n throw error\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Promisable } from '@xylabs/promise'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n asCryptoContractFunctionCallSuccess,\n ContractInfo,\n ContractInfoSchema,\n CryptoContractDivinerConfigSchema,\n CryptoContractDivinerLabels,\n CryptoContractDivinerParams,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport type FindCallResult<TResult = string, TPayload = Payload> = [TResult, TPayload] | [undefined, TPayload] | [undefined, undefined]\n\nexport class CryptoContractDiviner<TParams extends CryptoContractDivinerParams = CryptoContractDivinerParams> extends AbstractDiviner<TParams> {\n static override configSchemas = [CryptoContractDivinerConfigSchema]\n static labels: CryptoContractDivinerLabels = CryptoContractDivinerLabels\n\n protected static findCallResult<TResult = string>(\n address: string,\n functionName: string,\n payloads: CryptoContractFunctionCallResult[],\n ): TResult | undefined {\n const foundPayload = payloads.find((payload) => payload.functionName === functionName && payload.address === address)\n return asCryptoContractFunctionCallSuccess(foundPayload)?.result as TResult | undefined\n }\n\n protected static matchingExistingField<R = string, T extends Payload = Payload>(objs: T[], field: keyof T): R | undefined {\n const expectedValue = objs.at(0)?.[field] as R\n const didNotMatch = objs.reduce((prev, obj) => {\n return prev || obj[field] !== expectedValue\n }, false)\n return didNotMatch ? undefined : expectedValue\n }\n\n protected contractInfoRequiredFields(callResults: CryptoContractFunctionCallResult[]): ContractInfo {\n return {\n address: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'address'), 'Mismatched address'),\n chainId: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'chainId'), 'Mismatched chainId'),\n schema: ContractInfoSchema,\n }\n }\n\n protected override async divineHandler(inPayloads: CryptoContractFunctionCallResult[] = []): Promise<ContractInfo[]> {\n const callResults = inPayloads.filter(isPayloadOfSchemaType<CryptoContractFunctionCallResult>(CryptoContractFunctionCallResultSchema))\n const addresses = Object.keys(\n callResults.reduce<Record<string, boolean>>((prev, result) => {\n if (result.address) {\n prev[result.address] = true\n }\n return prev\n }, {}),\n )\n const result = await Promise.all(\n addresses.map(async (address) => {\n const foundCallResults = callResults.filter((callResult) => callResult.address === address)\n const info: ContractInfo = {\n ...{ results: await this.reduceResults(foundCallResults) },\n ...this.contractInfoRequiredFields(foundCallResults),\n }\n return info\n }),\n )\n\n return result\n }\n\n protected reduceResults(callResults: CryptoContractFunctionCallResult[]): Promisable<ContractInfo['results']> {\n return callResults.reduce<Record<string, unknown>>((prev, callResult) => {\n prev[callResult.functionName] = asCryptoContractFunctionCallSuccess(callResult)?.result\n return prev\n }, {})\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uCAA0B;AAC1B,IAAAA,wBAAiC;AACjC,+BAA8C;;;ACF9C,oBAAyB;AACzB,8BAAgC;AAChC,0DASO;AAEP,2BAAsC;AAEtC,oBAAmC;AAS5B,IAAM,oCAAN,cAEG,wCAAuF;AAAA,EAC/F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AAA,MAC3G,aAAS,yBAAS,uBAAsB,sBAAsB,aAAa,SAAS,GAAG,oBAAoB;AAAA,MAC3G,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,MAAyB,cAAc,aAAiD,CAAC,GAA4B;AACnH,UAAM,cAAc,WAAW,WAAO,6CAAwD,2FAAsC,CAAC;AACrI,UAAM,YAAY,OAAO;AAAA,MACvB,YAAY,OAAgC,CAAC,MAAMC,YAAW;AAC5D,YAAIA,QAAO,SAAS;AAClB,eAAKA,QAAO,OAAO,IAAI;AAAA,QACzB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,IACP;AACA,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B,UAAU,IAAI,OAAO,YAAY;AAC/B,cAAM,mBAAmB,YAAY,OAAO,CAAC,eAAe,WAAW,YAAY,OAAO;AAC1F,cAAM,OAAqB;AAAA,UACzB,GAAG,EAAE,SAAS,MAAM,KAAK,cAAc,gBAAgB,EAAE;AAAA,UACzD,GAAG,KAAK,2BAA2B,gBAAgB;AAAA,QACrD;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,cAAc,aAAsF;AAC5G,WAAO,YAAY,OAAgC,CAAC,MAAM,eAAe;AAvE7E;AAwEM,WAAK,WAAW,YAAY,KAAI,mGAAoC,UAAU,MAA9C,mBAAiD;AACjF,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AACF;;;AHpEA,IAAO,cAAQ;","names":["import_payload_model","import_assert","import_crypto_contract_function_read_payload_plugin","import_payload_model","result"]}
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CryptoContractFunctionReadWitnessPlugin } from './Plugin';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './Diviner';
|
|
3
3
|
export * from './Witness';
|
|
4
4
|
export { CryptoContractFunctionReadWitnessPlugin };
|
|
5
5
|
export default CryptoContractFunctionReadWitnessPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,uCAAuC,EAAE,CAAA;AAGlD,eAAe,uCAAuC,CAAA"}
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CryptoContractFunctionReadWitnessPlugin } from './Plugin';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './Diviner';
|
|
3
3
|
export * from './Witness';
|
|
4
4
|
export { CryptoContractFunctionReadWitnessPlugin };
|
|
5
5
|
export default CryptoContractFunctionReadWitnessPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,uCAAuC,EAAE,CAAA;AAGlD,eAAe,uCAAuC,CAAA"}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CryptoContractFunctionReadWitnessPlugin } from './Plugin';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './Diviner';
|
|
3
3
|
export * from './Witness';
|
|
4
4
|
export { CryptoContractFunctionReadWitnessPlugin };
|
|
5
5
|
export default CryptoContractFunctionReadWitnessPlugin;
|
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,UAAU,CAAA;AAElE,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,uCAAuC,EAAE,CAAA;AAGlD,eAAe,uCAAuC,CAAA"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,61 +1,34 @@
|
|
|
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
|
-
ContractInfoSchema: () => ContractInfoSchema,
|
|
24
|
-
CryptoContractDiviner: () => CryptoContractDiviner,
|
|
25
|
-
CryptoContractDivinerConfigSchema: () => CryptoContractDivinerConfigSchema,
|
|
26
|
-
CryptoContractFunctionReadWitness: () => CryptoContractFunctionReadWitness,
|
|
27
|
-
CryptoContractFunctionReadWitnessPlugin: () => CryptoContractFunctionReadWitnessPlugin,
|
|
28
|
-
default: () => src_default
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
|
|
32
1
|
// src/Plugin.ts
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
3
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
4
|
+
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
36
5
|
|
|
37
6
|
// src/Witness.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
import { assertEx } from "@xylabs/assert";
|
|
8
|
+
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
9
|
+
import {
|
|
10
|
+
CryptoContractFunctionCallResultSchema,
|
|
11
|
+
CryptoContractFunctionCallSchema,
|
|
12
|
+
CryptoContractFunctionReadWitnessConfigSchema
|
|
13
|
+
} from "@xyo-network/crypto-contract-function-read-payload-plugin";
|
|
14
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
15
|
+
import { Contract } from "ethers";
|
|
16
|
+
var CryptoContractFunctionReadWitness = class extends AbstractWitness {
|
|
17
|
+
static configSchemas = [CryptoContractFunctionReadWitnessConfigSchema];
|
|
45
18
|
get abi() {
|
|
46
|
-
return
|
|
19
|
+
return assertEx(this.config.abi, "Missing abi");
|
|
47
20
|
}
|
|
48
21
|
async observeHandler(inPayloads = []) {
|
|
49
22
|
await this.started("throw");
|
|
50
23
|
try {
|
|
51
24
|
const observations = await Promise.all(
|
|
52
|
-
inPayloads.filter(
|
|
25
|
+
inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {
|
|
53
26
|
const { providers } = this.params;
|
|
54
27
|
const provider = providers[Date.now() % providers.length];
|
|
55
|
-
const validatedAddress =
|
|
56
|
-
const validatedFunctionName =
|
|
28
|
+
const validatedAddress = assertEx(address ?? this.config.address, "Missing address");
|
|
29
|
+
const validatedFunctionName = assertEx(functionName ?? this.config.functionName, "Missing address");
|
|
57
30
|
const mergedArgs = [...args ?? this.config.args ?? []];
|
|
58
|
-
const contract = new
|
|
31
|
+
const contract = new Contract(validatedAddress, this.abi, provider);
|
|
59
32
|
try {
|
|
60
33
|
const result = await contract[validatedFunctionName](...mergedArgs);
|
|
61
34
|
const transformedResult = typeof result === "bigint" ? result.toString(16) : result;
|
|
@@ -65,7 +38,7 @@ var CryptoContractFunctionReadWitness = class extends import_abstract_witness.Ab
|
|
|
65
38
|
chainId: Number((await provider.getNetwork()).chainId),
|
|
66
39
|
functionName: validatedFunctionName,
|
|
67
40
|
result: transformedResult,
|
|
68
|
-
schema:
|
|
41
|
+
schema: CryptoContractFunctionCallResultSchema
|
|
69
42
|
};
|
|
70
43
|
return observation;
|
|
71
44
|
} catch (ex) {
|
|
@@ -77,7 +50,7 @@ var CryptoContractFunctionReadWitness = class extends import_abstract_witness.Ab
|
|
|
77
50
|
chainId: Number((await provider.getNetwork()).chainId),
|
|
78
51
|
error: error.code,
|
|
79
52
|
functionName: validatedFunctionName,
|
|
80
|
-
schema:
|
|
53
|
+
schema: CryptoContractFunctionCallResultSchema
|
|
81
54
|
};
|
|
82
55
|
return observation;
|
|
83
56
|
}
|
|
@@ -93,8 +66,8 @@ var CryptoContractFunctionReadWitness = class extends import_abstract_witness.Ab
|
|
|
93
66
|
};
|
|
94
67
|
|
|
95
68
|
// src/Plugin.ts
|
|
96
|
-
var CryptoContractFunctionReadWitnessPlugin = () =>
|
|
97
|
-
{ required: { [
|
|
69
|
+
var CryptoContractFunctionReadWitnessPlugin = () => createPayloadSetWitnessPlugin(
|
|
70
|
+
{ required: { [NftSchema]: 1 }, schema: PayloadSetSchema },
|
|
98
71
|
{
|
|
99
72
|
witness: async (params) => {
|
|
100
73
|
const result = await CryptoContractFunctionReadWitness.create(params);
|
|
@@ -103,19 +76,24 @@ var CryptoContractFunctionReadWitnessPlugin = () => (0, import_payloadset_plugin
|
|
|
103
76
|
}
|
|
104
77
|
);
|
|
105
78
|
|
|
106
|
-
// src/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
79
|
+
// src/Diviner/Diviner.ts
|
|
80
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
81
|
+
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
82
|
+
import {
|
|
83
|
+
asCryptoContractFunctionCallSuccess,
|
|
84
|
+
ContractInfoSchema,
|
|
85
|
+
CryptoContractDivinerConfigSchema,
|
|
86
|
+
CryptoContractDivinerLabels,
|
|
87
|
+
CryptoContractFunctionCallResultSchema as CryptoContractFunctionCallResultSchema2
|
|
88
|
+
} from "@xyo-network/crypto-contract-function-read-payload-plugin";
|
|
89
|
+
import { isPayloadOfSchemaType as isPayloadOfSchemaType2 } from "@xyo-network/payload-model";
|
|
90
|
+
var CryptoContractDiviner = class _CryptoContractDiviner extends AbstractDiviner {
|
|
114
91
|
static configSchemas = [CryptoContractDivinerConfigSchema];
|
|
92
|
+
static labels = CryptoContractDivinerLabels;
|
|
115
93
|
static findCallResult(address, functionName, payloads) {
|
|
116
94
|
var _a;
|
|
117
95
|
const foundPayload = payloads.find((payload) => payload.functionName === functionName && payload.address === address);
|
|
118
|
-
return (_a =
|
|
96
|
+
return (_a = asCryptoContractFunctionCallSuccess(foundPayload)) == null ? void 0 : _a.result;
|
|
119
97
|
}
|
|
120
98
|
static matchingExistingField(objs, field) {
|
|
121
99
|
var _a;
|
|
@@ -127,13 +105,13 @@ var CryptoContractDiviner = class _CryptoContractDiviner extends import_abstract
|
|
|
127
105
|
}
|
|
128
106
|
contractInfoRequiredFields(callResults) {
|
|
129
107
|
return {
|
|
130
|
-
address: (
|
|
131
|
-
chainId: (
|
|
108
|
+
address: assertEx2(_CryptoContractDiviner.matchingExistingField(callResults, "address"), "Mismatched address"),
|
|
109
|
+
chainId: assertEx2(_CryptoContractDiviner.matchingExistingField(callResults, "chainId"), "Mismatched chainId"),
|
|
132
110
|
schema: ContractInfoSchema
|
|
133
111
|
};
|
|
134
112
|
}
|
|
135
113
|
async divineHandler(inPayloads = []) {
|
|
136
|
-
const callResults = inPayloads.filter((
|
|
114
|
+
const callResults = inPayloads.filter(isPayloadOfSchemaType2(CryptoContractFunctionCallResultSchema2));
|
|
137
115
|
const addresses = Object.keys(
|
|
138
116
|
callResults.reduce((prev, result2) => {
|
|
139
117
|
if (result2.address) {
|
|
@@ -157,7 +135,7 @@ var CryptoContractDiviner = class _CryptoContractDiviner extends import_abstract
|
|
|
157
135
|
reduceResults(callResults) {
|
|
158
136
|
return callResults.reduce((prev, callResult) => {
|
|
159
137
|
var _a;
|
|
160
|
-
prev[callResult.functionName] = (_a =
|
|
138
|
+
prev[callResult.functionName] = (_a = asCryptoContractFunctionCallSuccess(callResult)) == null ? void 0 : _a.result;
|
|
161
139
|
return prev;
|
|
162
140
|
}, {});
|
|
163
141
|
}
|
|
@@ -165,12 +143,10 @@ var CryptoContractDiviner = class _CryptoContractDiviner extends import_abstract
|
|
|
165
143
|
|
|
166
144
|
// src/index.ts
|
|
167
145
|
var src_default = CryptoContractFunctionReadWitnessPlugin;
|
|
168
|
-
|
|
169
|
-
0 && (module.exports = {
|
|
170
|
-
ContractInfoSchema,
|
|
146
|
+
export {
|
|
171
147
|
CryptoContractDiviner,
|
|
172
|
-
CryptoContractDivinerConfigSchema,
|
|
173
148
|
CryptoContractFunctionReadWitness,
|
|
174
|
-
CryptoContractFunctionReadWitnessPlugin
|
|
175
|
-
|
|
149
|
+
CryptoContractFunctionReadWitnessPlugin,
|
|
150
|
+
src_default as default
|
|
151
|
+
};
|
|
176
152
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Witness.ts","../../src/CryptoContractDiviner.ts"],"sourcesContent":["import { CryptoContractFunctionReadWitnessPlugin } from './Plugin'\n\nexport * from './CryptoContractDiviner'\nexport * from './Witness'\n\nexport { CryptoContractFunctionReadWitnessPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default CryptoContractFunctionReadWitnessPlugin\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { CryptoContractFunctionReadWitness } from './Witness'\n\nexport const CryptoContractFunctionReadWitnessPlugin = () =>\n createPayloadSetWitnessPlugin<CryptoContractFunctionReadWitness>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await CryptoContractFunctionReadWitness.create(params)\n return result\n },\n },\n )\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport {\n CryptoContractFunctionCall,\n CryptoContractFunctionCallFailure,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n CryptoContractFunctionCallSchema,\n CryptoContractFunctionCallSuccess,\n CryptoContractFunctionReadWitnessConfig,\n CryptoContractFunctionReadWitnessConfigSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { Contract, Provider } from 'ethers'\n\nexport type CryptoContractFunctionReadWitnessParams = WitnessParams<\n AnyConfigSchema<CryptoContractFunctionReadWitnessConfig>,\n {\n providers: Provider[]\n }\n>\n\nexport class CryptoContractFunctionReadWitness<\n TParams extends CryptoContractFunctionReadWitnessParams = CryptoContractFunctionReadWitnessParams,\n> extends AbstractWitness<TParams, CryptoContractFunctionCall, CryptoContractFunctionCallResult> {\n static override configSchemas = [CryptoContractFunctionReadWitnessConfigSchema]\n\n get abi() {\n return assertEx(this.config.abi, 'Missing abi')\n }\n\n protected override async observeHandler(inPayloads: CryptoContractFunctionCall[] = []): Promise<CryptoContractFunctionCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {\n const { providers } = this.params\n const provider = providers[Date.now() % providers.length] //pick a random provider\n const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')\n const validatedFunctionName = assertEx(functionName ?? this.config.functionName, 'Missing address')\n const mergedArgs = [...(args ?? this.config.args ?? [])]\n\n const contract = new Contract(validatedAddress, this.abi, provider)\n try {\n const result = await contract[validatedFunctionName](...mergedArgs)\n const transformedResult = typeof result === 'bigint' ? result.toString(16) : result\n const observation: CryptoContractFunctionCallSuccess = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n functionName: validatedFunctionName,\n result: transformedResult,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n } catch (ex) {\n const error = ex as Error & { code: string }\n console.log(`Error [${this.config.name}]: ${error.code}`)\n const observation: CryptoContractFunctionCallFailure = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n error: error.code,\n functionName: validatedFunctionName,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n }\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\n throw error\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Promisable } from '@xylabs/promise'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n asCryptoContractFunctionCallSuccess,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport type FindCallResult<TResult = string, TPayload = Payload> = [TResult, TPayload] | [undefined, TPayload] | [undefined, undefined]\n\nexport const CryptoContractDivinerConfigSchema = 'network.xyo.crypto.contract.diviner.config'\nexport type CryptoContractDivinerConfigSchema = typeof CryptoContractDivinerConfigSchema\n\nexport type CryptoContractDivinerConfig = DivinerConfig<{\n schema: CryptoContractDivinerConfigSchema\n}>\nexport type CryptoContractDivinerParams = DivinerParams<CryptoContractDivinerConfig>\n\nexport const ContractInfoSchema = 'network.xyo.crypto.contract.info'\nexport type ContractInfoSchema = typeof ContractInfoSchema\n\nexport type ContractInfo = Payload<\n {\n address: string\n chainId: string\n results?: Record<string, unknown>\n },\n ContractInfoSchema\n>\n\nexport class CryptoContractDiviner<TParams extends CryptoContractDivinerParams = CryptoContractDivinerParams> extends AbstractDiviner<TParams> {\n static override configSchemas = [CryptoContractDivinerConfigSchema]\n\n protected static findCallResult<TResult = string>(\n address: string,\n functionName: string,\n payloads: CryptoContractFunctionCallResult[],\n ): TResult | undefined {\n const foundPayload = payloads.find((payload) => payload.functionName === functionName && payload.address === address)\n return asCryptoContractFunctionCallSuccess(foundPayload)?.result as TResult | undefined\n }\n\n protected static matchingExistingField<R = string, T extends Payload = Payload>(objs: T[], field: keyof T): R | undefined {\n const expectedValue = objs.at(0)?.[field] as R\n const didNotMatch = objs.reduce((prev, obj) => {\n return prev || obj[field] !== expectedValue\n }, false)\n return didNotMatch ? undefined : expectedValue\n }\n\n protected contractInfoRequiredFields(callResults: CryptoContractFunctionCallResult[]): ContractInfo {\n return {\n address: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'address'), 'Mismatched address'),\n chainId: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'chainId'), 'Mismatched chainId'),\n schema: ContractInfoSchema,\n }\n }\n\n protected override async divineHandler(inPayloads: CryptoContractFunctionCallResult[] = []): Promise<ContractInfo[]> {\n const callResults = inPayloads.filter(isPayloadOfSchemaType<CryptoContractFunctionCallResult>(CryptoContractFunctionCallResultSchema))\n const addresses = Object.keys(\n callResults.reduce<Record<string, boolean>>((prev, result) => {\n if (result.address) {\n prev[result.address] = true\n }\n return prev\n }, {}),\n )\n const result = await Promise.all(\n addresses.map(async (address) => {\n const foundCallResults = callResults.filter((callResult) => callResult.address === address)\n const info: ContractInfo = {\n ...{ results: await this.reduceResults(foundCallResults) },\n ...this.contractInfoRequiredFields(foundCallResults),\n }\n return info\n }),\n )\n\n return result\n }\n\n protected reduceResults(callResults: CryptoContractFunctionCallResult[]): Promisable<ContractInfo['results']> {\n return callResults.reduce<Record<string, unknown>>((prev, callResult) => {\n prev[callResult.functionName] = asCryptoContractFunctionCallSuccess(callResult)?.result\n return prev\n }, {})\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uCAA0B;AAC1B,IAAAA,wBAAiC;AACjC,+BAA8C;;;ACF9C,oBAAyB;AACzB,8BAAgC;AAChC,0DASO;AAEP,2BAAsC;AAEtC,oBAAmC;AAS5B,IAAM,oCAAN,cAEG,wCAAuF;AAAA,EAC/F,OAAgB,gBAAgB,CAAC,iGAA6C;AAAA,EAE9E,IAAI,MAAM;AACR,eAAO,wBAAS,KAAK,OAAO,KAAK,aAAa;AAAA,EAChD;AAAA,EAEA,MAAyB,eAAe,aAA2C,CAAC,GAAgD;AAClI,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,eAAe,MAAM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,CAAC;AACrI,UAAM,YAAY,OAAO;AAAA,MACvB,YAAY,OAAgC,CAAC,MAAMC,YAAW;AAC5D,YAAIA,QAAO,SAAS;AAClB,eAAKA,QAAO,OAAO,IAAI;AAAA,QACzB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,IACP;AACA,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B,UAAU,IAAI,OAAO,YAAY;AAC/B,cAAM,mBAAmB,YAAY,OAAO,CAAC,eAAe,WAAW,YAAY,OAAO;AAC1F,cAAM,OAAqB;AAAA,UACzB,GAAG,EAAE,SAAS,MAAM,KAAK,cAAc,gBAAgB,EAAE;AAAA,UACzD,GAAG,KAAK,2BAA2B,gBAAgB;AAAA,QACrD;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,cAAc,aAAsF;AAC5G,WAAO,YAAY,OAAgC,CAAC,MAAM,eAAe;AAtF7E;AAuFM,WAAK,WAAW,YAAY,KAAI,mGAAoC,UAAU,MAA9C,mBAAiD;AACjF,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AACF;;;AHnFA,IAAO,cAAQ;","names":["import_payload_model","import_assert","import_crypto_contract_function_read_payload_plugin","import_payload_model","result"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Plugin.ts","../../src/Witness.ts","../../src/Diviner/Diviner.ts","../../src/index.ts"],"sourcesContent":["import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { CryptoContractFunctionReadWitness } from './Witness'\n\nexport const CryptoContractFunctionReadWitnessPlugin = () =>\n createPayloadSetWitnessPlugin<CryptoContractFunctionReadWitness>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await CryptoContractFunctionReadWitness.create(params)\n return result\n },\n },\n )\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport {\n CryptoContractFunctionCall,\n CryptoContractFunctionCallFailure,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n CryptoContractFunctionCallSchema,\n CryptoContractFunctionCallSuccess,\n CryptoContractFunctionReadWitnessConfig,\n CryptoContractFunctionReadWitnessConfigSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { Contract, Provider } from 'ethers'\n\nexport type CryptoContractFunctionReadWitnessParams = WitnessParams<\n AnyConfigSchema<CryptoContractFunctionReadWitnessConfig>,\n {\n providers: Provider[]\n }\n>\n\nexport class CryptoContractFunctionReadWitness<\n TParams extends CryptoContractFunctionReadWitnessParams = CryptoContractFunctionReadWitnessParams,\n> extends AbstractWitness<TParams, CryptoContractFunctionCall, CryptoContractFunctionCallResult> {\n static override configSchemas = [CryptoContractFunctionReadWitnessConfigSchema]\n\n get abi() {\n return assertEx(this.config.abi, 'Missing abi')\n }\n\n protected override async observeHandler(inPayloads: CryptoContractFunctionCall[] = []): Promise<CryptoContractFunctionCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {\n const { providers } = this.params\n const provider = providers[Date.now() % providers.length] //pick a random provider\n const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')\n const validatedFunctionName = assertEx(functionName ?? this.config.functionName, 'Missing address')\n const mergedArgs = [...(args ?? this.config.args ?? [])]\n\n const contract = new Contract(validatedAddress, this.abi, provider)\n try {\n const result = await contract[validatedFunctionName](...mergedArgs)\n const transformedResult = typeof result === 'bigint' ? result.toString(16) : result\n const observation: CryptoContractFunctionCallSuccess = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n functionName: validatedFunctionName,\n result: transformedResult,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n } catch (ex) {\n const error = ex as Error & { code: string }\n console.log(`Error [${this.config.name}]: ${error.code}`)\n const observation: CryptoContractFunctionCallFailure = {\n address: validatedAddress,\n args: mergedArgs,\n chainId: Number((await provider.getNetwork()).chainId),\n error: error.code,\n functionName: validatedFunctionName,\n schema: CryptoContractFunctionCallResultSchema,\n }\n return observation\n }\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\n throw error\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Promisable } from '@xylabs/promise'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n asCryptoContractFunctionCallSuccess,\n ContractInfo,\n ContractInfoSchema,\n CryptoContractDivinerConfigSchema,\n CryptoContractDivinerLabels,\n CryptoContractDivinerParams,\n CryptoContractFunctionCallResult,\n CryptoContractFunctionCallResultSchema,\n} from '@xyo-network/crypto-contract-function-read-payload-plugin'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport type FindCallResult<TResult = string, TPayload = Payload> = [TResult, TPayload] | [undefined, TPayload] | [undefined, undefined]\n\nexport class CryptoContractDiviner<TParams extends CryptoContractDivinerParams = CryptoContractDivinerParams> extends AbstractDiviner<TParams> {\n static override configSchemas = [CryptoContractDivinerConfigSchema]\n static labels: CryptoContractDivinerLabels = CryptoContractDivinerLabels\n\n protected static findCallResult<TResult = string>(\n address: string,\n functionName: string,\n payloads: CryptoContractFunctionCallResult[],\n ): TResult | undefined {\n const foundPayload = payloads.find((payload) => payload.functionName === functionName && payload.address === address)\n return asCryptoContractFunctionCallSuccess(foundPayload)?.result as TResult | undefined\n }\n\n protected static matchingExistingField<R = string, T extends Payload = Payload>(objs: T[], field: keyof T): R | undefined {\n const expectedValue = objs.at(0)?.[field] as R\n const didNotMatch = objs.reduce((prev, obj) => {\n return prev || obj[field] !== expectedValue\n }, false)\n return didNotMatch ? undefined : expectedValue\n }\n\n protected contractInfoRequiredFields(callResults: CryptoContractFunctionCallResult[]): ContractInfo {\n return {\n address: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'address'), 'Mismatched address'),\n chainId: assertEx(CryptoContractDiviner.matchingExistingField(callResults, 'chainId'), 'Mismatched chainId'),\n schema: ContractInfoSchema,\n }\n }\n\n protected override async divineHandler(inPayloads: CryptoContractFunctionCallResult[] = []): Promise<ContractInfo[]> {\n const callResults = inPayloads.filter(isPayloadOfSchemaType<CryptoContractFunctionCallResult>(CryptoContractFunctionCallResultSchema))\n const addresses = Object.keys(\n callResults.reduce<Record<string, boolean>>((prev, result) => {\n if (result.address) {\n prev[result.address] = true\n }\n return prev\n }, {}),\n )\n const result = await Promise.all(\n addresses.map(async (address) => {\n const foundCallResults = callResults.filter((callResult) => callResult.address === address)\n const info: ContractInfo = {\n ...{ results: await this.reduceResults(foundCallResults) },\n ...this.contractInfoRequiredFields(foundCallResults),\n }\n return info\n }),\n )\n\n return result\n }\n\n protected reduceResults(callResults: CryptoContractFunctionCallResult[]): Promisable<ContractInfo['results']> {\n return callResults.reduce<Record<string, unknown>>((prev, callResult) => {\n prev[callResult.functionName] = asCryptoContractFunctionCallSuccess(callResult)?.result\n return prev\n }, {})\n }\n}\n","import { CryptoContractFunctionReadWitnessPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './Witness'\n\nexport { CryptoContractFunctionReadWitnessPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default CryptoContractFunctionReadWitnessPlugin\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACF9C,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC;AAAA,EAIE;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AAEP,SAAS,6BAA6B;AAEtC,SAAS,gBAA0B;AAS5B,I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EACnC;AAAA,EAEU,2BAA2B,aAA+D;AAClG,WAAO;AAAA,MACL,SAASF,UAAS,uBAAsB,sBAAsB,aAAa,SAAS,GAAG,oBAAoB;AAAA,MAC3G,SAASA,UAAS,uBAAsB,sBAAsB,aAAa,SAAS,GAAG,oBAAoB;AAAA,MAC3G,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,MAAyB,cAAc,aAAiD,CAAC,GAA4B;AACnH,UAAM,cAAc,WAAW,OAAOE,uBAAwDD,uCAAsC,CAAC;AACrI,UAAM,YAAY,OAAO;AAAA,MACvB,YAAY,OAAgC,CAAC,MAAME,YAAW;AAC5D,YAAIA,QAAO,SAAS;AAClB,eAAKA,QAAO,OAAO,IAAI;AAAA,QACzB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,IACP;AACA,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B,UAAU,IAAI,OAAO,YAAY;AAC/B,cAAM,mBAAmB,YAAY,OAAO,CAAC,eAAe,WAAW,YAAY,OAAO;AAC1F,cAAM,OAAqB;AAAA,UACzB,GAAG,EAAE,SAAS,MAAM,KAAK,cAAc,gBAAgB,EAAE;AAAA,UACzD,GAAG,KAAK,2BAA2B,gBAAgB;AAAA,QACrD;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,cAAc,aAAsF;AAC5G,WAAO,YAAY,OAAgC,CAAC,MAAM,eAAe;AAvE7E;AAwEM,WAAK,WAAW,YAAY,KAAI,yCAAoC,UAAU,MAA9C,mBAAiD;AACjF,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AACF;;;ACpEA,IAAO,cAAQ;","names":["assertEx","CryptoContractFunctionCallResultSchema","isPayloadOfSchemaType","result"]}
|
package/package.json
CHANGED
|
@@ -12,34 +12,40 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
14
|
"@xylabs/promise": "^2.13.20",
|
|
15
|
-
"@xyo-network/abstract-diviner": "^2.
|
|
16
|
-
"@xyo-network/abstract-witness": "^2.
|
|
17
|
-
"@xyo-network/crypto-contract-function-read-payload-plugin": "~2.
|
|
18
|
-
"@xyo-network/crypto-nft-payload-plugin": "~2.
|
|
19
|
-
"@xyo-network/
|
|
20
|
-
"@xyo-network/
|
|
21
|
-
"@xyo-network/
|
|
22
|
-
"@xyo-network/
|
|
23
|
-
"@xyo-network/payloadset-plugin": "^2.83.2",
|
|
24
|
-
"@xyo-network/witness-model": "^2.83.2",
|
|
15
|
+
"@xyo-network/abstract-diviner": "^2.84.3",
|
|
16
|
+
"@xyo-network/abstract-witness": "^2.84.3",
|
|
17
|
+
"@xyo-network/crypto-contract-function-read-payload-plugin": "~2.84.1",
|
|
18
|
+
"@xyo-network/crypto-nft-payload-plugin": "~2.84.1",
|
|
19
|
+
"@xyo-network/module-model": "^2.84.3",
|
|
20
|
+
"@xyo-network/payload-model": "^2.84.3",
|
|
21
|
+
"@xyo-network/payloadset-plugin": "^2.84.3",
|
|
22
|
+
"@xyo-network/witness-model": "^2.84.3",
|
|
25
23
|
"ethers": "^6.9.0"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
26
|
"@xylabs/hex": "^2.13.20",
|
|
29
27
|
"@xylabs/jest-helpers": "^2.13.20",
|
|
30
|
-
"@xylabs/ts-scripts-yarn3": "^3.2.
|
|
31
|
-
"@xylabs/tsconfig": "^3.2.
|
|
32
|
-
"@xyo-network/account": "^2.
|
|
33
|
-
"@xyo-network/
|
|
28
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.19",
|
|
29
|
+
"@xylabs/tsconfig": "^3.2.19",
|
|
30
|
+
"@xyo-network/account": "^2.84.3",
|
|
31
|
+
"@xyo-network/diviner-boundwitness-memory": "^2.84.3",
|
|
32
|
+
"@xyo-network/diviner-jsonpatch": "^2.84.3",
|
|
33
|
+
"@xyo-network/diviner-model": "^2.84.3",
|
|
34
|
+
"@xyo-network/diviner-payload-memory": "^2.84.3",
|
|
35
|
+
"@xyo-network/diviner-payload-model": "^2.84.3",
|
|
36
|
+
"@xyo-network/diviner-temporal-indexing": "^2.84.3",
|
|
37
|
+
"@xyo-network/manifest": "^2.84.3",
|
|
38
|
+
"@xyo-network/memory-archivist": "^2.84.3",
|
|
39
|
+
"@xyo-network/node-memory": "^2.84.3",
|
|
34
40
|
"@xyo-network/open-zeppelin-typechain": "^3.0.5",
|
|
35
|
-
"@xyo-network/sentinel-model": "^2.
|
|
36
|
-
"@xyo-network/witness-blockchain-abstract": "^2.
|
|
41
|
+
"@xyo-network/sentinel-model": "^2.84.3",
|
|
42
|
+
"@xyo-network/witness-blockchain-abstract": "^2.84.3",
|
|
43
|
+
"@xyo-network/witness-timestamp": "^2.84.3",
|
|
37
44
|
"async-mutex": "^0.4.0",
|
|
38
45
|
"jest": "^29.7.0",
|
|
39
46
|
"typescript": "^5.3.3"
|
|
40
47
|
},
|
|
41
48
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
42
|
-
"docs": "dist/docs.json",
|
|
43
49
|
"types": "dist/node/index.d.ts",
|
|
44
50
|
"exports": {
|
|
45
51
|
".": {
|
|
@@ -55,19 +61,19 @@
|
|
|
55
61
|
},
|
|
56
62
|
"node": {
|
|
57
63
|
"require": {
|
|
58
|
-
"types": "./dist/node/index.d.
|
|
59
|
-
"default": "./dist/node/index.
|
|
64
|
+
"types": "./dist/node/index.d.cts",
|
|
65
|
+
"default": "./dist/node/index.cjs"
|
|
60
66
|
},
|
|
61
67
|
"import": {
|
|
62
68
|
"types": "./dist/node/index.d.mts",
|
|
63
|
-
"default": "./dist/node/index.
|
|
69
|
+
"default": "./dist/node/index.js"
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
},
|
|
67
73
|
"./package.json": "./package.json"
|
|
68
74
|
},
|
|
69
|
-
"main": "dist/node/index.
|
|
70
|
-
"module": "dist/node/index.
|
|
75
|
+
"main": "dist/node/index.cjs",
|
|
76
|
+
"module": "dist/node/index.js",
|
|
71
77
|
"homepage": "https://xyo.network",
|
|
72
78
|
"license": "LGPL-3.0-only",
|
|
73
79
|
"publishConfig": {
|
|
@@ -78,5 +84,6 @@
|
|
|
78
84
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
79
85
|
},
|
|
80
86
|
"sideEffects": false,
|
|
81
|
-
"version": "2.
|
|
87
|
+
"version": "2.84.1",
|
|
88
|
+
"type": "module"
|
|
82
89
|
}
|
|
@@ -3,36 +3,21 @@ import { Promisable } from '@xylabs/promise'
|
|
|
3
3
|
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
4
4
|
import {
|
|
5
5
|
asCryptoContractFunctionCallSuccess,
|
|
6
|
+
ContractInfo,
|
|
7
|
+
ContractInfoSchema,
|
|
8
|
+
CryptoContractDivinerConfigSchema,
|
|
9
|
+
CryptoContractDivinerLabels,
|
|
10
|
+
CryptoContractDivinerParams,
|
|
6
11
|
CryptoContractFunctionCallResult,
|
|
7
12
|
CryptoContractFunctionCallResultSchema,
|
|
8
13
|
} from '@xyo-network/crypto-contract-function-read-payload-plugin'
|
|
9
|
-
import { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'
|
|
10
14
|
import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'
|
|
11
15
|
|
|
12
16
|
export type FindCallResult<TResult = string, TPayload = Payload> = [TResult, TPayload] | [undefined, TPayload] | [undefined, undefined]
|
|
13
17
|
|
|
14
|
-
export const CryptoContractDivinerConfigSchema = 'network.xyo.crypto.contract.diviner.config'
|
|
15
|
-
export type CryptoContractDivinerConfigSchema = typeof CryptoContractDivinerConfigSchema
|
|
16
|
-
|
|
17
|
-
export type CryptoContractDivinerConfig = DivinerConfig<{
|
|
18
|
-
schema: CryptoContractDivinerConfigSchema
|
|
19
|
-
}>
|
|
20
|
-
export type CryptoContractDivinerParams = DivinerParams<CryptoContractDivinerConfig>
|
|
21
|
-
|
|
22
|
-
export const ContractInfoSchema = 'network.xyo.crypto.contract.info'
|
|
23
|
-
export type ContractInfoSchema = typeof ContractInfoSchema
|
|
24
|
-
|
|
25
|
-
export type ContractInfo = Payload<
|
|
26
|
-
{
|
|
27
|
-
address: string
|
|
28
|
-
chainId: string
|
|
29
|
-
results?: Record<string, unknown>
|
|
30
|
-
},
|
|
31
|
-
ContractInfoSchema
|
|
32
|
-
>
|
|
33
|
-
|
|
34
18
|
export class CryptoContractDiviner<TParams extends CryptoContractDivinerParams = CryptoContractDivinerParams> extends AbstractDiviner<TParams> {
|
|
35
19
|
static override configSchemas = [CryptoContractDivinerConfigSchema]
|
|
20
|
+
static labels: CryptoContractDivinerLabels = CryptoContractDivinerLabels
|
|
36
21
|
|
|
37
22
|
protected static findCallResult<TResult = string>(
|
|
38
23
|
address: string,
|
package/src/Diviner/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './Diviner'
|