Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
staffik committed Dec 14, 2023
1 parent fb82386 commit 07a9069
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fn view_request(env: &TestEnv, request: QueryRequest) -> QueryResponse {
.unwrap()
}

/// Tests that ETH-implicit account is created correctly, with Wallet Contract hash.
#[test]
fn test_eth_implicit_account_creation() {
if !checked_feature!("stable", EthImplicitAccounts, PROTOCOL_VERSION) {
Expand Down Expand Up @@ -97,7 +98,8 @@ fn test_eth_implicit_account_creation() {

let magic_bytes = wallet_contract_magic_bytes();

// Verify the ETH-implicit account has zero balance, wallet contract hash, and its storage fits within zero balance account limit.
// Verify the ETH-implicit account has zero balance and appropriate code hash.
// Check that the account storage fits within zero balance account limit.
let request = QueryRequest::ViewAccount { account_id: eth_implicit_account_id.clone() };
match view_request(&env, request).kind {
QueryResponseKind::ViewAccount(view) => {
Expand Down
6 changes: 3 additions & 3 deletions runtime/near-wallet-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ See https://github.com/near/NEPs/issues/518.

Must not use in production!

To use the contract you need to make sure that this crate was compiled.
The contract is built via `build.rs` and WASM file is generated 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.
9 changes: 4 additions & 5 deletions runtime/runtime/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ fn get_contract_code(
if checked_feature!("stable", EthImplicitAccounts, protocol_version)
&& account_id.get_account_type() == AccountType::EthImplicitAccount
{
let contract = wallet_contract();
debug_assert!(code_hash == *wallet_contract_magic_bytes().hash());
return Ok(Some(contract));
return Ok(Some(wallet_contract()));
}
runtime_ext.get_code(code_hash).map(|option| option.map(Arc::new))
}
Expand Down Expand Up @@ -500,17 +499,17 @@ pub(crate) fn action_implicit_account_creation_transfer(
// It holds because in the only calling site, we've checked the permissions before.
AccountType::EthImplicitAccount => {
if checked_feature!("stable", EthImplicitAccounts, current_protocol_version) {
// near[wallet contract hash]
// We deploy "near[wallet contract hash]" magic bytes as the contract code,
// to mark that this is a neard-defined contract. It will not be used on a function call.
// Instead, neard-defined Wallet Contract implementation will be used.
let magic_bytes = wallet_contract_magic_bytes();

let storage_usage = fee_config.storage_usage_config.num_bytes_account
+ magic_bytes.code().len() as u64
+ fee_config.storage_usage_config.num_extra_bytes_record;

// We do not literally deploy `Wallet Contract`, just store a reference to the contract.
*account =
Some(Account::new(transfer.deposit, 0, *magic_bytes.hash(), storage_usage));

set_code(state_update, account_id.clone(), &magic_bytes);

// Precompile Wallet Contract and store result (compiled code or error) in the database.
Expand Down

0 comments on commit 07a9069

Please sign in to comment.