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

Specify package version #58

Merged
merged 2 commits into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "alk03073135@gmail.com"
}
],
"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