From 9dfa2a8daf9b4e06a255be26d8d06f8a88cef031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Fri, 22 Nov 2024 09:14:41 +0100 Subject: [PATCH 1/2] Add to parameter to the decodeData function --- packages/api-kit/src/SafeApiKit.ts | 7 ++++--- packages/api-kit/tests/e2e/decodeData.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/api-kit/src/SafeApiKit.ts b/packages/api-kit/src/SafeApiKit.ts index be9089339..94eeb3632 100644 --- a/packages/api-kit/src/SafeApiKit.ts +++ b/packages/api-kit/src/SafeApiKit.ts @@ -115,20 +115,21 @@ class SafeApiKit { /** * Decodes the specified Safe transaction data. * - * @param data - The Safe transaction data + * @param data - The Safe transaction data. '0x' prefixed hexadecimal string. + * @param to - The address of the receiving contract. If provided, the decoded data will be more accurate, as in case of an ABI collision the Safe Transaction Service would know which ABI to use * @returns The transaction data decoded * @throws "Invalid data" * @throws "Not Found" * @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)." */ - async decodeData(data: string): Promise { + async decodeData(data: string, to: string = ''): Promise { if (data === '') { throw new Error('Invalid data') } return sendRequest({ url: `${this.#txServiceBaseUrl}/v1/data-decoder/`, method: HttpMethod.Post, - body: { data } + body: { data, to } }) } diff --git a/packages/api-kit/tests/e2e/decodeData.test.ts b/packages/api-kit/tests/e2e/decodeData.test.ts index 7d96a5548..436788970 100644 --- a/packages/api-kit/tests/e2e/decodeData.test.ts +++ b/packages/api-kit/tests/e2e/decodeData.test.ts @@ -45,4 +45,22 @@ describe('decodeData', () => { }) ) }) + + it('should decode the data and allow to specify the receiving contract', async () => { + const data = '0x610b592500000000000000000000000090F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + const to = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + const decodedData = await safeApiKit.decodeData(data, to) + chai.expect(JSON.stringify(decodedData)).to.be.equal( + JSON.stringify({ + method: 'enableModule', + parameters: [ + { + name: 'module', + type: 'address', + value: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + } + ] + }) + ) + }) }) From b8dc3ca40cdee4ef68223568c98db832ad1ac2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Fri, 22 Nov 2024 09:29:40 +0100 Subject: [PATCH 2/2] blank to makes endpoint fail --- packages/api-kit/src/SafeApiKit.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/api-kit/src/SafeApiKit.ts b/packages/api-kit/src/SafeApiKit.ts index 94eeb3632..2067ac103 100644 --- a/packages/api-kit/src/SafeApiKit.ts +++ b/packages/api-kit/src/SafeApiKit.ts @@ -122,14 +122,21 @@ class SafeApiKit { * @throws "Not Found" * @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)." */ - async decodeData(data: string, to: string = ''): Promise { + async decodeData(data: string, to?: string): Promise { if (data === '') { throw new Error('Invalid data') } + + const dataDecoderRequest: { data: string; to?: string } = { data } + + if (to) { + dataDecoderRequest.to = to + } + return sendRequest({ url: `${this.#txServiceBaseUrl}/v1/data-decoder/`, method: HttpMethod.Post, - body: { data, to } + body: dataDecoderRequest }) }