Skip to content

Commit

Permalink
Merge branch 'main' into remove-using-tla-on-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKushnir1 authored Nov 1, 2024
2 parents adec38f + 10a6c1a commit d10894a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 46 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## [Unreleased]

## [0.14.1](https://github.com/near/near-workspaces-rs/compare/near-workspaces-v0.14.0...near-workspaces-v0.14.1) - 2024-10-18

### Fixed

- TransactionStatus::status should not be waiting for Final ([#379](https://github.com/near/near-workspaces-rs/pull/379))

### Other

- fix clippy 1.82 (doc preambles) ([#381](https://github.com/near/near-workspaces-rs/pull/381))
- bump cargo-near-build to 0.2.0 ([#380](https://github.com/near/near-workspaces-rs/pull/380))

## [0.14.0](https://github.com/near/near-workspaces-rs/compare/near-workspaces-v0.13.0...near-workspaces-v0.14.0) - 2024-09-12

### Other
Expand Down
1 change: 1 addition & 0 deletions examples/src/croncat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum AgentStatus {

/// `Agent` struct taken from [croncat repo](github.com/CronCats/contracts/) to deserialize
/// into after we get the result of a transaction and converting over to this particular type.
///
/// Helpful for understanding what our output is from a contract call. For a more in depth
/// look at what an `Agent` is all about, refer to the [croncat docs](https://docs.cron.cat/docs/)
/// to understand further, but for this example all we care about is that an Agent is something
Expand Down
4 changes: 2 additions & 2 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-workspaces"
version = "0.14.0"
version = "0.14.1"
edition = "2018"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -14,7 +14,7 @@ async-trait = "0.1"
base64 = "0.22"
bs58 = "0.5"
cargo_metadata = { version = "0.18", optional = true }
cargo-near-build = { version = "0.1.0" }
cargo-near-build = { version = "0.2.0" }
chrono = "0.4.19"
fs2 = "0.4"
rand = "0.8.4"
Expand Down
5 changes: 3 additions & 2 deletions workspaces/src/network/betanet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use std::path::PathBuf;
/// URL to the betanet RPC node provided by near.org.
pub const RPC_URL: &str = "https://rpc.betanet.near.org";

/// Betanet related configuration for interacting with betanet. Look at
/// [`workspaces::betanet`] for how to spin up a [`Worker`] that can be
/// Betanet related configuration for interacting with betanet.
///
/// Look at [`workspaces::betanet`] for how to spin up a [`Worker`] that can be
/// used to interact with betanet. Note that betanet account creation
/// is not currently supported, and these calls into creating a betanet
/// worker is meant for retrieving data and/or making queries only.
Expand Down
5 changes: 3 additions & 2 deletions workspaces/src/network/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ pub const RPC_URL: &str = "https://rpc.mainnet.near.org";
/// URL to the mainnet archival RPC node provided by near.org.
pub const ARCHIVAL_URL: &str = "https://archival-rpc.mainnet.near.org";

/// Mainnet related configuration for interacting with mainnet. Look at
/// [`workspaces::mainnet`] and [`workspaces::mainnet_archival`] for how to
/// Mainnet related configuration for interacting with mainnet.
///
/// Look at [`workspaces::mainnet`] and [`workspaces::mainnet_archival`] for how to
/// spin up a [`Worker`] that can be used to interact with mainnet. Note that
/// mainnet account creation is not currently supported, and these calls into
/// creating a mainnet worker is meant for retrieving data and/or making
Expand Down
4 changes: 3 additions & 1 deletion workspaces/src/network/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use crate::{Account, Contract, Network, Worker};

// Constant taken from nearcore crate to avoid dependency
const DEFAULT_DEPOSIT: NearToken = NearToken::from_near(100);
/// Local sandboxed environment/network, which can be used to test without interacting with
/// Local sandboxed environment/network
///
/// Can be used to test without interacting with
/// networks that are online such as mainnet and testnet. Look at [`workspaces::sandbox`]
/// for how to spin up a sandboxed network and interact with it.
///
Expand Down
5 changes: 3 additions & 2 deletions workspaces/src/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ pub const HELPER_URL: &str = "https://helper.testnet.near.org";
/// URL to the testnet archival RPC node provided by near.org.
pub const ARCHIVAL_URL: &str = "https://archival-rpc.testnet.near.org";

/// Testnet related configuration for interacting with testnet. Look at
/// [`workspaces::testnet`] and [`workspaces::testnet_archival`] for how
/// Testnet related configuration for interacting with testnet.
///
/// Look at [`workspaces::testnet`] and [`workspaces::testnet_archival`] for how
/// to spin up a [`Worker`] that can be used to run tests in testnet.
///
/// [`workspaces::testnet`]: crate::testnet
Expand Down
46 changes: 31 additions & 15 deletions workspaces/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use near_primitives::transaction::{
Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction,
DeployContractAction, FunctionCallAction, StakeAction, TransferAction,
};
use near_primitives::views::FinalExecutionOutcomeView;
use near_primitives::views::{FinalExecutionOutcomeView, TxExecutionStatus};
use std::convert::TryInto;
use std::fmt;
use std::future::IntoFuture;
Expand Down Expand Up @@ -105,7 +105,9 @@ impl Function {
}

/// A builder-like object that will allow specifying various actions to be performed
/// in a single transaction. For details on each of the actions, find them in
/// in a single transaction.
///
/// For details on each of the actions, find them in
/// [NEAR transactions](https://docs.near.org/docs/concepts/transaction).
///
/// All actions are performed on the account specified by `receiver_id`. This object
Expand Down Expand Up @@ -513,30 +515,44 @@ impl TransactionStatus {
/// is in an unexpected state. The error should have further context. Otherwise, if an
/// `Ok` value with [`Poll::Pending`] is returned, then the transaction has not finished.
pub async fn status(&self) -> Result<Poll<ExecutionFinalResult>> {
let result = self
let rpc_resp = self
.worker
.client()
.tx_async_status(
&self.sender_id,
near_primitives::hash::CryptoHash(self.hash.0),
near_primitives::views::TxExecutionStatus::Final,
TxExecutionStatus::Included,
)
.await
.map(|o| {
o.final_execution_outcome
.map(|e| ExecutionFinalResult::from_view(e.into_outcome()))
});

match result {
Ok(Some(result)) => Ok(Poll::Ready(result)),
Ok(None) => Ok(Poll::Pending),
.await;

let rpc_resp = match rpc_resp {
Ok(rpc_resp) => rpc_resp,
Err(err) => match err {
JsonRpcError::ServerError(JsonRpcServerError::HandlerError(
RpcTransactionError::UnknownTransaction { .. },
)) => Ok(Poll::Pending),
other => Err(RpcErrorCode::BroadcastTxFailure.custom(other)),
)) => return Ok(Poll::Pending),
other => return Err(RpcErrorCode::BroadcastTxFailure.custom(other)),
},
};

if matches!(rpc_resp.final_execution_status, TxExecutionStatus::Included) {
return Ok(Poll::Pending);
}

let Some(final_outcome) = rpc_resp.final_execution_outcome else {
// final execution outcome is not available yet.
return Ok(Poll::Pending);
};

let outcome = final_outcome.into_outcome();

match outcome.status {
near_primitives::views::FinalExecutionStatus::NotStarted => return Ok(Poll::Pending),
near_primitives::views::FinalExecutionStatus::Started => return Ok(Poll::Pending),
_ => (),
}

Ok(Poll::Ready(ExecutionFinalResult::from_view(outcome)))
}

/// Wait until the completion of the transaction by polling [`TransactionStatus::status`].
Expand Down
5 changes: 4 additions & 1 deletion workspaces/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use crate::types::{CryptoHash, Gas, NearToken};
pub type Result<T, E = crate::error::Error> = core::result::Result<T, E>;

/// Execution related info as a result of performing a successful transaction
/// execution on the network. This value can be converted into the returned
/// execution on the network.
///
/// This value can be converted into the returned
/// value of the transaction via [`ExecutionSuccess::json`] or [`ExecutionSuccess::borsh`]
pub type ExecutionSuccess = ExecutionResult<Value>;

Expand All @@ -29,6 +31,7 @@ pub type ExecutionSuccess = ExecutionResult<Value>;
pub type ExecutionFailure = ExecutionResult<TxExecutionError>;

/// Struct to hold a type we want to return along w/ the execution result view.
///
/// This view has extra info about the execution, such as gas usage and whether
/// the transaction failed to be processed on the chain.
#[non_exhaustive]
Expand Down
7 changes: 4 additions & 3 deletions workspaces/src/rpc/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::types::{BlockHeight, KeyType, PublicKey, SecretKey};
use crate::{AccessKey, AccountDetailsPatch, Result};
use crate::{AccountId, Contract, CryptoHash, InMemorySigner, Network, Worker};

/// A [`Transaction`]-like object that allows us to specify details about importing
/// a contract from a different network into our sandbox local network. This creates
/// a new [`Transaction`] to be committed to the sandbox network once `transact()`
/// A [`Transaction`]-like object with details about importing a contract from a network
/// into sandbox local network.
///
/// This creates a new [`Transaction`] to be committed to the sandbox network once `transact()`
/// has been called. This does not commit any new transactions from the network
/// this object is importing from.
///
Expand Down
24 changes: 13 additions & 11 deletions workspaces/src/rpc/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! This module defines a bunch of internal types used solely for querying into RPC
//! methods to retrieve info about what's on the chain. Note that the types defined
//! are exposed as-is for users to reference in their own functions or structs as
//! needed. These types cannot be created outside of workspaces. To use them, refer
//! to surface level types like [`Account`], [`Contract`] and [`Worker`].
//! This module defines a bunch of internal types used solely for querying into
//! RPC methods to get info about what's on the chain.
//!
//! Note that the types defined are exposed as-is for users to reference in their own
//! functions or structs as needed. These types cannot be created outside of workspaces.
//! To use them, refer to surface level types like [`Account`], [`Contract`] and [`Worker`].
//!
//! For example, to query into downloading contract state:
//! ```
Expand Down Expand Up @@ -133,9 +134,10 @@ where
}

// Note: this trait is exposed publicly due to constraining with the impl offering `finality`.
/// Trait used as a converter from WorkspaceRequest to near-rpc request, and from near-rpc
/// response to a WorkspaceResult. Mostly used internally to facilitate syntax sugar for performing
/// RPC requests with async builders.
/// Trait used as a converter from WorkspaceRequest to near-rpc request,
/// and from near-rpc response to a WorkspaceResult.
///
/// Mostly used internally to facilitate syntax sugar for performing RPC requests with async builders.
pub trait ProcessQuery {
// TODO: associated default type is unstable. So for now, will require writing
// the manual impls for query_request
Expand Down Expand Up @@ -401,10 +403,10 @@ impl ProcessQuery for GasPrice {
}
}

/// Query object used to query for chunk related details at a specific `ChunkReference` which
/// consists of either a chunk [`CryptoHash`], or a `BlockShardId` (which consists of [`ShardId`]
/// and either block [`CryptoHash`] or [`BlockHeight`]).
/// Query object to query for chunk related details at a specific `ChunkReference` which
/// consists of either a chunk [`CryptoHash`], or a `BlockShardId`.
///
/// `BlockShardId` consists of [`ShardId`] and either block [`CryptoHash`] or [`BlockHeight`]
/// The default behavior where a `ChunkReference` is not supplied will use a `BlockShardId`
/// referencing the latest block `CryptoHash` with `ShardId` of 0.
pub struct QueryChunk<'a> {
Expand Down
8 changes: 6 additions & 2 deletions workspaces/src/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::operations::{CallTransaction, CreateAccountTransaction, Transaction};
use crate::result::{Execution, ExecutionFinalResult, Result};

/// `Account` is directly associated to an account in the network provided by the
/// [`Worker`] that creates it. This type offers methods to interact with any
/// [`Worker`] that creates it.
///
/// This type offers methods to interact with any
/// network, such as creating transactions and calling into contract functions.
#[derive(Clone)]
pub struct Account {
Expand Down Expand Up @@ -201,7 +203,9 @@ impl Account {
}

/// `Contract` is directly associated to a contract in the network provided by the
/// [`Worker`] that creates it. This type offers methods to interact with any
/// [`Worker`] that creates it.
///
/// This type offers methods to interact with any
/// network, such as creating transactions and calling into contract functions.
#[derive(Clone)]
pub struct Contract {
Expand Down
13 changes: 10 additions & 3 deletions workspaces/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Types used in the workspaces crate. A lot of these are types are copied over from near_primitives
//! Types used in the workspaces crate.
//!
//! A lot of these are types are copied over from near_primitives
//! since those APIs are not yet stable. Once they are, we can directly reference them here, so no
//! changes on the library consumer side is needed. Just keep using these types defined here as-is.
Expand Down Expand Up @@ -222,7 +224,9 @@ impl BorshDeserialize for PublicKey {
}
}

/// Secret key of an account on chain. Usually created along with a [`PublicKey`]
/// Secret key of an account on chain.
///
/// Usually created along with a [`PublicKey`]
/// to form a keypair associated to the account. To generate a new keypair, use
/// one of the creation methods found here, such as [`SecretKey::from_seed`]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -367,7 +371,9 @@ impl From<near_primitives::hash::CryptoHash> for CryptoHash {
}
}

/// Access key provides limited access to an account. Each access key belongs to some account and
/// Access key provides limited access to an account.
///
/// Each access key belongs to some account and
/// is identified by a unique (within the account) public key. One account may have large number of
/// access keys. Access keys allow to act on behalf of the account by restricting transactions
/// that can be issued.
Expand Down Expand Up @@ -434,6 +440,7 @@ pub enum AccessKeyPermission {
}

/// Grants limited permission to make transactions with FunctionCallActions
///
/// The permission can limit the allowed balance to be spent on the prepaid gas.
/// It also restrict the account ID of the receiver for this function call.
/// It also can restrict the method name for the allowed function calls.
Expand Down
6 changes: 4 additions & 2 deletions workspaces/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use crate::network::{Betanet, Custom, Mainnet, Sandbox, Testnet};
use crate::types::gas_meter::GasHook;
use crate::{Network, Result};

/// The `Worker` type allows us to interact with any NEAR related networks, such
/// as mainnet and testnet. This controls where the environment the worker is
/// The `Worker` type allows us to interact with any NEAR related networks,
/// such as mainnet and testnet.
///
/// This controls where the environment the worker is
/// running on top of it. Refer to this for all network related actions such as
/// deploying a contract, or interacting with transactions.
pub struct Worker<T: ?Sized> {
Expand Down

0 comments on commit d10894a

Please sign in to comment.