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

Support for bitcoin #1

Open
josecelano opened this issue Apr 11, 2015 · 8 comments
Open

Support for bitcoin #1

josecelano opened this issue Apr 11, 2015 · 8 comments
Assignees

Comments

@josecelano
Copy link

I have a problem using @mathiasverraes Money library: https://github.com/mathiasverraes/money

becuase max integer in 32 bits systems is to small for bitcoin becuase it uses 8 decimal places. See

moneyphp/money#79

I suppose there is no problem with this library, or is there?

@keiosweb
Copy link
Owner

Right now decimal places are controlled by Money class constant called GAAP_PRECISION, which is equal to 4 (as per GAAP advice on money value storing for banks). Constant is used without late static binding, so it's not easy to override this behavior. If you need 8 decimal places, I can try to change all self references to use static keyword.

You could then simply extend Money class and only redeclare const GAAP_PRECISION = 8; in it.

I used self references, because I was strongly considering declaring classes as final, since these are Value Objects that should not be changed (also via inheritance). There's simply no other simple way to control decimal precision and I don't know if late static binding won't bring performance hit to the table, but we could try.

@keiosweb
Copy link
Owner

BTC is already recognized as valid currency (since Ruby Money recognizes it), see https://github.com/keiosweb/moneyright/blob/master/src/config/currency_non_iso.json

@keiosweb keiosweb changed the title Support for bitocin Support for bitcoin Apr 11, 2015
@keiosweb keiosweb self-assigned this Apr 11, 2015
@josecelano
Copy link
Author

I have implemented a BigMoney class:

https://github.com/josecelano/money

from @mathiasverraes' Money class using Decimal class instead of integer to store amount. I have used this library:

https://github.com/Litipk/php-bignumbers

For the time being I do not need to extend Decimal class but I wanted to do it to add new shorcuts methods like greaterThan, ... See : Coder-Spirit/php-bignumbers#35 (comment)

I suppose in that case inheritance is valid even for a Value Object. I want to add new behavior to the class but each VO instance is inmutable.

@keiosweb
Copy link
Owner

Well, you basically reimplemented our Money class, since we use string representation of money with all operations performed via BCMath functions :)

@keiosweb
Copy link
Owner

Tell me if you want that late static binding here or are you going to be ok with your BigMoney?

@josecelano
Copy link
Author

I have to think about it.

First. If I want to use one class or two (Money and BigMoney from @mathiasverraes)
Second. If I prefer my Money implementation using external BigInteger/Decimal. It seems they have differents responsibilities.

@thedavidmeister
Copy link

if 4 decimal places arithmetic is GAAP for 2 decimal place currency, would we not want 10 decimal places arithmetic for 8 decimal currency?

@thedavidmeister
Copy link

+1 for BTC support btw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants