|
|
@ -5,7 +5,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
|
|
|
|
|
|
|
use Explorer.Chain.Supply |
|
|
|
use Explorer.Chain.Supply |
|
|
|
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2] |
|
|
|
import Ecto.Query, only: [from: 2, subquery: 1] |
|
|
|
import EthereumJSONRPC, only: [integer_to_quantity: 1] |
|
|
|
import EthereumJSONRPC, only: [integer_to_quantity: 1] |
|
|
|
|
|
|
|
|
|
|
|
alias EthereumJSONRPC.FetchedBalances |
|
|
|
alias EthereumJSONRPC.FetchedBalances |
|
|
@ -16,7 +16,9 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
|
|
|
|
|
|
|
@cache_name :rsk_balance |
|
|
|
@cache_name :rsk_balance |
|
|
|
@balance_key :balance |
|
|
|
@balance_key :balance |
|
|
|
|
|
|
|
@rsk_bridge_contract_address "0x0000000000000000000000000000000001000006" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@spec market_cap(any()) :: Decimal.t() |
|
|
|
def market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do |
|
|
|
def market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do |
|
|
|
btc = circulating() |
|
|
|
btc = circulating() |
|
|
|
|
|
|
|
|
|
|
@ -25,31 +27,32 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
|
|
|
|
|
|
|
def market_cap(_), do: Decimal.new(0) |
|
|
|
def market_cap(_), do: Decimal.new(0) |
|
|
|
|
|
|
|
|
|
|
|
@doc "Equivalent to getting the circulating value " |
|
|
|
@doc "Equivalent to getting the circulating value" |
|
|
|
def supply_for_days(days) do |
|
|
|
def supply_for_days(days) do |
|
|
|
now = Timex.now() |
|
|
|
now = Timex.now() |
|
|
|
|
|
|
|
|
|
|
|
balances_query = |
|
|
|
base_query = |
|
|
|
from(balance in CoinBalance, |
|
|
|
from(balance in CoinBalance, |
|
|
|
join: block in Block, |
|
|
|
join: block in Block, |
|
|
|
on: block.number == balance.block_number, |
|
|
|
on: block.number == balance.block_number, |
|
|
|
where: block.consensus == true, |
|
|
|
where: block.consensus == true, |
|
|
|
where: balance.address_hash == ^"0x0000000000000000000000000000000001000006", |
|
|
|
where: balance.address_hash == ^@rsk_bridge_contract_address, |
|
|
|
where: block.timestamp > ^Timex.shift(now, days: -days), |
|
|
|
select: %{timestamp: block.timestamp, value: balance.value} |
|
|
|
distinct: fragment("date_trunc('day', ?)", block.timestamp), |
|
|
|
) |
|
|
|
select: {block.timestamp, balance.value} |
|
|
|
|
|
|
|
|
|
|
|
balances_query = |
|
|
|
|
|
|
|
from(q in subquery(base_query), |
|
|
|
|
|
|
|
where: q.timestamp > ^Timex.shift(now, days: -days), |
|
|
|
|
|
|
|
distinct: fragment("date_trunc('day', ?)", q.timestamp), |
|
|
|
|
|
|
|
select: {q.timestamp, q.value} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
balance_before_query = |
|
|
|
balance_before_query = |
|
|
|
from(balance in CoinBalance, |
|
|
|
from(q in subquery(base_query), |
|
|
|
join: block in Block, |
|
|
|
where: q.timestamp <= ^Timex.shift(Timex.now(), days: -days), |
|
|
|
on: block.number == balance.block_number, |
|
|
|
order_by: [desc: q.timestamp], |
|
|
|
where: block.consensus == true, |
|
|
|
|
|
|
|
where: balance.address_hash == ^"0x0000000000000000000000000000000001000006", |
|
|
|
|
|
|
|
where: block.timestamp <= ^Timex.shift(Timex.now(), days: -days), |
|
|
|
|
|
|
|
order_by: [desc: block.timestamp], |
|
|
|
|
|
|
|
limit: 1, |
|
|
|
limit: 1, |
|
|
|
select: balance.value |
|
|
|
select: q.value |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
by_day = |
|
|
|
by_day = |
|
|
@ -105,7 +108,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
max_number = BlockNumber.get_max() |
|
|
|
max_number = BlockNumber.get_max() |
|
|
|
|
|
|
|
|
|
|
|
params = [ |
|
|
|
params = [ |
|
|
|
%{block_quantity: integer_to_quantity(max_number), hash_data: "0x0000000000000000000000000000000001000006"} |
|
|
|
%{block_quantity: integer_to_quantity(max_number), hash_data: @rsk_bridge_contract_address} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments) |
|
|
|
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments) |
|
|
@ -116,7 +119,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
errors: [], |
|
|
|
errors: [], |
|
|
|
params_list: [ |
|
|
|
params_list: [ |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
address_hash: "0x0000000000000000000000000000000001000006", |
|
|
|
address_hash: @rsk_bridge_contract_address, |
|
|
|
value: value |
|
|
|
value: value |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|