From 6c7f4a0d40093e7cfc6b87a61aac24676533ab34 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sun, 12 Apr 2020 00:39:49 +0530 Subject: [PATCH] Fixed bytes32 to string issue --- protocols/maker.sol | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/protocols/maker.sol b/protocols/maker.sol index 9c41b3c..935bb17 100644 --- a/protocols/maker.sol +++ b/protocols/maker.sol @@ -127,13 +127,22 @@ contract Helpers is DSMath { * @dev Convert bytes32 to String. */ 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++) { - 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) { address jug = InstaMcdAddress(getMcdAddresses()).jug(); (uint duty,) = JugLike(jug).ilks(ilk);