@avaprotocol/sdk-js 2.3.17 → 2.4.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/CHANGELOG.md +30 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5267 -6205
- package/dist/index.mjs +5269 -6204
- package/dist/models/node/contractRead.d.ts.map +1 -1
- package/dist/models/node/contractRead.js +27 -17
- package/dist/models/node/contractWrite.d.ts.map +1 -1
- package/dist/models/node/contractWrite.js +12 -53
- package/dist/models/node/loop.d.ts.map +1 -1
- package/dist/models/node/loop.js +3 -0
- package/dist/models/step.d.ts.map +1 -1
- package/dist/models/step.js +103 -66
- package/dist/models/trigger/event.d.ts.map +1 -1
- package/dist/models/trigger/event.js +71 -7
- package/dist/models/trigger/factory.d.ts.map +1 -1
- package/dist/models/trigger/factory.js +7 -38
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +49 -23
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractRead.d.ts","sourceRoot":"","sources":["../../../src/models/node/contractRead.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"contractRead.d.ts","sourceRoot":"","sources":["../../../src/models/node/contractRead.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAGL,qBAAqB,EAEtB,MAAM,oBAAoB,CAAC;AAS5B,cAAM,gBAAiB,SAAQ,IAAI;gBACrB,KAAK,EAAE,qBAAqB;IAIxC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,gBAAgB;IAgC3D,SAAS,IAAI,MAAM,CAAC,QAAQ;IAgD5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,qBAAqB,GAAG,GAAG;CAyBrE;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Node from "./interface";
|
|
2
2
|
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
3
|
-
import { NodeType } from "@avaprotocol/types";
|
|
4
|
-
import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
|
|
3
|
+
import { NodeType, } from "@avaprotocol/types";
|
|
4
|
+
import { convertProtobufValueToJs, convertInputToProtobuf, extractInputFromProtobuf, } from "../../utils";
|
|
5
5
|
// Required props for constructor: id, name, type and data
|
|
6
6
|
class ContractReadNode extends Node {
|
|
7
7
|
constructor(props) {
|
|
@@ -15,9 +15,10 @@ class ContractReadNode extends Node {
|
|
|
15
15
|
const data = {
|
|
16
16
|
contractAddress: protobufData.contractAddress,
|
|
17
17
|
contractAbi: protobufData.contractAbi,
|
|
18
|
-
methodCalls: protobufData.methodCallsList?.map(call => ({
|
|
18
|
+
methodCalls: protobufData.methodCallsList?.map((call) => ({
|
|
19
19
|
callData: call.callData,
|
|
20
20
|
methodName: call.methodName,
|
|
21
|
+
applyToFields: call.applyToFieldsList || [],
|
|
21
22
|
})) || [],
|
|
22
23
|
};
|
|
23
24
|
// Extract input data from top-level TaskNode.input field (not nested ContractReadNode.input)
|
|
@@ -49,6 +50,9 @@ class ContractReadNode extends Node {
|
|
|
49
50
|
if (methodCall.methodName) {
|
|
50
51
|
methodCallMsg.setMethodName(methodCall.methodName);
|
|
51
52
|
}
|
|
53
|
+
if (methodCall.applyToFields) {
|
|
54
|
+
methodCallMsg.setApplyToFieldsList(methodCall.applyToFields);
|
|
55
|
+
}
|
|
52
56
|
config.addMethodCalls(methodCallMsg);
|
|
53
57
|
});
|
|
54
58
|
node.setConfig(config);
|
|
@@ -63,20 +67,26 @@ class ContractReadNode extends Node {
|
|
|
63
67
|
}
|
|
64
68
|
static fromOutputData(outputData) {
|
|
65
69
|
const contractReadOutput = outputData.getContractRead();
|
|
66
|
-
if (contractReadOutput && contractReadOutput.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
if (contractReadOutput && contractReadOutput.getData()) {
|
|
71
|
+
// The new structure uses getData() which returns a protobuf Value
|
|
72
|
+
const data = contractReadOutput.getData();
|
|
73
|
+
if (data) {
|
|
74
|
+
// Convert protobuf Value to JavaScript object
|
|
75
|
+
const jsData = convertProtobufValueToJs(data);
|
|
76
|
+
// The data should now be directly an array of results
|
|
77
|
+
if (Array.isArray(jsData)) {
|
|
78
|
+
return jsData.map((result) => ({
|
|
79
|
+
methodName: result.methodName,
|
|
80
|
+
success: result.success,
|
|
81
|
+
error: result.error || "",
|
|
82
|
+
data: result.data || {},
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Fallback for old format or unexpected structure
|
|
87
|
+
return jsData;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
80
90
|
}
|
|
81
91
|
return null;
|
|
82
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractWrite.d.ts","sourceRoot":"","sources":["../../../src/models/node/contractWrite.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"contractWrite.d.ts","sourceRoot":"","sources":["../../../src/models/node/contractWrite.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAGL,sBAAsB,EAEvB,MAAM,oBAAoB,CAAC;AAM5B,cAAM,iBAAkB,SAAQ,IAAI;gBACtB,KAAK,EAAE,sBAAsB;IAIzC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,iBAAiB;IAgC5D,SAAS,IAAI,MAAM,CAAC,QAAQ;IA0C5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,qBAAqB,GAAG,GAAG;CAcrE;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Node from "./interface";
|
|
2
2
|
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
3
|
-
import { NodeType } from "@avaprotocol/types";
|
|
3
|
+
import { NodeType, } from "@avaprotocol/types";
|
|
4
4
|
import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
|
|
5
|
+
import { convertProtobufValueToJs } from "../../utils";
|
|
5
6
|
// Required props for constructor: id, name, type and data: { config: { contractAddress, callData, contractAbi, methodCallsList? } }
|
|
6
7
|
class ContractWriteNode extends Node {
|
|
7
8
|
constructor(props) {
|
|
@@ -16,7 +17,7 @@ class ContractWriteNode extends Node {
|
|
|
16
17
|
contractAddress: protobufData.contractAddress,
|
|
17
18
|
callData: protobufData.callData,
|
|
18
19
|
contractAbi: protobufData.contractAbi,
|
|
19
|
-
methodCalls: protobufData.methodCallsList?.map(call => ({
|
|
20
|
+
methodCalls: protobufData.methodCallsList?.map((call) => ({
|
|
20
21
|
callData: call.callData,
|
|
21
22
|
methodName: call.methodName,
|
|
22
23
|
})) || [],
|
|
@@ -43,7 +44,7 @@ class ContractWriteNode extends Node {
|
|
|
43
44
|
config.setContractAddress(this.data.contractAddress);
|
|
44
45
|
config.setCallData(this.data.callData);
|
|
45
46
|
config.setContractAbi(this.data.contractAbi);
|
|
46
|
-
// Handle method calls array
|
|
47
|
+
// Handle method calls array
|
|
47
48
|
const methodCalls = this.data.methodCalls || [];
|
|
48
49
|
methodCalls.forEach((methodCall) => {
|
|
49
50
|
const methodCallMsg = new avs_pb.ContractWriteNode.MethodCall();
|
|
@@ -67,56 +68,14 @@ class ContractWriteNode extends Node {
|
|
|
67
68
|
const contractWriteOutput = outputData.getContractWrite();
|
|
68
69
|
if (!contractWriteOutput)
|
|
69
70
|
return null;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
blockNumber: result.transaction.blockNumber,
|
|
79
|
-
blockHash: result.transaction.blockHash,
|
|
80
|
-
gasUsed: result.transaction.gasUsed,
|
|
81
|
-
gasLimit: result.transaction.gasLimit,
|
|
82
|
-
gasPrice: result.transaction.gasPrice,
|
|
83
|
-
effectiveGasPrice: result.transaction.effectiveGasPrice,
|
|
84
|
-
from: result.transaction.from,
|
|
85
|
-
to: result.transaction.to,
|
|
86
|
-
value: result.transaction.value,
|
|
87
|
-
nonce: result.transaction.nonce,
|
|
88
|
-
transactionIndex: result.transaction.transactionIndex,
|
|
89
|
-
confirmations: result.transaction.confirmations,
|
|
90
|
-
timestamp: result.transaction.timestamp,
|
|
91
|
-
} : null,
|
|
92
|
-
events: result.eventsList?.map((event) => ({
|
|
93
|
-
eventName: event.eventName,
|
|
94
|
-
address: event.address,
|
|
95
|
-
topics: event.topicsList || [],
|
|
96
|
-
data: event.data,
|
|
97
|
-
decoded: event.decodedMap || {},
|
|
98
|
-
})) || [],
|
|
99
|
-
error: result.error ? {
|
|
100
|
-
code: result.error.code,
|
|
101
|
-
message: result.error.message,
|
|
102
|
-
revertReason: result.error.revertReason,
|
|
103
|
-
} : null,
|
|
104
|
-
returnData: result.returnData ? {
|
|
105
|
-
name: result.returnData.name,
|
|
106
|
-
type: result.returnData.type,
|
|
107
|
-
value: result.returnData.value,
|
|
108
|
-
} : null,
|
|
109
|
-
inputData: result.inputData,
|
|
110
|
-
})) || [];
|
|
111
|
-
return {
|
|
112
|
-
results: transformedResults,
|
|
113
|
-
// For backward compatibility, provide legacy fields from first result
|
|
114
|
-
...(transformedResults.length > 0 && {
|
|
115
|
-
transaction: transformedResults[0].transaction,
|
|
116
|
-
success: transformedResults[0].success,
|
|
117
|
-
hash: transformedResults[0].transaction?.hash,
|
|
118
|
-
}),
|
|
119
|
-
};
|
|
71
|
+
// Use the new getData() method instead of the old resultsList
|
|
72
|
+
const data = contractWriteOutput.getData();
|
|
73
|
+
if (!data)
|
|
74
|
+
return null;
|
|
75
|
+
// Convert protobuf Value to JavaScript object
|
|
76
|
+
const jsData = convertProtobufValueToJs(data);
|
|
77
|
+
// Return the array directly, matching ContractRead format
|
|
78
|
+
return Array.isArray(jsData) ? jsData : [jsData];
|
|
120
79
|
}
|
|
121
80
|
}
|
|
122
81
|
export default ContractWriteNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../../src/models/node/loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EAGL,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAI5B,cAAM,QAAS,SAAQ,IAAI;gBACb,KAAK,EAAE,aAAa;IAIhC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ;IAuCnD,SAAS,IAAI,MAAM,CAAC,QAAQ;
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../../src/models/node/loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EAGL,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAI5B,cAAM,QAAS,SAAQ,IAAI;gBACb,KAAK,EAAE,aAAa;IAIhC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ;IAuCnD,SAAS,IAAI,MAAM,CAAC,QAAQ;IAiJ5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,qBAAqB,GAAG,GAAG;CAuCrE;AAED,eAAe,QAAQ,CAAC"}
|
package/dist/models/node/loop.js
CHANGED
|
@@ -104,6 +104,9 @@ class LoopNode extends Node {
|
|
|
104
104
|
if (methodCall.methodName) {
|
|
105
105
|
methodCallMsg.setMethodName(methodCall.methodName);
|
|
106
106
|
}
|
|
107
|
+
if (methodCall.applyToFields) {
|
|
108
|
+
methodCallMsg.setApplyToFieldsList(methodCall.applyToFields);
|
|
109
|
+
}
|
|
107
110
|
config.addMethodCalls(methodCallMsg);
|
|
108
111
|
});
|
|
109
112
|
contractRead.setConfig(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/models/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAMhD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE,cAAM,IAAK,YAAW,SAAS;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;gBAEF,KAAK,EAAE,SAAS;IAc5B;;;OAGG;IACH,MAAM,IAAI,SAAS;IAgBnB,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,eAAe;
|
|
1
|
+
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/models/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAMhD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE,cAAM,IAAK,YAAW,SAAS;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;gBAEF,KAAK,EAAE,SAAS;IAc5B;;;OAGG;IACH,MAAM,IAAI,SAAS;IAgBnB,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,eAAe;IAiX9D,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI;CAqFvD;AAED,eAAe,IAAI,CAAC"}
|
package/dist/models/step.js
CHANGED
|
@@ -92,6 +92,24 @@ class Step {
|
|
|
92
92
|
? step.getEventTrigger()
|
|
93
93
|
: step.eventTrigger;
|
|
94
94
|
if (eventTrigger) {
|
|
95
|
+
// Check for the new data field structure
|
|
96
|
+
if (typeof eventTrigger.hasData === "function" &&
|
|
97
|
+
eventTrigger.hasData()) {
|
|
98
|
+
try {
|
|
99
|
+
return convertProtobufValueToJs(eventTrigger.getData());
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.warn("Failed to convert event trigger data from protobuf Value:", error);
|
|
103
|
+
return eventTrigger.getData();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (eventTrigger.data) {
|
|
107
|
+
// For plain objects, try to convert or use directly
|
|
108
|
+
return typeof eventTrigger.data.getKindCase === "function"
|
|
109
|
+
? convertProtobufValueToJs(eventTrigger.data)
|
|
110
|
+
: eventTrigger.data;
|
|
111
|
+
}
|
|
112
|
+
// Fallback to old structure for backward compatibility
|
|
95
113
|
if (typeof eventTrigger.hasEvmLog === "function" &&
|
|
96
114
|
eventTrigger.hasEvmLog()) {
|
|
97
115
|
return eventTrigger.getEvmLog()?.toObject();
|
|
@@ -214,23 +232,54 @@ class Step {
|
|
|
214
232
|
? step.getContractRead()
|
|
215
233
|
: step.contractRead;
|
|
216
234
|
if (contractReadOutput) {
|
|
217
|
-
//
|
|
235
|
+
// Check if the output has a data field that's a protobuf Value
|
|
236
|
+
if (typeof contractReadOutput.hasData === "function" &&
|
|
237
|
+
contractReadOutput.hasData()) {
|
|
238
|
+
try {
|
|
239
|
+
// Convert protobuf Value to JavaScript object
|
|
240
|
+
const data = convertProtobufValueToJs(contractReadOutput.getData());
|
|
241
|
+
// Always return the array directly for contract read outputs
|
|
242
|
+
if (Array.isArray(data)) {
|
|
243
|
+
return data;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// If it's a single object, wrap it in an array for consistency
|
|
247
|
+
return [data];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.warn("Failed to convert contract read data from protobuf Value:", error);
|
|
252
|
+
// Fallback to raw data
|
|
253
|
+
return contractReadOutput.getData();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (contractReadOutput.data) {
|
|
257
|
+
// For plain objects, try to convert or use directly
|
|
258
|
+
const data = typeof contractReadOutput.data.getKindCase === "function"
|
|
259
|
+
? convertProtobufValueToJs(contractReadOutput.data)
|
|
260
|
+
: contractReadOutput.data;
|
|
261
|
+
// Always return the array directly for contract read outputs
|
|
262
|
+
if (Array.isArray(data)) {
|
|
263
|
+
return data;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// If it's a single object, wrap it in an array for consistency
|
|
267
|
+
return [data];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Fallback to old structure for backward compatibility
|
|
218
271
|
const outputObj = typeof contractReadOutput.toObject === "function"
|
|
219
272
|
? contractReadOutput.toObject()
|
|
220
273
|
: contractReadOutput;
|
|
221
274
|
// Convert resultsList to results for consistency with ContractReadNode.fromOutputData
|
|
222
275
|
if (outputObj && outputObj.resultsList) {
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
error: result.error,
|
|
231
|
-
data: result.dataList || [],
|
|
232
|
-
})),
|
|
233
|
-
};
|
|
276
|
+
// Return the results array directly
|
|
277
|
+
return outputObj.resultsList.map((result) => ({
|
|
278
|
+
methodName: result.methodName,
|
|
279
|
+
success: result.success,
|
|
280
|
+
error: result.error,
|
|
281
|
+
data: result.dataList || [],
|
|
282
|
+
}));
|
|
234
283
|
}
|
|
235
284
|
return outputObj;
|
|
236
285
|
}
|
|
@@ -240,69 +289,57 @@ class Step {
|
|
|
240
289
|
? step.getContractWrite()
|
|
241
290
|
: step.contractWrite;
|
|
242
291
|
if (contractWriteOutput) {
|
|
243
|
-
//
|
|
292
|
+
// Check if the output has a data field that's a protobuf Value
|
|
293
|
+
if (typeof contractWriteOutput.hasData === "function" &&
|
|
294
|
+
contractWriteOutput.hasData()) {
|
|
295
|
+
try {
|
|
296
|
+
// Convert protobuf Value to JavaScript object
|
|
297
|
+
const data = convertProtobufValueToJs(contractWriteOutput.getData());
|
|
298
|
+
// Always return the array directly for contract write outputs
|
|
299
|
+
if (Array.isArray(data)) {
|
|
300
|
+
return data;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
// If it's a single object, wrap it in an array for consistency
|
|
304
|
+
return [data];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.warn("Failed to convert contract write data from protobuf Value:", error);
|
|
309
|
+
// Fallback to raw data
|
|
310
|
+
return contractWriteOutput.getData();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (contractWriteOutput.data) {
|
|
314
|
+
// For plain objects, try to convert or use directly
|
|
315
|
+
const data = typeof contractWriteOutput.data.getKindCase === "function"
|
|
316
|
+
? convertProtobufValueToJs(contractWriteOutput.data)
|
|
317
|
+
: contractWriteOutput.data;
|
|
318
|
+
// Always return the array directly for contract write outputs
|
|
319
|
+
if (Array.isArray(data)) {
|
|
320
|
+
return data;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// If it's a single object, wrap it in an array for consistency
|
|
324
|
+
return [data];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// Fallback to old structure for backward compatibility
|
|
244
328
|
const outputObj = typeof contractWriteOutput.toObject === "function"
|
|
245
329
|
? contractWriteOutput.toObject()
|
|
246
330
|
: contractWriteOutput;
|
|
247
331
|
// Convert resultsList to results for consistency with ContractWriteNode.fromOutputData
|
|
248
332
|
if (outputObj && outputObj.resultsList) {
|
|
249
|
-
|
|
333
|
+
// Return the results array directly
|
|
334
|
+
return outputObj.resultsList.map((result) => ({
|
|
250
335
|
methodName: result.methodName,
|
|
251
336
|
success: result.success,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
blockNumber: result.transaction.blockNumber,
|
|
257
|
-
blockHash: result.transaction.blockHash,
|
|
258
|
-
gasUsed: result.transaction.gasUsed,
|
|
259
|
-
gasLimit: result.transaction.gasLimit,
|
|
260
|
-
gasPrice: result.transaction.gasPrice,
|
|
261
|
-
effectiveGasPrice: result.transaction.effectiveGasPrice,
|
|
262
|
-
from: result.transaction.from,
|
|
263
|
-
to: result.transaction.to,
|
|
264
|
-
value: result.transaction.value,
|
|
265
|
-
nonce: result.transaction.nonce,
|
|
266
|
-
transactionIndex: result.transaction.transactionIndex,
|
|
267
|
-
confirmations: result.transaction.confirmations,
|
|
268
|
-
timestamp: result.transaction.timestamp,
|
|
269
|
-
}
|
|
270
|
-
: null,
|
|
271
|
-
events: result.eventsList?.map((event) => ({
|
|
272
|
-
eventName: event.eventName,
|
|
273
|
-
address: event.address,
|
|
274
|
-
topics: event.topicsList || [],
|
|
275
|
-
data: event.data,
|
|
276
|
-
decoded: event.decodedMap || {},
|
|
277
|
-
})) || [],
|
|
278
|
-
error: result.error
|
|
279
|
-
? {
|
|
280
|
-
code: result.error.code,
|
|
281
|
-
message: result.error.message,
|
|
282
|
-
revertReason: result.error.revertReason,
|
|
283
|
-
}
|
|
284
|
-
: null,
|
|
285
|
-
returnData: result.returnData
|
|
286
|
-
? {
|
|
287
|
-
name: result.returnData.name,
|
|
288
|
-
type: result.returnData.type,
|
|
289
|
-
value: result.returnData.value,
|
|
290
|
-
}
|
|
291
|
-
: null,
|
|
337
|
+
error: result.error,
|
|
338
|
+
transaction: result.transaction,
|
|
339
|
+
events: result.eventsList || [],
|
|
340
|
+
returnData: result.returnData,
|
|
292
341
|
inputData: result.inputData,
|
|
293
342
|
}));
|
|
294
|
-
// Exclude resultsList from the spread to avoid duplication
|
|
295
|
-
const { resultsList, ...cleanOutputObj } = outputObj;
|
|
296
|
-
return {
|
|
297
|
-
...cleanOutputObj,
|
|
298
|
-
results: transformedResults,
|
|
299
|
-
// For backward compatibility, provide legacy fields from first result
|
|
300
|
-
...(transformedResults.length > 0 && {
|
|
301
|
-
transaction: transformedResults[0].transaction,
|
|
302
|
-
success: transformedResults[0].success,
|
|
303
|
-
hash: transformedResults[0].transaction?.hash,
|
|
304
|
-
}),
|
|
305
|
-
};
|
|
306
343
|
}
|
|
307
344
|
return outputObj;
|
|
308
345
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAGL,kBAAkB,EAClB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAGL,kBAAkB,EAClB,iBAAiB,EAIlB,MAAM,oBAAoB,CAAC;AAkD5B,cAAM,YAAa,SAAQ,OAAO;gBACpB,KAAK,EAAE,iBAAiB;IAIpC,SAAS,IAAI,MAAM,CAAC,WAAW;IAwG/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,YAAY;IAwF1D;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,GAAG,SAAS;IAI3C;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG;CA0B9D;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
2
2
|
import Trigger from "./interface";
|
|
3
3
|
import { TriggerType, } from "@avaprotocol/types";
|
|
4
|
-
import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
|
|
4
|
+
import { convertInputToProtobuf, extractInputFromProtobuf, convertProtobufValueToJs, } from "../../utils";
|
|
5
5
|
// Ref: https://github.com/AvaProtocol/EigenLayer-AVS/issues/94
|
|
6
6
|
// The trigger is an array of Condition, which can be topics, dateRage, etc.
|
|
7
7
|
// We imply or operator among all conditions.
|
|
@@ -85,6 +85,36 @@ class EventTrigger extends Trigger {
|
|
|
85
85
|
if (queryData.maxEventsPerBlock !== undefined) {
|
|
86
86
|
query.setMaxEventsPerBlock(queryData.maxEventsPerBlock);
|
|
87
87
|
}
|
|
88
|
+
// Set contractAbi if provided
|
|
89
|
+
if (queryData.contractAbi) {
|
|
90
|
+
query.setContractAbi(queryData.contractAbi);
|
|
91
|
+
}
|
|
92
|
+
// Set conditions if provided
|
|
93
|
+
if (queryData.conditions && queryData.conditions.length > 0) {
|
|
94
|
+
const conditionMessages = queryData.conditions.map((conditionData) => {
|
|
95
|
+
const condition = new avs_pb.EventCondition();
|
|
96
|
+
condition.setFieldName(conditionData.fieldName);
|
|
97
|
+
condition.setOperator(conditionData.operator);
|
|
98
|
+
condition.setValue(conditionData.value);
|
|
99
|
+
condition.setFieldType(conditionData.fieldType);
|
|
100
|
+
return condition;
|
|
101
|
+
});
|
|
102
|
+
query.setConditionsList(conditionMessages);
|
|
103
|
+
}
|
|
104
|
+
// Set method calls if provided
|
|
105
|
+
if (queryData.methodCalls && queryData.methodCalls.length > 0) {
|
|
106
|
+
const methodCallMessages = queryData.methodCalls.map((methodCallData) => {
|
|
107
|
+
const methodCall = new avs_pb.EventTrigger.MethodCall();
|
|
108
|
+
methodCall.setMethodName(methodCallData.methodName);
|
|
109
|
+
methodCall.setCallData(methodCallData.callData);
|
|
110
|
+
if (methodCallData.applyToFields &&
|
|
111
|
+
methodCallData.applyToFields.length > 0) {
|
|
112
|
+
methodCall.setApplyToFieldsList(methodCallData.applyToFields);
|
|
113
|
+
}
|
|
114
|
+
return methodCall;
|
|
115
|
+
});
|
|
116
|
+
query.setMethodCallsList(methodCallMessages);
|
|
117
|
+
}
|
|
88
118
|
return query;
|
|
89
119
|
});
|
|
90
120
|
config.setQueriesList(queryMessages);
|
|
@@ -122,7 +152,7 @@ class EventTrigger extends Trigger {
|
|
|
122
152
|
// Don't convert empty strings back to null - preserve the original values
|
|
123
153
|
// The backend may legitimately use empty strings, and we shouldn't assume
|
|
124
154
|
// they were originally null values from the client
|
|
125
|
-
values: topics.getValuesList() || []
|
|
155
|
+
values: topics.getValuesList() || [],
|
|
126
156
|
}));
|
|
127
157
|
}
|
|
128
158
|
// Extract maxEventsPerBlock
|
|
@@ -130,6 +160,28 @@ class EventTrigger extends Trigger {
|
|
|
130
160
|
if (maxEvents && maxEvents > 0) {
|
|
131
161
|
queryData.maxEventsPerBlock = maxEvents;
|
|
132
162
|
}
|
|
163
|
+
// Extract contractAbi
|
|
164
|
+
const contractAbi = query.getContractAbi();
|
|
165
|
+
if (contractAbi) {
|
|
166
|
+
queryData.contractAbi = contractAbi;
|
|
167
|
+
}
|
|
168
|
+
// Extract conditions
|
|
169
|
+
const conditions = [];
|
|
170
|
+
if (query.getConditionsList &&
|
|
171
|
+
query.getConditionsList().length > 0) {
|
|
172
|
+
query.getConditionsList().forEach((condition) => {
|
|
173
|
+
const conditionData = {
|
|
174
|
+
fieldName: condition.getFieldName(),
|
|
175
|
+
operator: condition.getOperator(),
|
|
176
|
+
value: condition.getValue(),
|
|
177
|
+
fieldType: condition.getFieldType(),
|
|
178
|
+
};
|
|
179
|
+
conditions.push(conditionData);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (conditions.length > 0) {
|
|
183
|
+
queryData.conditions = conditions;
|
|
184
|
+
}
|
|
133
185
|
queries.push(queryData);
|
|
134
186
|
});
|
|
135
187
|
}
|
|
@@ -161,13 +213,25 @@ class EventTrigger extends Trigger {
|
|
|
161
213
|
* @returns Plain JavaScript object with event trigger data
|
|
162
214
|
*/
|
|
163
215
|
static fromOutputData(outputData) {
|
|
216
|
+
// Try to get data from protobuf structure first
|
|
164
217
|
const eventOutput = outputData.getEventTrigger();
|
|
165
218
|
if (eventOutput) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
219
|
+
const dataValue = eventOutput.getData();
|
|
220
|
+
if (dataValue) {
|
|
221
|
+
try {
|
|
222
|
+
// Convert protobuf Value to JavaScript object
|
|
223
|
+
const convertedData = convertProtobufValueToJs(dataValue);
|
|
224
|
+
// If the converted data is an empty string, return null
|
|
225
|
+
if (convertedData === "") {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
return convertedData;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.warn("Failed to convert event trigger data from protobuf Value:", error);
|
|
232
|
+
// Return the raw protobuf Value object as fallback
|
|
233
|
+
return dataValue;
|
|
234
|
+
}
|
|
171
235
|
}
|
|
172
236
|
}
|
|
173
237
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,YAAY,MAAM,SAAS,CAAC;AACnC,OAAO,WAAW,MAAM,QAAQ,CAAC;AACjC,OAAO,YAAY,MAAM,SAAS,CAAC;AACnC,OAAO,gBAAgB,MAAM,aAAa,CAAC;AAC3C,OAAO,aAAa,MAAM,UAAU,CAAC;AACrC,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAEL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,cAAM,cAAc;IAClB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAkB3C;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,OAAO;IAiBrD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,YAAY,MAAM,SAAS,CAAC;AACnC,OAAO,WAAW,MAAM,QAAQ,CAAC;AACjC,OAAO,YAAY,MAAM,SAAS,CAAC;AACnC,OAAO,gBAAgB,MAAM,aAAa,CAAC;AAC3C,OAAO,aAAa,MAAM,UAAU,CAAC;AACrC,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAEL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,cAAM,cAAc;IAClB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAkB3C;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,OAAO;IAiBrD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG;CAkB9D;AAED,eAAe,cAAc,CAAC;AAG9B,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,aAAa,GACd,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,CAAC"}
|
|
@@ -6,7 +6,6 @@ import FixedTimeTrigger from "./fixedTime";
|
|
|
6
6
|
import ManualTrigger from "./manual";
|
|
7
7
|
import Trigger from "./interface";
|
|
8
8
|
import { TriggerType } from "@avaprotocol/types";
|
|
9
|
-
import { convertProtobufValueToJs } from "../../utils";
|
|
10
9
|
class TriggerFactory {
|
|
11
10
|
/**
|
|
12
11
|
* Static factory method to create Trigger instances
|
|
@@ -51,52 +50,22 @@ class TriggerFactory {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
static fromOutputData(outputData) {
|
|
54
|
-
//
|
|
55
|
-
// This works for all trigger types that follow the pattern of having a getData() method
|
|
56
|
-
let triggerOutput = null;
|
|
57
|
-
let rawData = null;
|
|
58
|
-
// Get the specific trigger output based on the case
|
|
53
|
+
// Delegate to the specific trigger type's fromOutputData method
|
|
59
54
|
switch (outputData.getOutputDataCase()) {
|
|
60
55
|
case avs_pb.RunTriggerResp.OutputDataCase.BLOCK_TRIGGER:
|
|
61
|
-
|
|
62
|
-
break;
|
|
56
|
+
return BlockTrigger.fromOutputData(outputData);
|
|
63
57
|
case avs_pb.RunTriggerResp.OutputDataCase.FIXED_TIME_TRIGGER:
|
|
64
|
-
|
|
65
|
-
break;
|
|
58
|
+
return FixedTimeTrigger.fromOutputData(outputData);
|
|
66
59
|
case avs_pb.RunTriggerResp.OutputDataCase.CRON_TRIGGER:
|
|
67
|
-
|
|
68
|
-
break;
|
|
60
|
+
return CronTrigger.fromOutputData(outputData);
|
|
69
61
|
case avs_pb.RunTriggerResp.OutputDataCase.EVENT_TRIGGER:
|
|
70
|
-
|
|
71
|
-
if (triggerOutput) {
|
|
72
|
-
if (triggerOutput.hasEvmLog()) {
|
|
73
|
-
return triggerOutput.getEvmLog()?.toObject();
|
|
74
|
-
}
|
|
75
|
-
else if (triggerOutput.hasTransferLog()) {
|
|
76
|
-
return triggerOutput.getTransferLog()?.toObject();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
62
|
+
return EventTrigger.fromOutputData(outputData);
|
|
80
63
|
case avs_pb.RunTriggerResp.OutputDataCase.MANUAL_TRIGGER:
|
|
81
|
-
|
|
82
|
-
break;
|
|
64
|
+
return ManualTrigger.fromOutputData(outputData);
|
|
83
65
|
case avs_pb.RunTriggerResp.OutputDataCase.OUTPUT_DATA_NOT_SET:
|
|
84
66
|
default:
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (!triggerOutput) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
// Try to get data using getData() method (works for most trigger types)
|
|
91
|
-
if (typeof triggerOutput.getData === 'function') {
|
|
92
|
-
rawData = triggerOutput.getData();
|
|
93
|
-
if (rawData) {
|
|
94
|
-
return convertProtobufValueToJs(rawData);
|
|
95
|
-
}
|
|
67
|
+
return null;
|
|
96
68
|
}
|
|
97
|
-
// For trigger types that don't have getData() or have special structures,
|
|
98
|
-
// fall back to toObject() for now (can be specialized later if needed)
|
|
99
|
-
return triggerOutput.toObject();
|
|
100
69
|
}
|
|
101
70
|
}
|
|
102
71
|
export default TriggerFactory;
|
package/dist/utils.d.ts
CHANGED
|
@@ -77,4 +77,10 @@ export declare function convertInputToProtobuf(input?: Record<string, any>): Pro
|
|
|
77
77
|
* @returns JavaScript object or undefined
|
|
78
78
|
*/
|
|
79
79
|
export declare function extractInputFromProtobuf(inputValue?: ProtobufValue | Record<string, any>): Record<string, any> | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Clean up gRPC error messages by extracting the actual message
|
|
82
|
+
* @param message - The raw gRPC error message
|
|
83
|
+
* @returns {string} - The cleaned error message
|
|
84
|
+
*/
|
|
85
|
+
export declare function cleanGrpcErrorMessage(message: string): string;
|
|
80
86
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,aAAa,EAGvB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,GAAG,CAiCnE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAkDxD;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa,CA6BlE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,aAAa,EAGvB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,GAAG,CAiCnE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAkDxD;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa,CA6BlE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,aAAa,GAAG,SAAS,CAK3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAiCjC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB7D"}
|