-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from OptimizorClub/strings
Clean up string handling (and drop openzeppelin dependency)
- Loading branch information
Showing
7 changed files
with
49 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule openzeppelin-contracts
deleted from
83277f
Submodule solmate
updated
47 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.15; | ||
|
||
library HexString { | ||
bytes16 constant ALPHABET = '0123456789abcdef'; | ||
|
||
function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string memory) { | ||
bytes memory buffer = new bytes(2 * length); | ||
for (uint256 i = buffer.length; i > 0; i--) { | ||
buffer[i - 1] = ALPHABET[value & 0xf]; | ||
value >>= 4; | ||
} | ||
return string(buffer); | ||
} | ||
|
||
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { | ||
bytes memory buffer = new bytes(2 * length + 2); | ||
buffer[0] = '0'; | ||
buffer[1] = 'x'; | ||
for (uint256 i = 2 * length + 1; i > 1; --i) { | ||
buffer[i] = ALPHABET[value & 0xf]; | ||
value >>= 4; | ||
} | ||
require(value == 0, 'Strings: hex length insufficient'); | ||
return string(buffer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters