@@ -72,20 +72,43 @@ class AciContractCallEncoder {
72
72
* const data = encoder.decodeCall('Test', 'test_string', 'cb_KxHwzCuVGyl3aG9vbHltb2x5zwMSnw==')
73
73
* console.log(`Decoded data: ${data}`)
74
74
* // Outputs:
75
- * // Decoded data: ["whoolymoly"]
75
+ * // Decoded data: { functionId: "f0cc2b95", args: ["whoolymoly"] }
76
76
*
77
77
* @param {string } contract - The contract name as defined in the ACI.
78
78
* @param {string } funName - The function name as defined in the ACI.
79
79
* @param {string } data - Encoded calldata in canonical format.
80
80
* @returns {string } Decoded data
81
81
*/
82
82
decodeCall ( contract , funName , data ) {
83
- const { types, _required } = this . _typeResolver . getCallTypes ( contract , funName )
83
+ const { types} = this . _typeResolver . getCallTypes ( contract , funName )
84
84
const calldataType = FateTypeCalldata ( funName , types )
85
85
86
86
return this . _byteArrayEncoder . decodeWithType ( data , calldataType )
87
87
}
88
88
89
+ /**
90
+ * Decodes function details by contract calldata
91
+ *
92
+ * @example
93
+ * const data = encoder.decodeFunction('cb_KxHwzCuVGyl3aG9vbHltb2x5zwMSnw==')
94
+ * console.log(`Decoded data: ${data}`)
95
+ * // Outputs:
96
+ * // Decoded data: {
97
+ * // contractName: "Test",
98
+ * // functionName: "test_string",
99
+ * // functionId: "f0cc2b95",
100
+ * // }
101
+ *
102
+ * @param {string } data - Encoded calldata in canonical format.
103
+ * @returns {object } Decoded function details
104
+ */
105
+ decodeFunction ( data ) {
106
+ const { functionId} = this . _byteArrayEncoder . decodeWithType ( data , FateTypeCalldata ( ) )
107
+ const { contractName, functionName} = this . _typeResolver . getFunction ( functionId )
108
+
109
+ return { contractName, functionName, functionId}
110
+ }
111
+
89
112
/**
90
113
* Decodes successful (resultType = ok) contract call return data
91
114
*
0 commit comments