Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ad-hoc token transfer code with storage API code #2287

Closed
Tracked by #2529
sug0 opened this issue Dec 15, 2023 · 5 comments · Fixed by #3109 or #3029
Closed
Tracked by #2529

Replace ad-hoc token transfer code with storage API code #2287

sug0 opened this issue Dec 15, 2023 · 5 comments · Fixed by #3109 or #3029
Assignees
Labels
pre-mainnet Must happen before mainnet. refactor / code quality

Comments

@sug0
Copy link
Collaborator

sug0 commented Dec 15, 2023

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.

@Kofituo
Copy link
Contributor

Kofituo commented Jan 11, 2024

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

@sug0
Copy link
Collaborator Author

sug0 commented Jan 12, 2024

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!

@cwgoes
Copy link
Collaborator

cwgoes commented Apr 24, 2024

@Fraccaman estimate: hours

@sug0
Copy link
Collaborator Author

sug0 commented Apr 27, 2024

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 sug0 reopened this Apr 27, 2024
@brentstone
Copy link
Collaborator

brentstone commented Apr 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pre-mainnet Must happen before mainnet. refactor / code quality
Projects
None yet
5 participants