99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

數(shù)組切片

2022-05-12 17:01 更新

數(shù)組切片是數(shù)組連續(xù)部分的視圖。它們寫成x[start:end], wherestart和 end是導(dǎo)致 uint256 類型(或隱式轉(zhuǎn)換為它)的表達式。切片的第x[start]一個元素是 ,最后一個元素是。x[end - 1]

如果start大于end或end大于數(shù)組的長度,則拋出異常。

兩者start和end都是可選的:默認start為數(shù)組的長度。0end

數(shù)組切片沒有任何成員。它們可以隱式轉(zhuǎn)換為其基礎(chǔ)類型的數(shù)組并支持索引訪問。索引訪問在底層數(shù)組中不是絕對的,而是相對于切片的開頭。

數(shù)組切片沒有類型名稱,這意味著沒有變量可以將數(shù)組切片作為類型,它們只存在于中間表達式中。

筆記

到目前為止,數(shù)組切片僅針對 calldata 數(shù)組實現(xiàn)。

數(shù)組切片對于 ABI 解碼函數(shù)參數(shù)中傳遞的輔助數(shù)據(jù)很有用:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.5 <0.9.0;
contract Proxy {
    /// @dev Address of the client contract managed by proxy i.e., this contract
    address client;

    constructor(address client_) {
        client = client_;
    }

    /// Forward call to "setOwner(address)" that is implemented by client
    /// after doing basic validation on the address argument.
    function forward(bytes calldata payload) external {
        bytes4 sig = bytes4(payload[:4]);
        // Due to truncating behaviour, bytes4(payload) performs identically.
        // bytes4 sig = bytes4(payload);
        if (sig == bytes4(keccak256("setOwner(address)"))) {
            address owner = abi.decode(payload[4:], (address));
            require(owner != address(0), "Address of owner cannot be zero.");
        }
        (bool status,) = client.delegatecall(payload);
        require(status, "Forwarded call failed.");
    }
}


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號