feat: migrate from near-openapi-client to near-openrpc-client#131
feat: migrate from near-openapi-client to near-openrpc-client#131
Conversation
Replace the OpenAPI-based RPC client dependency with the new OpenRPC-generated client. Updates all type imports, query builders, transaction handling, and error types across both the api and types crates to use the near-openrpc-client equivalents.
…tching Remove duplicated RpcError/RpcErrorCause from rpc_client.rs — now imported from near_openrpc_client's errors module. Simplify is_critical_* retry functions in utils.rs to use RpcError::is_retryable() and try_cause_as<RpcTransactionError>() instead of string-matching cause names. Add SendRequestError::try_cause_as<T>() convenience method so downstream users can pattern-match on typed RPC error enums (RpcQueryError, RpcTransactionError, etc.) without unwrapping. Re-export near_openrpc_client::errors as near_api::rpc_errors for easy access to the typed error enums.
94e4caf to
2ffc046
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #131 +/- ##
==========================================
+ Coverage 48.37% 52.85% +4.47%
==========================================
Files 41 42 +1
Lines 5550 4645 -905
==========================================
- Hits 2685 2455 -230
+ Misses 2865 2190 -675 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Extract take_single() and convert_block_hash() helpers in response handlers - Replace duplicated serde_json::from_value().map_err() with From impl via ? - Merge identical is_critical_blocks_error/is_critical_validator_error into is_critical_rpc_error - Remove redundant ContractExecutionError early return in is_critical_query_error - Add ContractExecutionError variant to SendRequestError, replacing synthetic RpcError construction - Remove unused QueryError::UnexpectedResponse variant - Collapse duplicate RpcTransactionResponse match arms in send.rs
Merge origin/main into feat/migrate-openrpc, resolving conflicts from 5 commits that landed on main (openapi-client upgrades, tx status/receipt/proof fetchers, archival rpc, v0.8.5 release). Ported TransactionStatusRpc, ReceiptRpc, and TransactionProofRpc to use the openrpc RpcClient instead of the openapi Client. Added is_critical_transaction_status_error, is_critical_receipt_error, and is_critical_light_client_proof_error using the unified RpcError approach. Added to_final_execution_outcome helper for openrpc RpcTransactionResponse variants.
…rate - cargo fmt across all files - Fix clippy useless_conversion in types/src/transaction/result.rs - Add "openrpc" to cspell.json dictionary - Switch from git branch dep to published near-openrpc-client v0.1.0
- Convert match expressions to matches! macro in utils.rs (clippy) - Bump workspace rust-version from 1.86 to 1.88 (near-openrpc-client requires it) - Update regression_85 test to accept ContractExecutionError (openrpc client returns query contract errors via result JSON error field rather than JSON-RPC error envelope)
There was a problem hiding this comment.
Pull request overview
This PR migrates the workspace from the OpenAPI-generated NEAR RPC client/types to the OpenRPC-generated near-openrpc-client, introducing a thin in-repo JSON-RPC transport and adapting request/response parsing, transaction handling, and error classification across api and types.
Changes:
- Replaced
near-openapi-*dependencies/usages withnear-openrpc-clienttypes and errors. - Added a minimal
RpcClient(reqwest-based) and updated query/tx RPC modules to useRpcClient::call. - Refactored error handling and retry criticality checks to leverage
RpcError::is_retryable()/ typed causes.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| types/src/transaction/result.rs | Ported execution outcome/result conversions to OpenRPC types and fallible conversions. |
| types/src/transaction/mod.rs | Updated signed transaction view conversions to OpenRPC types and string-parsed IDs/hashes. |
| types/src/transaction/delegate_action.rs | Updated delegate action conversions to OpenRPC action enums (includes gas-key action mapping changes). |
| types/src/transaction/actions.rs | Updated action conversions to OpenRPC types; introduced token parsing helper and new gas-key action mappings. |
| types/src/lib.rs | Switched re-exports to OpenRPC response types; updated CryptoHash conversions. |
| types/src/errors.rs | Updated TxExecutionError import; added InvalidAccountId conversion error. |
| types/src/crypto/public_key.rs | Updated PublicKey conversions to OpenRPC PublicKey representation. |
| types/src/account.rs | Updated account view conversion to OpenRPC account response and added parsing for string fields. |
| types/Cargo.toml | Replaced near-openapi-types dependency with near-openrpc-client. |
| cspell.json | Added openrpc to allowed words list. |
| api/tests/regression.rs | Updated regression test expectations for OpenRPC error shape (contract execution errors). |
| api/src/stake.rs | Migrated staking queries to new RpcClient and updated response parsing to handle OpenRPC string-wrapped values. |
| api/src/rpc_client.rs | Added new thin JSON-RPC client wrapper (RpcClient) returning OpenRPC types. |
| api/src/lib.rs | Exposed rpc_client module and re-exported near_openrpc_client::errors as rpc_errors. |
| api/src/errors.rs | Reworked query/tx error types around unified RpcError; added SendRequestError::try_cause_as. |
| api/src/contract.rs | Updated docs to reference OpenRPC response types for code/state queries. |
| api/src/config.rs | Switched endpoint client construction from OpenAPI client to RpcClient; updated retry closure signature. |
| api/src/common/utils.rs | Simplified retry criticality logic using RpcError::is_retryable() / typed cause extraction. |
| api/src/common/send.rs | Migrated send_tx flow to RpcClient::call and OpenRPC transaction response variants. |
| api/src/common/query/validator_rpc.rs | Migrated validators RPC to RpcClient::call and unified SendRequestError. |
| api/src/common/query/tx_rpc.rs | Migrated tx/receipt/light-client-proof RPCs to RpcClient::call and updated request shapes. |
| api/src/common/query/query_rpc.rs | Migrated query RPC to RpcClient::call, returning serde_json::Value and extracting contract execution errors. |
| api/src/common/query/query_request.rs | Replaced OpenAPI query request enums with JSON builders targeting the query RPC method. |
| api/src/common/query/mod.rs | Updated query executor abstractions to remove per-RPC error generic and use RpcClient. |
| api/src/common/query/handlers/transformers.rs | Updated handler combinators to use unified QueryError type. |
| api/src/common/query/handlers/mod.rs | Migrated handlers to parse OpenRPC response structs from JSON values and added helpers. |
| api/src/common/query/block_rpc.rs | Migrated block RPC to RpcClient::call and unified retry criticality. |
| api/src/chain.rs | Updated block hash extraction to fallible conversion from OpenRPC hash type. |
| api/src/account/mod.rs | Adjusted docs and continued query builder usage with migrated query stack. |
| api/Cargo.toml | Replaced near-openapi-client with near-openrpc-client and removed serde_dbgfmt. |
| Cargo.toml | Bumped MSRV to 1.88 and replaced OpenAPI deps with near-openrpc-client. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add .error_for_status()? to RpcClient::call so HTTP 502/503 errors surface as RpcCallError::Http (retryable) instead of being misclassified as RpcCallError::Deserialize (critical). Fix stale doc comment type names left over from the OpenAPI migration: ContractCodeView → RpcViewCodeResponse, ViewStateResult → RpcViewStateResponse, AccountView → Account.
RPCEndpoint::client() was building a new reqwest::Client (and thus a new connection pool) on every call. Since retry() clones NetworkConfig per operation, this meant every RPC call opened a fresh TCP connection. Introduce a global LazyLock<reqwest::Client> shared across all endpoints. Auth headers are set per-request via RpcClient::with_headers instead of as default_headers on separate client instances.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…f FullAccess GasKeyFunctionCall carries allowance, method_names, and receiver_id restrictions that were being silently dropped by mapping to FullAccess. This aligns the View conversion with the existing AccessKeyPermission conversion which already correctly maps GasKeyFunctionCall to FunctionCall.
Summary
near-openapi-client/near-openapi-typeswithnear-openrpc-client(OpenRPC-generated types and client)apiandtypescratesRpcError/RpcErrorCausefromrpc_client.rs— now imported fromnear_openrpc_client::errorsutils.rsto useRpcError::is_retryable()andtry_cause_as::<RpcTransactionError>()instead of string-matching cause namesSendRequestError::try_cause_as<T>()convenience for downstream typed error matchingnear_openrpc_client::errorsasnear_api::rpc_errorsTransactionStatusRpc,ReceiptRpc, andTransactionProofRpcto use the openrpcRpcClientis_critical_transaction_status_error,is_critical_receipt_error,is_critical_light_client_proof_error) to use unifiedRpcErrorapproachDependencies
Test plan
cargo checkpassescargo test --libpasses (40 tests)cargo doc --no-depsbuildsCargo.tomlgit dep to point to main after feat: add errors module with per-method RPC error enums near-openrpc-client-rs#9 merges