dont unwrao

This commit is contained in:
aniketfuryrocks 2023-01-12 19:25:04 +05:30
parent ee7814b137
commit d6a8968e4d
No known key found for this signature in database
GPG Key ID: 61F3C528CE664FF3
3 changed files with 48 additions and 27 deletions

View File

@ -14,6 +14,7 @@ use log::info;
use jsonrpsee::{server::ServerBuilder, types::SubscriptionResult, SubscriptionSink}; use jsonrpsee::{server::ServerBuilder, types::SubscriptionResult, SubscriptionSink};
use solana_client::{ use solana_client::{
nonblocking::{pubsub_client::PubsubClient, rpc_client::RpcClient, tpu_client::TpuClient}, nonblocking::{pubsub_client::PubsubClient, rpc_client::RpcClient, tpu_client::TpuClient},
rpc_client::SerializableTransaction,
rpc_config::{RpcContextConfig, RpcRequestAirdropConfig}, rpc_config::{RpcContextConfig, RpcRequestAirdropConfig},
rpc_response::{Response as RpcResponse, RpcBlockhash, RpcResponseContext, RpcVersionInfo}, rpc_response::{Response as RpcResponse, RpcBlockhash, RpcResponseContext, RpcVersionInfo},
tpu_client::TpuClientConfig, tpu_client::TpuClientConfig,
@ -157,10 +158,6 @@ impl LiteBridge {
#[jsonrpsee::core::async_trait] #[jsonrpsee::core::async_trait]
impl LiteRpcServer for LiteBridge { impl LiteRpcServer for LiteBridge {
async fn get_metrics(&self) -> crate::rpc::Result<Metrics> {
return Ok(self.metrics_capture.get_metrics().await);
}
async fn send_transaction( async fn send_transaction(
&self, &self,
tx: String, tx: String,
@ -171,11 +168,21 @@ impl LiteRpcServer for LiteBridge {
max_retries: _, max_retries: _,
} = send_transaction_config.unwrap_or_default(); } = send_transaction_config.unwrap_or_default();
let raw_tx = encoding.decode(tx).unwrap(); let raw_tx = match encoding.decode(tx) {
Ok(raw_tx) => raw_tx,
Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
let sig = bincode::deserialize::<VersionedTransaction>(&raw_tx) let tx = match bincode::deserialize::<VersionedTransaction>(&raw_tx) {
.unwrap() Ok(tx) => tx,
.signatures[0]; Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
let sig = tx.get_signature();
self.tx_sender.enqnueue_tx(sig.to_string(), raw_tx).await; self.tx_sender.enqnueue_tx(sig.to_string(), raw_tx).await;
@ -216,16 +223,26 @@ impl LiteRpcServer for LiteBridge {
let commitment = config.unwrap_or_default().commitment.unwrap_or_default(); let commitment = config.unwrap_or_default().commitment.unwrap_or_default();
let commitment = CommitmentConfig { commitment }; let commitment = CommitmentConfig { commitment };
let blockhash = Hash::from_str(&blockhash).unwrap(); let blockhash = match Hash::from_str(&blockhash) {
Ok(blockhash) => blockhash,
Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
let block_listner = self.get_block_listner(commitment); let block_listner = self.get_block_listner(commitment);
let is_valid = self let is_valid = match self
.tpu_client .tpu_client
.rpc_client() .rpc_client()
.is_blockhash_valid(&blockhash, commitment) .is_blockhash_valid(&blockhash, commitment)
.await .await
.unwrap(); {
Ok(is_valid) => is_valid,
Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
let slot = block_listner.get_slot().await; let slot = block_listner.get_slot().await;
@ -276,15 +293,24 @@ impl LiteRpcServer for LiteBridge {
lamports: u64, lamports: u64,
config: Option<RpcRequestAirdropConfig>, config: Option<RpcRequestAirdropConfig>,
) -> crate::rpc::Result<String> { ) -> crate::rpc::Result<String> {
let pubkey = Pubkey::from_str(&pubkey_str).unwrap(); let pubkey = match Pubkey::from_str(&pubkey_str) {
Ok(pubkey) => pubkey,
Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
let airdrop_sig = self let airdrop_sig = match self
.tpu_client .tpu_client
.rpc_client() .rpc_client()
.request_airdrop_with_config(&pubkey, lamports, config.unwrap_or_default()) .request_airdrop_with_config(&pubkey, lamports, config.unwrap_or_default())
.await .await
.unwrap() {
.to_string(); Ok(airdrop_sig) => airdrop_sig.to_string(),
Err(err) => {
return Err(jsonrpsee::core::Error::Custom(err.to_string()));
}
};
self.tx_sender self.tx_sender
.txs_sent .txs_sent
@ -293,6 +319,10 @@ impl LiteRpcServer for LiteBridge {
Ok(airdrop_sig) Ok(airdrop_sig)
} }
async fn get_metrics(&self) -> crate::rpc::Result<Metrics> {
return Ok(self.metrics_capture.get_metrics().await);
}
fn signature_subscribe( fn signature_subscribe(
&self, &self,
mut sink: SubscriptionSink, mut sink: SubscriptionSink,

View File

@ -1,4 +1,3 @@
use jsonrpsee::core::Error;
use jsonrpsee::proc_macros::rpc; use jsonrpsee::proc_macros::rpc;
use solana_client::rpc_config::{ use solana_client::rpc_config::{
RpcContextConfig, RpcRequestAirdropConfig, RpcSignatureStatusConfig, RpcContextConfig, RpcRequestAirdropConfig, RpcSignatureStatusConfig,
@ -12,7 +11,7 @@ use crate::{
workers::Metrics, workers::Metrics,
}; };
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, jsonrpsee::core::Error>;
#[rpc(server)] #[rpc(server)]
pub trait LiteRpc { pub trait LiteRpc {

View File

@ -108,7 +108,7 @@ impl BlockListener {
commitment: Some(self.commitment_config), commitment: Some(self.commitment_config),
encoding: None, encoding: None,
transaction_details: Some( transaction_details: Some(
solana_transaction_status::TransactionDetails::Full, solana_transaction_status::TransactionDetails::Accounts,
), ),
show_rewards: None, show_rewards: None,
max_supported_transaction_version: None, max_supported_transaction_version: None,
@ -135,11 +135,6 @@ impl BlockListener {
let Some(transactions) = block.transactions else { let Some(transactions) = block.transactions else {
continue; continue;
}; };
//
// let Some(signatures) = block.signatures else {
// info!("no signatures");
// continue;
// };
*self.latest_block_info.write().await = BlockInformation { *self.latest_block_info.write().await = BlockInformation {
slot, slot,
@ -147,8 +142,6 @@ impl BlockListener {
block_height, block_height,
}; };
// let mut transactions = transactions.into_iter();
for tx in transactions { for tx in transactions {
let Some(UiTransactionStatusMeta { err, status, .. }) = tx.meta else { let Some(UiTransactionStatusMeta { err, status, .. }) = tx.meta else {
info!("tx with no meta"); info!("tx with no meta");
@ -182,8 +175,7 @@ impl BlockListener {
api_version: None, api_version: None,
}, },
value: serde_json::json!({ "err": err }), value: serde_json::json!({ "err": err }),
}) })?;
.unwrap();
} }
} }
} }