Skip to content

Commit

Permalink
Merge pull request web3p#58 from sc0Vu/specify-package-version
Browse files Browse the repository at this point in the history
Specify package version
  • Loading branch information
sc0Vu authored Mar 31, 2018
2 parents 5ede0c0 + a2a68dd commit 4df0835
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {
"guzzlehttp/guzzle": "~6.0",
"PHP": "^7.1",
"kornrunner/keccak": "dev-master",
"phpseclib/phpseclib": "dev-master"
"kornrunner/keccak": "~1.0",
"phpseclib/phpseclib": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0"
Expand Down
22 changes: 21 additions & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,27 @@ public static function toWei($number, $unit)
throw new InvalidArgumentException('toWei fraction part is out of limit.');
}
$whole = $whole->multiply($bnt);
$base = (new BigNumber(10))->pow(new BigNumber($fractionLength));

// There is no pow function in phpseclib 2.0, only can see in dev-master
// Maybe implement own biginteger in the future
// See 2.0 BigInteger: https://github.com/phpseclib/phpseclib/blob/2.0/phpseclib/Math/BigInteger.php
// See dev-master BigInteger: https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Math/BigInteger.php#L700
// $base = (new BigNumber(10))->pow(new BigNumber($fractionLength));

// So we switch phpseclib special global param, change in the future
switch (MATH_BIGINTEGER_MODE) {
case $whole::MODE_GMP:
static $two;
$powerBase = gmp_pow(gmp_init(10), (int) $fractionLength);
break;
case $whole::MODE_BCMATH:
$powerBase = bcpow('10', (string) $fractionLength, 0);
break;
default:
$powerBase = pow(10, (int) $fractionLength);
break;
}
$base = new BigNumber($powerBase);
$fraction = $fraction->multiply($bnt)->divide($base)[0];

if ($negative1 !== false) {
Expand Down

0 comments on commit 4df0835

Please sign in to comment.