forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
toInt: require('./toInt'), | ||
toUint: require('./toUint'), | ||
toIntDownCast: require('./toIntDownCast'), | ||
toUintDownCast: require('./toUintDownCast'), | ||
} | ||
toInt: require('./toInt'), | ||
toUint: require('./toUint'), | ||
toIntDownCast: require('./toIntDownCast'), | ||
toUintDownCast: require('./toUintDownCast'), | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
module.exports = length => [ | ||
` /**`, | ||
` * @dev Converts an unsigned uint${length} into a signed int${length}.`, | ||
` *`, | ||
` * Requirements:`, | ||
` *`, | ||
` * - input must be less than or equal to maxInt${length}.`, | ||
` */`, | ||
` function toInt${length}(uint${length} value) internal pure returns (int${length}) {`, | ||
` // Note: Unsafe cast below is okay because \`type(int${length}).max\` is guaranteed to be positive`, | ||
` require(value <= uint${length}(type(int${length}).max), "SafeCast: value doesn't fit in an int${length}");`, | ||
` return int${length}(value);`, | ||
` }`, | ||
' /**', | ||
` * @dev Converts an unsigned uint${length} into a signed int${length}.`, | ||
' *', | ||
' * Requirements:', | ||
' *', | ||
` * - input must be less than or equal to maxInt${length}.`, | ||
' */', | ||
` function toInt${length}(uint${length} value) internal pure returns (int${length}) {`, | ||
` // Note: Unsafe cast below is okay because \`type(int${length}).max\` is guaranteed to be positive`, | ||
` require(value <= uint${length}(type(int${length}).max), "SafeCast: value doesn't fit in an int${length}");`, | ||
` return int${length}(value);`, | ||
' }', | ||
].join('\n'); |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
module.exports = length => [ | ||
` /**`, | ||
` * @dev Returns the downcasted int${length} from int256, reverting on`, | ||
` * overflow (when the input is less than smallest int${length} or`, | ||
` * greater than largest int${length}).`, | ||
` *`, | ||
` * Counterpart to Solidity's \`int${length}\` operator.`, | ||
` *`, | ||
` * Requirements:`, | ||
` *`, | ||
` * - input must fit into ${length} bits`, | ||
` *`, | ||
` * _Available since v3.1._`, | ||
` */`, | ||
` function toInt${length}(int256 value) internal pure returns (int${length}) {`, | ||
` require(value >= type(int${length}).min && value <= type(int${length}).max, "SafeCast: value doesn't fit in ${length} bits");`, | ||
` return int${length}(value);`, | ||
` }`, | ||
' /**', | ||
` * @dev Returns the downcasted int${length} from int256, reverting on`, | ||
` * overflow (when the input is less than smallest int${length} or`, | ||
` * greater than largest int${length}).`, | ||
' *', | ||
` * Counterpart to Solidity's \`int${length}\` operator.`, | ||
' *', | ||
' * Requirements:', | ||
' *', | ||
` * - input must fit into ${length} bits`, | ||
' *', | ||
' * _Available since v3.1._', | ||
' */', | ||
` function toInt${length}(int256 value) internal pure returns (int${length}) {`, | ||
// eslint-disable-next-line max-len | ||
` require(value >= type(int${length}).min && value <= type(int${length}).max, "SafeCast: value doesn't fit in ${length} bits");`, | ||
` return int${length}(value);`, | ||
' }', | ||
].join('\n'); |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module.exports = length => [ | ||
` /**`, | ||
` * @dev Converts a signed int${length} into an unsigned uint${length}.`, | ||
` *`, | ||
` * Requirements:`, | ||
` *`, | ||
` * - input must be greater than or equal to 0.`, | ||
` */`, | ||
` function toUint${length}(int${length} value) internal pure returns (uint${length}) {`, | ||
` require(value >= 0, "SafeCast: value must be positive");`, | ||
` return uint${length}(value);`, | ||
` }`, | ||
' /**', | ||
` * @dev Converts a signed int${length} into an unsigned uint${length}.`, | ||
' *', | ||
' * Requirements:', | ||
' *', | ||
' * - input must be greater than or equal to 0.', | ||
' */', | ||
` function toUint${length}(int${length} value) internal pure returns (uint${length}) {`, | ||
' require(value >= 0, "SafeCast: value must be positive");', | ||
` return uint${length}(value);`, | ||
' }', | ||
].join('\n'); |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
module.exports = length => [ | ||
` /**`, | ||
` * @dev Returns the downcasted uint${length} from uint256, reverting on`, | ||
` * overflow (when the input is greater than largest uint${length}).`, | ||
` *`, | ||
` * Counterpart to Solidity's \`uint${length}\` operator.`, | ||
` *`, | ||
` * Requirements:`, | ||
` *`, | ||
` * - input must fit into ${length} bits`, | ||
` */`, | ||
` function toUint${length}(uint256 value) internal pure returns (uint${length}) {`, | ||
` require(value <= type(uint${length}).max, "SafeCast: value doesn't fit in ${length} bits");`, | ||
` return uint${length}(value);`, | ||
` }`, | ||
' /**', | ||
` * @dev Returns the downcasted uint${length} from uint256, reverting on`, | ||
` * overflow (when the input is greater than largest uint${length}).`, | ||
' *', | ||
` * Counterpart to Solidity's \`uint${length}\` operator.`, | ||
' *', | ||
' * Requirements:', | ||
' *', | ||
` * - input must fit into ${length} bits`, | ||
' */', | ||
` function toUint${length}(uint256 value) internal pure returns (uint${length}) {`, | ||
` require(value <= type(uint${length}).max, "SafeCast: value doesn't fit in ${length} bits");`, | ||
` return uint${length}(value);`, | ||
' }', | ||
].join('\n'); |