-
Notifications
You must be signed in to change notification settings - Fork 0
Make search API that can search for Entity #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f6230c5
feat(wip): Entity search API
rbochenek d6fdd27
feat: add env var GOLEMBASE_ENABLED
rbochenek cf7d166
feat(wip): add migration to create golem_base_entities
rbochenek 97e0049
feat: add migration to create golem_base_entities
rbochenek 291e99e
feat: add owner
rbochenek 7f2ef97
feat: add status
rbochenek b432970
feat: check-redirect support
rbochenek f5a3bb9
feat: tests
rbochenek e5c794f
fix: add golembase
rbochenek 1108ff0
chore: alias nested module to fix credo
rbochenek 4f09d75
feat: run golem_base_entities migration in test environment only
rbochenek 48a04ca
fix: avoid Mix.env()
rbochenek eddaae4
fix: replace Mix.env() with custom config
rbochenek 86a5126
fix: skip tests when GolemBase support is disabled
rbochenek 59ed1c3
feat: enable Golem Base support for tests
rbochenek 0770f2b
fix: dialyzer flag --halt-exit-status is no longer valid
rbochenek d2f2a65
chore: update :pattern_match entries for lib/explorer/chain/search.ex
rbochenek 6f2fdeb
fix: dialyzer flag --halt-exit-status is not longer valid
rbochenek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| defmodule Explorer.Chain.GolemBase.Entity do | ||
| @moduledoc """ | ||
| The representation of a Golem Base entity | ||
| """ | ||
|
|
||
| import Ecto.Query, only: [where: 2] | ||
|
|
||
| use Explorer.Schema | ||
| alias Explorer.Chain | ||
| alias Explorer.Chain.Hash | ||
|
|
||
| @type api? :: {:api?, true | false} | ||
|
|
||
| @primary_key false | ||
| typed_schema "golem_base_entities" do | ||
| field(:key, Hash.Full, primary_key: true, null: false) | ||
| field(:status, Ecto.Enum, values: [:active, :deleted, :expired]) | ||
| field(:owner, :binary, null: false) | ||
| field(:last_updated_at_tx_hash, :binary, null: false) | ||
| field(:expires_at_block_number, :integer, null: false) | ||
|
|
||
| timestamps() | ||
| end | ||
|
|
||
| def changeset(%__MODULE__{} = golembase_entity, attrs) do | ||
| golembase_entity | ||
| |> cast(attrs, [:key, :status, :owner, :last_updated_at_tx_hash, :expires_at_block_number]) | ||
| |> validate_required([:key, :status, :owner, :last_updated_at_tx_hash, :expires_at_block_number]) | ||
| end | ||
|
|
||
| @spec hash_to_golembase_entity(Hash.Full.t(), [api?]) :: | ||
| {:ok, __MODULE__.t()} | {:error, :not_found} | ||
| def hash_to_golembase_entity(%Hash{byte_count: unquote(Hash.Full.byte_count())} = hash, options \\ []) | ||
| when is_list(options) do | ||
| __MODULE__ | ||
| |> where(key: ^hash) | ||
| |> where(status: :active) | ||
| |> Chain.select_repo(options).one() | ||
| |> case do | ||
| nil -> | ||
| {:error, :not_found} | ||
|
|
||
| golembase_entity -> | ||
| {:ok, golembase_entity} | ||
| end | ||
| end | ||
|
|
||
| def enabled? do | ||
| Application.get_env(:explorer, __MODULE__)[:enabled] | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
apps/explorer/priv/repo/migrations/20250728191950_create_golem_base_entities.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| defmodule Explorer.Repo.Migrations.CreateGolemBaseEntities do | ||
kacperzuk-neti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use Ecto.Migration | ||
|
|
||
| def up do | ||
| # Create golem_base_entity_status_type enum type if it doesn't exist | ||
| execute(""" | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'golem_base_entity_status_type') THEN | ||
| CREATE TYPE golem_base_entity_status_type AS ENUM ('active', 'deleted', 'expired'); | ||
| END IF; | ||
| END$$; | ||
| """) | ||
|
|
||
| create table(:golem_base_entities, primary_key: false) do | ||
| add(:key, :binary, null: false, primary_key: true) | ||
| add(:data, :binary) | ||
| add(:status, :golem_base_entity_status_type, null: false) | ||
| add(:owner, :binary, null: false) | ||
|
|
||
| add(:created_at_tx_hash, :binary) | ||
| add(:last_updated_at_tx_hash, :binary, null: false) | ||
| add(:expires_at_block_number, :bigint, null: false) | ||
|
|
||
| add(:inserted_at, :naive_datetime, null: false, default: fragment("now()")) | ||
| add(:updated_at, :naive_datetime, null: false, default: fragment("now()")) | ||
| end | ||
| end | ||
|
|
||
| def down do | ||
| drop(table(:golem_base_entities)) | ||
|
|
||
| # Drop golem_base_entity_status_type enum if it exists | ||
| execute(""" | ||
| DO $$ | ||
| BEGIN | ||
| DROP TYPE IF EXISTS golem_base_entity_status_type; | ||
| END$$ | ||
| """) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.