Add total-supply command (#8722)

automerge
This commit is contained in:
Michael Vines
2020-03-09 01:28:44 -07:00
committed by GitHub
parent eab80d0aea
commit 132a2a73af
4 changed files with 80 additions and 0 deletions

View File

@ -164,6 +164,32 @@ impl RpcClient {
})
}
pub fn total_supply(&self) -> io::Result<u64> {
self.total_supply_with_commitment(CommitmentConfig::default())
}
pub fn total_supply_with_commitment(
&self,
commitment_config: CommitmentConfig,
) -> io::Result<u64> {
let response = self
.client
.send(&RpcRequest::GetTotalSupply, json!([commitment_config]), 0)
.map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("GetTotalSupply request failure: {:?}", err),
)
})?;
serde_json::from_value(response).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("GetTotalSupply parse failure: {}", err),
)
})
}
pub fn get_vote_accounts(&self) -> io::Result<RpcVoteAccountStatus> {
self.get_vote_accounts_with_commitment(CommitmentConfig::default())
}

View File

@ -30,6 +30,7 @@ pub enum RpcRequest {
GetStorageTurnRate,
GetSlotsPerSegment,
GetStoragePubkeysForSlot,
GetTotalSupply,
GetTransactionCount,
GetVersion,
GetVoteAccounts,
@ -74,6 +75,7 @@ impl RpcRequest {
RpcRequest::GetStorageTurnRate => "getStorageTurnRate",
RpcRequest::GetSlotsPerSegment => "getSlotsPerSegment",
RpcRequest::GetStoragePubkeysForSlot => "getStoragePubkeysForSlot",
RpcRequest::GetTotalSupply => "getTotalSupply",
RpcRequest::GetTransactionCount => "getTransactionCount",
RpcRequest::GetVersion => "getVersion",
RpcRequest::GetVoteAccounts => "getVoteAccounts",