Question about default module

I’m looking about default module of LibraCoin and have one question about mint function.

There is this code, _ = move(capability);, inside the mint function.
However, I have no idea about what this means.

Do you have any idea about this ?

Thank you.

This is the code of LibraCoin module and mint function.

resource MintCapability {
    _dummy: bool 
}

public mint(value: u64, capability: &Self.MintCapability): Self.T acquires MarketCap {
    let market_cap_ref: &mut Self.MarketCap;
    let market_cap_total_value: u128;

    _ = move(capability);

    assert(copy(value) <= 1000000000 * 1000000, 11); // * 1000000 because the unit is microlibra
    market_cap_ref = borrow_global_mut<MarketCap>(0xA550C18);
    market_cap_total_value = *&copy(market_cap_ref).total_value;
    *(&mut move(market_cap_ref).total_value) = move(market_cap_total_value) + to_u128(copy(value));

    return T{value: move(value)};
}
1 Like

Good question! The short answer is that this isn’t needed and I’ve sent https://github.com/libra/libra/pull/2253 to eliminate it (thanks for noticing this!).

The longer answer is that _ = move(capability) will move the reference out of the capability local and onto the stack, then pop the stack. I believe this was here because an older version of the Move bytecode verifier required explicit destruction of all references (similar to the way it requires explicit destruction of all resources). The current version of the bytecode verifier doesn’t have this limitation.

1 Like

Hi !
Thank you for answering my question!
I got it!

I have one more question about *.
Why do we need * before &copy(market_cap_ref).total_value; and (&mut move(market_cap_ref).total_value) ?

It looks that those variable are already referenced by & in rust language rule.

What does * mean in Move ?

* means the same thing as it does in Rust, C, and C++: dereference. For example: the type of &market_cap.total_value is &u64, but the type of *&market_cap.total_value is u64.

OK ! Thank you so much !

* and & are the difficult concept for rust and C language leaner …