Skip to content

Commit

Permalink
Migrate to fast NEAR API
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreLeGuen committed Apr 20, 2024
1 parent 9e241c2 commit 32e7b98
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,16 @@ struct StakingReportRow {
pub block_id: u128,
}

#[derive(Debug, Deserialize, Clone)]
struct StakingDeposit {
pub deposit: String,
pub validator_id: String,
#[derive(Debug, Serialize, Deserialize)]
struct StakingData {
account_id: String,
pools: Vec<Pool>,
}

#[derive(Debug, Serialize, Deserialize)]
struct Pool {
last_update_block_height: Option<u64>,
pool_id: String,
}

async fn get_staking_report(
Expand Down Expand Up @@ -668,31 +674,28 @@ async fn get_staking_report(

let staking_deposits = client
.get(format!(
"https://api.kitwallet.app/staking-deposits/{account}"
"https://api.fastnear.com/v1/account/{account}/staking"
))
.send()
.await?
.json::<Vec<StakingDeposit>>()
.json::<StakingData>()
.await?;
info!(
"Account {} staking deposits: {:?}",
account, staking_deposits
);

let handles: Vec<_> = staking_deposits
.pools
.iter()
.map(|staking_deposit| {
let staking_deposit = staking_deposit.clone();
.map(|pool| {
let pool_id = pool.pool_id.clone();
let account = account.clone();
let ft_service = ft_service.clone();
let master_account = master_account.clone();
async move {
let staking_details = match ft_service
.get_staking_details(
&staking_deposit.validator_id,
&account,
block_id as u64,
)
.get_staking_details(&pool_id, &account, block_id as u64)
.await
{
Ok(v) => v,
Expand All @@ -708,7 +711,7 @@ async fn get_staking_report(

let record = StakingReportRow {
account,
staking_pool: staking_deposit.validator_id.clone(),
staking_pool: pool_id.clone(),
amount_staked: staking_details.0,
amount_unstaked: staking_details.1,
ready_for_withdraw: staking_details.2,
Expand Down

0 comments on commit 32e7b98

Please sign in to comment.