diff --git a/Cargo.lock b/Cargo.lock index 2a8d77e2d..79d8f3a92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "actix" version = "0.13.1" @@ -631,6 +637,7 @@ version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ + "jobserver", "libc", ] @@ -2435,6 +2442,18 @@ dependencies = [ "tempfile", ] +[[package]] +name = "near-abi" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b8eefe71c3aad3f0a02083db99552982ee2d1a97c06e31a8958245d5955be0c" +dependencies = [ + "borsh", + "schemars", + "semver", + "serde", +] + [[package]] name = "near-account-id" version = "1.0.0" @@ -2442,6 +2461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35cbb989542587b47205e608324ddd391f0cee1c22b4b64ae49f458334b95907" dependencies = [ "borsh", + "schemars", "serde", ] @@ -2489,6 +2509,8 @@ dependencies = [ "interactive-clap-derive", "keyring", "linked-hash-map", + "near-abi", + "near-contract-standards", "near-crypto", "near-gas", "near-jsonrpc-client", @@ -2516,6 +2538,7 @@ dependencies = [ "toml", "url", "wasmer", + "zstd", ] [[package]] @@ -2530,6 +2553,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "near-contract-standards" +version = "5.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d38b06d3d0820dcf796f82b3990c6131a683ac24632a7bd4a06e2f06efa22aa" +dependencies = [ + "near-sdk", +] + [[package]] name = "near-crypto" version = "0.20.0" @@ -2574,6 +2606,7 @@ checksum = "95b30860db1eceba9b445dc56558a0fdcdfe29fd612a088e697b32dfb681aaac" dependencies = [ "borsh", "interactive-clap", + "schemars", "serde", ] @@ -2762,6 +2795,44 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "near-sdk" +version = "5.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8869ab54cd71a1a4239002f8c00b9e6742725c386e23084be98dd4bb69336266" +dependencies = [ + "base64 0.13.1", + "borsh", + "bs58 0.4.0", + "near-abi", + "near-account-id", + "near-gas", + "near-sdk-macros", + "near-sys", + "near-token", + "once_cell", + "schemars", + "serde", + "serde_json", +] + +[[package]] +name = "near-sdk-macros" +version = "5.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0efa94eb99a64491323b71ba2c0591ce4649817f26339de56f110f00649ea908" +dependencies = [ + "Inflector", + "darling", + "proc-macro2", + "quote", + "serde", + "serde_json", + "strum", + "strum_macros", + "syn 2.0.38", +] + [[package]] name = "near-socialdb-client" version = "0.2.2" @@ -2785,6 +2856,12 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6cc34a471c6e01f9dafa6aaa2d0553a3fe859dbb0d7fc73ca73f72731392226" +[[package]] +name = "near-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397688591acf8d3ebf2c2485ba32d4b24fc10aad5334e3ad8ec0b7179bfdf06b" + [[package]] name = "near-token" version = "0.2.0" @@ -2793,6 +2870,7 @@ checksum = "7b68f3f8a2409f72b43efdbeff8e820b81e70824c49fee8572979d789d1683fb" dependencies = [ "borsh", "interactive-clap", + "schemars", "serde", ] @@ -3851,6 +3929,30 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "schemars" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -3988,6 +4090,17 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "serde_json" version = "1.0.107" @@ -5613,6 +5726,35 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.9+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" +dependencies = [ + "cc", + "pkg-config", +] + [[package]] name = "zvariant" version = "3.15.0" diff --git a/Cargo.toml b/Cargo.toml index eadfbb8fa..8edff05cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,10 @@ near-token = { version = "0.2.0", features = [ "interactive-clap", ] } +near-abi = "0.4.2" +zstd = "0.11" +near-contract-standards = "5.0.0-alpha.2" + keyring = "2.0.5" interactive-clap = "0.2.8" interactive-clap-derive = "0.2.8" diff --git a/src/commands/contract/inspect_contract/mod.rs b/src/commands/contract/inspect_contract/mod.rs index 1d692bd55..6bea01579 100644 --- a/src/commands/contract/inspect_contract/mod.rs +++ b/src/commands/contract/inspect_contract/mod.rs @@ -1,5 +1,6 @@ use color_eyre::eyre::Context; +use crate::common::CallResultExt; use crate::common::JsonRpcClientExt; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] @@ -37,7 +38,7 @@ impl ContractContext { let account_id = scope.account_id.clone(); move |network_config, block_reference| { - let query_view_method_response = network_config + let query_view_code_response = network_config .json_rpc_client() .blocking_call(near_jsonrpc_client::methods::query::RpcQueryRequest { block_reference: block_reference.clone(), @@ -46,24 +47,76 @@ impl ContractContext { }, }) .wrap_err_with(|| format!("Failed to fetch query ViewCode for <{}> on network <{}>", &account_id, network_config.network_name))?; - let call_access_view = + + let mut table = prettytable::Table::new(); + table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); + + table.add_row(prettytable::row![ + Fy->account_id, + format!("At block #{}\n({})", query_view_code_response.block_height, query_view_code_response.block_hash) + ]); + + + if let Ok(contract_source_metadata_call_result) = network_config + .json_rpc_client() + .blocking_call_view_function( + &account_id.clone().into(), + "contract_source_metadata", + vec![], + block_reference.clone(), + ) { + println!("contract_source_metadata:"); + if let Ok(contract_source_metadata) = contract_source_metadata_call_result.parse_result_from_json::() { + println!("{}", serde_json::to_string_pretty(&contract_source_metadata)?); + } else { + eprintln!("The returned value is not printable (binary data)"); + } + + if let Ok(call_result) = network_config + .json_rpc_client() + .blocking_call_view_function( + &account_id.clone().into(), + "__contract_abi", + vec![], + block_reference.clone(), + ) { + if let Ok(abi_root) = serde_json::from_slice::(&zstd::decode_all(&call_result.result[..])?) { + println!("{:#?}", abi_root); + } + } + table.printstd(); + return Ok(()); + } + + + let contract_code_view = if let near_jsonrpc_primitives::types::query::QueryResponseKind::ViewCode(result) = - query_view_method_response.kind + query_view_code_response.kind { result } else { return Err(color_eyre::Report::msg("Error call result".to_string())); }; - for function in wasmer::Module::from_binary(&wasmer::Store::default(), &call_access_view.code) + + + table.set_titles(prettytable::row![Fg=>"metod name", "Arguments"]); + + for function in wasmer::Module::from_binary(&wasmer::Store::default(), &contract_code_view.code) .wrap_err_with(|| format!("Could not create new WebAssembly module from Wasm binary for contract <{account_id}>."))? .exports() - .filter(|e| matches!(e.ty(), wasmer::ExternType::Function(_fty))) + // .filter(|e| matches!(e.ty(), wasmer::ExternType::Function(_fty))) { - eprintln!("{}", function.name()); + table.add_row(prettytable::row![ + Fy->function.name(), + "" + ]); } + + table.printstd(); Ok(()) } + }); Ok(Self(crate::network_view_at_block::ArgsForViewContext { config: previous_context.config,