As you know the NEAR blockchain is based on Proof of stake protocol.the number of validators can be based on validators 'staking' or even 'not staking'. i'm new to this and i don't know which culoolumnsmns or tables should i use to find this number. should i use tx_hash or tx_reciever? i'm totally confused
WITH
staking AS (
SELECT tx_hash
FROM near.core.fact_actions_events_function_call
WHERE method_name IN ('deposit_and_stake', 'stake', 'stake_all')
),
stakes AS (
SELECT
block_timestamp,
tx_hash AS tx,
tx_receiver AS validator,
tx_signer AS delegator,
tx:actions[0]:FunctionCall:deposit/pow(10, 24) AS near_staked
FROM near.core.fact_transactions
WHERE tx_hash IN (SELECT * FROM staking)
),
monthly AS (
SELECT
trunc(block_timestamp, 'month') AS months,
tx,
validator,
near_staked
FROM stakes
WHERE near_staked IS NOT NULL
),
totals AS (
SELECT
months,
sum(near_staked) AS month_near_staked,
sum(month_near_staked) OVER (ORDER BY months) AS total_near_staked
FROM monthly
GROUP BY 1
ORDER BY 1
),
ranking AS (
SELECT
months,
validator,
count(DISTINCT tx) AS txs,
sum(near_staked) AS total_near_delegated,
sum(total_near_delegated) OVER (PARTITION BY validator ORDER BY months) AS cumulative_near_delegated
FROM monthly
GROUP BY 1, 2
)
SELECT COUNT(DISTINCT validator) AS num_validators
FROM ranking;
Running this query will provide the number of distinct validators present in the provided database information based on the staking activities analyzed. but i don't think it's true