@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.
- package/dist/browser/CryptoContractDiviner.d.cts +3 -4
- package/dist/browser/CryptoContractDiviner.d.cts.map +1 -1
- package/dist/browser/CryptoContractDiviner.d.mts +3 -4
- package/dist/browser/CryptoContractDiviner.d.mts.map +1 -1
- package/dist/browser/CryptoContractDiviner.d.ts +3 -4
- package/dist/browser/CryptoContractDiviner.d.ts.map +1 -1
- package/dist/browser/Plugin.d.cts +33 -3
- package/dist/browser/Plugin.d.cts.map +1 -1
- package/dist/browser/Plugin.d.mts +33 -3
- package/dist/browser/Plugin.d.mts.map +1 -1
- package/dist/browser/Plugin.d.ts +33 -3
- package/dist/browser/Plugin.d.ts.map +1 -1
- package/dist/browser/Witness.d.cts +5 -5
- package/dist/browser/Witness.d.cts.map +1 -1
- package/dist/browser/Witness.d.mts +5 -5
- package/dist/browser/Witness.d.mts.map +1 -1
- package/dist/browser/Witness.d.ts +5 -5
- package/dist/browser/Witness.d.ts.map +1 -1
- package/dist/browser/index.cjs +40 -38
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +42 -40
- package/dist/browser/index.js.map +1 -1
- package/dist/node/CryptoContractDiviner.d.cts +3 -4
- package/dist/node/CryptoContractDiviner.d.cts.map +1 -1
- package/dist/node/CryptoContractDiviner.d.mts +3 -4
- package/dist/node/CryptoContractDiviner.d.mts.map +1 -1
- package/dist/node/CryptoContractDiviner.d.ts +3 -4
- package/dist/node/CryptoContractDiviner.d.ts.map +1 -1
- package/dist/node/Plugin.d.cts +33 -3
- package/dist/node/Plugin.d.cts.map +1 -1
- package/dist/node/Plugin.d.mts +33 -3
- package/dist/node/Plugin.d.mts.map +1 -1
- package/dist/node/Plugin.d.ts +33 -3
- package/dist/node/Plugin.d.ts.map +1 -1
- package/dist/node/Witness.d.cts +5 -5
- package/dist/node/Witness.d.cts.map +1 -1
- package/dist/node/Witness.d.mts +5 -5
- package/dist/node/Witness.d.mts.map +1 -1
- package/dist/node/Witness.d.ts +5 -5
- package/dist/node/Witness.d.ts.map +1 -1
- package/dist/node/index.js +42 -38
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +44 -40
- package/dist/node/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/CryptoContractDiviner.ts +8 -23
- package/src/Erc721Sentinel.json +12 -63
- package/src/Witness.ts +44 -33
package/src/Erc721Sentinel.json
CHANGED
|
@@ -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
|
-
"
|
|
15
|
-
"
|
|
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
|
-
"
|
|
30
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
73
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
102
|
-
"
|
|
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": "
|
|
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
|
|
20
|
+
export type CryptoContractFunctionReadWitnessParams = WitnessParams<
|
|
18
21
|
AnyConfigSchema<CryptoContractFunctionReadWitnessConfig>,
|
|
19
22
|
{
|
|
20
|
-
|
|
23
|
+
providers: JsonRpcProvider[]
|
|
21
24
|
}
|
|
22
25
|
>
|
|
23
26
|
|
|
24
27
|
export class CryptoContractFunctionReadWitness<
|
|
25
|
-
|
|
26
|
-
|
|
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 (
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const validatedAddress = assertEx(address, 'Missing address')
|
|
40
|
-
const validatedFunctionName = assertEx(functionName, 'Missing
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
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
|
}
|