@xyo-network/crypto-contract-function-read-plugin 2.77.20 → 2.78.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.
Files changed (48) hide show
  1. package/dist/browser/CryptoContractDiviner.d.cts +3 -4
  2. package/dist/browser/CryptoContractDiviner.d.cts.map +1 -1
  3. package/dist/browser/CryptoContractDiviner.d.mts +3 -4
  4. package/dist/browser/CryptoContractDiviner.d.mts.map +1 -1
  5. package/dist/browser/CryptoContractDiviner.d.ts +3 -4
  6. package/dist/browser/CryptoContractDiviner.d.ts.map +1 -1
  7. package/dist/browser/Plugin.d.cts +33 -3
  8. package/dist/browser/Plugin.d.cts.map +1 -1
  9. package/dist/browser/Plugin.d.mts +33 -3
  10. package/dist/browser/Plugin.d.mts.map +1 -1
  11. package/dist/browser/Plugin.d.ts +33 -3
  12. package/dist/browser/Plugin.d.ts.map +1 -1
  13. package/dist/browser/Witness.d.cts +5 -5
  14. package/dist/browser/Witness.d.cts.map +1 -1
  15. package/dist/browser/Witness.d.mts +5 -5
  16. package/dist/browser/Witness.d.mts.map +1 -1
  17. package/dist/browser/Witness.d.ts +5 -5
  18. package/dist/browser/Witness.d.ts.map +1 -1
  19. package/dist/browser/index.cjs +40 -38
  20. package/dist/browser/index.cjs.map +1 -1
  21. package/dist/browser/index.js +42 -40
  22. package/dist/browser/index.js.map +1 -1
  23. package/dist/node/CryptoContractDiviner.d.cts +3 -4
  24. package/dist/node/CryptoContractDiviner.d.cts.map +1 -1
  25. package/dist/node/CryptoContractDiviner.d.mts +3 -4
  26. package/dist/node/CryptoContractDiviner.d.mts.map +1 -1
  27. package/dist/node/CryptoContractDiviner.d.ts +3 -4
  28. package/dist/node/CryptoContractDiviner.d.ts.map +1 -1
  29. package/dist/node/Plugin.d.cts +33 -3
  30. package/dist/node/Plugin.d.cts.map +1 -1
  31. package/dist/node/Plugin.d.mts +33 -3
  32. package/dist/node/Plugin.d.mts.map +1 -1
  33. package/dist/node/Plugin.d.ts +33 -3
  34. package/dist/node/Plugin.d.ts.map +1 -1
  35. package/dist/node/Witness.d.cts +5 -5
  36. package/dist/node/Witness.d.cts.map +1 -1
  37. package/dist/node/Witness.d.mts +5 -5
  38. package/dist/node/Witness.d.mts.map +1 -1
  39. package/dist/node/Witness.d.ts +5 -5
  40. package/dist/node/Witness.d.ts.map +1 -1
  41. package/dist/node/index.js +42 -38
  42. package/dist/node/index.js.map +1 -1
  43. package/dist/node/index.mjs +44 -40
  44. package/dist/node/index.mjs.map +1 -1
  45. package/package.json +14 -14
  46. package/src/CryptoContractDiviner.ts +8 -23
  47. package/src/Erc721Sentinel.json +12 -63
  48. package/src/Witness.ts +44 -33
@@ -3,7 +3,6 @@
3
3
  "nodes": [
4
4
  {
5
5
  "config": {
6
- "accountPath": "m/44'/60'/1'/0'/0'",
7
6
  "name": "NftInfo",
8
7
  "schema": "network.xyo.node.config"
9
8
  },
@@ -11,11 +10,8 @@
11
10
  "public": [
12
11
  {
13
12
  "config": {
14
- "accountPath": "m/44'/60'/1'/1'/0'",
15
- "call": {
16
- "functionName": "name",
17
- "params": []
18
- },
13
+ "functionName": "name",
14
+ "params": [],
19
15
  "labels": {
20
16
  "network.xyo.crypto.contract.interface": "Erc721"
21
17
  },
@@ -26,11 +22,8 @@
26
22
  },
27
23
  {
28
24
  "config": {
29
- "accountPath": "m/44'/60'/1'/1'/1'",
30
- "call": {
31
- "functionName": "symbol",
32
- "params": []
33
- },
25
+ "functionName": "symbol",
26
+ "params": [],
34
27
  "labels": {
35
28
  "network.xyo.crypto.contract.interface": "Erc721"
36
29
  },
@@ -41,10 +34,7 @@
41
34
  },
42
35
  {
43
36
  "config": {
44
- "accountPath": "m/44'/60'/1'/1'/2'",
45
- "call": {
46
- "functionName": "tokenURI"
47
- },
37
+ "functionName": "tokenURI",
48
38
  "labels": {
49
39
  "network.xyo.crypto.contract.interface": "Erc721"
50
40
  },
@@ -55,10 +45,7 @@
55
45
  },
56
46
  {
57
47
  "config": {
58
- "accountPath": "m/44'/60'/1'/1'/3'",
59
- "call": {
60
- "functionName": "ownerOf"
61
- },
48
+ "functionName": "ownerOf",
62
49
  "labels": {
63
50
  "network.xyo.crypto.contract.interface": "Erc721"
64
51
  },
@@ -69,11 +56,8 @@
69
56
  },
70
57
  {
71
58
  "config": {
72
- "accountPath": "m/44'/60'/1'/1'/4'",
73
- "call": {
74
- "functionName": "totalSupply",
75
- "params": []
76
- },
59
+ "functionName": "totalSupply",
60
+ "params": [],
77
61
  "labels": {
78
62
  "network.xyo.crypto.contract.interface": "Erc721Enumerable"
79
63
  },
@@ -84,10 +68,7 @@
84
68
  },
85
69
  {
86
70
  "config": {
87
- "accountPath": "m/44'/60'/1'/1'/5'",
88
- "call": {
89
- "functionName": "tokenByIndex"
90
- },
71
+ "functionName": "tokenByIndex",
91
72
  "labels": {
92
73
  "network.xyo.crypto.contract.interface": "Erc721Enumerable"
93
74
  },
@@ -98,11 +79,8 @@
98
79
  },
99
80
  {
100
81
  "config": {
101
- "accountPath": "m/44'/60'/1'/1'/8'",
102
- "call": {
103
- "functionName": "uri",
104
- "params": []
105
- },
82
+ "functionName": "uri",
83
+ "params": [],
106
84
  "labels": {
107
85
  "network.xyo.crypto.contract.interface": "Erc1155"
108
86
  },
@@ -113,7 +91,6 @@
113
91
  },
114
92
  {
115
93
  "config": {
116
- "accountPath": "m/44'/60'/1'/2'/0'",
117
94
  "language": "javascript",
118
95
  "name": "Erc721ContractInfoDiviner",
119
96
  "schema": "network.xyo.crypto.contract.diviner.config"
@@ -121,7 +98,6 @@
121
98
  },
122
99
  {
123
100
  "config": {
124
- "accountPath": "m/44'/60'/1'/2'/1'",
125
101
  "language": "javascript",
126
102
  "name": "Erc1155ContractInfoDiviner",
127
103
  "schema": "network.xyo.crypto.contract.diviner.config"
@@ -129,7 +105,6 @@
129
105
  },
130
106
  {
131
107
  "config": {
132
- "accountPath": "m/44'/60'/1'/3'/0'",
133
108
  "language": "javascript",
134
109
  "name": "NftInfoSentinel",
135
110
  "schema": "network.xyo.sentinel.config",
@@ -170,7 +145,6 @@
170
145
  },
171
146
  {
172
147
  "config": {
173
- "accountPath": "m/44'/60'/1'/3'/1'",
174
148
  "language": "javascript",
175
149
  "name": "NftTokenInfoSentinel",
176
150
  "schema": "network.xyo.sentinel.config",
@@ -178,32 +152,7 @@
178
152
  "tasks": [
179
153
  {
180
154
  "input": true,
181
- "module": "Erc721NameWitness"
182
- },
183
- {
184
- "input": true,
185
- "module": "Erc721SymbolWitness"
186
- },
187
- {
188
- "input": true,
189
- "module": "Erc721TotalSupplyWitness"
190
- },
191
- {
192
- "input": true,
193
- "module": "Erc1155UriWitness"
194
- },
195
- {
196
- "input": [
197
- "Erc721TokenURIWitness",
198
- "Erc721OwnerOfWitness"
199
- ],
200
- "module": "Erc721TokenContractInfoDiviner"
201
- },
202
- {
203
- "input": [
204
- "Erc1155UriWitness"
205
- ],
206
- "module": "Erc1155TokenContractInfoDiviner"
155
+ "module": "Erc721TokenByIndexWitness"
207
156
  }
208
157
  ]
209
158
  }
package/src/Witness.ts CHANGED
@@ -1,67 +1,78 @@
1
+ import { BigNumber } from '@ethersproject/bignumber'
2
+ import { Contract } from '@ethersproject/contracts'
3
+ import { JsonRpcProvider } from '@ethersproject/providers'
1
4
  import { assertEx } from '@xylabs/assert'
2
5
  import { AbstractWitness } from '@xyo-network/abstract-witness'
3
6
  import {
4
7
  CryptoContractFunctionCall,
8
+ CryptoContractFunctionCallFailure,
5
9
  CryptoContractFunctionCallResult,
6
10
  CryptoContractFunctionCallResultSchema,
7
11
  CryptoContractFunctionCallSchema,
12
+ CryptoContractFunctionCallSuccess,
8
13
  CryptoContractFunctionReadWitnessConfig,
9
14
  CryptoContractFunctionReadWitnessConfigSchema,
10
15
  } from '@xyo-network/crypto-contract-function-read-payload-plugin'
11
- import { PayloadHasher } from '@xyo-network/hash'
12
16
  import { AnyConfigSchema } from '@xyo-network/module-model'
13
17
  import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
14
18
  import { WitnessParams } from '@xyo-network/witness-model'
15
- import { BigNumber, Contract } from 'ethers'
16
19
 
17
- export type CryptoContractFunctionReadWitnessParams<TContract extends Contract> = WitnessParams<
20
+ export type CryptoContractFunctionReadWitnessParams = WitnessParams<
18
21
  AnyConfigSchema<CryptoContractFunctionReadWitnessConfig>,
19
22
  {
20
- factory: (address: string) => TContract
23
+ providers: JsonRpcProvider[]
21
24
  }
22
25
  >
23
26
 
24
27
  export class CryptoContractFunctionReadWitness<
25
- TContract extends Contract = Contract,
26
- TParams extends CryptoContractFunctionReadWitnessParams<TContract> = CryptoContractFunctionReadWitnessParams<TContract>,
27
- > extends AbstractWitness<TParams, CryptoContractFunctionCall<keyof TContract['callStatic']>, CryptoContractFunctionCallResult> {
28
+ TParams extends CryptoContractFunctionReadWitnessParams = CryptoContractFunctionReadWitnessParams,
29
+ > extends AbstractWitness<TParams, CryptoContractFunctionCall, CryptoContractFunctionCallResult> {
28
30
  static override configSchemas = [CryptoContractFunctionReadWitnessConfigSchema]
29
31
 
30
- protected override async observeHandler(
31
- inPayloads: CryptoContractFunctionCall<keyof TContract['callStatic']>[] = [],
32
- ): Promise<CryptoContractFunctionCallResult[]> {
32
+ protected override async observeHandler(inPayloads: CryptoContractFunctionCall[] = []): Promise<CryptoContractFunctionCallResult[]> {
33
33
  await this.started('throw')
34
34
  try {
35
35
  const observations = await Promise.all(
36
- inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async (callPayload) => {
37
- const fullCallPayload = { ...{ params: [] }, ...this.config.call, ...callPayload }
38
- const { address, functionName, params } = fullCallPayload
39
- const validatedAddress = assertEx(address, 'Missing address')
40
- const validatedFunctionName = assertEx(functionName, 'Missing functionName')
41
- const contract = this.params.factory(validatedAddress)
42
- const func = assertEx(contract.callStatic[validatedFunctionName], `functionName [${validatedFunctionName}] not found`)
43
- const rawResult = await func(...(params ?? []))
44
- const result: CryptoContractFunctionCallResult['result'] = BigNumber.isBigNumber(rawResult)
45
- ? { type: 'BigNumber', value: rawResult.toHexString() }
46
- : { value: rawResult }
47
- const observation: CryptoContractFunctionCallResult = {
48
- address: validatedAddress,
49
- call: await PayloadHasher.hashAsync(fullCallPayload),
50
- chainId: (await contract.provider.getNetwork()).chainId,
51
- functionName: validatedFunctionName,
52
- params,
53
- result,
54
- schema: CryptoContractFunctionCallResultSchema,
36
+ inPayloads.filter(isPayloadOfSchemaType(CryptoContractFunctionCallSchema)).map(async ({ functionName, args, address }) => {
37
+ const { providers } = this.params
38
+ const provider = providers[Date.now() % providers.length] //pick a random provider
39
+ const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')
40
+ const validatedFunctionName = assertEx(functionName ?? this.config.functionName, 'Missing address')
41
+ const mergedArgs = [...(args ?? this.config.args ?? [])]
42
+
43
+ const contract = new Contract(validatedAddress, this.config.contract, provider)
44
+ try {
45
+ const result = await contract.callStatic[validatedFunctionName](...mergedArgs)
46
+ const transformedResult = BigNumber.isBigNumber(result) ? result.toHexString() : result
47
+ const observation: CryptoContractFunctionCallSuccess = {
48
+ address: validatedAddress,
49
+ args: mergedArgs,
50
+ chainId: provider.network.chainId,
51
+ functionName: validatedFunctionName,
52
+ result: transformedResult,
53
+ schema: CryptoContractFunctionCallResultSchema,
54
+ }
55
+ return observation
56
+ } catch (ex) {
57
+ const error = ex as Error & { code: string }
58
+ console.log(`Error [${this.config.name}]: ${error.code}`)
59
+ const observation: CryptoContractFunctionCallFailure = {
60
+ address: validatedAddress,
61
+ args: mergedArgs,
62
+ chainId: provider.network.chainId,
63
+ error: error.code,
64
+ functionName: validatedFunctionName,
65
+ schema: CryptoContractFunctionCallResultSchema,
66
+ }
67
+ return observation
55
68
  }
56
- return observation
57
69
  }),
58
70
  )
59
- return observations.flat()
71
+ return observations
60
72
  } catch (ex) {
61
73
  const error = ex as Error
62
74
  console.log(`Error [${this.config.name}]: ${error.message}`)
75
+ throw error
63
76
  }
64
-
65
- return []
66
77
  }
67
78
  }