Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["api", "types"]
rust-version = "1.85"

[workspace.package]
edition = "2021"
edition = "2024"
version = "0.8.3"
authors = [
"akorchyn <artur.yurii.korchynskyi@gmail.com>",
Expand Down
4 changes: 2 additions & 2 deletions api/examples/account_key_pooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
/// This is an example of how to use account key pooling to send multiple transactions
/// using different keys.
use near_api::{
Account, NetworkConfig, Signer, Tokens,
signer::generate_secret_key,
types::{AccessKeyPermission, AccountId, NearToken},
Account, NetworkConfig, Signer, Tokens,
};
use near_sandbox::{
config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY},
GenesisAccount, SandboxConfig,
config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY},
};
use testresult::TestResult;

Expand Down
2 changes: 1 addition & 1 deletion api/examples/contract_source_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use near_api::{types::AccountId, Contract};
use near_api::{Contract, types::AccountId};
use testresult::TestResult;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion api/examples/create_account_and_send_near.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use near_api::{
Account, NetworkConfig, Signer, Tokens,
signer::generate_secret_key,
types::{AccountId, NearToken},
Account, NetworkConfig, Signer, Tokens,
};
use near_sandbox::config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY};
use testresult::TestResult;
Expand Down
2 changes: 1 addition & 1 deletion api/examples/deploy_and_call_method.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use near_api::{
types::{AccountId, Data},
Contract, NetworkConfig, Signer,
types::{AccountId, Data},
};
use near_sandbox::config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY};
use testresult::TestResult;
Expand Down
4 changes: 2 additions & 2 deletions api/examples/ft.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use near_api::{
types::{tokens::FTBalance, AccountId},
Contract, NetworkConfig, Signer, Tokens,
types::{AccountId, tokens::FTBalance},
};
use near_sandbox::{config::DEFAULT_GENESIS_ACCOUNT, GenesisAccount, SandboxConfig};
use near_sandbox::{GenesisAccount, SandboxConfig, config::DEFAULT_GENESIS_ACCOUNT};

use serde_json::json;
use testresult::TestResult;
Expand Down
2 changes: 1 addition & 1 deletion api/examples/global_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::{types::CryptoHash, Contract, NetworkConfig, Signer};
use near_api::{Contract, NetworkConfig, Signer, types::CryptoHash};
use near_sandbox::{GenesisAccount, SandboxConfig};

#[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions api/examples/nft.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use near_api::{
types::{nft::TokenMetadata, AccountId, NearToken},
Contract, NetworkConfig, Signer, Tokens,
types::{AccountId, NearToken, nft::TokenMetadata},
};
use near_sandbox::{
config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY},
GenesisAccount, SandboxConfig,
config::{DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY},
};
use serde_json::json;

Expand Down
2 changes: 1 addition & 1 deletion api/examples/sign_options.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::str::FromStr;

use near_api::{
Account, NetworkConfig, PublicKey, Signer,
signer::generate_seed_phrase_with_passphrase,
types::{AccessKeyPermission, AccountId},
Account, NetworkConfig, PublicKey, Signer,
};
use near_sandbox::config::{
DEFAULT_GENESIS_ACCOUNT, DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY,
Expand Down
2 changes: 1 addition & 1 deletion api/examples/specify_backup_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::{types::Reference, Chain, NetworkConfig, RPCEndpoint};
use near_api::{Chain, NetworkConfig, RPCEndpoint, types::Reference};

#[tokio::main]
async fn main() -> testresult::TestResult {
Expand Down
20 changes: 12 additions & 8 deletions api/examples/specifying_block.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
use near_api::{types::Reference, Chain};
use near_api::{Chain, types::Reference};

#[tokio::main]
async fn main() -> testresult::TestResult {
// Query latest block
let _block = Chain::block()
.at(Reference::Optimistic)
// Fetch a optimistic block
let _optimistic_block = Chain::block().fetch_from_mainnet().await?;

let block_number = Chain::block_number()
.at(Reference::Final)
.fetch_from_mainnet()
.await?;

let block_number = Chain::block_number().fetch_from_mainnet().await?;
let block_hash = Chain::block_hash().fetch_from_mainnet().await?;
let block_hash = Chain::block_hash()
.at(Reference::Final)
.fetch_from_mainnet()
.await?;

let _block = Chain::block()
let _block_by_number = Chain::block()
.at(Reference::AtBlock(block_number))
.fetch_from_mainnet()
.await?;

let _block = Chain::block()
let _block_by_hash = Chain::block()
.at(Reference::AtBlockHash(block_hash))
.fetch_from_mainnet()
.await?;
Expand Down
2 changes: 1 addition & 1 deletion api/examples/staking_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use near_api::{AccountId, NearToken, NetworkConfig, RPCEndpoint, Signer, Staking};
use near_sandbox::{
config::DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY, sandbox::patch::StateRecord, FetchData,
FetchData, config::DEFAULT_GENESIS_ACCOUNT_PRIVATE_KEY, sandbox::patch::StateRecord,
};

#[tokio::main]
Expand Down
6 changes: 3 additions & 3 deletions api/src/account/create.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::convert::Infallible;

use near_api_types::{
AccessKey, AccessKeyPermission, AccountId, Action, NearGas, NearToken, PublicKey,
transaction::{
actions::{AddKeyAction, CreateAccountAction, TransferAction},
PrepopulateTransaction,
actions::{AddKeyAction, CreateAccountAction, TransferAction},
},
AccessKey, AccessKeyPermission, AccountId, Action, NearGas, NearToken, PublicKey,
};
use reqwest::Response;
use serde_json::json;
use url::Url;

use crate::{
Contract, NetworkConfig,
common::send::Transactionable,
errors::{AccountCreationError, ArgumentValidationError, FaucetError, ValidationError},
transactions::{ConstructTransaction, TransactionWithSign},
Contract, NetworkConfig,
};

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion api/src/account/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use near_api_types::{
AccessKeyPermission, AccountId, Action, PublicKey, Reference,
json::U64,
transaction::actions::{AccessKey, AddKeyAction, DeleteAccountAction, DeleteKeyAction},
AccessKeyPermission, AccountId, Action, PublicKey, Reference,
};

use crate::advanced::{query_request::QueryRequest, query_rpc::SimpleQueryRpc};
Expand Down
6 changes: 3 additions & 3 deletions api/src/common/query/block_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use near_api_types::Reference;
use near_openapi_client::Client;
use near_openapi_client::types::{
BlockId, ErrorWrapperForRpcBlockError, Finality, JsonRpcRequestForBlock,
JsonRpcRequestForBlockMethod, JsonRpcResponseForRpcBlockResponseAndRpcBlockError,
RpcBlockError, RpcBlockRequest, RpcBlockResponse,
};
use near_openapi_client::Client;

use crate::common::utils::to_retry_error;
use crate::{
advanced::RpcType, common::utils::is_critical_blocks_error, config::RetryResponse,
errors::SendRequestError, NetworkConfig,
NetworkConfig, advanced::RpcType, common::utils::is_critical_blocks_error,
config::RetryResponse, errors::SendRequestError,
};

#[derive(Clone, Debug)]
Expand Down
10 changes: 5 additions & 5 deletions api/src/common/query/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use borsh::BorshDeserialize;
use near_api_types::{
json::U64, AccessKey, Account, AccountView, ContractCodeView, Data, PublicKey,
RpcBlockResponse, RpcValidatorResponse, ViewStateResult,
AccessKey, Account, AccountView, ContractCodeView, Data, PublicKey, RpcBlockResponse,
RpcValidatorResponse, ViewStateResult, json::U64,
};
use near_openapi_client::types::RpcQueryResponse;
use serde::de::DeserializeOwned;
Expand All @@ -10,10 +10,10 @@ use tracing::{info, trace, warn};

use crate::{
advanced::{
block_rpc::SimpleBlockRpc, query_rpc::SimpleQueryRpc, validator_rpc::SimpleValidatorRpc,
RpcType,
RpcType, block_rpc::SimpleBlockRpc, query_rpc::SimpleQueryRpc,
validator_rpc::SimpleValidatorRpc,
},
common::query::{ResultWithMethod, QUERY_EXECUTOR_TARGET},
common::query::{QUERY_EXECUTOR_TARGET, ResultWithMethod},
errors::QueryError,
};
pub mod transformers;
Expand Down
4 changes: 2 additions & 2 deletions api/src/common/query/handlers/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use tracing::trace;

use crate::{
advanced::{handlers::ResponseHandler, RpcType},
common::query::{ResultWithMethod, QUERY_EXECUTOR_TARGET},
advanced::{RpcType, handlers::ResponseHandler},
common::query::{QUERY_EXECUTOR_TARGET, ResultWithMethod},
errors::QueryError,
};

Expand Down
14 changes: 7 additions & 7 deletions api/src/common/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;
use tracing::{debug, error, info, instrument};

use crate::{
config::{retry, NetworkConfig, RetryResponse},
config::{NetworkConfig, RetryResponse, retry},
errors::{ArgumentValidationError, QueryError, SendRequestError},
};

Expand Down Expand Up @@ -172,9 +172,9 @@ where
pub fn and_then<MappedType>(
self,
map: impl Fn(Handler::Response) -> Result<MappedType, Box<dyn std::error::Error + Send + Sync>>
+ Send
+ Sync
+ 'static,
+ Send
+ Sync
+ 'static,
) -> MultiRpcBuilder<Query, AndThenHandler<MappedType, Handler>> {
MultiRpcBuilder {
handler: AndThenHandler::new(self.handler, map),
Expand Down Expand Up @@ -398,9 +398,9 @@ where
pub fn and_then<MappedType>(
self,
map: impl Fn(Handler::Response) -> Result<MappedType, Box<dyn std::error::Error + Send + Sync>>
+ Send
+ Sync
+ 'static,
+ Send
+ Sync
+ 'static,
) -> RpcBuilder<Query, AndThenHandler<MappedType, Handler>> {
RpcBuilder {
handler: AndThenHandler::new(self.handler, map),
Expand Down
4 changes: 2 additions & 2 deletions api/src/common/query/query_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use near_openapi_client::types::{
};

use crate::{
advanced::{query_request::QueryRequest, RpcType},
NetworkConfig,
advanced::{RpcType, query_request::QueryRequest},
common::utils::{is_critical_query_error, to_retry_error},
config::RetryResponse,
errors::SendRequestError,
NetworkConfig,
};
use near_api_types::Reference;

Expand Down
6 changes: 3 additions & 3 deletions api/src/common/query/validator_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use near_api_types::EpochReference;
use near_openapi_client::Client;
use near_openapi_client::types::{
BlockId, EpochId, ErrorWrapperForRpcValidatorError, JsonRpcRequestForValidators,
JsonRpcRequestForValidatorsMethod, JsonRpcResponseForRpcValidatorResponseAndRpcValidatorError,
RpcValidatorError, RpcValidatorRequest, RpcValidatorResponse,
};
use near_openapi_client::Client;

use crate::common::utils::to_retry_error;
use crate::errors::SendRequestError;
use crate::{
advanced::RpcType, common::utils::is_critical_validator_error, config::RetryResponse,
NetworkConfig,
NetworkConfig, advanced::RpcType, common::utils::is_critical_validator_error,
config::RetryResponse,
};

#[derive(Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions api/src/common/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use near_openapi_client::types::{
};

use near_api_types::{
BlockHeight, CryptoHash, Nonce, PublicKey, TxExecutionStatus,
transaction::{
PrepopulateTransaction, SignedTransaction,
delegate_action::{SignedDelegateAction, SignedDelegateActionAsBase64},
result::ExecutionFinalResult,
PrepopulateTransaction, SignedTransaction,
},
BlockHeight, CryptoHash, Nonce, PublicKey, TxExecutionStatus,
};
use reqwest::Response;
use tracing::{debug, info};

use crate::{
common::utils::{is_critical_transaction_error, to_retry_error},
config::{retry, NetworkConfig, RetryResponse},
config::{NetworkConfig, RetryResponse, retry},
errors::{
ArgumentValidationError, ExecuteMetaTransactionsError, ExecuteTransactionError,
MetaSignError, SendRequestError, SignerError, ValidationError,
Expand Down
2 changes: 1 addition & 1 deletion api/src/common/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// New errors can be added to the codebase, so we want to handle them gracefully
#![allow(unreachable_patterns)]

use base64::{prelude::BASE64_STANDARD, Engine};
use base64::{Engine, prelude::BASE64_STANDARD};
use near_api_types::NearToken;
use near_openapi_client::types::{
RpcBlockError, RpcQueryError, RpcTransactionError, RpcValidatorError,
Expand Down
4 changes: 2 additions & 2 deletions api/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::sync::Arc;

use borsh::BorshDeserialize;
use near_api_types::{
AccountId, Action, CryptoHash, Data, FunctionArgs, NearGas, NearToken, Reference, StoreKey,
contract::ContractSourceMetadata,
transaction::actions::{
DeployContractAction, DeployGlobalContractAction, FunctionCallAction,
GlobalContractDeployMode, GlobalContractIdentifier, UseGlobalContractAction,
},
AccountId, Action, CryptoHash, Data, FunctionArgs, NearGas, NearToken, Reference, StoreKey,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

use crate::{
advanced::{query_request::QueryRequest, query_rpc::SimpleQueryRpc},
Expand Down
2 changes: 1 addition & 1 deletion api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub use crate::{
tokens::Tokens,
transactions::Transaction,
types::{
tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
AccountId, CryptoHash, Data, EpochReference, NearGas, NearToken, PublicKey, Reference,
SecretKey,
tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
},
};

Expand Down
4 changes: 2 additions & 2 deletions api/src/signer/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use near_api_types::{
AccountId, BlockHeight, CryptoHash, Nonce, PublicKey, SecretKey, Signature,
crypto::KeyType,
transaction::{
delegate_action::{DelegateAction, NonDelegateAction, SignedDelegateAction},
PrepopulateTransaction, SignedTransaction, Transaction, TransactionV0,
delegate_action::{DelegateAction, NonDelegateAction, SignedDelegateAction},
},
AccountId, BlockHeight, CryptoHash, Nonce, PublicKey, SecretKey, Signature,
};
use slipped10::BIP32Path;
use tokio::sync::OnceCell;
Expand Down
Loading
Loading