Merge pull request #7564 from blockscout/vb-contract-type-in-api

Return contract type in address view
pull/7566/head
Victor Baranov 2 years ago committed by GitHub
commit 1adb68c116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 18
      apps/block_scout_web/lib/block_scout_web/views/api/v2/address_view.ex
  3. 3
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs

@ -3,6 +3,7 @@
## Current
### Features
- [#7513](https://github.com/blockscout/blockscout/pull/7513) - Add Polygon Edge support
- [#7532](https://github.com/blockscout/blockscout/pull/7532) - Handle empty id in json rpc responses
@ -10,6 +11,7 @@
### Fixes
- [#7564](https://github.com/blockscout/blockscout/pull/7564) - Return contract type in address view
- [#7562](https://github.com/blockscout/blockscout/pull/7562) - Remove fallback from Read methods
- [#7537](https://github.com/blockscout/blockscout/pull/7537), [#7553](https://github.com/blockscout/blockscout/pull/7553) - Withdrawals fixes and improvements
- [#7546](https://github.com/blockscout/blockscout/pull/7546) - API v2: fix today coin price (use in-memory or cached in DB value)

@ -108,7 +108,8 @@ defmodule BlockScoutWeb.API.V2.AddressView do
"has_tokens" => Chain.check_if_tokens_at_address(address.hash, @api_true),
"has_token_transfers" => Chain.check_if_token_transfers_at_address(address.hash, @api_true),
"watchlist_address_id" => Chain.select_watchlist_address_id(get_watchlist_id(conn), address.hash),
"has_beacon_chain_withdrawals" => Chain.check_if_withdrawals_at_address(address.hash, @api_true)
"has_beacon_chain_withdrawals" => Chain.check_if_withdrawals_at_address(address.hash, @api_true),
"contract_type" => contract_type(address)
})
end
@ -170,4 +171,19 @@ defmodule BlockScoutWeb.API.V2.AddressView do
TokenView.render("token_instance.json", %{token_instance: token_instance, token: token})
end
@spec contract_type(term) :: nil | :solidity | :vyper | :yul
def contract_type(%Address{smart_contract: nil}), do: nil
def contract_type(%Address{smart_contract: %SmartContract{}} = address) do
if address.smart_contract.is_vyper_contract do
:vyper
else
if address.smart_contract.abi do
:solidity
else
:yul
end
end
end
end

@ -67,7 +67,8 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"has_tokens" => false,
"has_token_transfers" => false,
"watchlist_address_id" => nil,
"has_beacon_chain_withdrawals" => false
"has_beacon_chain_withdrawals" => false,
"contract_type" => nil
}
request = get(conn, "/api/v2/addresses/#{Address.checksum(address.hash)}")

Loading…
Cancel
Save