diff --git a/CHANGELOG.md b/CHANGELOG.md index 90516400a4..eb776ae9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,15 @@ ## Current ### Features +- [#2918](https://github.com/poanetwork/blockscout/pull/2918) - Add tokenID for tokentx API action ### Fixes - [#2906](https://github.com/poanetwork/blockscout/pull/2906) - fix address sum cache - - [#2902](https://github.com/poanetwork/blockscout/pull/2902) - Offset in blocks retrieval for average block time - [#2900](https://github.com/poanetwork/blockscout/pull/2900) - check fetched instance metadata in multiple places ### Chore - - [#2896](https://github.com/poanetwork/blockscout/pull/2896) - Disable Parity websockets tests diff --git a/apps/block_scout_web/lib/block_scout_web/etherscan.ex b/apps/block_scout_web/lib/block_scout_web/etherscan.ex index abb358179c..5e6c05bb41 100644 --- a/apps/block_scout_web/lib/block_scout_web/etherscan.ex +++ b/apps/block_scout_web/lib/block_scout_web/etherscan.ex @@ -589,6 +589,12 @@ defmodule BlockScoutWeb.Etherscan do example: ~s("Some Token Name") } + @token_id_type %{ + type: "integer", + definition: "id of token", + example: ~s("0") + } + @token_symbol_type %{ type: "string", definition: "Trading symbol of the token.", @@ -752,6 +758,7 @@ defmodule BlockScoutWeb.Etherscan do example: ~s("663046792267785498951364") }, tokenName: @token_name_type, + tokenID: @token_id_type, tokenSymbol: @token_symbol_type, tokenDecimal: @token_decimal_type, transactionIndex: @transaction_index_type, diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex index 8063b1db40..62da759428 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex @@ -121,7 +121,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do } end - defp prepare_token_transfer(token_transfer) do + defp prepare_common_token_transfer(token_transfer) do %{ "blockNumber" => to_string(token_transfer.block_number), "timeStamp" => to_string(DateTime.to_unix(token_transfer.block_timestamp)), @@ -132,7 +132,6 @@ defmodule BlockScoutWeb.API.RPC.AddressView do "contractAddress" => to_string(token_transfer.token_contract_address_hash), "to" => to_string(token_transfer.to_address_hash), "logIndex" => to_string(token_transfer.token_log_index), - "value" => get_token_value(token_transfer), "tokenName" => token_transfer.token_name, "tokenSymbol" => token_transfer.token_symbol, "tokenDecimal" => to_string(token_transfer.token_decimals), @@ -146,12 +145,20 @@ defmodule BlockScoutWeb.API.RPC.AddressView do } end - defp get_token_value(%{token_type: "ERC-721"} = token_transfer) do - to_string(token_transfer.token_id) + defp prepare_token_transfer(%{token_type: "ERC-721"} = token_transfer) do + token_transfer + |> prepare_common_token_transfer() + |> Map.put_new(:tokenID, token_transfer.token_id) + end + + defp prepare_token_transfer(%{token_type: "ERC-20"} = token_transfer) do + token_transfer + |> prepare_common_token_transfer() + |> Map.put_new(:value, to_string(token_transfer.amount)) end - defp get_token_value(token_transfer) do - to_string(token_transfer.amount) + defp prepare_token_transfer(token_transfer) do + prepare_common_token_transfer(token_transfer) end defp prepare_block(block) do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs index 5b873bed10..2db1bdb33c 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs @@ -1807,7 +1807,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> get("/api", params) |> json_response(200) - assert result["value"] == to_string(token_transfer.token_id) + assert result["tokenID"] == to_string(token_transfer.token_id) assert response["status"] == "1" assert response["message"] == "OK" assert :ok = ExJsonSchema.Validator.validate(tokentx_schema(), response) @@ -2618,6 +2618,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do "logIndex" => %{"type" => "string"}, "value" => %{"type" => "string"}, "tokenName" => %{"type" => "string"}, + "tokenID" => %{"type" => "string"}, "tokenSymbol" => %{"type" => "string"}, "tokenDecimal" => %{"type" => "string"}, "transactionIndex" => %{"type" => "string"},