From 59fa26eae6b3ac1ed6d67d3a290674042e8f523c Mon Sep 17 00:00:00 2001 From: Femi Bankole Date: Fri, 22 Dec 2023 13:38:04 +0100 Subject: [PATCH 1/2] chore(docs): revise README docs (#91) --- README.md | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) diff --git a/README.md b/README.md index 73f8454..598495b 100644 --- a/README.md +++ b/README.md @@ -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, -} - -impl methods::RpcHandlerResponse for PartialGenesisConfig {} - -let mainnet_client = JsonRpcClient::connect("https://rpc.mainnet.near.org"); - -let genesis_config_request = methods::any::>( - "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 From fb0be84133b4ac74f35bdd71477fa74bc1240c2e Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Tue, 26 Dec 2023 00:59:44 +0100 Subject: [PATCH 2/2] fix: Fixed doc tests after the recent crate updates (#135) --- src/methods/broadcast_tx_async.rs | 8 ++++---- src/methods/broadcast_tx_commit.rs | 14 +++++++------- src/methods/experimental/changes.rs | 14 +++++++------- src/methods/experimental/check_tx.rs | 8 ++++---- src/methods/experimental/protocol_config.rs | 4 ++-- src/methods/experimental/receipt.rs | 2 +- src/methods/experimental/tx_status.rs | 6 +++--- src/methods/experimental/validators_ordered.rs | 2 +- src/methods/gas_price.rs | 2 +- src/methods/next_light_client_block.rs | 2 +- src/methods/query.rs | 9 +++++---- src/methods/validators.rs | 8 ++++---- 12 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/methods/broadcast_tx_async.rs b/src/methods/broadcast_tx_async.rs index e495c27..92d4724 100644 --- a/src/methods/broadcast_tx_async.rs +++ b/src/methods/broadcast_tx_async.rs @@ -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}; @@ -17,7 +17,7 @@ //! use serde_json::json; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let signer_account_id = "fido.testnet".parse::()?; @@ -34,7 +34,7 @@ //! nonce: 10223934 + 1, //! receiver_id: "nosedive.testnet".parse::()?, //! 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, @@ -44,7 +44,7 @@ //! .into_bytes(), //! gas: 100_000_000_000_000, // 100 TeraGas //! deposit: 0, -//! })], +//! }))], //! }; //! //! let request = methods::broadcast_tx_async::RpcBroadcastTxAsyncRequest { diff --git a/src/methods/broadcast_tx_commit.rs b/src/methods/broadcast_tx_commit.rs index 64ffbca..ea9ae7d 100644 --- a/src/methods/broadcast_tx_commit.rs +++ b/src/methods/broadcast_tx_commit.rs @@ -10,7 +10,7 @@ //! //! ## Example //! -//! ``` +//! ```no_run //! use near_jsonrpc_client::{methods, JsonRpcClient}; //! use near_jsonrpc_primitives::types::{query::QueryResponseKind, transactions::TransactionInfo}; //! use near_primitives::types::{AccountId, BlockReference}; @@ -18,24 +18,24 @@ //! use serde_json::json; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let signer_account_id = "fido.testnet".parse::()?; //! 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::()?; //! let rating = "4.5".parse::()?; -//! +//! //! let transaction = Transaction { //! signer_id: signer.account_id.clone(), //! public_key: signer.public_key.clone(), //! nonce: 904565 + 1, //! receiver_id: "nosedive.testnet".parse::()?, //! 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, @@ -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) diff --git a/src/methods/experimental/changes.rs b/src/methods/experimental/changes.rs index 46eebb5..9349831 100644 --- a/src/methods/experimental/changes.rs +++ b/src/methods/experimental/changes.rs @@ -13,7 +13,7 @@ //! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest { @@ -40,7 +40,7 @@ //! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, AccountWithPublicKey}}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest { @@ -55,8 +55,8 @@ //! account_id: "rpc_docs.testnet".parse()?, //! public_key: "ed25519:FxGiXr6Dgn92kqBqbQzuoYdKngiizCnywpaN7ALar3Vv".parse()?, //! } -//! -//! ], +//! +//! ], //! } //! }; //! @@ -77,7 +77,7 @@ //! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest { @@ -104,7 +104,7 @@ //! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest { @@ -131,7 +131,7 @@ //! use near_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, StoreKey}, hash::CryptoHash}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest { diff --git a/src/methods/experimental/check_tx.rs b/src/methods/experimental/check_tx.rs index a75abc4..6ff407a 100644 --- a/src/methods/experimental/check_tx.rs +++ b/src/methods/experimental/check_tx.rs @@ -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}; @@ -16,7 +16,7 @@ //! use serde_json::json; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let signer_account_id = "fido.testnet".parse::()?; @@ -33,7 +33,7 @@ //! nonce: 904565 + 1, //! receiver_id: "nosedive.testnet".parse::()?, //! 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, @@ -43,7 +43,7 @@ //! .into_bytes(), //! gas: 100_000_000_000_000, // 100 TeraGas //! deposit: 0, -//! })], +//! }))], //! }; //! //! let request = methods::EXPERIMENTAL_check_tx::RpcCheckTxRequest { diff --git a/src/methods/experimental/protocol_config.rs b/src/methods/experimental/protocol_config.rs index a7817be..ed8892e 100644 --- a/src/methods/experimental/protocol_config.rs +++ b/src/methods/experimental/protocol_config.rs @@ -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}; //! @@ -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?; diff --git a/src/methods/experimental/receipt.rs b/src/methods/experimental/receipt.rs index 9139976..d3952a9 100644 --- a/src/methods/experimental/receipt.rs +++ b/src/methods/experimental/receipt.rs @@ -11,7 +11,7 @@ //! use near_jsonrpc_primitives::types::receipts::ReceiptReference; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! //! let request = methods::EXPERIMENTAL_receipt::RpcReceiptRequest { diff --git a/src/methods/experimental/tx_status.rs b/src/methods/experimental/tx_status.rs index 2bbbb8e..08a6b0e 100644 --- a/src/methods/experimental/tx_status.rs +++ b/src/methods/experimental/tx_status.rs @@ -10,14 +10,14 @@ //! use near_primitives::views; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! 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()?, //! } //! }; //! diff --git a/src/methods/experimental/validators_ordered.rs b/src/methods/experimental/validators_ordered.rs index 2833787..94f7d71 100644 --- a/src/methods/experimental/validators_ordered.rs +++ b/src/methods/experimental/validators_ordered.rs @@ -9,7 +9,7 @@ //! use near_primitives::types::BlockId; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! //! let request = methods::EXPERIMENTAL_validators_ordered::RpcValidatorsOrderedRequest { diff --git a/src/methods/gas_price.rs b/src/methods/gas_price.rs index a21897c..b1f4e09 100644 --- a/src/methods/gas_price.rs +++ b/src/methods/gas_price.rs @@ -36,7 +36,7 @@ //! use near_primitives::types::BlockId; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! //! let request = methods::gas_price::RpcGasPriceRequest { diff --git a/src/methods/next_light_client_block.rs b/src/methods/next_light_client_block.rs index 63502b6..6ccb355 100644 --- a/src/methods/next_light_client_block.rs +++ b/src/methods/next_light_client_block.rs @@ -6,7 +6,7 @@ //! use near_jsonrpc_client::{methods, JsonRpcClient}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! //! let request = methods::next_light_client_block::RpcLightClientNextBlockRequest { diff --git a/src/methods/query.rs b/src/methods/query.rs index 439fc96..88b4e28 100644 --- a/src/methods/query.rs +++ b/src/methods/query.rs @@ -21,7 +21,7 @@ //! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! //! let request = methods::query::RpcQueryRequest { @@ -48,7 +48,7 @@ //! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::query::RpcQueryRequest { @@ -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, //! } //! }; //! @@ -133,7 +134,7 @@ //! use near_primitives::{types::{BlockReference, BlockId}, views::QueryRequest}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let request = methods::query::RpcQueryRequest { diff --git a/src/methods/validators.rs b/src/methods/validators.rs index 7770e75..9d9f7aa 100644 --- a/src/methods/validators.rs +++ b/src/methods/validators.rs @@ -11,13 +11,13 @@ //! use near_primitives::types::{EpochReference, EpochId, BlockReference, Finality}; //! //! # #[tokio::main] -//! # async fn main() -> Result<(), Box> { +//! # async fn main() -> Result<(), Box> { //! 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?;