Skip to content
This repository has been archived by the owner on Feb 24, 2025. It is now read-only.

Commit

Permalink
Fetch and save vote only for accounts that have activated votes
Browse files Browse the repository at this point in the history
  • Loading branch information
obasilakis committed Mar 17, 2022
1 parent 05065ad commit f4886eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ defmodule Explorer.Celo.ContractEvents.Election.ValidatorGroupVoteActivatedEvent
event_param(:value, {:uint, 256}, :unindexed)
event_param(:units, {:uint, 256}, :unindexed)

def get_account_group_pairs_with_activated_votes do
def get_account_group_pairs_with_activated_votes(block_number) do
query =
from(
event in CeloContractEvent,
inner_join: block in Block,
on: event.block_hash == block.hash,
where: event.name == "ValidatorGroupVoteActivated",
where: block.number < ^block_number,
select: %{
account_hash: json_extract_path(event.params, ["account"]),
group_hash: json_extract_path(event.params, ["group"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,47 @@ defmodule Explorer.Celo.Events.ValidatorGroupVoteActivatedEventTest do

describe "get_previous_epoch_voters_and_groups/1" do
test "returns accounts that have activated votes for groups" do
%Address{hash: voter_address_hash} = insert(:address)
%Address{hash: group_address_hash} = insert(:address)
%Address{hash: voter_1_address_hash} = insert(:address)
%Address{hash: group_1_address_hash} = insert(:address)
%Address{hash: voter_2_address_hash} = insert(:address)
%Address{hash: group_2_address_hash} = insert(:address)
%Address{hash: contract_address_hash} = insert(:address)

block = insert(:block, number: 10_692_863, timestamp: ~U[2022-01-01 13:08:43.162814Z])
log = insert(:log, block: block)
block_1 = insert(:block, number: 10_692_863, timestamp: ~U[2022-01-01 13:08:43.162814Z])
log_1 = insert(:log, block: block_1)

insert(:contract_event, %{
event: %ValidatorGroupVoteActivatedEvent{
block_hash: block.hash,
log_index: log.index,
account: voter_address_hash,
block_hash: block_1.hash,
log_index: log_1.index,
account: voter_1_address_hash,
contract_address_hash: contract_address_hash,
group: group_address_hash,
group: group_1_address_hash,
units: 1000,
value: 650
}
})

assert ValidatorGroupVoteActivatedEvent.get_account_group_pairs_with_activated_votes() ==
block_2 = insert(:block, number: 10_710_143, timestamp: ~U[2022-01-02 13:08:43.162814Z])
log_2 = insert(:log, block: block_2)

insert(:contract_event, %{
event: %ValidatorGroupVoteActivatedEvent{
block_hash: block_2.hash,
log_index: log_2.index,
account: voter_2_address_hash,
contract_address_hash: contract_address_hash,
group: group_2_address_hash,
units: 1000,
value: 650
}
})

assert ValidatorGroupVoteActivatedEvent.get_account_group_pairs_with_activated_votes(10_696_320) ==
[
%{
account_hash: voter_address_hash,
group_hash: group_address_hash
account_hash: voter_1_address_hash,
group_hash: group_1_address_hash
}
]
end
Expand Down

0 comments on commit f4886eb

Please sign in to comment.