namada
namada copied to clipboard
Replace ad-hoc token transfer code with storage API code
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 I'm new to the project. Could you please give further details as to how to go about the issue?
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!
@Fraccaman estimate: hours
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 I can take care of this in #3029, seems relevant enough.