From 848f74fdeccf52e67fd13c6d7ced392a98fe1f8e Mon Sep 17 00:00:00 2001 From: Yin Guanhao Date: Mon, 28 Aug 2023 10:52:47 +0800 Subject: [PATCH] Warn when parsing packet cell fails --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 1 + src/search.rs | 23 ++++++++--------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c420e02..1d85599 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1136,6 +1136,7 @@ dependencies = [ "serde_with", "tiny-keccak", "tokio", + "tracing", ] [[package]] @@ -2769,9 +2770,21 @@ dependencies = [ "cfg-if 1.0.0", "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + [[package]] name = "tracing-core" version = "0.1.31" diff --git a/Cargo.toml b/Cargo.toml index 6148113..7887ee1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ serde = { version = "1.0.183", features = ["derive"] } serde_with = "3.2.0" tiny-keccak = { version = "2.0.2", features = ["keccak"] } tokio = { version = "1.31.0", features = ["time"] } +tracing = "0.1.37" [dev-dependencies] axon-types = { git = "https://github.com/axonweb3/axon-contract", rev = "8c2338a" } diff --git a/src/search.rs b/src/search.rs index c4ca0b2..4beebee 100644 --- a/src/search.rs +++ b/src/search.rs @@ -83,15 +83,6 @@ impl PacketCell { } } -macro_rules! or_continue { - ($e:expr) => { - match $e { - Ok(a) => a, - Err(_) => continue, - } - }; -} - async fn search_packet_cells( client: &CkbRpcClient, config: &Config, @@ -130,15 +121,17 @@ async fn search_packet_cells( let mut result = Vec::new(); for c in cells.objects { let tx = client - .get_transaction(c.out_point.tx_hash) + .get_transaction(c.out_point.tx_hash.clone()) .await? .transaction .context("get transaction")?; - let p = or_continue!(parse_packet_tx( - tx, - c.out_point.index.value() as usize, - config - )); + let p = match parse_packet_tx(tx, c.out_point.index.value() as usize, config) { + Ok(p) => p, + Err(e) => { + tracing::warn!("failed to parse packet tx {}: {e:#}", c.out_point.tx_hash); + continue; + } + }; result.push(p); } *cursor = Some(cells.last_cursor);