From 3b2d7570b3bad5749bde4334fec14a6ad9789612 Mon Sep 17 00:00:00 2001 From: Nikita Pozdniakov Date: Tue, 8 Aug 2023 10:31:27 +0300 Subject: [PATCH] Add method_id to write methods in API v2 response --- .../controllers/api/v2/smart_contract_controller.ex | 10 +++++++--- .../api/v2/smart_contract_controller_test.exs | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex index 8d016c4047..b991044be9 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex @@ -82,7 +82,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do {:not_found, true} <- {:not_found, AddressView.check_custom_abi_for_having_write_functions(custom_abi)} do conn |> put_status(200) - |> json(Writer.filter_write_functions(custom_abi.abi)) + |> json(custom_abi.abi |> Writer.filter_write_functions() |> Reader.get_abi_with_method_id()) end end @@ -95,7 +95,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do {:not_found, false} <- {:not_found, is_nil(smart_contract)} do conn |> put_status(200) - |> json(Writer.write_functions(smart_contract)) + |> json(smart_contract |> Writer.write_functions() |> Reader.get_abi_with_method_id()) end end @@ -135,7 +135,11 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do conn |> put_status(200) - |> json(Writer.write_functions_proxy(implementation_address_hash_string, @api_true)) + |> json( + implementation_address_hash_string + |> Writer.write_functions_proxy(@api_true) + |> Reader.get_abi_with_method_id() + ) end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs index 12dd8c8c5f..863345a903 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs @@ -1205,6 +1205,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do assert [ %{ + "method_id" => "49ba1b49", "type" => "function", "stateMutability" => "nonpayable", "outputs" => [], @@ -1271,7 +1272,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do "stateMutability" => "nonpayable", "outputs" => [], "name" => "disableWhitelist", - "inputs" => [%{"type" => "bool", "name" => "disable", "internalType" => "bool"}] + "inputs" => [%{"type" => "bool", "name" => "disable", "internalType" => "bool"}], + "method_id" => "49ba1b49" } ] == response end @@ -1912,7 +1914,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do "stateMutability" => "nonpayable", "outputs" => [], "name" => "disableWhitelist", - "inputs" => [%{"type" => "bool", "name" => "disable", "internalType" => "bool"}] + "inputs" => [%{"type" => "bool", "name" => "disable", "internalType" => "bool"}], + "method_id" => "49ba1b49" } ] == response end