callした時の情報がstackの上に来る感じでそこからコピーからのdelegate callで実行している
contract Test1Facet {
event TestEvent(address something);
function test1Func1() external {}
}
fallback() external payable {
LibDiamond.DiamondStorage storage ds;
bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION;
// get diamond storage
assembly {
ds.slot := position
}
// get facet from function selector
address facet = ds.facetAddressAndSelectorPosition[msg.sig].facetAddress;
require(facet != address(0), "Diamond: Function does not exist");
// Execute external function from facet using delegatecall and return any value.
assembly {
// copy function selector and any arguments
calldatacopy(0, 0, calldatasize())
// execute function call using the facet
let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
// get any return value
returndatacopy(0, 0, returndatasize())
// return any return value or error back to the caller
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
gas
: amount of gas to send to the sub context to execute. The gas that is not used by the sub context is returned to this one.address
: the account which code to execute.argsOffset
: byte offset in the memory in bytes, the calldata of the sub context.argsSize
: byte size to copy (size of the calldata).retOffset
: byte offset in the memory in bytes, where to store the return data of the sub context.retSize
: byte size to copy (size of the return data).