isZeroPrefixed
This commit is contained in:
parent
adf3e45ccf
commit
de19210492
@ -69,6 +69,20 @@ class Utils
|
||||
return pack('H*', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* isZeroPrefixed
|
||||
*
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
public static function isZeroPrefixed($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
throw new InvalidArgumentException('The value to zeroPrefixed function must be string.');
|
||||
}
|
||||
return (strpos($value, '0x') === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* sha3
|
||||
* keccak256
|
||||
@ -90,5 +104,5 @@ class Utils
|
||||
return null;
|
||||
}
|
||||
return '0x' . $hash;
|
||||
}
|
||||
}
|
||||
}
|
@ -63,6 +63,22 @@ class UtilsTest extends TestCase
|
||||
$this->assertEquals($str, '七彩神仙鱼');
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsZeroPrefixed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsZeroPrefixed()
|
||||
{
|
||||
$isPrefixed = Utils::isZeroPrefixed($this->testHex);
|
||||
|
||||
$this->assertEquals($isPrefixed, false);
|
||||
|
||||
$isPrefixed = Utils::isZeroPrefixed('0x' . $this->testHex);
|
||||
|
||||
$this->assertEquals($isPrefixed, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSha3
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user