use crate::model::*;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use kaspa_consensus_core::sync_info::SyncInfo;
use kaspa_notify::subscription::{single::UtxosChangedSubscription, Command};
use serde::{Deserialize, Serialize};
use std::{
fmt::{Display, Formatter},
sync::Arc,
};
pub type RpcExtraData = Vec<u8>;
#[derive(Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SubmitBlockRequest {
pub block: RpcBlock,
#[serde(alias = "allowNonDAABlocks")]
pub allow_non_daa_blocks: bool,
}
impl SubmitBlockRequest {
pub fn new(block: RpcBlock, allow_non_daa_blocks: bool) -> Self {
Self { block, allow_non_daa_blocks }
}
}
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub enum SubmitBlockRejectReason {
BlockInvalid = 1,
IsInIBD = 2,
}
impl SubmitBlockRejectReason {
fn as_str(&self) -> &'static str {
match self {
SubmitBlockRejectReason::BlockInvalid => "Block is invalid",
SubmitBlockRejectReason::IsInIBD => "Node is in IBD",
}
}
}
impl Display for SubmitBlockRejectReason {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub enum SubmitBlockReport {
Success,
Reject(SubmitBlockRejectReason),
}
impl SubmitBlockReport {
pub fn is_success(&self) -> bool {
*self == SubmitBlockReport::Success
}
}
#[derive(Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SubmitBlockResponse {
pub report: SubmitBlockReport,
}
#[derive(Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockTemplateRequest {
pub pay_address: RpcAddress,
pub extra_data: RpcExtraData,
}
impl GetBlockTemplateRequest {
pub fn new(pay_address: RpcAddress, extra_data: RpcExtraData) -> Self {
Self { pay_address, extra_data }
}
}
#[derive(Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockTemplateResponse {
pub block: RpcBlock,
pub is_synced: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockRequest {
pub hash: RpcHash,
pub include_transactions: bool,
}
impl GetBlockRequest {
pub fn new(hash: RpcHash, include_transactions: bool) -> Self {
Self { hash, include_transactions }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockResponse {
pub block: RpcBlock,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetInfoRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetInfoResponse {
pub p2p_id: String,
pub mempool_size: u64,
pub server_version: String,
pub is_utxo_indexed: bool,
pub is_synced: bool,
pub has_notify_command: bool,
pub has_message_id: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetCurrentNetworkRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetCurrentNetworkResponse {
pub network: RpcNetworkType,
}
impl GetCurrentNetworkResponse {
pub fn new(network: RpcNetworkType) -> Self {
Self { network }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetPeerAddressesRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetPeerAddressesResponse {
pub known_addresses: Vec<RpcPeerAddress>,
pub banned_addresses: Vec<RpcPeerAddress>,
}
impl GetPeerAddressesResponse {
pub fn new(known_addresses: Vec<RpcPeerAddress>, banned_addresses: Vec<RpcPeerAddress>) -> Self {
Self { known_addresses, banned_addresses }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSelectedTipHashRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSelectedTipHashResponse {
pub selected_tip_hash: RpcHash,
}
impl GetSelectedTipHashResponse {
pub fn new(selected_tip_hash: RpcHash) -> Self {
Self { selected_tip_hash }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntryRequest {
pub transaction_id: RpcTransactionId,
pub include_orphan_pool: bool,
pub filter_transaction_pool: bool,
}
impl GetMempoolEntryRequest {
pub fn new(transaction_id: RpcTransactionId, include_orphan_pool: bool, filter_transaction_pool: bool) -> Self {
Self { transaction_id, include_orphan_pool, filter_transaction_pool }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntryResponse {
pub mempool_entry: RpcMempoolEntry,
}
impl GetMempoolEntryResponse {
pub fn new(mempool_entry: RpcMempoolEntry) -> Self {
Self { mempool_entry }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntriesRequest {
pub include_orphan_pool: bool,
pub filter_transaction_pool: bool,
}
impl GetMempoolEntriesRequest {
pub fn new(include_orphan_pool: bool, filter_transaction_pool: bool) -> Self {
Self { include_orphan_pool, filter_transaction_pool }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntriesResponse {
pub mempool_entries: Vec<RpcMempoolEntry>,
}
impl GetMempoolEntriesResponse {
pub fn new(mempool_entries: Vec<RpcMempoolEntry>) -> Self {
Self { mempool_entries }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetConnectedPeerInfoRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetConnectedPeerInfoResponse {
pub peer_info: Vec<RpcPeerInfo>,
}
impl GetConnectedPeerInfoResponse {
pub fn new(peer_info: Vec<RpcPeerInfo>) -> Self {
Self { peer_info }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct AddPeerRequest {
pub peer_address: RpcPeerAddress,
pub is_permanent: bool,
}
impl AddPeerRequest {
pub fn new(peer_address: RpcPeerAddress, is_permanent: bool) -> Self {
Self { peer_address, is_permanent }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct AddPeerResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SubmitTransactionRequest {
pub transaction: RpcTransaction,
pub allow_orphan: bool,
}
impl SubmitTransactionRequest {
pub fn new(transaction: RpcTransaction, allow_orphan: bool) -> Self {
Self { transaction, allow_orphan }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SubmitTransactionResponse {
pub transaction_id: RpcTransactionId,
}
impl SubmitTransactionResponse {
pub fn new(transaction_id: RpcTransactionId) -> Self {
Self { transaction_id }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSubnetworkRequest {
pub subnetwork_id: RpcSubnetworkId,
}
impl GetSubnetworkRequest {
pub fn new(subnetwork_id: RpcSubnetworkId) -> Self {
Self { subnetwork_id }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSubnetworkResponse {
pub gas_limit: u64,
}
impl GetSubnetworkResponse {
pub fn new(gas_limit: u64) -> Self {
Self { gas_limit }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetVirtualChainFromBlockRequest {
pub start_hash: RpcHash,
pub include_accepted_transaction_ids: bool,
}
impl GetVirtualChainFromBlockRequest {
pub fn new(start_hash: RpcHash, include_accepted_transaction_ids: bool) -> Self {
Self { start_hash, include_accepted_transaction_ids }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetVirtualChainFromBlockResponse {
pub removed_chain_block_hashes: Vec<RpcHash>,
pub added_chain_block_hashes: Vec<RpcHash>,
pub accepted_transaction_ids: Vec<RpcAcceptedTransactionIds>,
}
impl GetVirtualChainFromBlockResponse {
pub fn new(
removed_chain_block_hashes: Vec<RpcHash>,
added_chain_block_hashes: Vec<RpcHash>,
accepted_transaction_ids: Vec<RpcAcceptedTransactionIds>,
) -> Self {
Self { removed_chain_block_hashes, added_chain_block_hashes, accepted_transaction_ids }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlocksRequest {
pub low_hash: Option<RpcHash>,
pub include_blocks: bool,
pub include_transactions: bool,
}
impl GetBlocksRequest {
pub fn new(low_hash: Option<RpcHash>, include_blocks: bool, include_transactions: bool) -> Self {
Self { low_hash, include_blocks, include_transactions }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlocksResponse {
pub block_hashes: Vec<RpcHash>,
pub blocks: Vec<RpcBlock>,
}
impl GetBlocksResponse {
pub fn new(block_hashes: Vec<RpcHash>, blocks: Vec<RpcBlock>) -> Self {
Self { block_hashes, blocks }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockCountRequest {}
pub type GetBlockCountResponse = SyncInfo;
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockDagInfoRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBlockDagInfoResponse {
pub network_type: RpcNetworkType,
pub block_count: u64,
pub header_count: u64,
pub tip_hashes: Vec<RpcHash>,
pub difficulty: f64,
pub past_median_time: u64, pub virtual_parent_hashes: Vec<RpcHash>,
pub pruning_point_hash: RpcHash,
pub virtual_daa_score: u64,
}
impl GetBlockDagInfoResponse {
pub fn new(
network_type: RpcNetworkType,
block_count: u64,
header_count: u64,
tip_hashes: Vec<RpcHash>,
difficulty: f64,
past_median_time: u64,
virtual_parent_hashes: Vec<RpcHash>,
pruning_point_hash: RpcHash,
virtual_daa_score: u64,
) -> Self {
Self {
network_type,
block_count,
header_count,
tip_hashes,
difficulty,
past_median_time,
virtual_parent_hashes,
pruning_point_hash,
virtual_daa_score,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct ResolveFinalityConflictRequest {
pub finality_block_hash: RpcHash,
}
impl ResolveFinalityConflictRequest {
pub fn new(finality_block_hash: RpcHash) -> Self {
Self { finality_block_hash }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct ResolveFinalityConflictResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct ShutdownRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct ShutdownResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetHeadersRequest {
pub start_hash: RpcHash,
pub limit: u64,
pub is_ascending: bool,
}
impl GetHeadersRequest {
pub fn new(start_hash: RpcHash, limit: u64, is_ascending: bool) -> Self {
Self { start_hash, limit, is_ascending }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetHeadersResponse {
pub headers: Vec<RpcHeader>,
}
impl GetHeadersResponse {
pub fn new(headers: Vec<RpcHeader>) -> Self {
Self { headers }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBalanceByAddressRequest {
pub address: RpcAddress,
}
impl GetBalanceByAddressRequest {
pub fn new(address: RpcAddress) -> Self {
Self { address }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBalanceByAddressResponse {
pub balance: u64,
}
impl GetBalanceByAddressResponse {
pub fn new(balance: u64) -> Self {
Self { balance }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBalancesByAddressesRequest {
pub addresses: Vec<RpcAddress>,
}
impl GetBalancesByAddressesRequest {
pub fn new(addresses: Vec<RpcAddress>) -> Self {
Self { addresses }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetBalancesByAddressesResponse {
pub entries: Vec<RpcBalancesByAddressesEntry>,
}
impl GetBalancesByAddressesResponse {
pub fn new(entries: Vec<RpcBalancesByAddressesEntry>) -> Self {
Self { entries }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSinkBlueScoreRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetSinkBlueScoreResponse {
pub blue_score: u64,
}
impl GetSinkBlueScoreResponse {
pub fn new(blue_score: u64) -> Self {
Self { blue_score }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetUtxosByAddressesRequest {
pub addresses: Vec<RpcAddress>,
}
impl GetUtxosByAddressesRequest {
pub fn new(addresses: Vec<RpcAddress>) -> Self {
Self { addresses }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetUtxosByAddressesResponse {
pub entries: Vec<RpcUtxosByAddressesEntry>,
}
impl GetUtxosByAddressesResponse {
pub fn new(entries: Vec<RpcUtxosByAddressesEntry>) -> Self {
Self { entries }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct BanRequest {
pub address: RpcPeerAddress,
}
impl BanRequest {
pub fn new(address: RpcPeerAddress) -> Self {
Self { address }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct BanResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct UnbanRequest {
pub address: RpcPeerAddress,
}
impl UnbanRequest {
pub fn new(address: RpcPeerAddress) -> Self {
Self { address }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct UnbanResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct EstimateNetworkHashesPerSecondRequest {
pub window_size: u32,
pub start_hash: RpcHash,
}
impl EstimateNetworkHashesPerSecondRequest {
pub fn new(window_size: u32, start_hash: RpcHash) -> Self {
Self { window_size, start_hash }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct EstimateNetworkHashesPerSecondResponse {
pub network_hashes_per_second: u64,
}
impl EstimateNetworkHashesPerSecondResponse {
pub fn new(network_hashes_per_second: u64) -> Self {
Self { network_hashes_per_second }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntriesByAddressesRequest {
pub addresses: Vec<RpcAddress>,
pub include_orphan_pool: bool,
pub filter_transaction_pool: bool,
}
impl GetMempoolEntriesByAddressesRequest {
pub fn new(addresses: Vec<RpcAddress>, include_orphan_pool: bool, filter_transaction_pool: bool) -> Self {
Self { addresses, include_orphan_pool, filter_transaction_pool }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetMempoolEntriesByAddressesResponse {
pub entries: Vec<RpcMempoolEntryByAddress>,
}
impl GetMempoolEntriesByAddressesResponse {
pub fn new(entries: Vec<RpcMempoolEntryByAddress>) -> Self {
Self { entries }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetCoinSupplyRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetCoinSupplyResponse {
pub max_sompi: u64,
pub circulating_sompi: u64,
}
impl GetCoinSupplyResponse {
pub fn new(max_sompi: u64, circulating_sompi: u64) -> Self {
Self { max_sompi, circulating_sompi }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct PingRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetProcessMetricsRequest {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct GetProcessMetricsResponse {
pub uptime: u64,
pub memory_used: Vec<u64>,
pub storage_used: Vec<u64>,
pub grpc_connections: Vec<u64>,
pub wrpc_connections: Vec<u64>,
}
impl GetProcessMetricsResponse {
pub fn new(
uptime: u64,
memory_used: Vec<u64>,
storage_used: Vec<u64>,
grpc_connections: Vec<u64>,
wrpc_connections: Vec<u64>,
) -> Self {
Self { uptime, memory_used, storage_used, grpc_connections, wrpc_connections }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyBlockAddedRequest {
pub command: Command,
}
impl NotifyBlockAddedRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyBlockAddedResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockAddedNotification {
pub block: Arc<RpcBlock>,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyVirtualChainChangedRequest {
pub include_accepted_transaction_ids: bool,
pub command: Command,
}
impl NotifyVirtualChainChangedRequest {
pub fn new(include_accepted_transaction_ids: bool, command: Command) -> Self {
Self { include_accepted_transaction_ids, command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyVirtualChainChangedResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct VirtualChainChangedNotification {
pub removed_chain_block_hashes: Arc<Vec<RpcHash>>,
pub added_chain_block_hashes: Arc<Vec<RpcHash>>,
pub accepted_transaction_ids: Arc<Vec<RpcAcceptedTransactionIds>>,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyFinalityConflictRequest {
pub command: Command,
}
impl NotifyFinalityConflictRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyFinalityConflictResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct FinalityConflictNotification {
pub violating_block_hash: RpcHash,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyFinalityConflictResolvedRequest {
pub command: Command,
}
impl NotifyFinalityConflictResolvedRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyFinalityConflictResolvedResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct FinalityConflictResolvedNotification {
pub finality_block_hash: RpcHash,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyUtxosChangedRequest {
pub addresses: Vec<RpcAddress>,
pub command: Command,
}
impl NotifyUtxosChangedRequest {
pub fn new(addresses: Vec<RpcAddress>, command: Command) -> Self {
Self { addresses, command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyUtxosChangedResponse {}
#[derive(Clone, Debug, Default, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct UtxosChangedNotification {
pub added: Arc<Vec<RpcUtxosByAddressesEntry>>,
pub removed: Arc<Vec<RpcUtxosByAddressesEntry>>,
}
impl UtxosChangedNotification {
pub(crate) fn apply_utxos_changed_subscription(&self, subscription: &UtxosChangedSubscription) -> Option<Self> {
if subscription.to_all() {
Some(self.clone())
} else {
let added = Self::filter_utxos(&self.added, subscription);
let removed = Self::filter_utxos(&self.removed, subscription);
if added.is_empty() && removed.is_empty() {
None
} else {
Some(Self { added: Arc::new(added), removed: Arc::new(removed) })
}
}
}
fn filter_utxos(utxo_set: &[RpcUtxosByAddressesEntry], subscription: &UtxosChangedSubscription) -> Vec<RpcUtxosByAddressesEntry> {
utxo_set.iter().filter(|x| subscription.addresses().contains_key(&x.utxo_entry.script_public_key)).cloned().collect()
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifySinkBlueScoreChangedRequest {
pub command: Command,
}
impl NotifySinkBlueScoreChangedRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifySinkBlueScoreChangedResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SinkBlueScoreChangedNotification {
pub sink_blue_score: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyVirtualDaaScoreChangedRequest {
pub command: Command,
}
impl NotifyVirtualDaaScoreChangedRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyVirtualDaaScoreChangedResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct VirtualDaaScoreChangedNotification {
pub virtual_daa_score: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyPruningPointUtxoSetOverrideRequest {
pub command: Command,
}
impl NotifyPruningPointUtxoSetOverrideRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyPruningPointUtxoSetOverrideResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct PruningPointUtxoSetOverrideNotification {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyNewBlockTemplateRequest {
pub command: Command,
}
impl NotifyNewBlockTemplateRequest {
pub fn new(command: Command) -> Self {
Self { command }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NotifyNewBlockTemplateResponse {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct NewBlockTemplateNotification {}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct SubscribeResponse {
id: u64,
}
impl SubscribeResponse {
pub fn new(id: u64) -> Self {
Self { id }
}
}
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct UnsubscribeResponse {}