Skip to content

Commit

Permalink
feat: bytesMemoryToAddress helper function (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Nov 22, 2023
1 parent a902bea commit 6de3c9a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contracts/BytesHelperLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ library BytesHelperLib {
}
}

function bytesMemoryToAddress(
bytes memory data,
uint256 offset
) internal pure returns (address output) {
bytes memory b = new bytes(20);
for (uint256 i = 0; i < 20; i++) {
b[i] = data[i + offset];
}
assembly {
output := mload(add(b, 20))
}
}

function bytesToUint32(
bytes calldata data,
uint256 offset
Expand Down

0 comments on commit 6de3c9a

Please sign in to comment.