Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Enable fetcher (#66)
Browse files Browse the repository at this point in the history
* Enable fetcher, save original_json tx receipt

* Add missing migration
  • Loading branch information
fkrause98 authored Jul 27, 2023
1 parent ad59f37 commit 2aa16e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 1 addition & 3 deletions lib/starknet_explorer/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ defmodule StarknetExplorer.Application do
] ++
cache_child_specs ++
if_prod do
# TODO: Uncomment when it's ready
# [StarknetExplorer.BlockFetcher]
[]
[StarknetExplorer.BlockFetcher]
else
[]
end
Expand Down
11 changes: 9 additions & 2 deletions lib/starknet_explorer/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ defmodule StarknetExplorer.Block do
|> Transaction.changeset(tx)
|> Repo.insert!()

Ecto.build_assoc(tx, :receipt, receipts[tx.hash])
|> Receipt.changeset(receipts[tx.hash])
receipt = receipts[tx.hash]
receipt_binary = :erlang.term_to_binary(receipt)

receipt =
receipt
|> Map.put("original_json", receipt_binary)

Ecto.build_assoc(tx, :receipt, receipt)
|> Receipt.changeset(receipt)
|> Repo.insert!()
end)
end)
Expand Down
3 changes: 2 additions & 1 deletion lib/starknet_explorer/transaction_receipt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ defmodule StarknetExplorer.TransactionReceipt do
field :messages_sent, {:array, :map}
field :events, {:array, :map}
field :contract_address
field :original_json, :binary, load_in_query: false
timestamps()
end

def changeset(receipt, attrs) do
receipt
|> cast(
attrs,
@fields
@fields ++ [:original_json]
)
|> validate_according_to_type(attrs)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule StarknetExplorer.Repo.Migrations.TransactionReceiptsOriginalJson do
use Ecto.Migration

def change do
alter table("transaction_receipts") do
add :original_json, :binary
end
end
end

0 comments on commit 2aa16e7

Please sign in to comment.