Skip to content

Commit

Permalink
Merge branch 'master' into feature/docs/crate-level-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Dec 26, 2023
2 parents 544b6c0 + fb0be84 commit ea99eff
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 94 deletions.
55 changes: 0 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,61 +34,6 @@ println!("{:?}", tx_status);

Check out [`the examples folder`](https://github.com/near/near-jsonrpc-client-rs/tree/master/examples) for a comprehensive list of helpful demos. You can run the examples with `cargo`. For example: `cargo run --example view_account`.

For all intents and purposes, the predefined structures in `methods` should suffice, if you find that they
don't or you crave extra flexibility, well, you can opt in to use the generic constructor `methods::any()` with the `any` feature flag.

In this example, we retrieve only the parts from the genesis config response that we care about.

```toml
# in Cargo.toml
near-jsonrpc-client = { ..., features = ["any"] }
```

```rust
use serde::Deserialize;
use serde_json::json;

use near_jsonrpc_client::{methods, JsonRpcClient};
use near_primitives::serialize::dec_format;
use near_primitives::types::*;

#[derive(Debug, Deserialize)]
struct PartialGenesisConfig {
protocol_version: ProtocolVersion,
chain_id: String,
genesis_height: BlockHeight,
epoch_length: BlockHeightDelta,
#[serde(with = "dec_format")]
min_gas_price: Balance,
#[serde(with = "dec_format")]
max_gas_price: Balance,
#[serde(with = "dec_format")]
total_supply: Balance,
validators: Vec<AccountInfo>,
}

impl methods::RpcHandlerResponse for PartialGenesisConfig {}

let mainnet_client = JsonRpcClient::connect("https://rpc.mainnet.near.org");

let genesis_config_request = methods::any::<Result<PartialGenesisConfig, ()>>(
"EXPERIMENTAL_genesis_config",
json!(null),
);

let partial_genesis = mainnet_client.call(genesis_config_request).await?;

println!("{:#?}", partial_genesis);
```

By default, `near-jsonrpc-client` uses `native-tls`. On Linux, this introduces a dependency on the system `openssl` library. In some situations, for example when cross-compiling, it can be problematic to depend on non-Rust libraries.

If you wish to switch to an all-Rust TLS implementation, you may do so using the `rustls-tls` feature flag. Note that the `native-tls` feature is enabled by default. Therefore, to disable it and use `rustls-tls` instead, you must also use `default-features = false`. The default `auth` feature must then be declared explicitly.

```toml
# in Cargo.toml
near-jsonrpc-client = { ..., default-features = false, features = ["auth","rustls-tls"] }
```

## Releasing

Expand Down
8 changes: 4 additions & 4 deletions src/methods/broadcast_tx_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//!
//! A full example on how to use `broadcast_tx_async` method can be found at [`contract_change_method`](https://github.com/near/near-jsonrpc-client-rs/blob/master/examples/contract_change_method.rs).
//!
//! ```
//! ```no_run
//! use near_jsonrpc_client::{methods, JsonRpcClient};
//! use near_primitives::types::{AccountId};
//! use near_primitives::transaction::{Action, FunctionCallAction, Transaction};
Expand All @@ -17,7 +17,7 @@
//! use serde_json::json;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let signer_account_id = "fido.testnet".parse::<AccountId>()?;
Expand All @@ -34,7 +34,7 @@
//! nonce: 10223934 + 1,
//! receiver_id: "nosedive.testnet".parse::<AccountId>()?,
//! block_hash: "AUDcb2iNUbsmCsmYGfGuKzyXKimiNcCZjBKTVsbZGnoH".parse()?,
//! actions: vec![Action::FunctionCall(FunctionCallAction {
//! actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
//! method_name: "rate".to_string(),
//! args: json!({
//! "account_id": other_account,
Expand All @@ -44,7 +44,7 @@
//! .into_bytes(),
//! gas: 100_000_000_000_000, // 100 TeraGas
//! deposit: 0,
//! })],
//! }))],
//! };
//!
//! let request = methods::broadcast_tx_async::RpcBroadcastTxAsyncRequest {
Expand Down
14 changes: 7 additions & 7 deletions src/methods/broadcast_tx_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
//!
//! ## Example
//!
//! ```
//! ```no_run
//! use near_jsonrpc_client::{methods, JsonRpcClient};
//! use near_jsonrpc_primitives::types::{query::QueryResponseKind, transactions::TransactionInfo};
//! use near_primitives::types::{AccountId, BlockReference};
//! use near_primitives::transaction::{Action, FunctionCallAction, Transaction};
//! use serde_json::json;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let signer_account_id = "fido.testnet".parse::<AccountId>()?;
//! let signer_secret_key = "ed25519:12dhevYshfiRqFSu8DSfxA27pTkmGRv6C5qQWTJYTcBEoB7MSTyidghi5NWXzWqrxCKgxVx97bpXPYQxYN5dieU".parse()?;
//!
//! let signer = near_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key);
//!
//!
//! let other_account = "rpc_docs.testnet".parse::<AccountId>()?;
//! let rating = "4.5".parse::<f32>()?;
//!
//!
//! let transaction = Transaction {
//! signer_id: signer.account_id.clone(),
//! public_key: signer.public_key.clone(),
//! nonce: 904565 + 1,
//! receiver_id: "nosedive.testnet".parse::<AccountId>()?,
//! block_hash: "AUDcb2iNUbsmCsmYGfGuKzyXKimiNcCZjBKTVsbZGnoH".parse()?,
//! actions: vec![Action::FunctionCall(FunctionCallAction {
//! actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
//! method_name: "rate".to_string(),
//! args: json!({
//! "account_id": other_account,
Expand All @@ -45,8 +45,8 @@
//! .into_bytes(),
//! gas: 100_000_000_000_000, // 100 TeraGas
//! deposit: 0,
//! })],
//! };
//! }))],
//! };
//!
//! let request = methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest {
//! signed_transaction: transaction.sign(&signer)
Expand Down
14 changes: 7 additions & 7 deletions src/methods/experimental/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
Expand All @@ -40,7 +40,7 @@
//! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, AccountWithPublicKey}};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
Expand All @@ -55,8 +55,8 @@
//! account_id: "rpc_docs.testnet".parse()?,
//! public_key: "ed25519:FxGiXr6Dgn92kqBqbQzuoYdKngiizCnywpaN7ALar3Vv".parse()?,
//! }
//!
//! ],
//!
//! ],
//! }
//! };
//!
Expand All @@ -77,7 +77,7 @@
//! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
Expand All @@ -104,7 +104,7 @@
//! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
Expand All @@ -131,7 +131,7 @@
//! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, StoreKey}, hash::CryptoHash};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
Expand Down
8 changes: 4 additions & 4 deletions src/methods/experimental/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! ## Example
//!
//! ```
//! ```no_run
//! use near_jsonrpc_client::{methods, JsonRpcClient};
//! use near_jsonrpc_primitives::types::{query::QueryResponseKind, transactions};
//! use near_primitives::types::{AccountId, BlockReference};
Expand All @@ -16,7 +16,7 @@
//! use serde_json::json;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let signer_account_id = "fido.testnet".parse::<AccountId>()?;
Expand All @@ -33,7 +33,7 @@
//! nonce: 904565 + 1,
//! receiver_id: "nosedive.testnet".parse::<AccountId>()?,
//! block_hash: "AUDcb2iNUbsmCsmYGfGuKzyXKimiNcCZjBKTVsbZGnoH".parse()?,
//! actions: vec![Action::FunctionCall(FunctionCallAction {
//! actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
//! method_name: "rate".to_string(),
//! args: json!({
//! "account_id": other_account,
Expand All @@ -43,7 +43,7 @@
//! .into_bytes(),
//! gas: 100_000_000_000_000, // 100 TeraGas
//! deposit: 0,
//! })],
//! }))],
//! };
//!
//! let request = methods::EXPERIMENTAL_check_tx::RpcCheckTxRequest {
Expand Down
4 changes: 2 additions & 2 deletions src/methods/experimental/protocol_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! Returns the protocol config of the blockchain at a given block.
//!
//! ```
//! ```no_run
//! use near_jsonrpc_client::{methods, JsonRpcClient};
//! use near_primitives::types::{BlockReference, BlockId};
//!
Expand All @@ -15,7 +15,7 @@
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_protocol_config::RpcProtocolConfigRequest {
//! block_reference: BlockReference::BlockId(BlockId::Height(47988413))
//! block_reference: BlockReference::BlockId(BlockId::Height(100_000_000))
//! };
//!
//! let response = client.call(request).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/methods/experimental/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! use near_jsonrpc_primitives::types::receipts::ReceiptReference;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_receipt::RpcReceiptRequest {
Expand Down
6 changes: 3 additions & 3 deletions src/methods/experimental/tx_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
//! use near_primitives::views;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//! let tx_hash = "B9aypWiMuiWR5kqzewL9eC96uZWA3qCMhLe67eBMWacq".parse()?;
//!
//! let request = methods::EXPERIMENTAL_tx_status::RpcTransactionStatusRequest {
//! transaction_info: methods::EXPERIMENTAL_tx_status::TransactionInfo::TransactionId {
//! hash: tx_hash,
//! account_id: "itranscend.near".parse()?,
//! tx_hash,
//! sender_account_id: "itranscend.near".parse()?,
//! }
//! };
//!
Expand Down
2 changes: 1 addition & 1 deletion src/methods/experimental/validators_ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! use near_primitives::types::BlockId;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::EXPERIMENTAL_validators_ordered::RpcValidatorsOrderedRequest {
Expand Down
2 changes: 1 addition & 1 deletion src/methods/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! use near_primitives::types::BlockId;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::gas_price::RpcGasPriceRequest {
Expand Down
2 changes: 1 addition & 1 deletion src/methods/next_light_client_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! use near_jsonrpc_client::{methods, JsonRpcClient};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::next_light_client_block::RpcLightClientNextBlockRequest {
Expand Down
9 changes: 5 additions & 4 deletions src/methods/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::query::RpcQueryRequest {
Expand All @@ -48,7 +48,7 @@
//! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::query::RpcQueryRequest {
Expand Down Expand Up @@ -83,7 +83,8 @@
//! block_reference: BlockReference::latest(),
//! request: QueryRequest::ViewState {
//! account_id: "nosedive.testnet".parse()?,
//! prefix: StoreKey::from(vec![])
//! prefix: StoreKey::from(vec![]),
//! include_proof: false,
//! }
//! };
//!
Expand Down Expand Up @@ -133,7 +134,7 @@
//! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org");
//!
//! let request = methods::query::RpcQueryRequest {
Expand Down
8 changes: 4 additions & 4 deletions src/methods/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
//! use near_primitives::types::{EpochReference, EpochId, BlockReference, Finality};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
//!
//! let request = methods::validators::RpcValidatorRequest {
//! epoch_reference: EpochReference::EpochId(EpochId {
//! 0: "9xrjdZmgjoVkjVE3ui7tY37x9Mkw5wH385qNXE6cho7T".parse()?,
//! })
//! epoch_reference: EpochReference::EpochId(
//! "9xrjdZmgjoVkjVE3ui7tY37x9Mkw5wH385qNXE6cho7T".parse()?,
//! )
//! };
//!
//! let response = client.call(request).await?;
Expand Down

0 comments on commit ea99eff

Please sign in to comment.