REST API now returns supply in SOL rather than lamports (#10170)

automerge
This commit is contained in:
Michael Vines 2020-05-21 15:50:06 -07:00 committed by GitHub
parent 56c7e4a66c
commit 18be7a7966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -14,7 +14,7 @@ use solana_ledger::{
blockstore::Blockstore,
snapshot_utils,
};
use solana_sdk::{hash::Hash, pubkey::Pubkey};
use solana_sdk::{hash::Hash, native_token::lamports_to_sol, pubkey::Pubkey};
use std::{
collections::HashSet,
net::SocketAddr,
@ -261,13 +261,16 @@ fn process_rest(bank_forks: &Arc<RwLock<BankForks>>, path: &str) -> Option<Strin
let total_supply = bank.capitalization();
let non_circulating_supply =
crate::non_circulating_supply::calculate_non_circulating_supply(&bank).lamports;
Some(format!("{}", total_supply - non_circulating_supply))
Some(format!(
"{}",
lamports_to_sol(total_supply - non_circulating_supply)
))
}
"/v0/total-supply" => {
let r_bank_forks = bank_forks.read().unwrap();
let bank = r_bank_forks.root_bank();
let total_supply = bank.capitalization();
Some(format!("{}", total_supply))
Some(format!("{}", lamports_to_sol(total_supply)))
}
_ => None,
}
@ -458,11 +461,11 @@ mod tests {
assert_eq!(None, process_rest(&bank_forks, "not-a-supported-rest-api"));
assert_eq!(
Some("10127".to_string()),
Some("0.000010127".to_string()),
process_rest(&bank_forks, "/v0/circulating-supply")
);
assert_eq!(
Some("10127".to_string()),
Some("0.000010127".to_string()),
process_rest(&bank_forks, "/v0/total-supply")
);
}