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

fix!: add testnet create-tla exec details #309

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
32 changes: 5 additions & 27 deletions workspaces/src/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ use std::path::PathBuf;
use std::str::FromStr;

use async_trait::async_trait;
use near_gas::NearGas;
use url::Url;

use near_primitives::views::ExecutionStatusView;

use crate::network::builder::{FromNetworkBuilder, NetworkBuilder};
use crate::network::Info;
use crate::network::{AllowDevAccountCreation, NetworkClient, NetworkInfo, TopLevelAccountCreator};
use crate::result::{Execution, ExecutionDetails, ExecutionFinalResult, ExecutionOutcome, Result};
use crate::result::{Execution, ExecutionFinalResult, Result};
use crate::rpc::{client::Client, tool};
use crate::types::{AccountId, InMemorySigner, SecretKey};
use crate::{Account, Contract, CryptoHash, Network, Worker};
use crate::{Account, Contract, Network, Worker};

/// URL to the testnet RPC node provided by near.org.
pub const RPC_URL: &str = "https://rpc.testnet.near.org";
Expand Down Expand Up @@ -76,31 +73,12 @@ impl TopLevelAccountCreator for Testnet {
// TODO: return Account only, but then you don't get metadata info for it...
) -> Result<Execution<Account>> {
let url = Url::parse(HELPER_URL).unwrap();
tool::url_create_account(url, id.clone(), sk.public_key()).await?;
let signer = InMemorySigner::from_secret_key(id, sk);
let outcome = tool::url_create_account(url, id.clone(), sk.public_key()).await?;

let signer = InMemorySigner::from_secret_key(id, sk);
Ok(Execution {
result: Account::new(signer, worker),
details: ExecutionFinalResult {
// We technically have not burnt any gas ourselves since someone else paid to
// create the account for us in testnet when we used the Helper contract.
total_gas_burnt: NearGas::from_gas(0),

status: near_primitives::views::FinalExecutionStatus::SuccessValue(Vec::new()),
details: ExecutionDetails {
transaction: ExecutionOutcome {
transaction_hash: CryptoHash::default(),
block_hash: CryptoHash::default(),
logs: Vec::new(),
receipt_ids: Vec::new(),
gas_burnt: NearGas::from_gas(0),
tokens_burnt: 0,
executor_id: "testnet".parse().unwrap(),
status: ExecutionStatusView::SuccessValue(Vec::new()),
},
receipts: Vec::new(),
},
},
details: ExecutionFinalResult::from_view(outcome),
})
}

Expand Down
23 changes: 15 additions & 8 deletions workspaces/src/rpc/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rand::Rng;
use url::Url;

use near_crypto::SecretKey;
use near_primitives::views::StateItem;
use near_primitives::views::{FinalExecutionOutcomeView, StateItem};

use crate::error::{ErrorKind, RpcErrorCode};
use crate::result::Result;
Expand Down Expand Up @@ -39,12 +39,9 @@ pub(crate) async fn url_create_account(
helper_url: Url,
account_id: AccountId,
pk: PublicKey,
) -> Result<()> {
let helper_url = helper_url.join("account").unwrap();

// TODO(maybe): need this in near-jsonrpc-client as well:
let _resp = reqwest::Client::new()
.post(helper_url)
) -> Result<FinalExecutionOutcomeView> {
let response = reqwest::Client::new()
.post(helper_url.join("account").expect("helper url is valid"))
.header("Content-Type", "application/json")
.body(
serde_json::to_vec(&serde_json::json!({
Expand All @@ -57,7 +54,17 @@ pub(crate) async fn url_create_account(
.await
.map_err(|e| RpcErrorCode::HelperAccountCreationFailure.custom(e))?;

Ok(())
if response.status() >= reqwest::StatusCode::BAD_REQUEST {
RpcErrorCode::HelperAccountCreationFailure.custom(format!(
"The faucet (helper service) server failed with status code <{}>",
response.status()
));
}

response
.json::<FinalExecutionOutcomeView>()
.await
.map_err(|e| ErrorKind::DataConversion.custom(e))
}

pub(crate) fn write_cred_to_file(path: &Path, id: &AccountId, sk: &SecretKey) -> Result<()> {
Expand Down
Loading