From 85a6114f490b9302c8de9513e13c75a3f9c5513f Mon Sep 17 00:00:00 2001 From: Denis Paavilainen Date: Mon, 4 Feb 2019 04:37:29 +0300 Subject: [PATCH 1/7] Apply fixes from StyleCI (#40) --- tests/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 70ec117..7acd32f 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,8 +2,8 @@ namespace Denpa\Bitcoin\Tests; -use Denpa\Bitcoin\Config; use Denpa\Bitcoin\Client as BitcoinClient; +use Denpa\Bitcoin\Config; use Denpa\Bitcoin\Exceptions; use Denpa\Bitcoin\Responses\BitcoindResponse; use Denpa\Bitcoin\Responses\Response; From bcee1d141196e196d0a274bab9feb3a28c9e4f9f Mon Sep 17 00:00:00 2001 From: Denis Paavilainen Date: Mon, 18 Feb 2019 03:07:36 +0300 Subject: [PATCH 2/7] Remove link to php-altcoinrpc for now due to the ongoing api changes for v2.2.* branch --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e35688f..c982e1a 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ [![Code Coverage](https://codeclimate.com/github/denpamusic/php-bitcoinrpc/badges/coverage.svg)](https://codeclimate.com/github/denpamusic/php-bitcoinrpc/coverage) [![Join the chat at https://gitter.im/php-bitcoinrpc/Lobby](https://badges.gitter.im/php-bitcoinrpc/Lobby.svg)](https://gitter.im/php-bitcoinrpc/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -> :bell: __Want to fork this project for your altcoin?__ Check out [denpamusic/php-altcoinrpc](https://github.com/denpamusic/php-altcoinrpc) - fast and easy way to create JSON-RPC clients without having to maintain full fork and replace tons of lines of code. - ## Installation Run ```php composer.phar require denpa/php-bitcoinrpc``` in your project directory or add following lines to composer.json ```javascript From 450e01c70bba181b03fb2415c14ba93e694641d1 Mon Sep 17 00:00:00 2001 From: Laurynas Date: Mon, 17 Jun 2019 19:11:04 +0300 Subject: [PATCH 3/7] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c982e1a..5466361 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ $bitcoind = new BitcoinClient([ 'port' => 8332, // optional, default 8332 'user' => 'rpcuser', // required 'password' => 'rpcpassword', // required - 'ca' => '/etc/ssl/ca-cert.pem' // optional, for use with https scheme + 'ca' => '/etc/ssl/ca-cert.pem', // optional, for use with https scheme 'preserve_case' => false, // optional, send method names as defined instead of lowercasing them ]); ``` From 63cf33c16313f049f21fc50e445cd292c2c56727 Mon Sep 17 00:00:00 2001 From: partyka1 Date: Wed, 7 Aug 2019 23:16:26 +0200 Subject: [PATCH 4/7] use bcmul for multiplying big numbers in `to_fixed` --- src/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 62ac05d..071b3de 100644 --- a/src/functions.php +++ b/src/functions.php @@ -74,9 +74,9 @@ function to_mbtc($bitcoin) : string */ function to_fixed(float $number, int $precision = 8) : string { - $number = $number * pow(10, $precision); + $number = bcmul((string) $number, (string) pow(10, $precision)); - return bcdiv((string) $number, (string) pow(10, $precision), $precision); + return bcdiv($number, (string) pow(10, $precision), $precision); } } From 62533aa12c9add54944378643b2acfd43f58fe17 Mon Sep 17 00:00:00 2001 From: partyka1 Date: Wed, 7 Aug 2019 23:25:07 +0200 Subject: [PATCH 5/7] fix casting: with very small numbers, it yielded 0 --- src/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions.php b/src/functions.php index 071b3de..5c3be69 100644 --- a/src/functions.php +++ b/src/functions.php @@ -31,7 +31,7 @@ function to_bitcoin(int $satoshi) : string */ function to_satoshi($bitcoin) : string { - return bcmul(to_fixed((float) $bitcoin, 8), (string) 1e8); + return bcmul(to_fixed($bitcoin, 8), (string) 1e8); } } @@ -45,7 +45,7 @@ function to_satoshi($bitcoin) : string */ function to_ubtc($bitcoin) : string { - return bcmul(to_fixed((float) $bitcoin, 8), (string) 1e6, 4); + return bcmul(to_fixed($bitcoin, 8), (string) 1e6, 4); } } @@ -59,7 +59,7 @@ function to_ubtc($bitcoin) : string */ function to_mbtc($bitcoin) : string { - return bcmul(to_fixed((float) $bitcoin, 8), (string) 1e3, 4); + return bcmul(to_fixed($bitcoin, 8), (string) 1e3, 4); } } @@ -67,14 +67,14 @@ function to_mbtc($bitcoin) : string /** * Brings number to fixed precision without rounding. * - * @param float $number + * @param string $number * @param int $precision * * @return string */ - function to_fixed(float $number, int $precision = 8) : string + function to_fixed(string $number, int $precision = 8) : string { - $number = bcmul((string) $number, (string) pow(10, $precision)); + $number = bcmul($number, (string) pow(10, $precision)); return bcdiv($number, (string) pow(10, $precision), $precision); } From dc24532cc91df0230584b01517f56404b36fdc59 Mon Sep 17 00:00:00 2001 From: partyka1 Date: Wed, 7 Aug 2019 23:33:43 +0200 Subject: [PATCH 6/7] add test for very large number --- tests/FunctionsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index f9110e2..9b99352 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -173,6 +173,7 @@ public function satoshiBtcProvider() : array [-1000, '-0.00001000'], [100000000, '1.00000000'], [150000000, '1.50000000'], + [2100000000000000, '21000000.00000000'] ]; } From 34bd7859ec1ed2df3970b4342bc6a8eedc27f32a Mon Sep 17 00:00:00 2001 From: partyka1 Date: Wed, 7 Aug 2019 23:38:51 +0200 Subject: [PATCH 7/7] fix styling --- src/functions.php | 2 +- tests/FunctionsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 5c3be69..8ba2bf6 100644 --- a/src/functions.php +++ b/src/functions.php @@ -68,7 +68,7 @@ function to_mbtc($bitcoin) : string * Brings number to fixed precision without rounding. * * @param string $number - * @param int $precision + * @param int $precision * * @return string */ diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 9b99352..d643f32 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -173,7 +173,7 @@ public function satoshiBtcProvider() : array [-1000, '-0.00001000'], [100000000, '1.00000000'], [150000000, '1.50000000'], - [2100000000000000, '21000000.00000000'] + [2100000000000000, '21000000.00000000'], ]; }