Fixed bytes32 to string issue

This commit is contained in:
Thrilok Kumar 2020-04-12 00:39:49 +05:30
parent 0f2b125b5e
commit 6c7f4a0d40

View File

@ -127,13 +127,22 @@ contract Helpers is DSMath {
* @dev Convert bytes32 to String. * @dev Convert bytes32 to String.
*/ */
function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) { function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {
bytes memory bytesArray = new bytes(32); bytes32 _temp;
uint count;
for (uint256 i; i < 32; i++) { for (uint256 i; i < 32; i++) {
bytesArray[i] = _bytes32[i]; _temp = _bytes32[i];
if( _temp != bytes32(0)) {
count += 1;
} }
return string(bytesArray); }
bytes memory bytesArray = new bytes(count);
for (uint256 i; i < count; i++) {
bytesArray[i] = (_bytes32[i]);
}
return (string(bytesArray));
} }
function getFee(bytes32 ilk) internal view returns (uint fee) { function getFee(bytes32 ilk) internal view returns (uint fee) {
address jug = InstaMcdAddress(getMcdAddresses()).jug(); address jug = InstaMcdAddress(getMcdAddresses()).jug();
(uint duty,) = JugLike(jug).ilks(ilk); (uint duty,) = JugLike(jug).ilks(ilk);