-
Notifications
You must be signed in to change notification settings - Fork 89
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
Number of coins class #30
Comments
I'm thinking we might actually want to use |
Sure, long would be fine, too, whatever fits. As a starting point I created dexX7@6bbd6d0, but it was more about "testing the water", so to speak. :) BitcoinJ's Coin class looks great, might make sense to use this one and extend it to fit our needs. I think it's all not a very huge deal at all, and only nice to have, as everything we have done so far works pretty well. The biggest "issue" I see is that there are two types of amounts: indivisible amounts and divisible amounts, and it would be nice, if a NumberOfCoins class could deal with both properly. |
Make sure to take a look at the Bibliography and Links in the JSR 354 Java Money and Currency Specification. There's many years of experience dealing with currency issue to be found there. Edit: Note the "EVALUATION LICENCE" section of the specification. Wow. |
Note that The Java Money stuff looks like it does a lot of what we need. Downsides are that it may be too complicated for our needs, might require newer versions of Java that preclude Android, and that it isn't final yet. |
I've been researching JavaMoney further and despite possible issues with Android support, I think we should go ahead and use it for an initial implementation of Coin and Currency classes. There are multiple strategies we can use to support Android if or when needed, but implementing JavaMoney (and requiring Java 8 for the Spock tests) seems like the best way to start. |
I followed your research a bit and I'm impressed by the JavaMoney specification document, but haven't found the time to look into it, yet. A few questions:
Edit: regarding Java 8: if there is no significant downside, then I'd welcome the upgrade. Especially Java Lambdas could be handy. |
I've been writing some test code and it is going well. I should have something to post in a few days.
OK, then @dexX7, Java 8 it is. |
@dexX7 Here's some exploration of JavaMoney + Groovy: JavaMoney/javamoney-shelter#5 |
Very interesting As far as I can see we'd need to add special methods to handle arithmetic operations, and probably also to compare values. Since We'd probably need two Money classes - for indivisible amounts with range [0, 9223372036854775807] and a step of 1, and another for divisible amounts with range of [0, 92233720368.54775807] with step = 0.00000001? It would be great, if they were convertible from one to the other. |
I think the arithmetic methods can be added to a base class or possibly even an interface. I also think we can probably get support for that from the JavaMoney and Groovy communities, so hopefully it won't be something that we maintain as Omni-only. Although you may be right about the type combinations issue. The correct (default?) behavior for Note that the "Implementation Recommendations" in the JSR say:
(I'm hearing the voice of Fr. Capitolo, my high-school physics teacher saying "Don't forget your D.A.") The JSR does have complex and full-featured support for conversions and exchange rates. |
I've been thinking more about it, especially regarding the two units: the underlying data type is a 64 bit wide signed integer for both, and "divisibility", implied by the property type, comes into play in an UI or when interacting with the RPC interface of Master/Omni Core. Strictly seen one could say we're not combining different currencies, but have to handle different representations of one. Let's take a look at the context:
Basic operations:
We need to:
Usually "divisible amounts" convert to 100000000x "base units", and "indivisible amounts" convert to 1x "base units". There is an exception related to crowdsales, see: mastercoin-MSC/mastercore#234 (comment) |
This looks like a complete specification for what we need. You've looked at the spec carefully enough to see the use of I'm still undecided on whether we should try to require JavaMoney framework for the basic classes or whether we should design classes/interfaces that don't depend on classes/interfaces in JavaMoney, but are compatible with it. (The lack of multiple inheritance or traits in Java 6 may be an issue here) |
Sorry, I'm not sure, if I understand: are you wondering, if we should work with JavaMoney or use BigDecimal, Long, ... as underlying data type instead and mirror JavaMoney? Exposing and using interfaces should probably done either way. This could actually expand into a larger scope: "money" or "number" is one aspect, and another one is "being a transaction field", which At the moment objects are "passively processed": |
Yes, @dexX7 that's basically what I'm wondering. Unfortunately the type that would be most useful to us is I don't understand the raw transaction details as well as I should. That said, it seems we could use some kind of a builder approach to create them from our various types. The raw transaction support is something that we'll definitely want on Android, I think.
This would free us from having to implement Omni-specific serialization in the other classes. |
The JavaMoney API Backport project when final today and supports Android. This should be what we need: |
OK, I added the JavaMoney API Backport JAR to |
@dexX7: can we close this? Do OmniValue, OmniDivisbleValue, and OmniIndivisibleValue do the job? |
Yes! :) |
There are a few situations where one needs to be careful when using
BigDecimal
or rather number conversion.Here is an example:
This can become an issue when using external data, such as a test plan, with indivisible amounts like
9007199254740993
in this example.A "native" NumberOfCoins class would be helpful, with BigDecimal as underlying value type, but proper constructors, string representation and so on.
We have divisible and indivisible amounts, with different ranges each, and furthermore different use-cases, for example
send_MP
which consumes the number as string ("1,0", "0.00000001", "1"), as well as the creation methods, which use the number represented in units, where "1.0" is actually "100000000".The text was updated successfully, but these errors were encountered: