dont unwrao
This commit is contained in:
parent
ee7814b137
commit
d6a8968e4d
|
@ -14,6 +14,7 @@ use log::info;
|
|||
use jsonrpsee::{server::ServerBuilder, types::SubscriptionResult, SubscriptionSink};
|
||||
use solana_client::{
|
||||
nonblocking::{pubsub_client::PubsubClient, rpc_client::RpcClient, tpu_client::TpuClient},
|
||||
rpc_client::SerializableTransaction,
|
||||
rpc_config::{RpcContextConfig, RpcRequestAirdropConfig},
|
||||
rpc_response::{Response as RpcResponse, RpcBlockhash, RpcResponseContext, RpcVersionInfo},
|
||||
tpu_client::TpuClientConfig,
|
||||
|
@ -157,10 +158,6 @@ impl LiteBridge {
|
|||
|
||||
#[jsonrpsee::core::async_trait]
|
||||
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(
|
||||
&self,
|
||||
tx: String,
|
||||
|
@ -171,11 +168,21 @@ impl LiteRpcServer for LiteBridge {
|
|||
max_retries: _,
|
||||
} = 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)
|
||||
.unwrap()
|
||||
.signatures[0];
|
||||
let tx = match bincode::deserialize::<VersionedTransaction>(&raw_tx) {
|
||||
Ok(tx) => tx,
|
||||
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;
|
||||
|
||||
|
@ -216,16 +223,26 @@ impl LiteRpcServer for LiteBridge {
|
|||
let commitment = config.unwrap_or_default().commitment.unwrap_or_default();
|
||||
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 is_valid = self
|
||||
let is_valid = match self
|
||||
.tpu_client
|
||||
.rpc_client()
|
||||
.is_blockhash_valid(&blockhash, commitment)
|
||||
.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;
|
||||
|
||||
|
@ -276,15 +293,24 @@ impl LiteRpcServer for LiteBridge {
|
|||
lamports: u64,
|
||||
config: Option<RpcRequestAirdropConfig>,
|
||||
) -> 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
|
||||
.rpc_client()
|
||||
.request_airdrop_with_config(&pubkey, lamports, config.unwrap_or_default())
|
||||
.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
|
||||
.txs_sent
|
||||
|
@ -293,6 +319,10 @@ impl LiteRpcServer for LiteBridge {
|
|||
Ok(airdrop_sig)
|
||||
}
|
||||
|
||||
async fn get_metrics(&self) -> crate::rpc::Result<Metrics> {
|
||||
return Ok(self.metrics_capture.get_metrics().await);
|
||||
}
|
||||
|
||||
fn signature_subscribe(
|
||||
&self,
|
||||
mut sink: SubscriptionSink,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use jsonrpsee::core::Error;
|
||||
use jsonrpsee::proc_macros::rpc;
|
||||
use solana_client::rpc_config::{
|
||||
RpcContextConfig, RpcRequestAirdropConfig, RpcSignatureStatusConfig,
|
||||
|
@ -12,7 +11,7 @@ use crate::{
|
|||
workers::Metrics,
|
||||
};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type Result<T> = std::result::Result<T, jsonrpsee::core::Error>;
|
||||
|
||||
#[rpc(server)]
|
||||
pub trait LiteRpc {
|
||||
|
|
|
@ -108,7 +108,7 @@ impl BlockListener {
|
|||
commitment: Some(self.commitment_config),
|
||||
encoding: None,
|
||||
transaction_details: Some(
|
||||
solana_transaction_status::TransactionDetails::Full,
|
||||
solana_transaction_status::TransactionDetails::Accounts,
|
||||
),
|
||||
show_rewards: None,
|
||||
max_supported_transaction_version: None,
|
||||
|
@ -135,11 +135,6 @@ impl BlockListener {
|
|||
let Some(transactions) = block.transactions else {
|
||||
continue;
|
||||
};
|
||||
//
|
||||
// let Some(signatures) = block.signatures else {
|
||||
// info!("no signatures");
|
||||
// continue;
|
||||
// };
|
||||
|
||||
*self.latest_block_info.write().await = BlockInformation {
|
||||
slot,
|
||||
|
@ -147,8 +142,6 @@ impl BlockListener {
|
|||
block_height,
|
||||
};
|
||||
|
||||
// let mut transactions = transactions.into_iter();
|
||||
|
||||
for tx in transactions {
|
||||
let Some(UiTransactionStatusMeta { err, status, .. }) = tx.meta else {
|
||||
info!("tx with no meta");
|
||||
|
@ -182,8 +175,7 @@ impl BlockListener {
|
|||
api_version: None,
|
||||
},
|
||||
value: serde_json::json!({ "err": err }),
|
||||
})
|
||||
.unwrap();
|
||||
})?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue