bitcoinj / bitcoinj

A library for working with Bitcoin
https://bitcoinj.org
Apache License 2.0
4.98k stars 2.48k forks source link

Migrate Coin, Fiat, Monetary classes to Java Money #980

Closed mikehearn closed 1 year ago

mikehearn commented 9 years ago

Originally reported on Google Code with ID 614

Now that the Java Money (JSR 354) API Backport is available and should support Android
/ Java 6, it should be possible to modify the bitcoinj Monetary classes to be more
compatible with this implementation.

As a rough proposal, I suggest the following:

1) `Coin` should extend the `NumberValue` class
2) `Fiat` should implement `MonetaryAmount` (or perhaps be deprecated in favor of MonetaryAmount)
3) A MonetaryAmount subclass should be created for a Bitcoin (value, currency) pair

I realize this is not going to be a popular request so soon after the conversion to
`Coin` and while JavaMoney is so new. But I wanted to create the issue for discussion
and to raise awareness so this change might be included in a future release.

The Specification supports many important and interesting use cases (such as crypto
currency and currency exchanges) and even includes a link to bitcoinj in the appendix.

References
---------

The JavaMoney project home page:
http://javamoney.github.io

The JavaMoney specification:
https://github.com/JavaMoney/jsr354-api/blob/master/src/main/asciidoc/JavaMoneySpecification.adoc

The JavaMoney API (Java 8+)
https://github.com/JavaMoney/jsr354-api

The JavaMoney Reference Implementation (Java 8+):
https://github.com/JavaMoney/jsr354-ri

The Java Money API Backport (Java 6/7):
https://github.com/JavaMoney/jsr354-api-bp

The JavaMoney Reference Implementation Backport (Java 7):
https://github.com/JavaMoney/jsr354-ri-bp

Reported by sean@msgilligan.com on 2015-04-10 01:17:46

mikehearn commented 9 years ago
I am in favour of this as there wouldn't be any renaming, I guess.

Reported by c.lopez@kmels.net on 2015-04-10 04:34:41

mikehearn commented 9 years ago
I guess "Coin" is much more widely used than "Fiat" so a change to Fiat wouldn't be
that impactful. If Coin can be kept source compatible then that'd be OK with me. I'm
not sure if there's huge value to it, but ok ...

Reported by mh.in.england on 2015-04-10 09:30:37

mikehearn commented 9 years ago
That sounds like a reasonable approach, Mike.

I think the value will come from integrating with applications that handle multiple
fiat and crypto currencies (e.g. accounting software, currency trading applications,
multi currency wallets, etc.) It will also be possible to create bitcoin currency formatting
that uses the same APIs as those for fiat currencies. The value should increase when
(or if) applications start using these APIs and various plugins ('providers') are developed.

I'm experimenting with this stuff now on another project and will report back what
I've learned.

Reported by sean@msgilligan.com on 2015-04-11 01:37:43

mikehearn commented 9 years ago
As an example of value, Spring 4.2 will support Java Money for parsing and formatting
currency amounts. This means a bitcoinj plugin should give Spring-based web apps Bitcoin
currency parsing and formatting "automatically":

https://jira.spring.io/browse/SPR-12209

(Although this doesn't necessarily require integration with the Coin class)

Reported by sean@msgilligan.com on 2015-04-14 22:35:54

msgilligan commented 9 years ago

Nice to see this over on GitHub :) Thanks, @mikehearn !

p.s. Feel free to assign to me.

stokito commented 8 years ago

JFYI In JavaMoney examples there is small bitcoin currency provider

And some presentation from one of the authors of JavaMoney

When you start to implement this issue please leave a comment here or me know. I'm working on migration money classes in my company to JavaMoney and hope that some of my experience may be useful for you.

Thank

msgilligan commented 8 years ago

@stokito I've created a module in my bitcoinj-addons repository that a Bitcoin currency provider based on the one from javamoney-shelter. I've also added a prototype adapter that will wrap and adapt the Exchange interface from the extensive XChange library of Bitcoin exchange clients. See the README section

msgilligan commented 2 years ago

An update on this:

  1. The JavaMoney work that I have done is in the https://github.com/ConsensusJ/consensusj project in the consensusj-currency and consensusj-exchange modules. Feel free to try it out and submit issues or pull-requests.
  2. JavaMoney will not be bundled with the JDK as some had originally hoped.
  3. Although I am the one who originally opened this issue, I now believe -- partly because of (2) -- that it would be better not to make bitcoinj-core dependent upon JavaMoney.
  4. I do think that JavaMoney is a useful library for some applications and (via the ConsensusJ modules) can be useful in Bitcoin applications.

@schildbach I opened this issue on Google Code, but since Mike imported it to GitHub, I can't close it. I recommend we close it.