|
|
|
@ -5,7 +5,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
|
|
|
|
|
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] |
|
|
|
|
|
|
|
|
|
alias EthereumJSONRPC.FetchedBalances |
|
|
|
@ -16,7 +16,9 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
|
|
|
|
|
@cache_name :rsk_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 |
|
|
|
|
btc = circulating() |
|
|
|
|
|
|
|
|
@ -29,27 +31,28 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
def supply_for_days(days) do |
|
|
|
|
now = Timex.now() |
|
|
|
|
|
|
|
|
|
balances_query = |
|
|
|
|
base_query = |
|
|
|
|
from(balance in CoinBalance, |
|
|
|
|
join: block in Block, |
|
|
|
|
on: block.number == balance.block_number, |
|
|
|
|
where: block.consensus == true, |
|
|
|
|
where: balance.address_hash == ^"0x0000000000000000000000000000000001000006", |
|
|
|
|
where: block.timestamp > ^Timex.shift(now, days: -days), |
|
|
|
|
distinct: fragment("date_trunc('day', ?)", block.timestamp), |
|
|
|
|
select: {block.timestamp, balance.value} |
|
|
|
|
where: balance.address_hash == ^@rsk_bridge_contract_address, |
|
|
|
|
select: %{timestamp: block.timestamp, value: 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 = |
|
|
|
|
from(balance in CoinBalance, |
|
|
|
|
join: block in Block, |
|
|
|
|
on: block.number == balance.block_number, |
|
|
|
|
where: block.consensus == true, |
|
|
|
|
where: balance.address_hash == ^"0x0000000000000000000000000000000001000006", |
|
|
|
|
where: block.timestamp <= ^Timex.shift(Timex.now(), days: -days), |
|
|
|
|
order_by: [desc: block.timestamp], |
|
|
|
|
from(q in subquery(base_query), |
|
|
|
|
where: q.timestamp <= ^Timex.shift(Timex.now(), days: -days), |
|
|
|
|
order_by: [desc: q.timestamp], |
|
|
|
|
limit: 1, |
|
|
|
|
select: balance.value |
|
|
|
|
select: q.value |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
by_day = |
|
|
|
@ -105,7 +108,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
max_number = BlockNumber.get_max() |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
@ -116,7 +119,7 @@ defmodule Explorer.Chain.Supply.RSK do |
|
|
|
|
errors: [], |
|
|
|
|
params_list: [ |
|
|
|
|
%{ |
|
|
|
|
address_hash: "0x0000000000000000000000000000000001000006", |
|
|
|
|
address_hash: @rsk_bridge_contract_address, |
|
|
|
|
value: value |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|