Skip to content

Commit

Permalink
Proxy changes (#13)
Browse files Browse the repository at this point in the history
* RPC Responses can now be Serialized, Added Client Cert to Header to help with situations where fullnode is behind a proxy
  • Loading branch information
DaOneLuna authored Aug 9, 2023
1 parent 88fe03e commit 5271672
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
1 change: 1 addition & 0 deletions clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ serde_json = "1.0.89"
time = "0.3.21"
tokio = {version = "1.21.2", features=["rt-multi-thread", "sync", "signal", "macros", "process", "time", "fs", "net"]}
tokio-tungstenite = {version = "0.20.0", features = ["rustls-tls-webpki-roots", "rustls"] }
urlencoding = "2.1.3"
uuid = {version="1.2.2", features=["v4"]}
50 changes: 25 additions & 25 deletions clients/src/api/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,108 +12,108 @@ use dg_xch_core::blockchain::unfinished_block::UnfinishedBlock;
use dg_xch_core::blockchain::wallet_balance::WalletBalance;
use dg_xch_core::blockchain::wallet_info::WalletInfo;

use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AdditionsAndRemovalsResp {
pub additions: Vec<CoinRecord>,
pub removals: Vec<CoinRecord>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BlockchainStateResp {
pub blockchain_state: BlockchainState,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BlockRecordResp {
pub block_record: BlockRecord,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BlockRecordAryResp {
pub block_records: Vec<BlockRecord>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CoinRecordResp {
pub coin_record: Option<CoinRecord>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CoinRecordAryResp {
pub coin_records: Vec<CoinRecord>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CoinSpendResp {
pub coin_solution: CoinSpend,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FullBlockResp {
pub block: FullBlock,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FullBlockAryResp {
pub blocks: Vec<FullBlock>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct InitialFreezePeriodResp {
pub initial_freeze_end_timestamp: u64,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LoginResp {
pub fingerprint: u32,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MempoolItemResp {
pub mempool_item: MempoolItem,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MempoolItemsResp {
pub mempool_items: HashMap<String, MempoolItem>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MempoolTXResp {
pub tx_ids: Vec<String>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct NetworkInfoResp {
pub network_name: String,
pub network_prefix: String,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct NetSpaceResp {
pub space: u64,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SignagePointOrEOSResp {
pub signage_point: Option<SignagePoint>,
pub eos: Option<SubSlotBundle>,
Expand All @@ -122,43 +122,43 @@ pub struct SignagePointOrEOSResp {
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SignedTransactionRecordResp {
pub signed_tx: TransactionRecord,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct TXResp {
pub status: TXStatus,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct TransactionRecordResp {
pub transaction: TransactionRecord,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UnfinishedBlockAryResp {
pub headers: Vec<UnfinishedBlock>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct WalletBalanceResp {
pub wallets: Vec<WalletBalance>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct WalletInfoResp {
pub wallets: Vec<WalletInfo>,
pub success: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct WalletSyncResp {
pub genesis_initialized: bool,
pub synced: bool,
Expand Down
16 changes: 16 additions & 0 deletions clients/src/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::{
connect_async_tls_with_config, Connector, MaybeTlsStream, WebSocketStream,
};
use urlencoding::encode;
use uuid::Uuid;

pub async fn await_termination() -> Result<(), Error> {
Expand Down Expand Up @@ -151,6 +152,21 @@ pub async fn get_client_generated_tls(
format!("Failed to Parse Request: {}", e),
)
})?;
request.headers_mut().insert(
HeaderName::from_str("chia-client-cert").map_err(|e| {
Error::new(
ErrorKind::InvalidData,
format!("Failed to Parse Header Name chia-client-cert,\r\n {}", e),
)
})?,
HeaderValue::from_str(encode(&String::from_utf8(cert_bytes).unwrap_or_default()).as_ref())
.map_err(|e| {
Error::new(
ErrorKind::InvalidData,
format!("Failed to Parse Header value CHIA_CA_CRT,\r\n {}", e),
)
})?,
);
if let Some(m) = additional_headers {
for (k, v) in m {
request.headers_mut().insert(
Expand Down

0 comments on commit 5271672

Please sign in to comment.