-
Notifications
You must be signed in to change notification settings - Fork 70
chore: add verify_contract
/inspect_contract
feauture gates
#504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -2731,6 +2731,7 @@ pub(crate) fn teach_me_call_response(response: &impl serde::Serialize) { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "inspect_contract")] | |||
pub(crate) fn teach_me_request_payload( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only used in contract/inspect/mod.rs so maybe it should be moved there
#[tracing::instrument(name = "Obtaining the ABI for the contract ...", skip_all)] | ||
pub async fn get_contract_abi( | ||
json_rpc_client: &near_jsonrpc_client::JsonRpcClient, | ||
block_reference: &BlockReference, | ||
account_id: &near_primitives::types::AccountId, | ||
) -> Result<near_abi::AbiRoot, FetchAbiError> { | ||
let mut retries_left = (0..5).rev(); | ||
loop { | ||
let contract_abi_response = json_rpc_client | ||
.call(near_jsonrpc_client::methods::query::RpcQueryRequest { | ||
block_reference: block_reference.clone(), | ||
request: near_primitives::views::QueryRequest::CallFunction { | ||
account_id: account_id.clone(), | ||
method_name: "__contract_abi".to_owned(), | ||
args: near_primitives::types::FunctionArgs::from(vec![]), | ||
}, | ||
}) | ||
.await; | ||
|
||
match contract_abi_response { | ||
Err(near_jsonrpc_client::errors::JsonRpcError::TransportError(_)) | ||
if retries_left.next().is_some() => | ||
{ | ||
eprintln!("Transport error.\nPlease wait. The next try to send this query is happening right now ..."); | ||
} | ||
Err(near_jsonrpc_client::errors::JsonRpcError::ServerError( | ||
near_jsonrpc_client::errors::JsonRpcServerError::HandlerError( | ||
near_jsonrpc_primitives::types::query::RpcQueryError::ContractExecutionError { | ||
vm_error, | ||
.. | ||
}, | ||
), | ||
)) if vm_error.contains("MethodNotFound") => { | ||
return Err(FetchAbiError::AbiNotSupported); | ||
} | ||
Err(err) => { | ||
return Err(FetchAbiError::RpcError(err)); | ||
} | ||
Ok(contract_abi_response) => { | ||
return serde_json::from_slice::<near_abi::AbiRoot>( | ||
&zstd::decode_all( | ||
contract_abi_response | ||
.call_result() | ||
.map_err(FetchAbiError::AbiUnknownFormat)? | ||
.result | ||
.as_slice(), | ||
) | ||
.wrap_err("Failed to 'zstd::decode_all' NEAR ABI") | ||
.map_err(FetchAbiError::AbiUnknownFormat)?, | ||
) | ||
.wrap_err("Failed to parse NEAR ABI schema") | ||
.map_err(FetchAbiError::AbiUnknownFormat); | ||
} | ||
} | ||
tokio::time::sleep(std::time::Duration::from_millis(100)).await; | ||
} | ||
} | ||
#[derive(Error, Debug)] | ||
pub enum FetchAbiError { | ||
#[error("Contract does not support NEAR ABI (https://github.com/near/abi), so there is no way to get details about the function argument and return values.")] | ||
AbiNotSupported, | ||
#[error("The contract has unknown NEAR ABI format (https://github.com/near/abi), so there is no way to get details about the function argument and return values. See more details about the error:\n\n{0}")] | ||
AbiUnknownFormat(Report), | ||
#[error("'__contract_abi' function call failed due to RPC error, so there is no way to get details about the function argument and return values. See more details about the error:\n\n{0}")] | ||
RpcError( | ||
near_jsonrpc_client::errors::JsonRpcError< | ||
near_jsonrpc_primitives::types::query::RpcQueryError, | ||
>, | ||
), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these 2 were moved up 1 level in module tree, as they're used in 3 commands: inspect, download_abi and call_function
@race-of-sloths include |
@dj8yfo Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: executed
Your contribution is much appreciated with a final score of 3! @frol received 25 Sloth Points for reviewing and scoring this pull request. What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@race-of-sloths score 3
## 🤖 New release * `near-cli-rs`: 0.20.0 -> 0.21.0 (⚠ API breaking changes) ### ⚠ `near-cli-rs` breaking changes ```text --- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value --- Description: The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`. ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_no_repr_variant_discriminant_changed.ron Failed in: variant ContractActionsDiscriminants::DownloadAbi 4 -> 5 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:61 variant ContractActionsDiscriminants::DownloadWasm 5 -> 6 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:64 variant ContractActionsDiscriminants::ViewStorage 6 -> 7 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:67 variant ContractActionsDiscriminants::DownloadAbi 4 -> 5 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:61 variant ContractActionsDiscriminants::DownloadWasm 5 -> 6 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:64 variant ContractActionsDiscriminants::ViewStorage 6 -> 7 in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:67 --- failure enum_variant_added: enum variant added on exhaustive enum --- Description: A publicly-visible enum without #[non_exhaustive] has a new variant. ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_variant_added.ron Failed in: variant SignWithDiscriminants:SubmitAsDaoProposal in /tmp/.tmpHq8aq0/near-cli-rs/src/transaction_signature_options/mod.rs:64 variant SignWithDiscriminants:SubmitAsDaoProposal in /tmp/.tmpHq8aq0/near-cli-rs/src/transaction_signature_options/mod.rs:64 variant CliContractActions:Verify in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:26 variant CliSignWith:SubmitAsDaoProposal in /tmp/.tmpHq8aq0/near-cli-rs/src/transaction_signature_options/mod.rs:19 variant SignWith:SubmitAsDaoProposal in /tmp/.tmpHq8aq0/near-cli-rs/src/transaction_signature_options/mod.rs:64 variant ContractActionsDiscriminants:Verify in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:58 variant ContractActionsDiscriminants:Verify in /tmp/.tmpHq8aq0/near-cli-rs/src/commands/contract/mod.rs:58 --- failure trait_newly_sealed: pub trait became sealed --- Description: A publicly-visible trait became sealed, so downstream crates are no longer able to implement it ref: https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/trait_newly_sealed.ron Failed in: trait near_cli_rs::common::JsonRpcClientExt in file /tmp/.tmpHq8aq0/near-cli-rs/src/common.rs:2342 ``` <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.21.0](v0.20.0...v0.21.0) - 2025-07-08 ### Added - Improved support for importing implicit accounts ([#498](#498)) - Added a command to confirm locally that the deployed contract matches the source code it was built from ([#480](#480)) - Add support for submitting general DAO proposals ([#492](#492)) ### Fixed - Fixed typos in the default CLI config ([#501](#501)) - Fixed error RpcError: [missing field disable_9393_fix] ([#502](#502)) - use re-rexported version of `indicatif` module, needed for `tracing-indicatif` ([#503](#503)) - `clippy::result_large_err` warning ([#488](#488)) ### Other - Added `verify_contract`/`inspect_contract` feauture gates ([#504](#504)) - Pinned binary releases to use ubuntu-22.04 ([#506](#506)) - Fixed linting errors - non-inlined formatting syntax ([#499](#499)) - fix some typos ([#494](#494)) - simplified action struct ([#493](#493)) - added more RPCs (FAST NEAR and Lava) to the default config generation ([#491](#491)) - introduced `BoxedJsonRpcResult` type ([#490](#490)) - fixed shell configuration for command history ([#487](#487)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
No description provided.