-
Notifications
You must be signed in to change notification settings - Fork 1
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
Create custom currencies (support for crypto like $BTC) #8
Comments
Can you define your custom currencies statically or do you need to create them at runtime? |
One option I can do is to have a repository with all currencies known today (or whitelisted ones) and then update the list with PR I'm trying to implement the runtime option based on this library but it's getting messy as you force to implement the Looking forward to reading your thoughts about both options. |
I have been looking for solutions for the dynamic extension of enums, but these seem too complex to me. ISO 4217 currencies are limited in number, rarely change and there is a universally recognized authority that maintains them. I would therefore like to stick with a static solution for these. |
I agree with you and that was the point I was trying to made, in crypto you can create a new currency in seconds and there are actually way more than 25k so the only way to manage is at runtime. Still all the rules for a currency should apply, for example to change one amount in currency X to an amount on currency Y you need a exchange rate X/Y, I just need this algebra without the static currency types. Thanks a lot for looking into this I really appreciate the work you put on this crate. |
After some experiments I find that providing the possibility to create additional currencies at runtime would need several breaking changes to the underlying quantities crate.
And then down-stream:
This would still force you to define the crypto currencies you need statically, but without any need to have a new version of the crate moneta. I'd appreciate your comments. |
I think that would work but I don't want to overcomplicate your library just for one use case. Something like this: struct CryptoCurrency { symbol: String }
impl CryptoCurrency {
fn new ...
}
let btc = CryptoCurrency::new("BTC");
let eth = CryptoCurrency::new("ETH");
let btc_eth_ratio =
... |
I think supporting crypto currencies is definitely a relevant use case. |
I think the best is to separate in two different domains (Currency and CryptoCurrency) as a first approach. If at some point we can find the convergence without affecting current API then merge with the Enum approach. I say that because in crypto things are really more complex, for example the symbol can change with time, same symbol can be used by two different projects, the same currency exists in different networks (for example ETH has testnet networks where the value is virtual, and then what is called mainnet network with the "real value"). You have native currencies like ETH and tokens like ERC20 (where you should have the network + smart contract address to identify the token), it's really a domain in itself. |
Finally, I managed to redesign the impl of |
Thanks for the effort, it looks really good I'll test in my project and let you know. Only one question, I understand I can't have 2 currencies with the same symbol is that right? |
Yes, the symbol is mapped to an u64, which is used as unique identifying key. The mapping is done by stripping all whitespace and eliminaing all non-ascii characters. |
You library + quantities is exactly what I was looking for long time ago, even the support for 18 decimals amount without rounding using integer for math operations, the only thing is I need to work with custom currencies, something like:
Is this an option on your library?
The text was updated successfully, but these errors were encountered: