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: Added the ability to use TEACH ME mode to create an account with a faucet service sponsor #407

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,30 @@ pub fn before_creating_account(
)))
};
tracing::Span::current().pb_set_message(faucet_service_url.as_str());
tracing::info!(target: "near_teach_me", "{}", faucet_service_url.as_str());
let mut data = std::collections::HashMap::new();
data.insert("newAccountId", new_account_id.to_string());
data.insert("newAccountPublicKey", public_key.to_string());

let client = reqwest::blocking::Client::new();
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"I am making HTTP call to create an account"
);
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"HTTP POST {}",
faucet_service_url.as_str()
);
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON Body:\n{}",
crate::common::indent_payload(&format!("{:#?}", data))
);

let result = client.post(faucet_service_url.clone()).json(&data).send();

print_account_creation_status(
Expand All @@ -107,6 +126,12 @@ fn print_account_creation_status(
eprintln!();
match result {
Ok(response) => {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
crate::common::indent_payload(&format!("{:#?}", response))
);
if response.status() >= reqwest::StatusCode::BAD_REQUEST {
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
return Err(color_eyre::Report::msg(format!(
Expand Down Expand Up @@ -163,6 +188,12 @@ fn print_account_creation_status(
Ok(())
}
Err(err) => {
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"JSON RPC Response:\n{}",
crate::common::indent_payload(&err.to_string())
);
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
Err(color_eyre::Report::msg(err.to_string()))
}
Expand Down
Loading