智能合约-15.枚举

枚举

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

contract Enum {
    enum Status {
        Node,
        Pedding,
        Shipped,
        Completed,
        Rejected,
        Canceled
    }

    Status public status;

    struct Order {
        address buyer;
        Status status
    }

    Order[] public orders;

    function get() view returns (Status) {
        return status;
    }

    // 设置枚举类型
    function set(Status _status) external {
        status = _status;
    }

    // 指定特定的枚举类型
    function ship() external {
        status = Status.Shipped;
    }

    // 恢复为默认值
    function reset() external {
        delete status;
    }
 }