浏览代码

Revert "client: allow execution stack to have multiple program ids (#1954)" (#2282)

This reverts commit 52b32d24591bbda0d974adabe8112b1e679b2f05.
Henry-E 2 年之前
父节点
当前提交
686c97e45b
共有 1 个文件被更改,包括 14 次插入33 次删除
  1. 14 33
      client/src/lib.rs

+ 14 - 33
client/src/lib.rs

@@ -334,19 +334,21 @@ struct Execution {
 
 impl Execution {
     pub fn new(logs: &mut &[String]) -> Result<Self, ClientError> {
-        let re = Regex::new(r"^Program (.*) invoke.*$").unwrap();
-        let programs: Vec<String> = logs
-            .iter()
-            .filter_map(|l| re.captures(l))
-            .filter_map(|str| str.get(1))
-            .map(|matched_item| matched_item.as_str().to_string())
-            .collect();
-
-        if programs.is_empty() {
-            return Err(ClientError::MissingInvokeLogError());
-        }
+        let l = &logs[0];
+        *logs = &logs[1..];
 
-        Ok(Self { stack: programs })
+        let re = Regex::new(r"^Program (.*) invoke.*$").unwrap();
+        let c = re
+            .captures(l)
+            .ok_or_else(|| ClientError::LogParseError(l.to_string()))?;
+        let program = c
+            .get(1)
+            .ok_or_else(|| ClientError::LogParseError(l.to_string()))?
+            .as_str()
+            .to_string();
+        Ok(Self {
+            stack: vec![program],
+        })
     }
 
     pub fn program(&self) -> String {
@@ -384,8 +386,6 @@ pub enum ClientError {
     SolanaClientPubsubError(#[from] PubsubClientError),
     #[error("Unable to parse log: {0}")]
     LogParseError(String),
-    #[error("Program invoke log is missing")]
-    MissingInvokeLogError(),
 }
 
 /// `RequestBuilder` provides a builder interface to create and send
@@ -605,25 +605,6 @@ mod tests {
         );
     }
 
-    #[test]
-    fn new_execution_multiple_instruction() {
-        let mut logs: &[String] = &[
-            "Program 7Y8VDzehoewALqJfyxZYMgYCnMTCDhWuGfJKUvjYWATw invoke [1]".to_string(),
-            "Program 7y8vdZEHOEWalQjFYXzymGycNmtcdHwUgFjkuVJywatW invoke [1]".to_string(),
-        ];
-        let exe = Execution::new(&mut logs).unwrap();
-
-        assert!(exe.stack.len() == 2);
-        assert_eq!(
-            exe.stack[0],
-            "7Y8VDzehoewALqJfyxZYMgYCnMTCDhWuGfJKUvjYWATw".to_string()
-        );
-        assert_eq!(
-            exe.stack[1],
-            "7y8vdZEHOEWalQjFYXzymGycNmtcdHwUgFjkuVJywatW".to_string()
-        );
-    }
-
     #[test]
     fn handle_system_log_pop() {
         let log = "Program 7Y8VDzehoewALqJfyxZYMgYCnMTCDhWuGfJKUvjYWATw success";