Skip to content

Commit e2f1ff6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into await-InBlock
2 parents 094ed88 + 47edb70 commit e2f1ff6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/rpc/client.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn on_extrinsic_msg_until_finalized(
9696
debug!("got msg {}", retstr);
9797
match parse_status(retstr) {
9898
(XtStatus::Finalized, val) => end_process(out, result, val),
99-
(XtStatus::Error, _) => end_process(out, result, None),
99+
(XtStatus::Error, e) => end_process(out, result, e),
100100
(XtStatus::Future, _) => {
101101
warn!("extrinsic has 'future' status. aborting");
102102
end_process(out, result, None);
@@ -119,15 +119,20 @@ pub fn on_extrinsic_msg_until_ready(
119119
(XtStatus::InBlock, _) => end_process(out, result, None),
120120
(XtStatus::Broadcast, _) => end_process(out, result, None),
121121
(XtStatus::Future, _) => end_process(out, result, None),
122-
(XtStatus::Error, _) => end_process(out, result, None),
122+
(XtStatus::Error, e) => end_process(out, result, e),
123123
_ => (),
124124
};
125125
Ok(())
126126
}
127127

128128
fn end_process(out: Sender, result: ThreadOut<String>, value: Option<String>) {
129129
// return result to calling thread
130-
let val = value.unwrap_or_else(|| "nix".to_string());
130+
debug!(
131+
"Thread end result :{:?} value:{:?}",
132+
result.clone(),
133+
value.clone()
134+
);
135+
let val = value.unwrap();
131136
result.send(val).unwrap();
132137
out.close(CloseCode::Normal).unwrap();
133138
}
@@ -136,12 +141,13 @@ fn parse_status(msg: &str) -> (XtStatus, Option<String>) {
136141
let value: serde_json::Value = serde_json::from_str(msg).unwrap();
137142
match value["error"].as_object() {
138143
Some(obj) => {
144+
let error_message = obj.get("message").unwrap().as_str().unwrap().to_owned();
139145
error!(
140146
"extrinsic error code {}: {}",
141147
obj.get("code").unwrap().as_u64().unwrap(),
142-
obj.get("message").unwrap().as_str().unwrap()
148+
error_message.clone()
143149
);
144-
(XtStatus::Error, None)
150+
(XtStatus::Error, Some(error_message))
145151
}
146152
None => match value["params"]["result"].as_object() {
147153
Some(obj) => {
@@ -209,12 +215,15 @@ mod tests {
209215
);
210216

211217
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700,\"message\":\"Parse error\"},\"id\":null}";
212-
assert_eq!(parse_status(msg), (XtStatus::Error, None));
218+
assert_eq!(parse_status(msg), (XtStatus::Error, Some("Parse error".into())));
213219

214220
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1010,\"message\":\"Invalid Transaction\",\"data\":0},\"id\":\"4\"}";
215-
assert_eq!(parse_status(msg), (XtStatus::Error, None));
221+
assert_eq!(parse_status(msg), (XtStatus::Error, Some("Invalid Transaction".into())));
216222

217223
let msg = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1001,\"message\":\"Extrinsic has invalid format.\"},\"id\":\"0\"}";
218-
assert_eq!(parse_status(msg), (XtStatus::Error, None));
224+
assert_eq!(parse_status(msg), (XtStatus::Error, Some("Extrinsic has invalid format.".into())));
225+
226+
let msg = r#"{"jsonrpc":"2.0","error":{"code":1002,"message":"Verification Error: Execution(Wasmi(Trap(Trap { kind: Unreachable })))","data":"RuntimeApi(\"Execution(Wasmi(Trap(Trap { kind: Unreachable })))\")"},"id":"3"}"#;
227+
assert_eq!(parse_status(msg), (XtStatus::Error, Some("Verification Error: Execution(Wasmi(Trap(Trap { kind: Unreachable })))".into())));
219228
}
220229
}

0 commit comments

Comments
 (0)