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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
name = "near-jsonrpc-client"
version = "0.20.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/near/near-jsonrpc-client-rs"
description = "Lower-level API for interfacing with the NEAR Protocol via JSONRPC"
categories = ["asynchronous", "api-bindings", "network-programming"]
keywords = ["near", "api", "jsonrpc", "rpc", "async"]
rust-version = "1.67.1"
rust-version = "1.85.0"

[dependencies]
log = "0.4.17"
Expand Down
2 changes: 1 addition & 1 deletion examples/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use near_jsonrpc_client::errors::{
JsonRpcError::ServerError, JsonRpcServerError::ResponseStatusError,
JsonRpcServerResponseStatusError::Unauthorized,
};
use near_jsonrpc_client::{auth, methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, auth, methods};
use near_primitives::types::{BlockReference, Finality};

mod utils;
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_change_method.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, methods};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_jsonrpc_primitives::types::transactions::{RpcTransactionError, TransactionInfo};
use near_primitives::gas::Gas;
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_change_method_commit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, methods};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_primitives::gas::Gas;
use near_primitives::transaction::{Action, FunctionCallAction, Transaction, TransactionV0};
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_view_method.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, methods};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_primitives::types::{BlockReference, Finality, FunctionArgs};
use near_primitives::views::QueryRequest;
Expand Down
6 changes: 4 additions & 2 deletions examples/create_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! This script is interactive.

use near_jsonrpc_client::methods::broadcast_tx_commit::RpcTransactionError;
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, methods};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_jsonrpc_primitives::types::transactions::TransactionInfo;
use near_primitives::gas::Gas;
Expand Down Expand Up @@ -164,7 +164,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if client.server_addr().ends_with("mainnet.near.org") {
"near".parse()?
} else {
Err("can only create non-sub accounts for mainnet / testnet\nconsider creating a sub-account instead")?
Err(
"can only create non-sub accounts for mainnet / testnet\nconsider creating a sub-account instead",
)?
};
(
TransactionV0 {
Expand Down
4 changes: 2 additions & 2 deletions examples/query_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn specify_block_reference() -> std::io::Result<near_primitives::types::Bloc
Ok(block_hash) => {
break Some(near_primitives::types::BlockReference::BlockId(
near_primitives::types::BlockId::Hash(block_hash),
))
));
}
_ => println!("(i) Invalid block hash, please reenter!"),
}
Expand All @@ -44,7 +44,7 @@ pub fn specify_block_reference() -> std::io::Result<near_primitives::types::Bloc
Ok(block_height) => {
break Some(near_primitives::types::BlockReference::BlockId(
near_primitives::types::BlockId::Height(block_height),
))
));
}
_ => println!("(i) Invalid block height, please reenter!"),
}
Expand Down
8 changes: 5 additions & 3 deletions examples/query_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn specify_block_reference() -> std::io::Result<near_primitives::types::Bloc
Ok(block_hash) => {
break Some(near_primitives::types::BlockReference::BlockId(
near_primitives::types::BlockId::Hash(block_hash),
))
));
}
_ => println!("(i) Invalid block hash, please reenter!"),
}
Expand All @@ -47,7 +47,7 @@ pub fn specify_block_reference() -> std::io::Result<near_primitives::types::Bloc
Ok(block_height) => {
break Some(near_primitives::types::BlockReference::BlockId(
near_primitives::types::BlockId::Height(block_height),
))
));
}
_ => println!("(i) Invalid block height, please reenter!"),
}
Expand Down Expand Up @@ -86,7 +86,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
for _ in 1..=3 {
let tx_hash: CryptoHash = get_valid_input("What transaction hash should we query", 3)?;
let account_id: AccountId = get_valid_input("What account signed this transaction", 3)?;
let wait_until_str = utils::input("Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ")?;
let wait_until_str = utils::input(
"Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ",
)?;
let wait_until = serde_json::from_value(serde_json::json!(wait_until_str))?;

match client
Expand Down
6 changes: 4 additions & 2 deletions examples/send_tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_client::{JsonRpcClient, methods};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_jsonrpc_primitives::types::transactions::{RpcTransactionError, TransactionInfo};
use near_primitives::gas::Gas;
Expand All @@ -17,7 +17,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let signer_account_id = utils::input("Enter the signer Account ID: ")?.parse()?;
let signer_secret_key = utils::input("Enter the signer's private key: ")?.parse()?;
let wait_until_str = utils::input("Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ")?;
let wait_until_str = utils::input(
"Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ",
)?;
let wait_until: TxExecutionStatus = serde_json::from_value(serde_json::json!(wait_until_str))?;

let signer = near_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key);
Expand Down
6 changes: 3 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<E: super::methods::RpcHandlerError> From<RpcError> for JsonRpcError<E> {
Ok(handler_error) => {
return JsonRpcError::ServerError(JsonRpcServerError::HandlerError(
handler_error,
))
));
}
Err(err) => {
handler_parse_error.replace(err);
Expand All @@ -140,7 +140,7 @@ impl<E: super::methods::RpcHandlerError> From<RpcError> for JsonRpcError<E> {
info: err["info"]["error_message"]
.as_str()
.map(|info| info.to_string()),
})
});
}
None => {}
}
Expand All @@ -149,7 +149,7 @@ impl<E: super::methods::RpcHandlerError> From<RpcError> for JsonRpcError<E> {
Some(Ok(handler_error)) => {
return JsonRpcError::ServerError(JsonRpcServerError::HandlerError(
handler_error,
))
));
}
Some(Err(err)) => {
handler_parse_error.replace(err);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl AsUrl for reqwest::Url {}

#[cfg(test)]
mod tests {
use crate::{methods, JsonRpcClient};
use crate::{JsonRpcClient, methods};

#[tokio::test]
async fn chk_status_testnet() {
Expand Down
2 changes: 1 addition & 1 deletion src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub use experimental::EXPERIMENTAL_validators_ordered;
#[cfg(feature = "any")]
mod any;
#[cfg(feature = "any")]
pub use any::{request as any, RpcAnyRequest};
pub use any::{RpcAnyRequest, request as any};
// ======== any ========

// ======== sandbox ========
Expand Down
6 changes: 3 additions & 3 deletions src/methods/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ mod tests {
matches!(
response_err.handler_error(),
Some(RpcQueryError::ContractExecutionError {
ref vm_error,
vm_error,
..
}) if vm_error.contains("MethodResolveError(MethodNotFound)")
),
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
matches!(
response_err.handler_error(),
Some(RpcQueryError::UnknownAccessKey {
ref public_key,
public_key,
block_height: 63503911,
..
}) if public_key.to_string() == "ed25519:9KnjTjL6vVoM8heHvCcTgLZ67FwFkiLsNtknFAVsVvYY"
Expand Down Expand Up @@ -368,7 +368,7 @@ mod tests {
matches!(
response_err.handler_error(),
Some(RpcQueryError::ContractExecutionError {
ref vm_error,
vm_error,
block_height: 63503911,
..
}) if vm_error.contains("MethodResolveError(MethodEmptyName)")
Expand Down