Skip to content

Commit

Permalink
Do not check-in wallet_contract.wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
staffik committed Dec 15, 2023
1 parent 07a9069 commit efdfa9b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion runtime/near-wallet-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ near-primitives-core.workspace = true
anyhow.workspace = true

[features]
build_wallet_contract = []
nightly_protocol = [
"near-vm-runner/nightly_protocol",
]
Expand Down
8 changes: 6 additions & 2 deletions runtime/near-wallet-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
15 changes: 6 additions & 9 deletions runtime/near-wallet-contract/build.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand Down
1 change: 1 addition & 0 deletions runtime/near-wallet-contract/res/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm
Binary file not shown.
4 changes: 3 additions & 1 deletion runtime/near-wallet-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub fn wallet_contract() -> Arc<ContractCode> {

/// 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)
}

Expand All @@ -26,6 +27,7 @@ pub fn wallet_contract_magic_bytes() -> Arc<ContractCode> {
.clone()
}

#[cfg(feature = "nightly")]
#[cfg(test)]
mod tests {
use crate::{wallet_contract, wallet_contract_magic_bytes};
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit efdfa9b

Please sign in to comment.