Skip to content

Commit

Permalink
Natspec for MarshaLib
Browse files Browse the repository at this point in the history
  • Loading branch information
remedcu committed Oct 29, 2024
1 parent 99481e4 commit b69c2a0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/handler/extensible/MarshalLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ library MarshalLib {
data = bytes32(uint256(uint160(handler)) | (isStatic ? 0 : (1 << 248)));
}

/**
* Encode a method handler into a `bytes32` value with a selector
* @dev The first byte of the `bytes32` value is set to 0x01 if the method is not static (`view`)
* @dev The next 4 bytes of the `bytes32` value are set to the selector of the method
* @dev The last 20 bytes of the `bytes32` value are set to the address of the handler contract
* @param isStatic Whether the method is static (`view`) or not
* @param selector The selector of the method
* @param handler The address of the handler contract implementing the `IFallbackMethod` or `IStaticFallbackMethod` interface
*/
function encodeWithSelector(bool isStatic, bytes4 selector, address handler) internal pure returns (bytes32 data) {
data = bytes32(uint256(uint160(handler)) | (isStatic ? 0 : (1 << 248)) | (uint256(uint32(selector)) << 216));
}
Expand All @@ -32,6 +41,13 @@ library MarshalLib {
}
}

/**
* Given a `bytes32` value, decode it into a method handler and return it
* @param data The packed data to decode
* @return isStatic Whether the method is static (`view`) or not
* @return selector The selector of the method
* @return handler The address of the handler contract implementing the `IFallbackMethod` or `IStaticFallbackMethod` interface
*/
function decodeWithSelector(bytes32 data) internal pure returns (bool isStatic, bytes4 selector, address handler) {
// solhint-disable-next-line no-inline-assembly
assembly {
Expand Down

0 comments on commit b69c2a0

Please sign in to comment.