Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix updated transactions issue (#706)
* Fix updated transactions issue
  • Loading branch information
shazarre committed Aug 3, 2022
1 parent 91553fc commit b88c5a2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/indexer/lib/indexer/transform/token_transfers.ex
Expand Up @@ -101,7 +101,9 @@ defmodule Indexer.Transform.TokenTransfers do
block_hash: itx.block_hash,
# Celo token transfers discerned from itx do not have a valid log index, so an id is calculated here to
# satisfy schema constraints
log_index: -transfer_count,
# and it needs to be negative (starting with -1) not to generate conflicts with
# log_index for token transfers from block transactions as they start from 0
log_index: -1 * (transfer_count + 1),
from_address_hash: itx.from_address_hash,
to_address_hash: to_hash,
token_contract_address_hash: gold_token,
Expand Down
51 changes: 48 additions & 3 deletions apps/indexer/test/indexer/transform/token_transfers_test.exs
Expand Up @@ -20,7 +20,6 @@ defmodule Indexer.Transform.TokenTransfersTest do
second_topic: "0x000000000000000000000000556813d9cc20acfe8388af029a679d34a63388db",
third_topic: "0x00000000000000000000000092148dd870fa1b7c4700f2bd7f44238821c26f73",
transaction_hash: "0x43dfd761974e8c3351d285ab65bee311454eb45b149a015fe7804a33252f19e5",
# block_hash: "0x43dfd761974e8c3351d285ab65bee311454eb45b149a015fe7804a33252f19e5",
type: "mined"
},
%{
Expand Down Expand Up @@ -191,10 +190,56 @@ defmodule Indexer.Transform.TokenTransfersTest do
}
end)

%{token_transfers: result} = TokenTransfers.parse_itx(test_itx_maps, "0xgoldtokenaddresshash")
%{token_transfers: result_itx} = TokenTransfers.parse_itx(test_itx_maps, "0xgoldtokenaddresshash")

%{token_transfers: result_tx} =
TokenTransfers.parse([
%{
address_hash: "0xf2eec76e45b328df99a34fa696320a262cb92154",
block_number: 3_530_917,
block_hash: "0x79594150677f083756a37eee7b97ed99ab071f502104332cb3835bac345711ca",
data: "0x000000000000000000000000000000000000000000000000ebec21ee1da40000",
first_topic: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
fourth_topic: nil,
index: 0,
second_topic: "0x000000000000000000000000556813d9cc20acfe8388af029a679d34a63388db",
third_topic: "0x00000000000000000000000092148dd870fa1b7c4700f2bd7f44238821c26f73",
transaction_hash: "0x43dfd761974e8c3351d285ab65bee311454eb45b149a015fe7804a33252f19e5",
type: "mined"
},
%{
address_hash: "0xf2eec76e45b328df99a34fa696320a262cb92154",
block_number: 3_530_917,
block_hash: "0x79594150677f083756a37eee7b97ed99ab071f502104332cb3835bac345711ca",
data: "0x000000000000000000000000000000000000000000000000ebec21ee1da40000",
first_topic: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
fourth_topic: nil,
index: 1,
second_topic: "0x000000000000000000000000556813d9cc20acfe8388af029a679d34a63388db",
third_topic: "0x00000000000000000000000092148dd870fa1b7c4700f2bd7f44238821c26f73",
transaction_hash: "0x43dfd761974e8c3351d285ab65bee311454eb45b149a015fe7804a33252f19e5",
type: "mined"
},
%{
address_hash: "0xf2eec76e45b328df99a34fa696320a262cb92154",
block_number: 3_530_917,
block_hash: "0x79594150677f083756a37eee7b97ed99ab071f502104332cb3835bac345711ca",
data: "0x000000000000000000000000000000000000000000000000ebec21ee1da40000",
first_topic: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
fourth_topic: nil,
index: 2,
second_topic: "0x000000000000000000000000556813d9cc20acfe8388af029a679d34a63388db",
third_topic: "0x00000000000000000000000092148dd870fa1b7c4700f2bd7f44238821c26f73",
transaction_hash: "0x43dfd761974e8c3351d285ab65bee311454eb45b149a015fe7804a33252f19e5",
type: "mined"
}
])

# create a map of log_index -> count of log_index in result
log_indexes = result |> Enum.map(& &1.log_index) |> Enum.reduce(%{}, &Map.put(&2, &1, Map.get(&2, &1, 0) + 1))
log_indexes =
Enum.concat(result_itx, result_tx)
|> Enum.map(& &1.log_index)
|> Enum.reduce(%{}, &Map.put(&2, &1, Map.get(&2, &1, 0) + 1))

log_indexes
|> Enum.each(fn {index, count} ->
Expand Down

0 comments on commit b88c5a2

Please sign in to comment.