|
|
@ -4727,14 +4727,14 @@ defmodule Explorer.Chain do |
|
|
|
@spec staking_pools( |
|
|
|
@spec staking_pools( |
|
|
|
filter :: :validator | :active | :inactive, |
|
|
|
filter :: :validator | :active | :inactive, |
|
|
|
paging_options :: PagingOptions.t() | :all, |
|
|
|
paging_options :: PagingOptions.t() | :all, |
|
|
|
delegator_address_hash :: Hash.t() | nil, |
|
|
|
address_hash :: Hash.t() | nil, |
|
|
|
filter_banned :: boolean() | nil, |
|
|
|
filter_banned :: boolean() | nil, |
|
|
|
filter_my :: boolean() | nil |
|
|
|
filter_my :: boolean() | nil |
|
|
|
) :: [map()] |
|
|
|
) :: [map()] |
|
|
|
def staking_pools( |
|
|
|
def staking_pools( |
|
|
|
filter, |
|
|
|
filter, |
|
|
|
paging_options \\ @default_paging_options, |
|
|
|
paging_options \\ @default_paging_options, |
|
|
|
delegator_address_hash \\ nil, |
|
|
|
address_hash \\ nil, |
|
|
|
filter_banned \\ false, |
|
|
|
filter_banned \\ false, |
|
|
|
filter_my \\ false |
|
|
|
filter_my \\ false |
|
|
|
) do |
|
|
|
) do |
|
|
@ -4745,11 +4745,11 @@ defmodule Explorer.Chain do |
|
|
|
|> staking_pools_paging_query(paging_options) |
|
|
|
|> staking_pools_paging_query(paging_options) |
|
|
|
|
|
|
|
|
|
|
|
delegator_query = |
|
|
|
delegator_query = |
|
|
|
if delegator_address_hash do |
|
|
|
if address_hash do |
|
|
|
base_query |
|
|
|
base_query |
|
|
|
|> join(:left, [p], pd in StakingPoolsDelegator, |
|
|
|
|> join(:left, [p], pd in StakingPoolsDelegator, |
|
|
|
on: |
|
|
|
on: |
|
|
|
p.staking_address_hash == pd.pool_address_hash and pd.delegator_address_hash == ^delegator_address_hash and |
|
|
|
p.staking_address_hash == pd.staking_address_hash and pd.address_hash == ^address_hash and |
|
|
|
not pd.is_deleted |
|
|
|
not pd.is_deleted |
|
|
|
) |
|
|
|
) |
|
|
|
|> select([p, pd], %{pool: p, delegator: pd}) |
|
|
|
|> select([p, pd], %{pool: p, delegator: pd}) |
|
|
@ -4766,7 +4766,7 @@ defmodule Explorer.Chain do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
filtered_query = |
|
|
|
filtered_query = |
|
|
|
if delegator_address_hash && filter_my do |
|
|
|
if address_hash && filter_my do |
|
|
|
where(banned_query, [..., pd], not is_nil(pd)) |
|
|
|
where(banned_query, [..., pd], not is_nil(pd)) |
|
|
|
else |
|
|
|
else |
|
|
|
banned_query |
|
|
|
banned_query |
|
|
@ -4824,22 +4824,22 @@ defmodule Explorer.Chain do |
|
|
|
|
|
|
|
|
|
|
|
def staking_pool_delegators(staking_address_hash) do |
|
|
|
def staking_pool_delegators(staking_address_hash) do |
|
|
|
StakingPoolsDelegator |
|
|
|
StakingPoolsDelegator |
|
|
|
|> where(pool_address_hash: ^staking_address_hash, is_active: true) |
|
|
|
|> where(staking_address_hash: ^staking_address_hash, is_active: true) |
|
|
|
|> order_by(desc: :stake_amount) |
|
|
|
|> order_by(desc: :stake_amount) |
|
|
|
|> Repo.all() |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def staking_pool_delegator(pool_address_hash, delegator_address_hash) do |
|
|
|
def staking_pool_delegator(staking_address_hash, address_hash) do |
|
|
|
Repo.get_by(StakingPoolsDelegator, |
|
|
|
Repo.get_by(StakingPoolsDelegator, |
|
|
|
pool_address_hash: pool_address_hash, |
|
|
|
staking_address_hash: staking_address_hash, |
|
|
|
delegator_address_hash: delegator_address_hash, |
|
|
|
address_hash: address_hash, |
|
|
|
is_deleted: false |
|
|
|
is_deleted: false |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def get_total_staked(address_hash) do |
|
|
|
def get_total_staked_and_ordered(address_hash) do |
|
|
|
StakingPoolsDelegator |
|
|
|
StakingPoolsDelegator |
|
|
|
|> where([delegator], delegator.delegator_address_hash == ^address_hash and not delegator.is_deleted) |
|
|
|
|> where([delegator], delegator.address_hash == ^address_hash and not delegator.is_deleted) |
|
|
|
|> select([delegator], %{ |
|
|
|
|> select([delegator], %{ |
|
|
|
stake_amount: coalesce(sum(delegator.stake_amount), 0), |
|
|
|
stake_amount: coalesce(sum(delegator.stake_amount), 0), |
|
|
|
ordered_withdraw: coalesce(sum(delegator.ordered_withdraw), 0) |
|
|
|
ordered_withdraw: coalesce(sum(delegator.ordered_withdraw), 0) |
|
|
|