Rpc: Add getCirculatingSupply endpoint, redux (#9953)
* Add Bank.clock() helper * Add non-circulating calculations * Plumb getSupply rpc endpoint * Add docs for getSupply, and remove getTotalSupply from docs * Add pubkeys! procedural macro * Use procedural macro in non_circulating_supply
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::{
|
||||
cluster_info::ClusterInfo,
|
||||
commitment::{BlockCommitmentArray, BlockCommitmentCache},
|
||||
contact_info::ContactInfo,
|
||||
non_circulating_supply::calculate_non_circulating_supply,
|
||||
storage_stage::StorageState,
|
||||
validator::ValidatorExit,
|
||||
};
|
||||
@@ -302,6 +303,25 @@ impl JsonRpcRequestProcessor {
|
||||
)
|
||||
}
|
||||
|
||||
fn get_supply(&self, commitment: Option<CommitmentConfig>) -> RpcResponse<RpcSupply> {
|
||||
let bank = self.bank(commitment)?;
|
||||
let non_circulating_supply = calculate_non_circulating_supply(bank.clone());
|
||||
let total_supply = bank.capitalization();
|
||||
new_response(
|
||||
&bank,
|
||||
RpcSupply {
|
||||
total: total_supply,
|
||||
circulating: total_supply - non_circulating_supply.lamports,
|
||||
non_circulating: non_circulating_supply.lamports,
|
||||
non_circulating_accounts: non_circulating_supply
|
||||
.accounts
|
||||
.iter()
|
||||
.map(|pubkey| pubkey.to_string())
|
||||
.collect(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn get_vote_accounts(
|
||||
&self,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
@@ -786,6 +806,7 @@ pub trait RpcSol {
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<u64>;
|
||||
|
||||
// DEPRECATED
|
||||
#[rpc(meta, name = "getTotalSupply")]
|
||||
fn get_total_supply(
|
||||
&self,
|
||||
@@ -800,6 +821,13 @@ pub trait RpcSol {
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<Vec<RpcAccountBalance>>;
|
||||
|
||||
#[rpc(meta, name = "getSupply")]
|
||||
fn get_supply(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcSupply>;
|
||||
|
||||
#[rpc(meta, name = "requestAirdrop")]
|
||||
fn request_airdrop(
|
||||
&self,
|
||||
@@ -1213,6 +1241,18 @@ impl RpcSol for RpcSolImpl {
|
||||
.get_largest_accounts(commitment)
|
||||
}
|
||||
|
||||
fn get_supply(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcSupply> {
|
||||
debug!("get_supply rpc request received");
|
||||
meta.request_processor
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_supply(commitment)
|
||||
}
|
||||
|
||||
fn request_airdrop(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
|
Reference in New Issue
Block a user