Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Updated to use the --teach-me flag in the BOS program #389

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added error handler for blocking_call_view_function()
  • Loading branch information
FroVolod committed Aug 25, 2024
commit fbc6038c9d5e1a4468d37a9ab8c493f40ca93b0f
64 changes: 40 additions & 24 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ impl JsonRpcClientExt for near_jsonrpc_client::JsonRpcClient {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"I am making HTTP call to NEAR JSON RPC to call a read-only function {} on `{}` account, learn more https://docs.near.org/api/rpc/contracts#call-a-contract-function",
"I am making HTTP call to NEAR JSON RPC to call a read-only `{}` function on `{}` account, learn more https://docs.near.org/api/rpc/contracts#call-a-contract-function",
method_name,
account_id
);
Expand All @@ -2169,30 +2169,46 @@ impl JsonRpcClientExt for near_jsonrpc_client::JsonRpcClient {
indent_payload(&format!("{:#}", request_payload))
);

let query_view_method_response = self
.blocking_call(query_view_method_request)
.wrap_err("Failed to make a view-function call")?;

let call_result = query_view_method_response.call_result()?;
let query_view_method_response = match self.blocking_call(query_view_method_request) {
Ok(response) => response,
Err(err) => {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
indent_payload(&err.to_string())
);
color_eyre::eyre::bail!("Failed to make a view-function call.\n{err}")
}
};

tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
indent_payload(&format!(
"{{\n \"block_hash\": {}\n \"block_height\": {}\n \"logs\": {:?}\n \"result\": {:?}\n}}",
query_view_method_response.block_hash,
query_view_method_response.block_height,
call_result.logs,
call_result.result
))
);
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"Decoding the \"result\" array of bytes as UTF-8 string (tip: here is a Python snippet: `\"\".join([chr(c) for c in result])`):\n{}",
indent_payload(&String::from_utf8(call_result.result.clone()).unwrap_or_else(|_| "<decoding failed - the result is not a UTF-8 string>".to_owned()))
);
if let Ok(call_result) = query_view_method_response.call_result() {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
indent_payload(&format!(
"{{\n \"block_hash\": {}\n \"block_height\": {}\n \"logs\": {:?}\n \"result\": {:?}\n}}",
query_view_method_response.block_hash,
query_view_method_response.block_height,
call_result.logs,
call_result.result
))
);
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"Decoding the \"result\" array of bytes as UTF-8 string (tip: here is a Python snippet: `\"\".join([chr(c) for c in result])`):\n{}",
indent_payload(&String::from_utf8(call_result.result.clone()).unwrap_or_else(|_| "<decoding failed - the result is not a UTF-8 string>".to_owned()))
);
} else {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
indent_payload("Internal error: Received unexpected query kind in response to a view-function query call")
);
}

query_view_method_response.call_result()
}
Expand Down