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

Rewriting the Wallet.toml file to have a subsection for tokens #135

Closed
bengtlofgren opened this issue Jun 8, 2022 · 8 comments · Fixed by #1081
Closed

Rewriting the Wallet.toml file to have a subsection for tokens #135

bengtlofgren opened this issue Jun 8, 2022 · 8 comments · Fixed by #1081
Assignees
Labels
enhancement New feature or request

Comments

@bengtlofgren
Copy link
Contributor

At the moment, the wallet.toml has a simple structure of the addresses data structure in the wallet.toml file as below:
Addresses

However, ideally, we have functions that check balances of tokens, and there could be some structure that keeps track of token addresses specifically in order to be friendly with such functionality (there is no point in looking through the every address when we are just looking for tokens). Something like below.
How_we_want_it

This may require us to have a separate function such as add_token_address, add_internal_address , that adds these addresses specifically to the subfolder it corresponds to. This may have some issues I cannot foresee, but will require some rewriting. However, I think it may be worth it in the long term.

Finally, there seems to be some rewriting of the wallet.toml (for example when I run anomac balances) that will need to be looked at.

@bengtlofgren bengtlofgren added the enhancement New feature or request label Jun 8, 2022
@james-chf
Copy link
Contributor

Doing this would allow us to move away from using the hardcoded address::tokens() in anomac balance, as not all chains may have these test tokens, instead we could actually read token addresses from the wallet. It could also be useful to have at some point an easy way to specifically add token addresses to the wallet.toml e.g. anomaw address add --type token (out of scope for this issue)

@bengtlofgren
Copy link
Contributor Author

This seems to be much harder than I imagined ... Will need to discuss with someone, naive solution becomes very messy

@james-chf
Copy link
Contributor

It could be worth doing a pre-refactor of Wallet/Store to make a solution less messy (depending on the solution)

@tzemanovic
Copy link
Member

I propose that rather than splitting up the addresses into different groups, we add another field just for tokens: HashSet<Address> to the wallet store and keep the addresses: HashMap<Alias, Address> as is just for alias associations, which would have the advantage of making it a non-breaking change and I think it could be less messy.

We could add this in a sub-table "traits" and following the same pattern we could then add other special account traits and they don't have to be exclusive (hence traits, not types):

#[derive(Copy)]
enum AddressTrait { Token }

struct Store {
   ...,
   address_traits: HashMap<AddressTrait, HashSet<Address>>,
}

...

fn get_addresses_with_trait(&self, r#type: AddressTrait) -> HashSet<Address> {
  // defaults to an empty set
  self.address_traits.get(r#type).unwrap_or_default()
}

In toml I guess it could look like this:

[addresses]
dot = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn"
schnitzel = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"
faucet = "atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3"
governance = "atest1v9hx7w36gahhvetjdeskucm9yqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpq5a20qt"

[address_traits]
token = ["atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn", "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"]

@tzemanovic
Copy link
Member

just a note for wallet::store::Store::new we'll want to add the genesis.token addresses to the token traits

@cwgoes
Copy link
Collaborator

cwgoes commented Jan 13, 2023

@karbyshev can you take this on as part of the wallet work?

@bengtlofgren
Copy link
Contributor Author

I'm working on this btw @karbyshev

@bengtlofgren
Copy link
Contributor Author

#1081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants