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

Commit

Permalink
update if contract or class already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Pittella authored and Santiago Pittella committed Nov 2, 2023
1 parent 72c5a86 commit f61b5c4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/starknet_explorer/block/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,20 @@ defmodule StarknetExplorer.Block do
Message.insert_from_transaction(inserted_tx, block.timestamp, network)
end)

Enum.each(declared_classes_changeset, fn changeset ->
Repo.insert(changeset)
Enum.each(declared_classes_changeset, fn class ->
Repo.insert(
class,
on_conflict: [set: [block_number: class.data["block_number"]]],
conflict_target: [:hash, :network]
)
end)

Enum.each(deployed_contracts, fn changeset ->
Repo.insert(changeset)
Enum.each(deployed_contracts, fn contract ->
Repo.insert(
contract,
on_conflict: [set: [block_number: contract.data["block_number"]]],
conflict_target: [:address, :network]
)
end)

Enum.each(events, fn event -> {:ok, _event} = Events.insert(event) end)
Expand Down

0 comments on commit f61b5c4

Please sign in to comment.