Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Plumb getCirculatingSupply endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed May 8, 2020
1 parent f829bcc commit 86de148
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/src/rpc_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,12 @@ pub struct RpcAccountBalance {
pub address: String,
pub lamports: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcCirculatingSupply {
pub epoch: Epoch,
pub circulating_supply: u64,
pub non_circulating_supply: u64,
pub non_circulating_accounts: Vec<String>,
}
38 changes: 38 additions & 0 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ impl JsonRpcRequestProcessor {
)
}

fn get_circulating_supply(
&self,
commitment: Option<CommitmentConfig>,
) -> Result<RpcCirculatingSupply> {
let bank = self.bank(commitment)?;
let epoch = bank.epoch();
Ok(RpcCirculatingSupply {
epoch,
circulating_supply: bank.supply.circulating,
non_circulating_supply: bank.supply.non_circulating,
non_circulating_accounts: bank
.supply
.non_circulating_accounts
.iter()
.map(|pubkey| pubkey.to_string())
.collect(),
})
}

fn get_vote_accounts(
&self,
commitment: Option<CommitmentConfig>,
Expand Down Expand Up @@ -800,6 +819,13 @@ pub trait RpcSol {
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Vec<RpcAccountBalance>>;

#[rpc(meta, name = "getCirculatingSupply")]
fn get_circulating_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<RpcCirculatingSupply>;

#[rpc(meta, name = "requestAirdrop")]
fn request_airdrop(
&self,
Expand Down Expand Up @@ -1213,6 +1239,18 @@ impl RpcSol for RpcSolImpl {
.get_largest_accounts(commitment)
}

fn get_circulating_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<RpcCirculatingSupply> {
debug!("get_circulating_supply rpc request received");
meta.request_processor
.read()
.unwrap()
.get_circulating_supply(commitment)
}

fn request_airdrop(
&self,
meta: Self::Metadata,
Expand Down

0 comments on commit 86de148

Please sign in to comment.