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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide helpers for converting units #22

Closed
marvinroger opened this issue Mar 8, 2018 · 9 comments
Closed

Provide helpers for converting units #22

marvinroger opened this issue Mar 8, 2018 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@marvinroger
Copy link
Owner

The goal of the library is to contain everything needed to deal with the Nano currency. We should add helpers to convert units (Nano, nano, raw, NANO...).

Please vote 馃憤 if this is important to you.

@marvinroger marvinroger added the enhancement New feature or request label Mar 8, 2018
@vano21
Copy link

vano21 commented Mar 8, 2018

I can't seem to find a helper function for converting amounts to zero-filled hex. I know this is trivial to do, but was thinking since this library is also useful to those who would be making blocks, exporting the helper function _convertAmountDecimalIntegerToHex would probably not be a bad idea?

@marvinroger
Copy link
Owner Author

Just wondering, what's the point of creating the block yourself when you can use https://github.com/marvinroger/nanocurrency-js/blob/develop/DOCUMENTATION.md#nanocurrencycreateopenblocksecretkey-data--object ?

@vano21
Copy link

vano21 commented Mar 8, 2018

Wasn't aware that the method didn't do PoW. Thanks for letting me know. Usually when I see a create block method, it's always with PoW included.

@marvinroger
Copy link
Owner Author

Even if it is kind of optimized with the WebAssembly, it's still very expensive (time-speaking) to compute a PoW, so the library does not compute one when you create a block, you'll have to provide it yourself.

Another reason is that you might already have a PoW precomputed in cache, so you can pass it.

@marvinroger
Copy link
Owner Author

@kilkelly considering you've 馃憤 this issue, and you're the author of nano-prettify, would you mind if I reuse some of your code? With the proper copyright notice, obviously!

@kilkelly
Copy link

kilkelly commented Mar 9, 2018

Sure thing @marvinroger , just include the MIT license and it's cool. Alternatively link it as a package to receive future bug fixes. The choice is completely up to you 馃挴

@marvinroger marvinroger added this to the v1.8.0 milestone Mar 9, 2018
@marvinroger
Copy link
Owner Author

@kilkelly there was some limitation with your code (we can only convert raw to another unit, not the other way around) and the prettify part is out of scope for this library (Numeral.js does it best), so I ended up coding the convert code myself: https://github.com/marvinroger/nanocurrency-js/blob/a7e66ab50301644fff60444a6dc784f7c5a8bb41/src/conversion.js

Thanks for the permission, though. 馃槈

@kilkelly
Copy link

No worries, it was only ever intended to be a raw to unit one-way conversion. Your code looks good, will give it a try soon.

@marvinroger
Copy link
Owner Author

Released! There's now the convert function. @vano21 it can convert any value from/to hex, as requested.

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

No branches or pull requests

3 participants