Skip to content

feat: migrate from near-openapi-client to near-openrpc-client#131

Open
r-near wants to merge 12 commits intomainfrom
feat/migrate-openrpc
Open

feat: migrate from near-openapi-client to near-openrpc-client#131
r-near wants to merge 12 commits intomainfrom
feat/migrate-openrpc

Conversation

@r-near
Copy link
Copy Markdown
Contributor

@r-near r-near commented Mar 4, 2026

Summary

  • Replace near-openapi-client / near-openapi-types with near-openrpc-client (OpenRPC-generated types and client)
  • Update all type imports, query builders, transaction handling, and error types across both api and types crates
  • Remove duplicated RpcError/RpcErrorCause from rpc_client.rs — now imported from near_openrpc_client::errors
  • Simplify retry logic 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 for downstream typed error matching
  • Re-export near_openrpc_client::errors as near_api::rpc_errors
  • Port TransactionStatusRpc, ReceiptRpc, and TransactionProofRpc to use the openrpc RpcClient
  • Port error criticality functions (is_critical_transaction_status_error, is_critical_receipt_error, is_critical_light_client_proof_error) to use unified RpcError approach

Dependencies

Test plan

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.
@r-near r-near force-pushed the feat/migrate-openrpc branch from 94e4caf to 2ffc046 Compare March 4, 2026 19:26
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 50.86705% with 255 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.85%. Comparing base (730bacd) to head (dc0711b).

Files with missing lines Patch % Lines
types/src/transaction/actions.rs 27.65% 68 Missing ⚠️
api/src/common/query/handlers/mod.rs 67.64% 33 Missing ⚠️
api/src/stake.rs 0.00% 31 Missing ⚠️
api/src/common/utils.rs 28.20% 28 Missing ⚠️
types/src/transaction/delegate_action.rs 0.00% 21 Missing ⚠️
api/src/common/query/query_request.rs 72.60% 20 Missing ⚠️
api/src/errors.rs 26.66% 11 Missing ⚠️
api/src/common/query/mod.rs 16.66% 10 Missing ⚠️
api/src/rpc_client.rs 75.00% 10 Missing ⚠️
api/src/common/send.rs 71.42% 8 Missing ⚠️
... and 10 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

r-near added 6 commits March 4, 2026 13:28
- 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)
@r-near r-near marked this pull request as ready for review March 11, 2026 22:16
@r-near r-near requested review from a team and akorchyn as code owners March 11, 2026 22:16
Copilot AI review requested due to automatic review settings March 11, 2026 22:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with near-openrpc-client types and errors.
  • Added a minimal RpcClient (reqwest-based) and updated query/tx RPC modules to use RpcClient::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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

r-near added 2 commits March 12, 2026 11:31
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: NEW❗

Development

Successfully merging this pull request may close these issues.

4 participants