diff --git a/runtime/near-wallet-contract/Cargo.toml b/runtime/near-wallet-contract/Cargo.toml index c966818173d..c8978386a67 100644 --- a/runtime/near-wallet-contract/Cargo.toml +++ b/runtime/near-wallet-contract/Cargo.toml @@ -22,7 +22,6 @@ near-primitives-core.workspace = true anyhow.workspace = true [features] -build_wallet_contract = [] nightly_protocol = [ "near-vm-runner/nightly_protocol", ] diff --git a/runtime/near-wallet-contract/README.md b/runtime/near-wallet-contract/README.md index b601d22ea21..51ca7112bc9 100644 --- a/runtime/near-wallet-contract/README.md +++ b/runtime/near-wallet-contract/README.md @@ -4,8 +4,12 @@ See https://github.com/near/NEPs/issues/518. Must not use in production! +Currently, the contract can only be used in nightly build. +The `build.rs` generates WASM file and saves it to the `./res` directory. + If you want to use the contract from nearcore, add this crate as a dependency to the Cargo.toml and use `near_wallet_contract::wallet_contract()`. -The contract can be rebuilt by `build.rs` if you run `cargo build` with `--features build_wallet_contract` flag. -It would generate WASM file and save it to the `./res` directory. +In order to review changes to the WASM file, rebuild the wallet contract locally +(remove it beforehand to make sure it was rebuilt later) and check the hashes +by running `check_wallet_contract` and `check_wallet_contract_magic_bytes` tests in `src/lib.rs`. diff --git a/runtime/near-wallet-contract/build.rs b/runtime/near-wallet-contract/build.rs index 7066696e55a..968bbf0a82b 100644 --- a/runtime/near-wallet-contract/build.rs +++ b/runtime/near-wallet-contract/build.rs @@ -1,18 +1,15 @@ /// This file is run as a part of `cargo build` process and it builds the `Wallet Contract`. /// The generated WASM file is put to the `./res` directory. -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, Context, Ok, Result}; use std::path::{Path, PathBuf}; -use std::process::{exit, Command}; +use std::process::Command; -fn main() { - if cfg!(not(feature = "build_wallet_contract")) { - return; +fn main() -> Result<()> { + if cfg!(not(feature = "nightly")) { + return Ok(()); } - build_contract("./wallet-contract", &[], "wallet_contract").unwrap_or_else(|err| { - eprintln!("Error: {}", err); - exit(1); - }); + build_contract("./wallet-contract", &[], "wallet_contract") } fn build_contract(dir: &str, args: &[&str], output: &str) -> Result<()> { diff --git a/runtime/near-wallet-contract/res/.gitignore b/runtime/near-wallet-contract/res/.gitignore new file mode 100644 index 00000000000..917660a3481 --- /dev/null +++ b/runtime/near-wallet-contract/res/.gitignore @@ -0,0 +1 @@ +*.wasm \ No newline at end of file diff --git a/runtime/near-wallet-contract/res/wallet_contract.wasm b/runtime/near-wallet-contract/res/wallet_contract.wasm deleted file mode 100755 index 95df1c33c4f..00000000000 Binary files a/runtime/near-wallet-contract/res/wallet_contract.wasm and /dev/null differ diff --git a/runtime/near-wallet-contract/src/lib.rs b/runtime/near-wallet-contract/src/lib.rs index 77c3d74916b..7d5c36402fa 100644 --- a/runtime/near-wallet-contract/src/lib.rs +++ b/runtime/near-wallet-contract/src/lib.rs @@ -10,7 +10,8 @@ pub fn wallet_contract() -> Arc { /// Include the WASM file content directly in the binary at compile time. fn read_contract() -> ContractCode { - let code = include_bytes!("../res/wallet_contract.wasm"); + let code: &[u8] = + if cfg!(feature = "nightly") { include_bytes!("../res/wallet_contract.wasm") } else { &[] }; ContractCode::new(code.to_vec(), None) } @@ -26,6 +27,7 @@ pub fn wallet_contract_magic_bytes() -> Arc { .clone() } +#[cfg(feature = "nightly")] #[cfg(test)] mod tests { use crate::{wallet_contract, wallet_contract_magic_bytes}; diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index 7ca55deef45..d03d5164016 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -56,7 +56,7 @@ fn get_contract_code( if checked_feature!("stable", EthImplicitAccounts, protocol_version) && account_id.get_account_type() == AccountType::EthImplicitAccount { - debug_assert!(code_hash == *wallet_contract_magic_bytes().hash()); + assert!(code_hash == *wallet_contract_magic_bytes().hash()); return Ok(Some(wallet_contract())); } runtime_ext.get_code(code_hash).map(|option| option.map(Arc::new))