Skip to content

Commit

Permalink
✨ Update consoleext
Browse files Browse the repository at this point in the history
  • Loading branch information
Philogy committed Aug 26, 2024
1 parent 116b384 commit 325f1dc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/libraries/consoleext.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
pragma solidity ^0.8.0;

import {console} from "forge-std/console.sol";
import {safeconsole} from "forge-std/safeconsole.sol";
import {LibString} from "solady/src/utils/LibString.sol";

/// @author philogy <https://github.com/philogy>
library consoleext {
using LibString for uint256;

function logWords(bytes memory data) public pure {
function logInWords(bytes memory data) public pure {
for (uint256 i = 0; i < data.length; i += 32) {
uint256 word;
assembly ("memory-safe") {
Expand All @@ -19,4 +20,12 @@ library consoleext {
console.log("%s", word.toHexString(len));
}
}

function logMemWords(uint256 startOffset, uint256 endOffset) public pure {
for (uint256 offset = startOffset; offset < endOffset; offset += 32) {
uint256 wordEnd = offset + 32;
if (wordEnd > endOffset) wordEnd = endOffset;
safeconsole.logMemory(offset, wordEnd - offset);
}
}
}

0 comments on commit 325f1dc

Please sign in to comment.