Skip to content

Commit

Permalink
feat!: Remove logging
Browse files Browse the repository at this point in the history
This crate is a thin wrapper, which calls RPC. Thus logged data is available to the caller be it the error, result or data passed in.
  • Loading branch information
willemneal committed Dec 3, 2024
1 parent 208adfb commit 0f9c342
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ serde = "1.0.82"
serde_with = "3.9.0"
tokio = "1.28.1"
sha2 = "0.10.7"
tracing = "0.1.40"

# networking
jsonrpsee-http-client = "0.20.1"
Expand Down
28 changes: 6 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ impl Client {
}
let uri = Uri::from_parts(parts).map_err(Error::InvalidRpcUrlFromUriParts)?;
let base_url = Arc::from(uri.to_string());
tracing::trace!(?uri);
let headers = Self::default_http_headers();
let http_client = Arc::new(
HttpClientBuilder::default()
Expand Down Expand Up @@ -751,7 +750,6 @@ impl Client {
///
/// # Errors
pub async fn get_network(&self) -> Result<GetNetworkResponse, Error> {
tracing::trace!("Getting network");
Ok(self
.client()
.request("getNetwork", ObjectParams::new())
Expand All @@ -761,7 +759,6 @@ impl Client {
///
/// # Errors
pub async fn get_latest_ledger(&self) -> Result<GetLatestLedgerResponse, Error> {
tracing::trace!("Getting latest ledger");
Ok(self
.client()
.request("getLatestLedger", ObjectParams::new())
Expand All @@ -771,7 +768,6 @@ impl Client {
///
/// # Errors
pub async fn get_account(&self, address: &str) -> Result<AccountEntry, Error> {
tracing::trace!("Getting address {}", address);
let key = LedgerKey::Account(LedgerKeyAccount {
account_id: AccountId(PublicKey::PublicKeyTypeEd25519(Uint256(
stellar_strkey::ed25519::PublicKey::from_string(address)?.0,
Expand All @@ -786,7 +782,6 @@ impl Client {
let ledger_entry = &entries[0];
let mut read = Limited::new(ledger_entry.xdr.as_bytes(), Limits::none());
if let LedgerEntryData::Account(entry) = LedgerEntryData::read_xdr_base64(&mut read)? {
tracing::trace!(account=?entry);
Ok(entry)
} else {
Err(Error::InvalidResponse)
Expand All @@ -796,7 +791,6 @@ impl Client {
/// Send a transaction to the network and get back the hash of the transaction.
/// # Errors
pub async fn send_transaction(&self, tx: &TransactionEnvelope) -> Result<Hash, Error> {
tracing::trace!("Sending:\n{tx:#?}");
let mut oparams = ObjectParams::new();
oparams.insert("transaction", tx.to_xdr_base64(Limits::none())?)?;
let SendTransactionResponse {
Expand All @@ -822,9 +816,8 @@ impl Client {
))
.map_err(|_| Error::InvalidResponse)
})
.map(|r| r.result);
tracing::error!("TXN {hash} failed:\n {error:#?}");
return Err(Error::TransactionSubmissionFailed(format!("{:#?}", error?)));
.map(|r| r.result)?;
return Err(Error::TransactionSubmissionFailed(format!("{error:#?}")));
}
Ok(Hash::from_str(&hash)?)
}
Expand All @@ -845,15 +838,13 @@ impl Client {
&self,
tx: &TransactionEnvelope,
) -> Result<SimulateTransactionResponse, Error> {
tracing::trace!("Simulating:\n{tx:#?}");
let base64_tx = tx.to_xdr_base64(Limits::none())?;
let mut oparams = ObjectParams::new();
oparams.insert("transaction", base64_tx)?;
let sim_res = self
.client()
.request("simulateTransaction", oparams)
.await?;
tracing::trace!("Simulation response:\n {sim_res:#?}");
Ok(sim_res)
}

Expand Down Expand Up @@ -910,19 +901,15 @@ impl Client {
loop {
let response = self.get_transaction(tx_id).await?;
match response.status.as_str() {
"SUCCESS" => {
// TODO: the caller should probably be printing this
tracing::trace!("{response:#?}");
return Ok(response);
}
"SUCCESS" => return Ok(response),

"FAILED" => {
tracing::error!("{response:#?}");
// TODO: provide a more elaborate error
return Err(Error::TransactionSubmissionFailed(format!(
"{:#?}",
response.result
)));
)))
}

"NOT_FOUND" => (),
_ => {
return Err(Error::UnexpectedTransactionStatus(response.status));
Expand Down Expand Up @@ -966,12 +953,10 @@ impl Client {
.filter(|key| !matches!(key, LedgerKey::Ttl(_)))
.map(Clone::clone)
.collect::<Vec<_>>();
tracing::trace!("keys: {keys:#?}");
let GetLedgerEntriesResponse {
entries,
latest_ledger,
} = self.get_ledger_entries(&keys).await?;
tracing::trace!("raw: {entries:#?}");
let entries = entries
.unwrap_or_default()
.iter()
Expand All @@ -991,7 +976,6 @@ impl Client {
},
)
.collect::<Result<Vec<_>, Error>>()?;
tracing::trace!("parsed: {entries:#?}");
Ok(FullLedgerEntries {
entries,
latest_ledger,
Expand Down

0 comments on commit 0f9c342

Please sign in to comment.