namada icon indicating copy to clipboard operation
namada copied to clipboard

Replace ad-hoc token transfer code with storage API code

Open sug0 opened this issue 1 year ago • 5 comments

As part of the modularization effort of Namada, we should strive to replace all custom token transfer logic with the storage_api equivalents. Here is an example (from the ethereum_bridge crate):

/// Reads the `Amount` from key, applies update then writes it back
pub fn amount<D, H>(
    wl_storage: &mut WlStorage<D, H>,
    key: &storage::Key,
    update: impl FnOnce(&mut Amount),
) -> Result<Amount>
where
    D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
    H: 'static + StorageHasher + Sync,
{
    let mut amount = super::read::amount_or_default(wl_storage, key)?;
    update(&mut amount);
    wl_storage.write_bytes(key, borsh::to_vec(&amount)?)?;
    Ok(amount)
}

Functionally, it is a more generic version of token::transfer, token::credit_tokens and friends.

sug0 avatar Dec 15 '23 14:12 sug0

@sug0 I'm new to the project. Could you please give further details as to how to go about the issue?

Kofituo avatar Jan 11 '24 23:01 Kofituo

Hello there @Kofituo. Currently, we don't have the bandwidth to guide OSS contributors. Unfortunately, for the time being, you're on your own if you want to learn the codebase. Sorry!

sug0 avatar Jan 12 '24 16:01 sug0

@Fraccaman estimate: hours

cwgoes avatar Apr 24 '24 15:04 cwgoes

There are still a few instances left to change on v0.34.0, namely: https://github.com/anoma/namada/blob/v0.34.0/crates/ethereum_bridge/src/protocol/transactions/update.rs#L10-L24

sug0 avatar Apr 27 '24 12:04 sug0

@sug0 I can take care of this in #3029, seems relevant enough.

brentstone avatar Apr 29 '24 06:04 brentstone