Skip to content

Commit

Permalink
provisional RpcConnection propagation via RpcApi methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jun 12, 2024
1 parent 804f406 commit 22730f5
Show file tree
Hide file tree
Showing 13 changed files with 666 additions and 280 deletions.
57 changes: 30 additions & 27 deletions cli/src/modules/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ impl Rpc {
self.println(&ctx, result);
}
RpcApiOps::GetServerInfo => {
let result = rpc.get_server_info_call(GetServerInfoRequest {}).await?;
let result = rpc.get_server_info_call(None, GetServerInfoRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::GetSyncStatus => {
let result = rpc.get_sync_status_call(GetSyncStatusRequest {}).await?;
let result = rpc.get_sync_status_call(None, GetSyncStatusRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::GetCurrentNetwork => {
let result = rpc.get_current_network_call(GetCurrentNetworkRequest {}).await?;
let result = rpc.get_current_network_call(None, GetCurrentNetworkRequest {}).await?;
self.println(&ctx, result);
}
// RpcApiOps::SubmitBlock => {
Expand All @@ -62,11 +62,11 @@ impl Rpc {
// self.println(&ctx, result);
// }
RpcApiOps::GetPeerAddresses => {
let result = rpc.get_peer_addresses_call(GetPeerAddressesRequest {}).await?;
let result = rpc.get_peer_addresses_call(None, GetPeerAddressesRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::GetSink => {
let result = rpc.get_sink_call(GetSinkRequest {}).await?;
let result = rpc.get_sink_call(None, GetSinkRequest {}).await?;
self.println(&ctx, result);
}
// RpcApiOps::GetMempoolEntry => {
Expand All @@ -76,12 +76,15 @@ impl Rpc {
RpcApiOps::GetMempoolEntries => {
// TODO
let result = rpc
.get_mempool_entries_call(GetMempoolEntriesRequest { include_orphan_pool: true, filter_transaction_pool: true })
.get_mempool_entries_call(
None,
GetMempoolEntriesRequest { include_orphan_pool: true, filter_transaction_pool: true },
)
.await?;
self.println(&ctx, result);
}
RpcApiOps::GetConnectedPeerInfo => {
let result = rpc.get_connected_peer_info_call(GetConnectedPeerInfoRequest {}).await?;
let result = rpc.get_connected_peer_info_call(None, GetConnectedPeerInfoRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::AddPeer => {
Expand All @@ -90,7 +93,7 @@ impl Rpc {
}
let peer_address = argv.remove(0).parse::<RpcContextualPeerAddress>()?;
let is_permanent = argv.remove(0).parse::<bool>().unwrap_or(false);
let result = rpc.add_peer_call(AddPeerRequest { peer_address, is_permanent }).await?;
let result = rpc.add_peer_call(None, AddPeerRequest { peer_address, is_permanent }).await?;
self.println(&ctx, result);
}
// RpcApiOps::SubmitTransaction => {
Expand All @@ -103,7 +106,7 @@ impl Rpc {
}
let hash = argv.remove(0);
let hash = RpcHash::from_hex(hash.as_str())?;
let result = rpc.get_block_call(GetBlockRequest { hash, include_transactions: true }).await?;
let result = rpc.get_block_call(None, GetBlockRequest { hash, include_transactions: true }).await?;
self.println(&ctx, result);
}
// RpcApiOps::GetSubnetwork => {
Expand All @@ -119,19 +122,19 @@ impl Rpc {
// self.println(&ctx, result);
// }
RpcApiOps::GetBlockCount => {
let result = rpc.get_block_count_call(GetBlockCountRequest {}).await?;
let result = rpc.get_block_count_call(None, GetBlockCountRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::GetBlockDagInfo => {
let result = rpc.get_block_dag_info_call(GetBlockDagInfoRequest {}).await?;
let result = rpc.get_block_dag_info_call(None, GetBlockDagInfoRequest {}).await?;
self.println(&ctx, result);
}
// RpcApiOps::ResolveFinalityConflict => {
// let result = rpc.resolve_finality_conflict_call(ResolveFinalityConflictRequest { }).await?;
// self.println(&ctx, result);
// }
RpcApiOps::Shutdown => {
let result = rpc.shutdown_call(ShutdownRequest {}).await?;
let result = rpc.shutdown_call(None, ShutdownRequest {}).await?;
self.println(&ctx, result);
}
// RpcApiOps::GetHeaders => {
Expand All @@ -143,7 +146,7 @@ impl Rpc {
return Err(Error::custom("Please specify at least one address"));
}
let addresses = argv.iter().map(|s| Address::try_from(s.as_str())).collect::<std::result::Result<Vec<_>, _>>()?;
let result = rpc.get_utxos_by_addresses_call(GetUtxosByAddressesRequest { addresses }).await?;
let result = rpc.get_utxos_by_addresses_call(None, GetUtxosByAddressesRequest { addresses }).await?;
self.println(&ctx, result);
}
RpcApiOps::GetBalanceByAddress => {
Expand All @@ -152,7 +155,7 @@ impl Rpc {
}
let addresses = argv.iter().map(|s| Address::try_from(s.as_str())).collect::<std::result::Result<Vec<_>, _>>()?;
for address in addresses {
let result = rpc.get_balance_by_address_call(GetBalanceByAddressRequest { address }).await?;
let result = rpc.get_balance_by_address_call(None, GetBalanceByAddressRequest { address }).await?;
self.println(&ctx, sompi_to_kaspa(result.balance));
}
}
Expand All @@ -161,31 +164,31 @@ impl Rpc {
return Err(Error::custom("Please specify at least one address"));
}
let addresses = argv.iter().map(|s| Address::try_from(s.as_str())).collect::<std::result::Result<Vec<_>, _>>()?;
let result = rpc.get_balances_by_addresses_call(GetBalancesByAddressesRequest { addresses }).await?;
let result = rpc.get_balances_by_addresses_call(None, GetBalancesByAddressesRequest { addresses }).await?;
self.println(&ctx, result);
}
RpcApiOps::GetSinkBlueScore => {
let result = rpc.get_sink_blue_score_call(GetSinkBlueScoreRequest {}).await?;
let result = rpc.get_sink_blue_score_call(None, GetSinkBlueScoreRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::Ban => {
if argv.is_empty() {
return Err(Error::custom("Please specify peer IP address"));
}
let ip: RpcIpAddress = argv.remove(0).parse()?;
let result = rpc.ban_call(BanRequest { ip }).await?;
let result = rpc.ban_call(None, BanRequest { ip }).await?;
self.println(&ctx, result);
}
RpcApiOps::Unban => {
if argv.is_empty() {
return Err(Error::custom("Please specify peer IP address"));
}
let ip: RpcIpAddress = argv.remove(0).parse()?;
let result = rpc.unban_call(UnbanRequest { ip }).await?;
let result = rpc.unban_call(None, UnbanRequest { ip }).await?;
self.println(&ctx, result);
}
RpcApiOps::GetInfo => {
let result = rpc.get_info_call(GetInfoRequest {}).await?;
let result = rpc.get_info_call(None, GetInfoRequest {}).await?;
self.println(&ctx, result);
}
// RpcApiOps::EstimateNetworkHashesPerSecond => {
Expand All @@ -200,16 +203,15 @@ impl Rpc {
let include_orphan_pool = true;
let filter_transaction_pool = true;
let result = rpc
.get_mempool_entries_by_addresses_call(GetMempoolEntriesByAddressesRequest {
addresses,
include_orphan_pool,
filter_transaction_pool,
})
.get_mempool_entries_by_addresses_call(
None,
GetMempoolEntriesByAddressesRequest { addresses, include_orphan_pool, filter_transaction_pool },
)
.await?;
self.println(&ctx, result);
}
RpcApiOps::GetCoinSupply => {
let result = rpc.get_coin_supply_call(GetCoinSupplyRequest {}).await?;
let result = rpc.get_coin_supply_call(None, GetCoinSupplyRequest {}).await?;
self.println(&ctx, result);
}
RpcApiOps::GetDaaScoreTimestampEstimate => {
Expand All @@ -220,8 +222,9 @@ impl Rpc {

match daa_score_result {
Ok(daa_scores) => {
let result =
rpc.get_daa_score_timestamp_estimate_call(GetDaaScoreTimestampEstimateRequest { daa_scores }).await?;
let result = rpc
.get_daa_score_timestamp_estimate_call(None, GetDaaScoreTimestampEstimateRequest { daa_scores })
.await?;
self.println(&ctx, result);
}
Err(_err) => {
Expand Down
7 changes: 7 additions & 0 deletions rpc/core/src/api/connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::sync::Arc;

pub trait RpcConnection: Send + Sync {
fn id(&self) -> u64;
}

pub type DynRpcConnection = Arc<dyn RpcConnection>;
1 change: 1 addition & 0 deletions rpc/core/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod connection;
pub mod ctl;
pub mod notifications;
pub mod ops;
Expand Down
Loading

0 comments on commit 22730f5

Please sign in to comment.