Ver código fonte

client: Ignore logs that are not base64 encoded (#1075)

Paul 3 anos atrás
pai
commit
064d8bb286
3 arquivos alterados com 12 adições e 3 exclusões
  1. 3 0
      client/Cargo.toml
  2. 1 1
      client/example/Cargo.toml
  3. 8 2
      client/src/lib.rs

+ 3 - 0
client/Cargo.toml

@@ -6,6 +6,9 @@ edition = "2018"
 license = "Apache-2.0"
 description = "Rust client for Anchor programs"
 
+[features]
+debug = []
+
 [dependencies]
 anchor-lang = { path = "../lang", version = "0.18.2" }
 anyhow = "1.0.32"

+ 1 - 1
client/example/Cargo.toml

@@ -7,7 +7,7 @@ edition = "2018"
 [workspace]
 
 [dependencies]
-anchor-client = { path = "../" }
+anchor-client = { path = "../", features = ["debug"] }
 basic-2 = { path = "../../examples/tutorial/basic-2/programs/basic-2", features = ["no-entrypoint"] }
 basic-4 = { path = "../../examples/tutorial/basic-4/programs/basic-4", features = ["no-entrypoint"] }
 composite = { path = "../../tests/composite/programs/composite", features = ["no-entrypoint"] }

+ 8 - 2
client/src/lib.rs

@@ -209,8 +209,14 @@ fn handle_program_log<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
     // Log emitted from the current program.
     if l.starts_with("Program log:") {
         let log = l.to_string().split_off("Program log: ".len());
-        let borsh_bytes = anchor_lang::__private::base64::decode(log)
-            .map_err(|_| ClientError::LogParseError(l.to_string()))?;
+        let borsh_bytes = match anchor_lang::__private::base64::decode(&log) {
+            Ok(borsh_bytes) => borsh_bytes,
+            _ => {
+                #[cfg(feature = "debug")]
+                println!("Could not base64 decode log: {}", log);
+                return Ok((None, None, false));
+            }
+        };
 
         let mut slice: &[u8] = &borsh_bytes[..];
         let disc: [u8; 8] = {