Skip to content

Commit

Permalink
Merge branch 'master' into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Aug 14, 2019
2 parents 21bf629 + 0e53768 commit a39b0e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,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
]);
```
Expand Down
16 changes: 8 additions & 8 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -59,24 +59,24 @@ 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);
}
}

if (!function_exists('to_fixed')) {
/**
* Brings number to fixed precision without rounding.
*
* @param float $number
* @param int $precision
* @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 = $number * pow(10, $precision);
$number = bcmul($number, (string) pow(10, $precision));

return bcdiv((string) $number, (string) pow(10, $precision), $precision);
return bcdiv($number, (string) pow(10, $precision), $precision);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function satoshiBtcProvider() : array
[-1000, '-0.00001000'],
[100000000, '1.00000000'],
[150000000, '1.50000000'],
[2100000000000000, '21000000.00000000'],
];
}

Expand Down

0 comments on commit a39b0e2

Please sign in to comment.