false
false

Contract Address Details

0xB5447342cA17A40e59d410b340ba412E22e36201

Contract Name
WitnetErrorsLib
Creator
0xbf58be–84de46 at 0xf5adc9–7fdda3
Balance
0 KCS ( )
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
44200768
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
WitnetErrorsLib




Optimization enabled
true
Compiler version
v0.8.17+commit.8df45f5f




Optimization runs
200
EVM Version
london




Verified at
2023-08-01T09:30:33.721440Z

/contracts/libs/WitnetErrorsLib.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./Witnet.sol";

/// @title A library for interpreting Witnet resolution errors
/// @author The Witnet Foundation.
library WitnetErrorsLib {

    using Witnet for uint8;
    using Witnet for uint256;
    using WitnetCBOR for WitnetCBOR.CBOR;

    // ================================================================================================================
    // --- Library public methods -------------------------------------------------------------------------------------
    
    /// @notice Extract error code and description string from given Witnet.Result.
    /// @dev Client contracts should wrap this function into a try-catch foreseeing potential parsing errors.
    /// @return _error Witnet.ResultError data struct containing error code and description.
    function asError(Witnet.Result memory result)
        public pure
        returns (Witnet.ResultError memory _error)
    {
         return _fromErrorArray(
            _errorsFromResult(result)
        );
    }

    /// @notice Extract error code and description string from given CBOR-encoded value.
    /// @dev Client contracts should wrap this function into a try-catch foreseeing potential parsing errors.
    /// @return _error Witnet.ResultError data struct containing error code and description.
    function resultErrorFromCborBytes(bytes memory cborBytes)
        public pure
        returns (Witnet.ResultError memory _error)
    {
        WitnetCBOR.CBOR[] memory errors = _errorsFromCborBytes(cborBytes);
        return _fromErrorArray(errors);
    }


    // ================================================================================================================
    // --- Library private methods ------------------------------------------------------------------------------------

    /// @dev Extract error codes from a CBOR-encoded `bytes` value.
    /// @param cborBytes CBOR-encode `bytes` value.
    /// @return The `uint[]` error parameters as decoded from the `Witnet.Result`.
    function _errorsFromCborBytes(bytes memory cborBytes)
        private pure
        returns(WitnetCBOR.CBOR[] memory)
    {
        Witnet.Result memory result = Witnet.resultFromCborBytes(cborBytes);
        return _errorsFromResult(result);
    }

    /// @dev Extract error codes from a Witnet.Result value.
    /// @param result An instance of `Witnet.Result`.
    /// @return The `uint[]` error parameters as decoded from the `Witnet.Result`.
    function _errorsFromResult(Witnet.Result memory result)
        private pure
        returns (WitnetCBOR.CBOR[] memory)
    {
        require(!result.success, "no errors");
        return result.value.readArray();
    }

    /// @dev Extract Witnet.ResultErrorCodes and error description from given array of CBOR values.
    function _fromErrorArray(WitnetCBOR.CBOR[] memory errors)
        private pure
        returns (Witnet.ResultError memory _error)
    {
        if (errors.length < 2) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "Unknown error: no error code was found."
            });
        }
        else {
            _error.code = Witnet.ResultErrorCodes(errors[0].readUint());
        }
        // switch on _error.code
        if (
            _error.code == Witnet.ResultErrorCodes.SourceScriptNotCBOR
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: invalid CBOR value."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.SourceScriptNotArray
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: CBOR value expected to be an array of calls."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.SourceScriptNotRADON
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: CBOR value expected to be a data request."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.RequestTooManySources
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: too many sources."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.ScriptTooManyCalls
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: too many calls."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.UnsupportedOperator
                && errors.length > 3
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Radon: unsupported '",
                errors[2].readString(),
                "' for input type '",
                errors[1].readString(),
                "'."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.HTTP
                && errors.length > 2
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Retrieval: HTTP/",
                errors[1].readUint().toString(), 
                " error."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.RetrievalTimeout
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Retrieval: timeout."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.Underflow
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Aggregation: math underflow."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.Overflow
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Aggregation: math overflow."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.DivisionByZero
                && errors.length > 1
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Aggregation: division by zero."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.BridgeMalformedRequest
        ) {
            _error.reason = "Witnet: Bridge: malformed data request cannot be processed.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.BridgePoorIncentives
        ) {
            _error.reason = "Witnet: Bridge: rejected due to poor witnessing incentives.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.BridgeOversizedResult
        ) {
            _error.reason = "Witnet: Bridge: rejected due to poor bridging incentives.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.InsufficientConsensus
                && errors.length > 3
        ) {
            uint reached = (errors[1].additionalInformation == 25
                ? uint(int(errors[1].readFloat16() / 10 ** 4))
                : uint(int(errors[1].readFloat64() / 10 ** 15))
            );
            uint expected = (errors[2].additionalInformation == 25
                ? uint(int(errors[2].readFloat16() / 10 ** 4))
                : uint(int(errors[2].readFloat64() / 10 ** 15))
            );
            _error.reason = string(abi.encodePacked(
                "Witnet: Tally: insufficient consensus: ",
                reached.toString(), 
                "% <= ",
                expected.toString(), 
                "%."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.InsufficientCommits
        ) {
            _error.reason = "Witnet: Tally: insufficient commits.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.TallyExecution
                && errors.length > 3
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Tally: execution error: ",
                errors[2].readString(),
                "."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.ArrayIndexOutOfBounds
                && errors.length > 2
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Aggregation: tried to access a value from an array with an index (",
                errors[1].readUint().toString(),
                ") out of bounds."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.MapKeyNotFound
                && errors.length > 2
        ) {
            _error.reason = string(abi.encodePacked(
                "Witnet: Aggregation: tried to access a value from a map with a key (\"",
                errors[1].readString(),
                "\") that was not found."
            ));
        } else if (
            _error.code == Witnet.ResultErrorCodes.NoReveals
        ) {
            _error.reason = "Witnet: Tally: no reveals.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.MalformedReveal
        ) {
            _error.reason = "Witnet: Tally: malformed reveal.";
        } else if (
            _error.code == Witnet.ResultErrorCodes.UnhandledIntercept
        ) {
            _error.reason = "Witnet: Tally: unhandled intercept.";
        } else {
            _error.reason = string(abi.encodePacked(
                "Unhandled error: 0x",
                Witnet.toHexString(uint8(_error.code)),
                errors.length > 2
                    ? string(abi.encodePacked(" (", uint(errors.length - 1).toString(), " params)."))
                    : "."
            ));
        }
    }

    /// @notice Convert a stage index number into the name of the matching Witnet request stage.
    /// @param stageIndex A `uint64` identifying the index of one of the Witnet request stages.
    /// @return The name of the matching stage.
    function _stageName(uint64 stageIndex)
        private pure
        returns (string memory)
    {
        if (stageIndex == 0) {
            return "Retrieval";
        } else if (stageIndex == 1) {
            return "Aggregation";
        } else if (stageIndex == 2) {
            return "Tally";
        } else {
            return "(unknown)";
        }
    }
}
        

/contracts/interfaces/IWitnetRequest.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title The Witnet Data Request basic interface.
/// @author The Witnet Foundation.
interface IWitnetRequest {
    
    /// @notice A `IWitnetRequest` is constructed around a `bytes` value containing 
    /// @notice a well-formed Witnet Data Request using Protocol Buffers.
    function bytecode() external view returns (bytes memory);

    /// @notice Returns SHA256 hash of Witnet Data Request as CBOR-encoded bytes.
    function hash() external view returns (bytes32);
}
          

/contracts/libs/Witnet.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../interfaces/IWitnetRequest.sol";
import "./WitnetCBOR.sol";

library Witnet {

    using WitnetBuffer for WitnetBuffer.Buffer;
    using WitnetCBOR for WitnetCBOR.CBOR;
    using WitnetCBOR for WitnetCBOR.CBOR[];

    /// Struct containing both request and response data related to every query posted to the Witnet Request Board
    struct Query {
        Request request;
        Response response;
        address from;      // Address from which the request was posted.
    }

    /// Possible status of a Witnet query.
    enum QueryStatus {
        Unknown,
        Posted,
        Reported,
        Deleted
    }

    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct Request {
        address addr;       // Address of the IWitnetRequest contract containing Witnet data request raw bytecode.
        bytes32 slaHash;    // Radon SLA hash of the Witnet data request.
        bytes32 radHash;    // Radon radHash of the Witnet data request.
        uint256 gasprice;   // Minimum gas price the DR resolver should pay on the solving tx.
        uint256 reward;     // Escrowed reward to be paid to the DR resolver.
    }

    /// Data kept in EVM-storage containing Witnet-provided response metadata and result.
    struct Response {
        address reporter;       // Address from which the result was reported.
        uint256 timestamp;      // Timestamp of the Witnet-provided result.
        bytes32 drTxHash;       // Hash of the Witnet transaction that solved the queried Data Request.
        bytes   cborBytes;      // Witnet-provided result CBOR-bytes to the queried Data Request.
    }

    /// Data struct containing the Witnet-provided result to a Data Request.
    struct Result {
        bool success;           // Flag stating whether the request could get solved successfully, or not.
        WitnetCBOR.CBOR value;  // Resulting value, in CBOR-serialized bytes.
    }

    /// Final query's result status from a requester's point of view.
    enum ResultStatus {
        Void,
        Awaiting,
        Ready,
        Error
    }

    /// Data struct describing an error when trying to fetch a Witnet-provided result to a Data Request.
    struct ResultError {
        ResultErrorCodes code;
        string reason;
    }

    enum ResultErrorCodes {
        /// 0x00: Unknown error. Something went really bad!
        Unknown, 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Script format errors =============================================================================================
            /// 0x01: At least one of the source scripts is not a valid CBOR-encoded value.
            SourceScriptNotCBOR, 
            /// 0x02: The CBOR value decoded from a source script is not an Array.
            SourceScriptNotArray,
            /// 0x03: The Array value decoded form a source script is not a valid Data Request.
            SourceScriptNotRADON,
            /// Unallocated
            ScriptFormat0x04, ScriptFormat0x05, ScriptFormat0x06, ScriptFormat0x07, ScriptFormat0x08, ScriptFormat0x09,
            ScriptFormat0x0A, ScriptFormat0x0B, ScriptFormat0x0C, ScriptFormat0x0D, ScriptFormat0x0E, ScriptFormat0x0F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Complexity errors ================================================================================================
            /// 0x10: The request contains too many sources.
            RequestTooManySources,
            /// 0x11: The script contains too many calls.
            ScriptTooManyCalls,
            /// Unallocated
            Complexity0x12, Complexity0x13, Complexity0x14, Complexity0x15, Complexity0x16, Complexity0x17, Complexity0x18,
            Complexity0x19, Complexity0x1A, Complexity0x1B, Complexity0x1C, Complexity0x1D, Complexity0x1E, Complexity0x1F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Operator errors ===================================================================================================
            /// 0x20: The operator does not exist.
            UnsupportedOperator,
            /// Unallocated
            Operator0x21, Operator0x22, Operator0x23, Operator0x24, Operator0x25, Operator0x26, Operator0x27, Operator0x28,
            Operator0x29, Operator0x2A, Operator0x2B, Operator0x2C, Operator0x2D, Operator0x2E, Operator0x2F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Retrieval-specific errors =========================================================================================
            /// 0x30: At least one of the sources could not be retrieved, but returned HTTP error.
            HTTP,
            /// 0x31: Retrieval of at least one of the sources timed out.
            RetrievalTimeout,
            /// Unallocated
            Retrieval0x32, Retrieval0x33, Retrieval0x34, Retrieval0x35, Retrieval0x36, Retrieval0x37, Retrieval0x38, 
            Retrieval0x39, Retrieval0x3A, Retrieval0x3B, Retrieval0x3C, Retrieval0x3D, Retrieval0x3E, Retrieval0x3F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Math errors =======================================================================================================
            /// 0x40: Math operator caused an underflow.
            Underflow,
            /// 0x41: Math operator caused an overflow.
            Overflow,
            /// 0x42: Tried to divide by zero.
            DivisionByZero,
            /// Unallocated
            Math0x43, Math0x44, Math0x45, Math0x46, Math0x47, Math0x48, Math0x49, 
            Math0x4A, Math0x4B, Math0x4C, Math0x4D, Math0x4E, Math0x4F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Other errors ======================================================================================================
            /// 0x50: Received zero reveals
            NoReveals,
            /// 0x51: Insufficient consensus in tally precondition clause
            InsufficientConsensus,
            /// 0x52: Received zero commits
            InsufficientCommits,
            /// 0x53: Generic error during tally execution
            TallyExecution,
            /// Unallocated
            OtherError0x54, OtherError0x55, OtherError0x56, OtherError0x57, OtherError0x58, OtherError0x59,
            OtherError0x5A, OtherError0x5B, OtherError0x5C, OtherError0x5D, OtherError0x5E, OtherError0x5F,
            /// 0x60: Invalid reveal serialization (malformed reveals are converted to this value)
            MalformedReveal,
            /// Unallocated
            OtherError0x61, OtherError0x62, OtherError0x63, OtherError0x64, OtherError0x65, OtherError0x66,
            OtherError0x67, OtherError0x68, OtherError0x69, OtherError0x6A, OtherError0x6B, OtherError0x6C,
            OtherError0x6D, OtherError0x6E,OtherError0x6F,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Access errors =====================================================================================================
            /// 0x70: Tried to access a value from an array using an index that is out of bounds
            ArrayIndexOutOfBounds,
            /// 0x71: Tried to access a value from a map using a key that does not exist
            MapKeyNotFound,
            /// Unallocated
            OtherError0x72, OtherError0x73, OtherError0x74, OtherError0x75, OtherError0x76, OtherError0x77, OtherError0x78, 
            OtherError0x79, OtherError0x7A, OtherError0x7B, OtherError0x7C, OtherError0x7D, OtherError0x7E, OtherError0x7F, 
            OtherError0x80, OtherError0x81, OtherError0x82, OtherError0x83, OtherError0x84, OtherError0x85, OtherError0x86, 
            OtherError0x87, OtherError0x88, OtherError0x89, OtherError0x8A, OtherError0x8B, OtherError0x8C, OtherError0x8D, 
            OtherError0x8E, OtherError0x8F, OtherError0x90, OtherError0x91, OtherError0x92, OtherError0x93, OtherError0x94, 
            OtherError0x95, OtherError0x96, OtherError0x97, OtherError0x98, OtherError0x99, OtherError0x9A, OtherError0x9B,
            OtherError0x9C, OtherError0x9D, OtherError0x9E, OtherError0x9F, OtherError0xA0, OtherError0xA1, OtherError0xA2, 
            OtherError0xA3, OtherError0xA4, OtherError0xA5, OtherError0xA6, OtherError0xA7, OtherError0xA8, OtherError0xA9, 
            OtherError0xAA, OtherError0xAB, OtherError0xAC, OtherError0xAD, OtherError0xAE, OtherError0xAF, OtherError0xB0,
            OtherError0xB1, OtherError0xB2, OtherError0xB3, OtherError0xB4, OtherError0xB5, OtherError0xB6, OtherError0xB7,
            OtherError0xB8, OtherError0xB9, OtherError0xBA, OtherError0xBB, OtherError0xBC, OtherError0xBD, OtherError0xBE,
            OtherError0xBF, OtherError0xC0, OtherError0xC1, OtherError0xC2, OtherError0xC3, OtherError0xC4, OtherError0xC5,
            OtherError0xC6, OtherError0xC7, OtherError0xC8, OtherError0xC9, OtherError0xCA, OtherError0xCB, OtherError0xCC,
            OtherError0xCD, OtherError0xCE, OtherError0xCF, OtherError0xD0, OtherError0xD1, OtherError0xD2, OtherError0xD3,
            OtherError0xD4, OtherError0xD5, OtherError0xD6, OtherError0xD7, OtherError0xD8, OtherError0xD9, OtherError0xDA,
            OtherError0xDB, OtherError0xDC, OtherError0xDD, OtherError0xDE, OtherError0xDF,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Bridge errors: errors that only belong in inter-client communication ==============================================
            /// 0xE0: Requests that cannot be parsed must always get this error as their result.
            /// However, this is not a valid result in a Tally transaction, because invalid requests
            /// are never included into blocks and therefore never get a Tally in response.
            BridgeMalformedRequest,
            /// 0xE1: Witnesses exceeds 100
            BridgePoorIncentives,
            /// 0xE2: The request is rejected on the grounds that it may cause the submitter to spend or stake an
            /// amount of value that is unjustifiably high when compared with the reward they will be getting
            BridgeOversizedResult,
            /// Unallocated
            OtherError0xE3, OtherError0xE4, OtherError0xE5, OtherError0xE6, OtherError0xE7, OtherError0xE8, OtherError0xE9,
            OtherError0xEA, OtherError0xEB, OtherError0xEC, OtherError0xED, OtherError0xEE, OtherError0xEF, OtherError0xF0,
            OtherError0xF1, OtherError0xF2, OtherError0xF3, OtherError0xF4, OtherError0xF5, OtherError0xF6, OtherError0xF7,
            OtherError0xF8, OtherError0xF9, OtherError0xFA, OtherError0xFB, OtherError0xFC, OtherError0xFD, OtherError0xFE,
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// 0xFF: Some tally error is not intercepted but should
        UnhandledIntercept
    }


    /// ===============================================================================================================
    /// --- 'Witnet.Result' helper methods ----------------------------------------------------------------------------

    modifier _isError(Result memory result) {
        require(!result.success, "Witnet: no actual errors");
        _;
    }

    modifier _isReady(Result memory result) {
        require(result.success, "Witnet: tried to decode value from errored result.");
        _;
    }

    /// @dev Decode an address from the Witnet.Result's CBOR value.
    function asAddress(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (address)
    {
        if (result.value.majorType == uint8(WitnetCBOR.MAJOR_TYPE_BYTES)) {
            return toAddress(result.value.readBytes());
        } else {
            // TODO
            revert("WitnetLib: reading address from string not yet supported.");
        }
    }

    /// @dev Decode a `bool` value from the Witnet.Result's CBOR value.
    function asBool(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bool)
    {
        return result.value.readBool();
    }

    /// @dev Decode a `bytes` value from the Witnet.Result's CBOR value.
    function asBytes(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns(bytes memory)
    {
        return result.value.readBytes();
    }

    /// @dev Decode a `bytes4` value from the Witnet.Result's CBOR value.
    function asBytes4(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bytes4)
    {
        return toBytes4(asBytes(result));
    }

    /// @dev Decode a `bytes32` value from the Witnet.Result's CBOR value.
    function asBytes32(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (bytes32)
    {
        return toBytes32(asBytes(result));
    }

    /// @notice Returns the Witnet.Result's unread CBOR value.
    function asCborValue(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (WitnetCBOR.CBOR memory)
    {
        return result.value;
    }

    /// @notice Decode array of CBOR values from the Witnet.Result's CBOR value. 
    function asCborArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (WitnetCBOR.CBOR[] memory)
    {
        return result.value.readArray();
    }

    /// @dev Decode a fixed16 (half-precision) numeric value from the Witnet.Result's CBOR value.
    /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values.
    /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`.
    /// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
    function asFixed16(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int32)
    {
        return result.value.readFloat16();
    }

    /// @dev Decode an array of fixed16 values from the Witnet.Result's CBOR value.
    function asFixed16Array(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int32[] memory)
    {
        return result.value.readFloat16Array();
    }

    /// @dev Decode an `int64` value from the Witnet.Result's CBOR value.
    function asInt(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int)
    {
        return result.value.readInt();
    }

    /// @dev Decode an array of integer numeric values from a Witnet.Result as an `int[]` array.
    /// @param result An instance of Witnet.Result.
    /// @return The `int[]` decoded from the Witnet.Result.
    function asIntArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (int[] memory)
    {
        return result.value.readIntArray();
    }

    /// @dev Decode a `string` value from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `string` decoded from the Witnet.Result.
    function asText(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns(string memory)
    {
        return result.value.readString();
    }

    /// @dev Decode an array of strings from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `string[]` decoded from the Witnet.Result.
    function asTextArray(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (string[] memory)
    {
        return result.value.readStringArray();
    }

    /// @dev Decode a `uint64` value from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `uint` decoded from the Witnet.Result.
    function asUint(Witnet.Result memory result)
        internal pure
        _isReady(result)
        returns (uint)
    {
        return result.value.readUint();
    }

    /// @dev Decode an array of `uint64` values from the Witnet.Result's CBOR value.
    /// @param result An instance of Witnet.Result.
    /// @return The `uint[]` decoded from the Witnet.Result.
    function asUintArray(Witnet.Result memory result)
        internal pure
        returns (uint[] memory)
    {
        return result.value.readUintArray();
    }


    /// ===============================================================================================================
    /// --- 'bytes' helper methods ------------------------------------------------------------------------------------

    /// @dev Witnet function that computes the hash of a CBOR-encoded Data Request.
    function hash(bytes memory _bytecode) internal view returns (bytes32) {
        if (
            block.chainid != 1101           // Polygon zkEVM mainnet
                && block.chainid != 1442    // Polygon zkEVM testnet
        ) {
            return sha256(_bytecode);
        } else {
            return keccak256(_bytecode);
        }
    }

    /// @dev Transform given bytes into a Witnet.Result instance.
    /// @param bytecode Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory bytecode)
        internal pure
        returns (Witnet.Result memory)
    {
        WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(bytecode);
        return _resultFromCborValue(cborValue);
    }

    function toAddress(bytes memory _value) internal pure returns (address) {
        return address(toBytes20(_value));
    }

    function toBytes4(bytes memory _value) internal pure returns (bytes4) {
        return bytes4(toFixedBytes(_value, 4));
    }
    
    function toBytes20(bytes memory _value) internal pure returns (bytes20) {
        return bytes20(toFixedBytes(_value, 20));
    }
    
    function toBytes32(bytes memory _value) internal pure returns (bytes32) {
        return toFixedBytes(_value, 32);
    }

    function toFixedBytes(bytes memory _value, uint8 _numBytes)
        internal pure
        returns (bytes32 _bytes32)
    {
        assert(_numBytes <= 32);
        unchecked {
            uint _len = _value.length > _numBytes ? _numBytes : _value.length;
            for (uint _i = 0; _i < _len; _i ++) {
                _bytes32 |= bytes32(_value[_i] & 0xff) >> (_i * 8);
            }
        }
    }


    /// ===============================================================================================================
    /// --- 'string' helper methods -----------------------------------------------------------------------------------

    function toLowerCase(string memory str)
        internal pure
        returns (string memory)
    {
        bytes memory lowered = new bytes(bytes(str).length);
        unchecked {
            for (uint i = 0; i < lowered.length; i ++) {
                uint8 char = uint8(bytes(str)[i]);
                if (char >= 65 && char <= 90) {
                    lowered[i] = bytes1(char + 32);
                } else {
                    lowered[i] = bytes1(char);
                }
            }
        }
        return string(lowered);
    }

    /// @notice Converts bytes32 into string.
    function toString(bytes32 _bytes32)
        internal pure
        returns (string memory)
    {
        bytes memory _bytes = new bytes(_toStringLength(_bytes32));
        for (uint _i = 0; _i < _bytes.length;) {
            _bytes[_i] = _bytes32[_i];
            unchecked {
                _i ++;
            }
        }
        return string(_bytes);
    }

    function tryUint(string memory str)
        internal pure
        returns (uint res, bool)
    {
        unchecked {
            for (uint256 i = 0; i < bytes(str).length; i++) {
                if (
                    (uint8(bytes(str)[i]) - 48) < 0
                        || (uint8(bytes(str)[i]) - 48) > 9
                ) {
                    return (0, false);
                }
                res += (uint8(bytes(str)[i]) - 48) * 10 ** (bytes(str).length - i - 1);
            }
            return (res, true);
        }   
    }


    /// ===============================================================================================================
    /// --- 'uint8' helper methods ------------------------------------------------------------------------------------

    /// @notice Convert a `uint8` into a 2 characters long `string` representing its two less significant hexadecimal values.
    function toHexString(uint8 _u)
        internal pure
        returns (string memory)
    {
        bytes memory b2 = new bytes(2);
        uint8 d0 = uint8(_u / 16) + 48;
        uint8 d1 = uint8(_u % 16) + 48;
        if (d0 > 57)
            d0 += 7;
        if (d1 > 57)
            d1 += 7;
        b2[0] = bytes1(d0);
        b2[1] = bytes1(d1);
        return string(b2);
    }

    /// @notice Convert a `uint8` into a 1, 2 or 3 characters long `string` representing its.
    /// three less significant decimal values.
    function toString(uint8 _u)
        internal pure
        returns (string memory)
    {
        if (_u < 10) {
            bytes memory b1 = new bytes(1);
            b1[0] = bytes1(uint8(_u) + 48);
            return string(b1);
        } else if (_u < 100) {
            bytes memory b2 = new bytes(2);
            b2[0] = bytes1(uint8(_u / 10) + 48);
            b2[1] = bytes1(uint8(_u % 10) + 48);
            return string(b2);
        } else {
            bytes memory b3 = new bytes(3);
            b3[0] = bytes1(uint8(_u / 100) + 48);
            b3[1] = bytes1(uint8(_u % 100 / 10) + 48);
            b3[2] = bytes1(uint8(_u % 10) + 48);
            return string(b3);
        }
    }

    /// @notice Convert a `uint` into a string` representing its value.
    function toString(uint v)
        internal pure 
        returns (string memory)
    {
        uint maxlength = 100;
        bytes memory reversed = new bytes(maxlength);
        uint i = 0;
        do {
            uint8 remainder = uint8(v % 10);
            v = v / 10;
            reversed[i ++] = bytes1(48 + remainder);
        } while (v != 0);
        bytes memory buf = new bytes(i);
        for (uint j = 1; j <= i; j ++) {
            buf[j - 1] = reversed[i - j];
        }
        return string(buf);
    }


    /// ===============================================================================================================
    /// --- Witnet library private methods ----------------------------------------------------------------------------

    /// @dev Decode a CBOR value into a Witnet.Result instance.
    function _resultFromCborValue(WitnetCBOR.CBOR memory cbor)
        private pure
        returns (Witnet.Result memory)    
    {
        // Witnet uses CBOR tag 39 to represent RADON error code identifiers.
        // [CBOR tag 39] Identifiers for CBOR: https://github.com/lucas-clemente/cbor-specs/blob/master/id.md
        bool success = cbor.tag != 39;
        return Witnet.Result(success, cbor);
    }

    /// @dev Calculate length of string-equivalent to given bytes32.
    function _toStringLength(bytes32 _bytes32)
        private pure
        returns (uint _length)
    {
        for (; _length < 32; ) {
            if (_bytes32[_length] == 0) {
                break;
            }
            unchecked {
                _length ++;
            }
        }
    }
}
          

/contracts/libs/WitnetBuffer.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

/// @title A convenient wrapper around the `bytes memory` type that exposes a buffer-like interface
/// @notice The buffer has an inner cursor that tracks the final offset of every read, i.e. any subsequent read will
/// start with the byte that goes right after the last one in the previous read.
/// @dev `uint32` is used here for `cursor` because `uint16` would only enable seeking up to 8KB, which could in some
/// theoretical use cases be exceeded. Conversely, `uint32` supports up to 512MB, which cannot credibly be exceeded.
/// @author The Witnet Foundation.
library WitnetBuffer {

  error EmptyBuffer();
  error IndexOutOfBounds(uint index, uint range);
  error MissingArgs(uint expected, uint given);

  /// Iterable bytes buffer.
  struct Buffer {
      bytes data;
      uint cursor;
  }

  // Ensures we access an existing index in an array
  modifier withinRange(uint index, uint _range) {
    if (index > _range) {
      revert IndexOutOfBounds(index, _range);
    }
    _;
  }

  /// @notice Concatenate undefinite number of bytes chunks.
  /// @dev Faster than looping on `abi.encodePacked(output, _buffs[ix])`.
  function concat(bytes[] memory _buffs)
    internal pure
    returns (bytes memory output)
  {
    unchecked {
      uint destinationPointer;
      uint destinationLength;
      assembly {
        // get safe scratch location
        output := mload(0x40)
        // set starting destination pointer
        destinationPointer := add(output, 32)
      }      
      for (uint ix = 1; ix <= _buffs.length; ix ++) {  
        uint source;
        uint sourceLength;
        uint sourcePointer;        
        assembly {
          // load source length pointer
          source := mload(add(_buffs, mul(ix, 32)))
          // load source length
          sourceLength := mload(source)
          // sets source memory pointer
          sourcePointer := add(source, 32)
        }
        memcpy(
          destinationPointer,
          sourcePointer,
          sourceLength
        );
        assembly {          
          // increase total destination length
          destinationLength := add(destinationLength, sourceLength)
          // sets destination memory pointer
          destinationPointer := add(destinationPointer, sourceLength)
        }
      }
      assembly {
        // protect output bytes
        mstore(output, destinationLength)
        // set final output length
        mstore(0x40, add(mload(0x40), add(destinationLength, 32)))
      }
    }
  }

  function fork(WitnetBuffer.Buffer memory buffer)
    internal pure
    returns (WitnetBuffer.Buffer memory)
  {
    return Buffer(
      buffer.data,
      buffer.cursor
    );
  }

  function mutate(
      WitnetBuffer.Buffer memory buffer,
      uint length,
      bytes memory pokes
    )
    internal pure
    withinRange(length, buffer.data.length - buffer.cursor + 1)
  {
    bytes[] memory parts = new bytes[](3);
    parts[0] = peek(
      buffer,
      0,
      buffer.cursor
    );
    parts[1] = pokes;
    parts[2] = peek(
      buffer,
      buffer.cursor + length,
      buffer.data.length - buffer.cursor - length
    );
    buffer.data = concat(parts);
  }

  /// @notice Read and consume the next byte from the buffer.
  /// @param buffer An instance of `Buffer`.
  /// @return The next byte in the buffer counting from the cursor position.
  function next(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor, buffer.data.length)
    returns (bytes1)
  {
    // Return the byte at the position marked by the cursor and advance the cursor all at once
    return buffer.data[buffer.cursor ++];
  }

  function peek(
      WitnetBuffer.Buffer memory buffer,
      uint offset,
      uint length
    )
    internal pure
    withinRange(offset + length, buffer.data.length)
    returns (bytes memory)
  {
    bytes memory data = buffer.data;
    bytes memory peeks = new bytes(length);
    uint destinationPointer;
    uint sourcePointer;
    assembly {
      destinationPointer := add(peeks, 32)
      sourcePointer := add(add(data, 32), offset)
    }
    memcpy(
      destinationPointer,
      sourcePointer,
      length
    );
    return peeks;
  }

  // @notice Extract bytes array from buffer starting from current cursor.
  /// @param buffer An instance of `Buffer`.
  /// @param length How many bytes to peek from the Buffer.
  // solium-disable-next-line security/no-assign-params
  function peek(
      WitnetBuffer.Buffer memory buffer,
      uint length
    )
    internal pure
    withinRange(length, buffer.data.length - buffer.cursor)
    returns (bytes memory)
  {
    return peek(
      buffer,
      buffer.cursor,
      length
    );
  }

  /// @notice Read and consume a certain amount of bytes from the buffer.
  /// @param buffer An instance of `Buffer`.
  /// @param length How many bytes to read and consume from the buffer.
  /// @return output A `bytes memory` containing the first `length` bytes from the buffer, counting from the cursor position.
  function read(Buffer memory buffer, uint length)
    internal pure
    withinRange(buffer.cursor + length, buffer.data.length)
    returns (bytes memory output)
  {
    // Create a new `bytes memory destination` value
    output = new bytes(length);
    // Early return in case that bytes length is 0
    if (length > 0) {
      bytes memory input = buffer.data;
      uint offset = buffer.cursor;
      // Get raw pointers for source and destination
      uint sourcePointer;
      uint destinationPointer;
      assembly {
        sourcePointer := add(add(input, 32), offset)
        destinationPointer := add(output, 32)
      }
      // Copy `length` bytes from source to destination
      memcpy(
        destinationPointer,
        sourcePointer,
        length
      );
      // Move the cursor forward by `length` bytes
      seek(
        buffer,
        length,
        true
      );
    }
  }
  
  /// @notice Read and consume the next 2 bytes from the buffer as an IEEE 754-2008 floating point number enclosed in an
  /// `int32`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `float16`
  /// use cases. In other words, the integer output of this method is 10,000 times the actual value. The input bytes are
  /// expected to follow the 16-bit base-2 format (a.k.a. `binary16`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int32` value of the next 4 bytes in the buffer counting from the cursor position.
  function readFloat16(Buffer memory buffer)
    internal pure
    returns (int32 result)
  {
    uint32 value = readUint16(buffer);
    // Get bit at position 0
    uint32 sign = value & 0x8000;
    // Get bits 1 to 5, then normalize to the [-15, 16] range so as to counterweight the IEEE 754 exponent bias
    int32 exponent = (int32(value & 0x7c00) >> 10) - 15;
    // Get bits 6 to 15
    int32 fraction = int32(value & 0x03ff);
    // Add 2^10 to the fraction if exponent is not -15
    if (exponent != -15) {
      fraction |= 0x400;
    } else if (exponent == 16) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat16: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 1024)`
    if (exponent >= 0) {
      result = int32(int(
        int(1 << uint256(int256(exponent)))
          * 10000
          * fraction
      ) >> 10);
    } else {
      result = int32(int(
        int(fraction)
          * 10000
          / int(1 << uint(int(- exponent)))
      ) >> 10);
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  /// @notice Consume the next 4 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `float32`
  /// use cases. In other words, the integer output of this method is 10^9 times the actual value. The input bytes are
  /// expected to follow the 64-bit base-2 format (a.k.a. `binary32`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
  function readFloat32(Buffer memory buffer)
    internal pure
    returns (int result)
  {
    uint value = readUint32(buffer);
    // Get bit at position 0
    uint sign = value & 0x80000000;
    // Get bits 1 to 8, then normalize to the [-127, 128] range so as to counterweight the IEEE 754 exponent bias
    int exponent = (int(value & 0x7f800000) >> 23) - 127;
    // Get bits 9 to 31
    int fraction = int(value & 0x007fffff);
    // Add 2^23 to the fraction if exponent is not -127
    if (exponent != -127) {
      fraction |= 0x800000;
    } else if (exponent == 128) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat32: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 2^23)`
    if (exponent >= 0) {
      result = (
        int(1 << uint(exponent))
          * (10 ** 9)
          * fraction
      ) >> 23;
    } else {
      result = (
        fraction 
          * (10 ** 9)
          / int(1 << uint(-exponent)) 
      ) >> 23;
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  /// @notice Consume the next 8 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `float64`
  /// use cases. In other words, the integer output of this method is 10^15 times the actual value. The input bytes are
  /// expected to follow the 64-bit base-2 format (a.k.a. `binary64`) in the IEEE 754-2008 standard.
  /// @param buffer An instance of `Buffer`.
  /// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
  function readFloat64(Buffer memory buffer)
    internal pure
    returns (int result)
  {
    uint value = readUint64(buffer);
    // Get bit at position 0
    uint sign = value & 0x8000000000000000;
    // Get bits 1 to 12, then normalize to the [-1023, 1024] range so as to counterweight the IEEE 754 exponent bias
    int exponent = (int(value & 0x7ff0000000000000) >> 52) - 1023;
    // Get bits 6 to 15
    int fraction = int(value & 0x000fffffffffffff);
    // Add 2^52 to the fraction if exponent is not -1023
    if (exponent != -1023) {
      fraction |= 0x10000000000000;
    } else if (exponent == 1024) {
      revert(
        string(abi.encodePacked(
          "WitnetBuffer.readFloat64: ",
          sign != 0 ? "negative" : hex"",
          " infinity"
        ))
      );
    }
    // Compute `2 ^ exponent · (1 + fraction / 1024)`
    if (exponent >= 0) {
      result = (
        int(1 << uint(exponent))
          * (10 ** 15)
          * fraction
      ) >> 52;
    } else {
      result = (
        fraction 
          * (10 ** 15)
          / int(1 << uint(-exponent)) 
      ) >> 52;
    }
    // Make the result negative if the sign bit is not 0
    if (sign != 0) {
      result *= -1;
    }
  }

  // Read a text string of a given length from a buffer. Returns a `bytes memory` value for the sake of genericness,
  /// but it can be easily casted into a string with `string(result)`.
  // solium-disable-next-line security/no-assign-params
  function readText(
      WitnetBuffer.Buffer memory buffer,
      uint64 length
    )
    internal pure
    returns (bytes memory text)
  {
    text = new bytes(length);
    unchecked {
      for (uint64 index = 0; index < length; index ++) {
        uint8 char = readUint8(buffer);
        if (char & 0x80 != 0) {
          if (char < 0xe0) {
            char = (char & 0x1f) << 6
              | (readUint8(buffer) & 0x3f);
            length -= 1;
          } else if (char < 0xf0) {
            char  = (char & 0x0f) << 12
              | (readUint8(buffer) & 0x3f) << 6
              | (readUint8(buffer) & 0x3f);
            length -= 2;
          } else {
            char = (char & 0x0f) << 18
              | (readUint8(buffer) & 0x3f) << 12
              | (readUint8(buffer) & 0x3f) << 6  
              | (readUint8(buffer) & 0x3f);
            length -= 3;
          }
        }
        text[index] = bytes1(char);
      }
      // Adjust text to actual length:
      assembly {
        mstore(text, length)
      }
    }
  }

  /// @notice Read and consume the next byte from the buffer as an `uint8`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint8` value of the next byte in the buffer counting from the cursor position.
  function readUint8(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor, buffer.data.length)
    returns (uint8 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 1), offset))
    }
    buffer.cursor ++;
  }

  /// @notice Read and consume the next 2 bytes from the buffer as an `uint16`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint16` value of the next 2 bytes in the buffer counting from the cursor position.
  function readUint16(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 2, buffer.data.length)
    returns (uint16 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 2), offset))
    }
    buffer.cursor += 2;
  }

  /// @notice Read and consume the next 4 bytes from the buffer as an `uint32`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint32` value of the next 4 bytes in the buffer counting from the cursor position.
  function readUint32(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 4, buffer.data.length)
    returns (uint32 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 4), offset))
    }
    buffer.cursor += 4;
  }

  /// @notice Read and consume the next 8 bytes from the buffer as an `uint64`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint64` value of the next 8 bytes in the buffer counting from the cursor position.
  function readUint64(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 8, buffer.data.length)
    returns (uint64 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 8), offset))
    }
    buffer.cursor += 8;
  }

  /// @notice Read and consume the next 16 bytes from the buffer as an `uint128`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint128` value of the next 16 bytes in the buffer counting from the cursor position.
  function readUint128(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 16, buffer.data.length)
    returns (uint128 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 16), offset))
    }
    buffer.cursor += 16;
  }

  /// @notice Read and consume the next 32 bytes from the buffer as an `uint256`.
  /// @param buffer An instance of `Buffer`.
  /// @return value The `uint256` value of the next 32 bytes in the buffer counting from the cursor position.
  function readUint256(Buffer memory buffer)
    internal pure
    withinRange(buffer.cursor + 32, buffer.data.length)
    returns (uint256 value)
  {
    bytes memory data = buffer.data;
    uint offset = buffer.cursor;
    assembly {
      value := mload(add(add(data, 32), offset))
    }
    buffer.cursor += 32;
  }

  /// @notice Count number of required parameters for given bytes arrays
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input Bytes array containing strings.
  /// @param count Highest wildcard index found, plus 1.
  function argsCountOf(bytes memory input)
    internal pure
    returns (uint8 count)
  {
    if (input.length < 3) {
      return 0;
    }
    unchecked {
      uint ix = 0; 
      uint length = input.length - 2;
      for (; ix < length; ) {
        if (
          input[ix] == bytes1("\\")
            && input[ix + 2] == bytes1("\\")
            && input[ix + 1] >= bytes1("0")
            && input[ix + 1] <= bytes1("9")
        ) {
          uint8 ax = uint8(uint8(input[ix + 1]) - uint8(bytes1("0")) + 1);
          if (ax > count) {
            count = ax;
          }
          ix += 3;
        } else {
          ix ++;
        }
      }
    }
  }

  /// @notice Replace bytecode indexed wildcards by correspondent substrings.
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input Bytes array containing strings.
  /// @param args Array of substring values for replacing indexed wildcards.
  /// @return output Resulting bytes array after replacing all wildcards.
  /// @return hits Total number of replaced wildcards.
  function replace(bytes memory input, string[] memory args)
    internal pure
    returns (bytes memory output, uint hits)
  {
    uint ix = 0; uint lix = 0;
    uint inputLength;
    uint inputPointer;
    uint outputLength;
    uint outputPointer;    
    uint source;
    uint sourceLength;
    uint sourcePointer;

    if (input.length < 3) {
      return (input, 0);
    }
    
    assembly {
      // set starting input pointer
      inputPointer := add(input, 32)
      // get safe output location
      output := mload(0x40)
      // set starting output pointer
      outputPointer := add(output, 32)
    }         

    unchecked {
      uint length = input.length - 2;
      for (; ix < length; ) {
        if (
          input[ix] == bytes1("\\")
            && input[ix + 2] == bytes1("\\")
            && input[ix + 1] >= bytes1("0")
            && input[ix + 1] <= bytes1("9")
        ) {
          inputLength = (ix - lix);
          if (ix > lix) {
            memcpy(
              outputPointer,
              inputPointer,
              inputLength
            );
            inputPointer += inputLength + 3;
            outputPointer += inputLength;
          } else {
            inputPointer += 3;
          }
          uint ax = uint(uint8(input[ix + 1]) - uint8(bytes1("0")));
          if (ax >= args.length) {
            revert MissingArgs(ax + 1, args.length);
          }
          assembly {
            source := mload(add(args, mul(32, add(ax, 1))))
            sourceLength := mload(source)
            sourcePointer := add(source, 32)      
          }        
          memcpy(
            outputPointer,
            sourcePointer,
            sourceLength
          );
          outputLength += inputLength + sourceLength;
          outputPointer += sourceLength;
          ix += 3;
          lix = ix;
          hits ++;
        } else {
          ix ++;
        }
      }
      ix = input.length;    
    }
    if (outputLength > 0) {
      if (ix > lix ) {
        memcpy(
          outputPointer,
          inputPointer,
          ix - lix
        );
        outputLength += (ix - lix);
      }
      assembly {
        // set final output length
        mstore(output, outputLength)
        // protect output bytes
        mstore(0x40, add(mload(0x40), add(outputLength, 32)))
      }
    }
    else {
      return (input, 0);
    }
  }

  /// @notice Replace string indexed wildcards by correspondent substrings.
  /// @dev Wildcard format: "\#\", with # in ["0".."9"].
  /// @param input String potentially containing wildcards.
  /// @param args Array of substring values for replacing indexed wildcards.
  /// @return output Resulting string after replacing all wildcards.
  function replace(string memory input, string[] memory args)
    internal pure
    returns (string memory)
  {
    (bytes memory _outputBytes, ) = replace(bytes(input), args);
    return string(_outputBytes);
  }

  /// @notice Move the inner cursor of the buffer to a relative or absolute position.
  /// @param buffer An instance of `Buffer`.
  /// @param offset How many bytes to move the cursor forward.
  /// @param relative Whether to count `offset` from the last position of the cursor (`true`) or the beginning of the
  /// buffer (`true`).
  /// @return The final position of the cursor (will equal `offset` if `relative` is `false`).
  // solium-disable-next-line security/no-assign-params
  function seek(
      Buffer memory buffer,
      uint offset,
      bool relative
    )
    internal pure
    withinRange(offset, buffer.data.length)
    returns (uint)
  {
    // Deal with relative offsets
    if (relative) {
      offset += buffer.cursor;
    }
    buffer.cursor = offset;
    return offset;
  }

  /// @notice Move the inner cursor a number of bytes forward.
  /// @dev This is a simple wrapper around the relative offset case of `seek()`.
  /// @param buffer An instance of `Buffer`.
  /// @param relativeOffset How many bytes to move the cursor forward.
  /// @return The final position of the cursor.
  function seek(
      Buffer memory buffer,
      uint relativeOffset
    )
    internal pure
    returns (uint)
  {
    return seek(
      buffer,
      relativeOffset,
      true
    );
  }

  /// @notice Copy bytes from one memory address into another.
  /// @dev This function was borrowed from Nick Johnson's `solidity-stringutils` lib, and reproduced here under the terms
  /// of [Apache License 2.0](https://github.com/Arachnid/solidity-stringutils/blob/master/LICENSE).
  /// @param dest Address of the destination memory.
  /// @param src Address to the source memory.
  /// @param len How many bytes to copy.
  // solium-disable-next-line security/no-assign-params
  function memcpy(
      uint dest,
      uint src,
      uint len
    )
    private pure
  {
    unchecked {
      // Copy word-length chunks while possible
      for (; len >= 32; len -= 32) {
        assembly {
          mstore(dest, mload(src))
        }
        dest += 32;
        src += 32;
      }
      if (len > 0) {
        // Copy remaining bytes
        uint _mask = 256 ** (32 - len) - 1;
        assembly {
          let srcpart := and(mload(src), not(_mask))
          let destpart := and(mload(dest), _mask)
          mstore(dest, or(destpart, srcpart))
        }
      }
    }
  }

}
          

/contracts/libs/WitnetCBOR.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./WitnetBuffer.sol";

/// @title A minimalistic implementation of “RFC 7049 Concise Binary Object Representation”
/// @notice This library leverages a buffer-like structure for step-by-step decoding of bytes so as to minimize
/// the gas cost of decoding them into a useful native type.
/// @dev Most of the logic has been borrowed from Patrick Gansterer’s cbor.js library: https://github.com/paroga/cbor-js
/// @author The Witnet Foundation.

library WitnetCBOR {

  using WitnetBuffer for WitnetBuffer.Buffer;
  using WitnetCBOR for WitnetCBOR.CBOR;

  /// Data struct following the RFC-7049 standard: Concise Binary Object Representation.
  struct CBOR {
      WitnetBuffer.Buffer buffer;
      uint8 initialByte;
      uint8 majorType;
      uint8 additionalInformation;
      uint64 len;
      uint64 tag;
  }

  uint8 internal constant MAJOR_TYPE_INT = 0;
  uint8 internal constant MAJOR_TYPE_NEGATIVE_INT = 1;
  uint8 internal constant MAJOR_TYPE_BYTES = 2;
  uint8 internal constant MAJOR_TYPE_STRING = 3;
  uint8 internal constant MAJOR_TYPE_ARRAY = 4;
  uint8 internal constant MAJOR_TYPE_MAP = 5;
  uint8 internal constant MAJOR_TYPE_TAG = 6;
  uint8 internal constant MAJOR_TYPE_CONTENT_FREE = 7;

  uint32 internal constant UINT32_MAX = type(uint32).max;
  uint64 internal constant UINT64_MAX = type(uint64).max;
  
  error EmptyArray();
  error InvalidLengthEncoding(uint length);
  error UnexpectedMajorType(uint read, uint expected);
  error UnsupportedPrimitive(uint primitive);
  error UnsupportedMajorType(uint unexpected);  

  modifier isMajorType(
      WitnetCBOR.CBOR memory cbor,
      uint8 expected
  ) {
    if (cbor.majorType != expected) {
      revert UnexpectedMajorType(cbor.majorType, expected);
    }
    _;
  }

  modifier notEmpty(WitnetBuffer.Buffer memory buffer) {
    if (buffer.data.length == 0) {
      revert WitnetBuffer.EmptyBuffer();
    }
    _;
  }

  function eof(CBOR memory cbor)
    internal pure
    returns (bool)
  {
    return cbor.buffer.cursor >= cbor.buffer.data.length;
  }

  /// @notice Decode a CBOR structure from raw bytes.
  /// @dev This is the main factory for CBOR instances, which can be later decoded into native EVM types.
  /// @param bytecode Raw bytes representing a CBOR-encoded value.
  /// @return A `CBOR` instance containing a partially decoded value.
  function fromBytes(bytes memory bytecode)
    internal pure
    returns (CBOR memory)
  {
    WitnetBuffer.Buffer memory buffer = WitnetBuffer.Buffer(bytecode, 0);
    return fromBuffer(buffer);
  }

  /// @notice Decode a CBOR structure from raw bytes.
  /// @dev This is an alternate factory for CBOR instances, which can be later decoded into native EVM types.
  /// @param buffer A Buffer structure representing a CBOR-encoded value.
  /// @return A `CBOR` instance containing a partially decoded value.
  function fromBuffer(WitnetBuffer.Buffer memory buffer)
    internal pure
    notEmpty(buffer)
    returns (CBOR memory)
  {
    uint8 initialByte;
    uint8 majorType = 255;
    uint8 additionalInformation;
    uint64 tag = UINT64_MAX;
    uint256 len;
    bool isTagged = true;
    while (isTagged) {
      // Extract basic CBOR properties from input bytes
      initialByte = buffer.readUint8();
      len ++;
      majorType = initialByte >> 5;
      additionalInformation = initialByte & 0x1f;
      // Early CBOR tag parsing.
      if (majorType == MAJOR_TYPE_TAG) {
        uint _cursor = buffer.cursor;
        tag = readLength(buffer, additionalInformation);
        len += buffer.cursor - _cursor;
      } else {
        isTagged = false;
      }
    }
    if (majorType > MAJOR_TYPE_CONTENT_FREE) {
      revert UnsupportedMajorType(majorType);
    }
    return CBOR(
      buffer,
      initialByte,
      majorType,
      additionalInformation,
      uint64(len),
      tag
    );
  }

  function fork(WitnetCBOR.CBOR memory self)
    internal pure
    returns (WitnetCBOR.CBOR memory)
  {
    return CBOR({
      buffer: self.buffer.fork(),
      initialByte: self.initialByte,
      majorType: self.majorType,
      additionalInformation: self.additionalInformation,
      len: self.len,
      tag: self.tag
    });
  }

  function settle(CBOR memory self)
      internal pure
      returns (WitnetCBOR.CBOR memory)
  {
    if (!self.eof()) {
      return fromBuffer(self.buffer);
    } else {
      return self;
    }
  }

  function skip(CBOR memory self)
      internal pure
      returns (WitnetCBOR.CBOR memory)
  {
    if (
      self.majorType == MAJOR_TYPE_INT
        || self.majorType == MAJOR_TYPE_NEGATIVE_INT
        || (
          self.majorType == MAJOR_TYPE_CONTENT_FREE 
            && self.additionalInformation >= 25
            && self.additionalInformation <= 27
        )
    ) {
      self.buffer.cursor += self.peekLength();
    } else if (
        self.majorType == MAJOR_TYPE_STRING
          || self.majorType == MAJOR_TYPE_BYTES
    ) {
      uint64 len = readLength(self.buffer, self.additionalInformation);
      self.buffer.cursor += len;
    } else if (
      self.majorType == MAJOR_TYPE_ARRAY
        || self.majorType == MAJOR_TYPE_MAP
    ) { 
      self.len = readLength(self.buffer, self.additionalInformation);      
    } else if (
       self.majorType != MAJOR_TYPE_CONTENT_FREE
        || (
          self.additionalInformation != 20
            && self.additionalInformation != 21
        )
    ) {
      revert("WitnetCBOR.skip: unsupported major type");
    }
    return self;
  }

  function peekLength(CBOR memory self)
    internal pure
    returns (uint64)
  {
    if (self.additionalInformation < 24) {
      return 0;
    } else if (self.additionalInformation < 28) {
      return uint64(1 << (self.additionalInformation - 24));
    } else {
      revert InvalidLengthEncoding(self.additionalInformation);
    }
  }

  function readArray(CBOR memory self)
    internal pure
    isMajorType(self, MAJOR_TYPE_ARRAY)
    returns (CBOR[] memory items)
  {
    // read array's length and move self cursor forward to the first array element:
    uint64 len = readLength(self.buffer, self.additionalInformation);
    items = new CBOR[](len + 1);
    for (uint ix = 0; ix < len; ix ++) {
      // settle next element in the array:
      self = self.settle();
      // fork it and added to the list of items to be returned:
      items[ix] = self.fork();
      if (self.majorType == MAJOR_TYPE_ARRAY) {
        CBOR[] memory _subitems = self.readArray();
        // move forward to the first element after inner array:
        self = _subitems[_subitems.length - 1];
      } else if (self.majorType == MAJOR_TYPE_MAP) {
        CBOR[] memory _subitems = self.readMap();
        // move forward to the first element after inner map:
        self = _subitems[_subitems.length - 1];
      } else {
        // move forward to the next element:
        self.skip();
      }
    }
    // return self cursor as extra item at the end of the list,
    // as to optimize recursion when jumping over nested arrays:
    items[len] = self;
  }

  function readMap(CBOR memory self)
    internal pure
    isMajorType(self, MAJOR_TYPE_MAP)
    returns (CBOR[] memory items)
  {
    // read number of items within the map and move self cursor forward to the first inner element:
    uint64 len = readLength(self.buffer, self.additionalInformation) * 2;
    items = new CBOR[](len + 1);
    for (uint ix = 0; ix < len; ix ++) {
      // settle next element in the array:
      self = self.settle();
      // fork it and added to the list of items to be returned:
      items[ix] = self.fork();
      if (ix % 2 == 0 && self.majorType != MAJOR_TYPE_STRING) {
        revert UnexpectedMajorType(self.majorType, MAJOR_TYPE_STRING);
      } else if (self.majorType == MAJOR_TYPE_ARRAY || self.majorType == MAJOR_TYPE_MAP) {
        CBOR[] memory _subitems = (self.majorType == MAJOR_TYPE_ARRAY
            ? self.readArray()
            : self.readMap()
        );
        // move forward to the first element after inner array or map:
        self = _subitems[_subitems.length - 1];
      } else {
        // move forward to the next element:
        self.skip();
      }
    }
    // return self cursor as extra item at the end of the list,
    // as to optimize recursion when jumping over nested arrays:
    items[len] = self;
  }

  /// Reads the length of the settle CBOR item from a buffer, consuming a different number of bytes depending on the
  /// value of the `additionalInformation` argument.
  function readLength(
      WitnetBuffer.Buffer memory buffer,
      uint8 additionalInformation
    ) 
    internal pure
    returns (uint64)
  {
    if (additionalInformation < 24) {
      return additionalInformation;
    }
    if (additionalInformation == 24) {
      return buffer.readUint8();
    }
    if (additionalInformation == 25) {
      return buffer.readUint16();
    }
    if (additionalInformation == 26) {
      return buffer.readUint32();
    }
    if (additionalInformation == 27) {
      return buffer.readUint64();
    }
    if (additionalInformation == 31) {
      return UINT64_MAX;
    }
    revert InvalidLengthEncoding(additionalInformation);
  }

  /// @notice Read a `CBOR` structure into a native `bool` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as a `bool` value.
  function readBool(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (bool)
  {
    if (cbor.additionalInformation == 20) {
      return false;
    } else if (cbor.additionalInformation == 21) {
      return true;
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `bytes` value.
  /// @param cbor An instance of `CBOR`.
  /// @return output The value represented by the input, as a `bytes` value.   
  function readBytes(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_BYTES)
    returns (bytes memory output)
  {
    cbor.len = readLength(
      cbor.buffer,
      cbor.additionalInformation
    );
    if (cbor.len == UINT32_MAX) {
      // These checks look repetitive but the equivalent loop would be more expensive.
      uint32 length = uint32(_readIndefiniteStringLength(
        cbor.buffer,
        cbor.majorType
      ));
      if (length < UINT32_MAX) {
        output = abi.encodePacked(cbor.buffer.read(length));
        length = uint32(_readIndefiniteStringLength(
          cbor.buffer,
          cbor.majorType
        ));
        if (length < UINT32_MAX) {
          output = abi.encodePacked(
            output,
            cbor.buffer.read(length)
          );
        }
      }
    } else {
      return cbor.buffer.read(uint32(cbor.len));
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed16` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`
  /// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int128` value.
  function readFloat16(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int32)
  {
    if (cbor.additionalInformation == 25) {
      return cbor.buffer.readFloat16();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed32` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `fixed64`
  /// use cases. In other words, the output of this method is 10^9 times the actual value, encoded into an `int`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int` value.
  function readFloat32(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int)
  {
    if (cbor.additionalInformation == 26) {
      return cbor.buffer.readFloat32();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a `fixed64` value.
  /// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
  /// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `fixed64`
  /// use cases. In other words, the output of this method is 10^15 times the actual value, encoded into an `int`.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int` value.
  function readFloat64(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
    returns (int)
  {
    if (cbor.additionalInformation == 27) {
      return cbor.buffer.readFloat64();
    } else {
      revert UnsupportedPrimitive(cbor.additionalInformation);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int128[]` value whose inner values follow the same convention 
  /// @notice as explained in `decodeFixed16`.
  /// @param cbor An instance of `CBOR`.
  function readFloat16Array(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (int32[] memory values)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      values = new int32[](length);
      for (uint64 i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        values[i] = readFloat16(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int128` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `int128` value.
  function readInt(CBOR memory cbor)
    internal pure
    returns (int)
  {
    if (cbor.majorType == 1) {
      uint64 _value = readLength(
        cbor.buffer,
        cbor.additionalInformation
      );
      return int(-1) - int(uint(_value));
    } else if (cbor.majorType == 0) {
      // Any `uint64` can be safely casted to `int128`, so this method supports majorType 1 as well so as to have offer
      // a uniform API for positive and negative numbers
      return int(readUint(cbor));
    }
    else {
      revert UnexpectedMajorType(cbor.majorType, 1);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `int[]` value.
  /// @param cbor instance of `CBOR`.
  /// @return array The value represented by the input, as an `int[]` value.
  function readIntArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (int[] memory array)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      array = new int[](length);
      for (uint i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        array[i] = readInt(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `string` value.
  /// @param cbor An instance of `CBOR`.
  /// @return text The value represented by the input, as a `string` value.
  function readString(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_STRING)
    returns (string memory text)
  {
    cbor.len = readLength(cbor.buffer, cbor.additionalInformation);
    if (cbor.len == UINT64_MAX) {
      bool _done;
      while (!_done) {
        uint64 length = _readIndefiniteStringLength(
          cbor.buffer,
          cbor.majorType
        );
        if (length < UINT64_MAX) {
          text = string(abi.encodePacked(
            text,
            cbor.buffer.readText(length / 4)
          ));
        } else {
          _done = true;
        }
      }
    } else {
      return string(cbor.buffer.readText(cbor.len));
    }
  }

  /// @notice Decode a `CBOR` structure into a native `string[]` value.
  /// @param cbor An instance of `CBOR`.
  /// @return strings The value represented by the input, as an `string[]` value.
  function readStringArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (string[] memory strings)
  {
    uint length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      strings = new string[](length);
      for (uint i = 0; i < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        strings[i] = readString(item);
        unchecked {
          i ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }

  /// @notice Decode a `CBOR` structure into a native `uint64` value.
  /// @param cbor An instance of `CBOR`.
  /// @return The value represented by the input, as an `uint64` value.
  function readUint(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_INT)
    returns (uint)
  {
    return readLength(
      cbor.buffer,
      cbor.additionalInformation
    );
  }

  /// @notice Decode a `CBOR` structure into a native `uint64[]` value.
  /// @param cbor An instance of `CBOR`.
  /// @return values The value represented by the input, as an `uint64[]` value.
  function readUintArray(CBOR memory cbor)
    internal pure
    isMajorType(cbor, MAJOR_TYPE_ARRAY)
    returns (uint[] memory values)
  {
    uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
    if (length < UINT64_MAX) {
      values = new uint[](length);
      for (uint ix = 0; ix < length; ) {
        CBOR memory item = fromBuffer(cbor.buffer);
        values[ix] = readUint(item);
        unchecked {
          ix ++;
        }
      }
    } else {
      revert InvalidLengthEncoding(length);
    }
  }  

  /// Read the length of a CBOR indifinite-length item (arrays, maps, byte strings and text) from a buffer, consuming
  /// as many bytes as specified by the first byte.
  function _readIndefiniteStringLength(
      WitnetBuffer.Buffer memory buffer,
      uint8 majorType
    )
    private pure
    returns (uint64 len)
  {
    uint8 initialByte = buffer.readUint8();
    if (initialByte == 0xff) {
      return UINT64_MAX;
    }
    len = readLength(
      buffer,
      initialByte & 0x1f
    );
    if (len >= UINT64_MAX) {
      revert InvalidLengthEncoding(len);
    } else if (majorType != (initialByte >> 5)) {
      revert UnexpectedMajorType((initialByte >> 5), majorType);
    }
  }
 
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{},"evmVersion":"london"}
              

Contract ABI

[{"type":"function","stateMutability":"pure","outputs":[{"type":"tuple","name":"_error","internalType":"struct Witnet.ResultError","components":[{"type":"uint8"},{"type":"string"}]}],"name":"asError","inputs":[{"type":"tuple","name":"result","internalType":"struct Witnet.Result","components":[{"type":"bool"},{"type":"tuple","components":[{"type":"tuple","components":[{"type":"bytes"},{"type":"uint256"}]},{"type":"uint8"},{"type":"uint8"},{"type":"uint8"},{"type":"uint64"},{"type":"uint64"}]}]}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"tuple","name":"_error","internalType":"struct Witnet.ResultError","components":[{"type":"uint8"},{"type":"string"}]}],"name":"resultErrorFromCborBytes","inputs":[{"type":"bytes","name":"cborBytes","internalType":"bytes"}]},{"type":"error","name":"EmptyBuffer","inputs":[]},{"type":"error","name":"IndexOutOfBounds","inputs":[{"type":"uint256","name":"index","internalType":"uint256"},{"type":"uint256","name":"range","internalType":"uint256"}]},{"type":"error","name":"InvalidLengthEncoding","inputs":[{"type":"uint256","name":"length","internalType":"uint256"}]},{"type":"error","name":"UnexpectedMajorType","inputs":[{"type":"uint256","name":"read","internalType":"uint256"},{"type":"uint256","name":"expected","internalType":"uint256"}]},{"type":"error","name":"UnsupportedMajorType","inputs":[{"type":"uint256","name":"unexpected","internalType":"uint256"}]},{"type":"error","name":"UnsupportedPrimitive","inputs":[{"type":"uint256","name":"primitive","internalType":"uint256"}]}]
              

Contract Creation Code

0x612b4b61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063059c737f146100455780637e1a92b71461006e575b600080fd5b6100586100533660046120c2565b610081565b6040516100659190612263565b60405180910390f35b61005861007c3660046122b1565b6100ad565b6040805180820190915260008152606060208201526100a76100a2836100df565b61012f565b92915050565b60408051808201909152600081526060602082015260006100cd83610b4b565b90506100d88161012f565b9392505050565b8051606090156101225760405162461bcd60e51b81526020600482015260096024820152686e6f206572726f727360b81b60448201526064015b60405180910390fd5b6100a78260200151610b63565b60408051808201909152600081526060602082015260028251101561018157604080518082019091528060008152602001604051806060016040528060278152602001612a9060279139905292915050565b6101a482600081518110610197576101976122e5565b6020026020010151610d1d565b60ff8111156101b5576101b56121fd565b819060ff8111156101c8576101c86121fd565b908160ff8111156101db576101db6121fd565b9052506001815160ff8111156101f3576101f36121fd565b148015610201575060018251115b1561025e57604051602001610244907f5769746e65743a205261646f6e3a20696e76616c69642043424f522076616c75815261329760f11b602082015260220190565b60408051601f198184030181529190526020820152919050565b6002815160ff811115610273576102736121fd565b148015610281575060018251115b156102df57604051602001610244907f5769746e65743a205261646f6e3a2043424f522076616c75652065787065637481527f656420746f20626520616e206172726179206f662063616c6c732e00000000006020820152603b0190565b6003815160ff8111156102f4576102f46121fd565b148015610302575060018251115b1561036057604051602001610244907f5769746e65743a205261646f6e3a2043424f522076616c75652065787065637481527f656420746f2062652061206461746120726571756573742e0000000000000000602082015260380190565b6010815160ff811115610375576103756121fd565b148015610383575060018251115b156103b857604080517f5769746e65743a205261646f6e3a20746f6f206d616e7920736f75726365732e602082015201610244565b6011815160ff8111156103cd576103cd6121fd565b1480156103db575060018251115b15610411576040517f5769746e65743a205261646f6e3a20746f6f206d616e792063616c6c732e00006020820152603e01610244565b6020815160ff811115610426576104266121fd565b148015610434575060038251115b156104835761045c8260028151811061044f5761044f6122e5565b6020026020010151610d82565b6104728360018151811061044f5761044f6122e5565b6040516020016102449291906122fb565b6030815160ff811115610498576104986121fd565b1480156104a6575060028251115b156104d9576104c96104c483600181518110610197576101976122e5565b610e88565b6040516020016102449190612380565b6031815160ff8111156104ee576104ee6121fd565b1480156104fc575060018251115b15610532576040517f5769746e65743a2052657472696576616c3a2074696d656f75742e00000000006020820152603b01610244565b6040815160ff811115610547576105476121fd565b148015610555575060018251115b1561059a57604051602001610244907f5769746e65743a204167677265676174696f6e3a206d61746820756e646572668152633637bb9760e11b602082015260240190565b6041815160ff8111156105af576105af6121fd565b1480156105bd575060018251115b1561060157604051602001610244907f5769746e65743a204167677265676174696f6e3a206d617468206f766572666c81526237bb9760e91b602082015260230190565b6042815160ff811115610616576106166121fd565b148015610624575060018251115b1561066b57604051602001610244907f5769746e65743a204167677265676174696f6e3a206469766973696f6e206279815265103d32b9379760d11b602082015260260190565b60e0815160ff811115610680576106806121fd565b036106a8576040518060600160405280603b8152602001612a55603b91396020820152919050565b60e1815160ff8111156106bd576106bd6121fd565b036106e5576040518060600160405280603b8152602001612ab7603b91396020820152919050565b60e2815160ff8111156106fa576106fa6121fd565b03610722576040518060600160405280603981526020016129f9603991396020820152919050565b6051815160ff811115610737576107376121fd565b148015610745575060038251115b156108a65760008260018151811061075f5761075f6122e5565b60200260200101516060015160ff166019146107af5766038d7ea4c680006107a084600181518110610793576107936122e5565b6020026020010151610fe3565b6107aa9190612402565b6107e3565b6127106107d5846001815181106107c8576107c86122e5565b6020026020010151611061565b6107df9190612430565b60030b5b90506000836002815181106107fa576107fa6122e5565b60200260200101516060015160ff1660191461083d5766038d7ea4c6800061082e85600281518110610793576107936122e5565b6108389190612402565b610864565b612710610856856002815181106107c8576107c86122e5565b6108609190612430565b60030b5b905061086f82610e88565b61087882610e88565b60405160200161088992919061246b565b60408051601f19818403018152919052602084015250610b469050565b6052815160ff8111156108bb576108bb6121fd565b036108e357604051806060016040528060248152602001612af2602491396020820152919050565b6053815160ff8111156108f8576108f86121fd565b148015610906575060038251115b15610931576109218260028151811061044f5761044f6122e5565b60405160200161024491906124f3565b6070815160ff811115610946576109466121fd565b148015610954575060028251115b15610982576109726104c483600181518110610197576101976122e5565b6040516020016102449190612543565b6071815160ff811115610997576109976121fd565b1480156109a5575060028251115b156109d0576109c08260018151811061044f5761044f6122e5565b60405160200161024491906125db565b6050815160ff8111156109e5576109e56121fd565b03610a2d576040518060400160405280601a81526020017f5769746e65743a2054616c6c793a206e6f2072657665616c732e0000000000008152508160200181905250919050565b6060815160ff811115610a4257610a426121fd565b03610a83576040805180820190915260208082527f5769746e65743a2054616c6c793a206d616c666f726d65642072657665616c2e81830152820152919050565b60ff815160ff811115610a9857610a986121fd565b03610ac057604051806060016040528060238152602001612a32602391396020820152919050565b8051610adc9060ff811115610ad757610ad76121fd565b6110bb565b6002835111610b0457604051806040016040528060018152602001601760f91b815250610b35565b610b15600184516104c49190612674565b604051602001610b259190612687565b6040516020818303038152906040525b6040516020016102449291906126c4565b919050565b60606000610b58836111ad565b90506100d8816100df565b60608160048060ff16826040015160ff1614610ba357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b6000610bb7856000015186606001516111cb565b9050610bc4816001612715565b6001600160401b03166001600160401b03811115610be457610be4611fae565b604051908082528060200260200182016040528015610c1d57816020015b610c0a611f46565b815260200190600190039081610c025790505b50935060005b816001600160401b0316811015610ced57610c3d86611293565b9550610c48866112bb565b858281518110610c5a57610c5a6122e5565b6020026020010181905250600460ff16866040015160ff1603610cb3576000610c8287610b63565b90508060018251610c939190612674565b81518110610ca357610ca36122e5565b6020026020010151965050610cdb565b600560ff16866040015160ff1603610cd0576000610c8287611353565b610cd986611547565b505b80610ce581612735565b915050610c23565b508484826001600160401b031681518110610d0a57610d0a6122e5565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff1614610d5d57604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b610d6f846000015185606001516111cb565b6001600160401b031692505b5050919050565b60608160038060ff16826040015160ff1614610dc257604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b610dd4846000015185606001516111cb565b6001600160401b03166080850181905267fffffffffffffffe1901610e715760005b80610e6b576000610e0f8660000151876040015161170c565b90506001600160401b038082161015610e605784610e39610e3160048461274e565b8851906117b9565b604051602001610e4a929190612774565b6040516020818303038152906040529450610e65565b600191505b50610df6565b50610d7b565b60808401518451610e81916117b9565b9250610d7b565b60408051606480825260a08201909252606091906000908260208201818036833701905050905060005b6000610ebf600a876127a3565b9050610ecc600a876127b7565b9550610ed98160306127cb565b60f81b8383610ee781612735565b945081518110610ef957610ef96122e5565b60200101906001600160f81b031916908160001a9053505084600003610eb2576000816001600160401b03811115610f3357610f33611fae565b6040519080825280601f01601f191660200182016040528015610f5d576020820181803683370190505b50905060015b828111610fd95783610f758285612674565b81518110610f8557610f856122e5565b01602001516001600160f81b03191682610fa0600184612674565b81518110610fb057610fb06122e5565b60200101906001600160f81b031916908160001a90535080610fd181612735565b915050610f63565b5095945050505050565b60008160078060ff16826040015160ff161461102357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b836060015160ff16601b0361103d578351610e8190611940565b6060840151604051630c0304c160e21b815260ff9091166004820152602401610119565b60008160078060ff16826040015160ff16146110a157604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b836060015160ff1660190361103d578351610e8190611aa2565b6040805160028082528183019092526060916000919060208201818036833701905050905060006110ed6010856127e4565b6110f89060306127cb565b90506000611107601086612806565b6111129060306127cb565b905060398260ff16111561112e5761112b6007836127cb565b91505b60398160ff161115611148576111456007826127cb565b90505b8160f81b8360008151811061115f5761115f6122e5565b60200101906001600160f81b031916908160001a9053508060f81b8360018151811061118d5761118d6122e5565b60200101906001600160f81b031916908160001a90535091949350505050565b6111b5611f8d565b60006111c083611bd4565b90506100d881611bf9565b600060188260ff1610156111e3575060ff81166100a7565b8160ff16601803611201576111f783611c2d565b60ff1690506100a7565b8160ff166019036112205761121583611c8f565b61ffff1690506100a7565b8160ff16601a036112415761123483611cfb565b63ffffffff1690506100a7565b8160ff16601b0361125c5761125583611d5a565b90506100a7565b8160ff16601f0361127557506001600160401b036100a7565b604051636d785b1360e01b815260ff83166004820152602401610119565b61129b611f46565b815180515160209091015110156112b75781516100a790611db9565b5090565b6112c3611f46565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff161461139357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b60006113a7856000015186606001516111cb565b6113b2906002612828565b90506113bf816001612715565b6001600160401b03166001600160401b038111156113df576113df611fae565b60405190808252806020026020018201604052801561141857816020015b611405611f46565b8152602001906001900390816113fd5790505b50935060005b816001600160401b0316811015610ced5761143886611293565b9550611443866112bb565b858281518110611455576114556122e5565b602090810291909101015261146b6002826127a3565b1580156114805750604086015160ff16600314155b156114ae57604080870151905161800560e51b815260ff909116600482015260036024820152604401610119565b604086015160ff16600414806114cb5750604086015160ff166005145b1561152a57604086015160009060ff166004146114f0576114eb87611353565b6114f9565b6114f987610b63565b9050806001825161150a9190612674565b8151811061151a5761151a6122e5565b6020026020010151965050611535565b61153386611547565b505b8061153f81612735565b91505061141e565b61154f611f46565b604082015160ff16158061156a5750604082015160ff166001145b806115a35750604082015160ff16600714801561158f57506019826060015160ff1610155b80156115a35750601b826060015160ff1611155b156115d6576115b182611ed9565b6001600160401b031682600001516020018181516115cf9190612853565b9052505090565b604082015160ff16600314806115f35750604082015160ff166002145b1561163757600061160c836000015184606001516111cb565b9050806001600160401b0316836000015160200181815161162d9190612853565b9052506112b79050565b604082015160ff16600414806116545750604082015160ff166005145b1561167d5761166b826000015183606001516111cb565b6001600160401b031660808301525090565b604082015160ff1660071415806116af5750816060015160ff166014141580156116af5750816060015160ff16601514155b156112b75760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b6064820152608401610119565b60008061171884611c2d565b90508060ff1660ff03611735576001600160401b039150506100a7565b6117428482601f166111cb565b91506001600160401b038083161061177857604051636d785b1360e01b81526001600160401b0383166004820152602401610119565b60ff83166007600583901c16146117b25760405161800560e51b81526007600583901c16600482015260ff84166024820152604401610119565b5092915050565b6060816001600160401b03166001600160401b038111156117dc576117dc611fae565b6040519080825280601f01601f191660200182016040528015611806576020820181803683370190505b50905060005b826001600160401b0316816001600160401b0316101561193757600061183185611c2d565b905060808116156118f85760e08160ff16101561186d5761185185611c2d565b603f16600682601f1660ff16901b1790506001840393506118f8565b60f08160ff1610156118b25761188285611c2d565b603f16600661189087611c2d565b603f1660ff16901b600c83600f1660ff16901b171790506002840393506118f8565b6118bb85611c2d565b603f1660066118c987611c2d565b603f16901b600c6118d988611c2d565b603f1660ff16901b601284600f1660ff16901b17171790506003840393505b8060f81b83836001600160401b031681518110611917576119176122e5565b60200101906001600160f81b031916908160001a9053505060010161180c565b50908152919050565b60008061194c83611d5a565b6001600160401b0381169150678000000000000000811690600090611981906103ff90677ff00000000000001660341d612866565b9050660fffffffffffff83166103fe1982146119a557661000000000000017611a23565b8161040003611a2357826000036119cb57604051806020016040528060008152506119ed565b604051806040016040528060088152602001676e6567617469766560c01b8152505b6040516020016119fd9190612886565b60408051601f198184030181529082905262461bcd60e51b8252610119916004016128de565b60008212611a5557603481611a426001851b66038d7ea4c680006128f1565b611a4c91906128f1565b901d9450611a84565b6034611a6083612921565b6001901b611a758366038d7ea4c680006128f1565b611a7f9190612402565b901d94505b8215611a9957611a96600019866128f1565b94505b50505050919050565b600080611aae83611c8f565b61ffff81169150618000811690600090611ad490600f90617c001660030b600a1d61293d565b90506103ff8316600e19600383900b14611af15761040017611b51565b8160030b601003611b51578263ffffffff16600003611b1f5760405180602001604052806000815250611b41565b604051806040016040528060088152602001676e6567617469766560c01b8152505b6040516020016119fd9190612964565b60008260030b12611b8a57600a8160030b8360030b6001901b612710611b7791906128f1565b611b8191906128f1565b901d9450611bbc565b600a611b958361299c565b60030b6001901b8260030b612710611bad91906128f1565b611bb79190612402565b901d94505b63ffffffff831615611a9957611a96600019866129bf565b611bdc611f46565b60408051808201909152828152600060208201526100d881611db9565b611c01611f8d565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b6000816020015182600001515180821115611c65576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051808301600101519550908190611c8282612735565b8152505050505050919050565b600081602001516002611ca29190612853565b82515180821115611cd0576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600281840181015196509091611cee8284612853565b9052509395945050505050565b600081602001516004611d0e9190612853565b82515180821115611d3c576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600481840181015196509091611cee8284612853565b600081602001516008611d6d9190612853565b82515180821115611d9b576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600881840181015196509091611cee8284612853565b611dc1611f46565b8151518290600003611de6576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611e6957611e0689611c2d565b955081611e1281612735565b6007600589901c169650601f881695509250506005198501611e61576020890151611e3d8a866111cb565b9350808a60200151611e4f9190612674565b611e599084612853565b925050611df7565b506000611df7565b600760ff86161115611e935760405163bd2ac87960e01b815260ff86166004820152602401610119565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b60006018826060015160ff161015611ef357506000919050565b601c826060015160ff161015611f225760188260600151611f1491906129df565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff9091166004820152602401610119565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b6040518060400160405280600015158152602001611fa9611f46565b905290565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715611fe657611fe6611fae565b60405290565b60405160c081016001600160401b0381118282101715611fe657611fe6611fae565b600082601f83011261201f57600080fd5b81356001600160401b038082111561203957612039611fae565b604051601f8301601f19908116603f0116810190828211818310171561206157612061611fae565b8160405283815286602085880101111561207a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b803560ff81168114610b4657600080fd5b80356001600160401b0381168114610b4657600080fd5b600060208083850312156120d557600080fd5b82356001600160401b03808211156120ec57600080fd5b908401906040828703121561210057600080fd5b612108611fc4565b8235801515811461211857600080fd5b8152828401358281111561212b57600080fd5b929092019160c0838803121561214057600080fd5b612148611fec565b83358381111561215757600080fd5b84016040818a03121561216957600080fd5b612171611fc4565b81358581111561218057600080fd5b61218c8b82850161200e565b825250908601358682015281526121a484860161209a565b858201526121b46040850161209a565b60408201526121c56060850161209a565b60608201526121d6608085016120ab565b60808201526121e760a085016120ab565b60a0820152938101939093525090949350505050565b634e487b7160e01b600052602160045260246000fd5b60005b8381101561222e578181015183820152602001612216565b50506000910152565b6000815180845261224f816020860160208601612213565b601f01601f19169290920160200192915050565b6020815260008251610100811061228a57634e487b7160e01b600052602160045260246000fd5b8060208401525060208301516040808401526122a96060840182612237565b949350505050565b6000602082840312156122c357600080fd5b81356001600160401b038111156122d957600080fd5b6122a98482850161200e565b634e487b7160e01b600052603260045260246000fd5b7f5769746e65743a205261646f6e3a20756e737570706f7274656420270000000081526000835161233381601c850160208801612213565b712720666f7220696e7075742074797065202760701b601c91840191820152835161236581602e840160208801612213565b61139760f11b602e9290910191820152603001949350505050565b7f5769746e65743a2052657472696576616c3a20485454502f00000000000000008152600082516123b8816018850160208701612213565b661032b93937b91760c91b6018939091019283015250601f01919050565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600082612411576124116123d6565b600160ff1b82146000198414161561242b5761242b6123ec565b500590565b60008160030b8360030b80612447576124476123d6565b637fffffff19821460001982141615612462576124626123ec565b90059392505050565b7f5769746e65743a2054616c6c793a20696e73756666696369656e7420636f6e73815266032b739bab99d160cd1b6020820152600083516124b3816027850160208801612213565b64012901e1e960dd1b60279184019182015283516124d881602c840160208801612213565b61129760f11b602c9290910191820152602e01949350505050565b7f5769746e65743a2054616c6c793a20657865637574696f6e206572726f723a2081526000825161252b816020850160208701612213565b601760f91b6020939091019283015250602101919050565b7f5769746e65743a204167677265676174696f6e3a20747269656420746f20616381527f6365737320612076616c75652066726f6d20616e2061727261792077697468206020820152690c2dc40d2dcc8caf040560b31b6040820152600082516125b481604a850160208701612213565b6f149037baba1037b3103137bab732399760811b604a939091019283015250605a01919050565b7f5769746e65743a204167677265676174696f6e3a20747269656420746f20616381527f6365737320612076616c75652066726f6d2061206d617020776974682061206b60208201526432bc90141160d91b604082015260008251612647816045850160208701612213565b751114903a3430ba103bb0b9903737ba103337bab7321760511b6045939091019283015250605b01919050565b818103818111156100a7576100a76123ec565b61040560f31b8152600082516126a4816002850160208701612213565b68103830b930b6b9949760b91b6002939091019283015250600b01919050565b720aadcd0c2dcc8d8cac840cae4e4dee4744060f606b1b8152600083516126f2816013850160208801612213565b835190830190612709816013840160208801612213565b01601301949350505050565b6001600160401b038181168382160190808211156117b2576117b26123ec565b600060018201612747576127476123ec565b5060010190565b60006001600160401b0380841680612768576127686123d6565b92169190910492915050565b60008351612786818460208801612213565b83519083019061279a818360208801612213565b01949350505050565b6000826127b2576127b26123d6565b500690565b6000826127c6576127c66123d6565b500490565b60ff81811683821601908111156100a7576100a76123ec565b600060ff8316806127f7576127f76123d6565b8060ff84160491505092915050565b600060ff831680612819576128196123d6565b8060ff84160691505092915050565b6001600160401b0381811683821602808216919082811461284b5761284b6123ec565b505092915050565b808201808211156100a7576100a76123ec565b81810360008312801583831316838312821617156117b2576117b26123ec565b7f5769746e65744275666665722e72656164466c6f617436343a200000000000008152600082516128be81601a850160208701612213565b6820696e66696e69747960b81b601a939091019283015250602301919050565b6020815260006100d86020830184612237565b80820260008212600160ff1b8414161561290d5761290d6123ec565b81810583148215176100a7576100a76123ec565b6000600160ff1b8201612936576129366123ec565b5060000390565b600382810b9082900b03637fffffff198112637fffffff821317156100a7576100a76123ec565b7f5769746e65744275666665722e72656164466c6f617431363a200000000000008152600082516128be81601a850160208701612213565b60008160030b637fffffff1981036129b6576129b66123ec565b60000392915050565b60008260030b8260030b028060030b91508082146117b2576117b26123ec565b60ff82811682821603908111156100a7576100a76123ec56fe5769746e65743a204272696467653a2072656a65637465642064756520746f20706f6f72206272696467696e6720696e63656e74697665732e5769746e65743a2054616c6c793a20756e68616e646c656420696e746572636570742e5769746e65743a204272696467653a206d616c666f726d6564206461746120726571756573742063616e6e6f742062652070726f6365737365642e556e6b6e6f776e206572726f723a206e6f206572726f7220636f64652077617320666f756e642e5769746e65743a204272696467653a2072656a65637465642064756520746f20706f6f72207769746e657373696e6720696e63656e74697665732e5769746e65743a2054616c6c793a20696e73756666696369656e7420636f6d6d6974732ea264697066735822122008d88e8641f5b05bf9e2d6bb4ec96e521a3415ba6fe58014e76ec99a217fb51864736f6c63430008110033

Deployed ByteCode

0x73b5447342ca17a40e59d410b340ba412e22e3620130146080604052600436106100405760003560e01c8063059c737f146100455780637e1a92b71461006e575b600080fd5b6100586100533660046120c2565b610081565b6040516100659190612263565b60405180910390f35b61005861007c3660046122b1565b6100ad565b6040805180820190915260008152606060208201526100a76100a2836100df565b61012f565b92915050565b60408051808201909152600081526060602082015260006100cd83610b4b565b90506100d88161012f565b9392505050565b8051606090156101225760405162461bcd60e51b81526020600482015260096024820152686e6f206572726f727360b81b60448201526064015b60405180910390fd5b6100a78260200151610b63565b60408051808201909152600081526060602082015260028251101561018157604080518082019091528060008152602001604051806060016040528060278152602001612a9060279139905292915050565b6101a482600081518110610197576101976122e5565b6020026020010151610d1d565b60ff8111156101b5576101b56121fd565b819060ff8111156101c8576101c86121fd565b908160ff8111156101db576101db6121fd565b9052506001815160ff8111156101f3576101f36121fd565b148015610201575060018251115b1561025e57604051602001610244907f5769746e65743a205261646f6e3a20696e76616c69642043424f522076616c75815261329760f11b602082015260220190565b60408051601f198184030181529190526020820152919050565b6002815160ff811115610273576102736121fd565b148015610281575060018251115b156102df57604051602001610244907f5769746e65743a205261646f6e3a2043424f522076616c75652065787065637481527f656420746f20626520616e206172726179206f662063616c6c732e00000000006020820152603b0190565b6003815160ff8111156102f4576102f46121fd565b148015610302575060018251115b1561036057604051602001610244907f5769746e65743a205261646f6e3a2043424f522076616c75652065787065637481527f656420746f2062652061206461746120726571756573742e0000000000000000602082015260380190565b6010815160ff811115610375576103756121fd565b148015610383575060018251115b156103b857604080517f5769746e65743a205261646f6e3a20746f6f206d616e7920736f75726365732e602082015201610244565b6011815160ff8111156103cd576103cd6121fd565b1480156103db575060018251115b15610411576040517f5769746e65743a205261646f6e3a20746f6f206d616e792063616c6c732e00006020820152603e01610244565b6020815160ff811115610426576104266121fd565b148015610434575060038251115b156104835761045c8260028151811061044f5761044f6122e5565b6020026020010151610d82565b6104728360018151811061044f5761044f6122e5565b6040516020016102449291906122fb565b6030815160ff811115610498576104986121fd565b1480156104a6575060028251115b156104d9576104c96104c483600181518110610197576101976122e5565b610e88565b6040516020016102449190612380565b6031815160ff8111156104ee576104ee6121fd565b1480156104fc575060018251115b15610532576040517f5769746e65743a2052657472696576616c3a2074696d656f75742e00000000006020820152603b01610244565b6040815160ff811115610547576105476121fd565b148015610555575060018251115b1561059a57604051602001610244907f5769746e65743a204167677265676174696f6e3a206d61746820756e646572668152633637bb9760e11b602082015260240190565b6041815160ff8111156105af576105af6121fd565b1480156105bd575060018251115b1561060157604051602001610244907f5769746e65743a204167677265676174696f6e3a206d617468206f766572666c81526237bb9760e91b602082015260230190565b6042815160ff811115610616576106166121fd565b148015610624575060018251115b1561066b57604051602001610244907f5769746e65743a204167677265676174696f6e3a206469766973696f6e206279815265103d32b9379760d11b602082015260260190565b60e0815160ff811115610680576106806121fd565b036106a8576040518060600160405280603b8152602001612a55603b91396020820152919050565b60e1815160ff8111156106bd576106bd6121fd565b036106e5576040518060600160405280603b8152602001612ab7603b91396020820152919050565b60e2815160ff8111156106fa576106fa6121fd565b03610722576040518060600160405280603981526020016129f9603991396020820152919050565b6051815160ff811115610737576107376121fd565b148015610745575060038251115b156108a65760008260018151811061075f5761075f6122e5565b60200260200101516060015160ff166019146107af5766038d7ea4c680006107a084600181518110610793576107936122e5565b6020026020010151610fe3565b6107aa9190612402565b6107e3565b6127106107d5846001815181106107c8576107c86122e5565b6020026020010151611061565b6107df9190612430565b60030b5b90506000836002815181106107fa576107fa6122e5565b60200260200101516060015160ff1660191461083d5766038d7ea4c6800061082e85600281518110610793576107936122e5565b6108389190612402565b610864565b612710610856856002815181106107c8576107c86122e5565b6108609190612430565b60030b5b905061086f82610e88565b61087882610e88565b60405160200161088992919061246b565b60408051601f19818403018152919052602084015250610b469050565b6052815160ff8111156108bb576108bb6121fd565b036108e357604051806060016040528060248152602001612af2602491396020820152919050565b6053815160ff8111156108f8576108f86121fd565b148015610906575060038251115b15610931576109218260028151811061044f5761044f6122e5565b60405160200161024491906124f3565b6070815160ff811115610946576109466121fd565b148015610954575060028251115b15610982576109726104c483600181518110610197576101976122e5565b6040516020016102449190612543565b6071815160ff811115610997576109976121fd565b1480156109a5575060028251115b156109d0576109c08260018151811061044f5761044f6122e5565b60405160200161024491906125db565b6050815160ff8111156109e5576109e56121fd565b03610a2d576040518060400160405280601a81526020017f5769746e65743a2054616c6c793a206e6f2072657665616c732e0000000000008152508160200181905250919050565b6060815160ff811115610a4257610a426121fd565b03610a83576040805180820190915260208082527f5769746e65743a2054616c6c793a206d616c666f726d65642072657665616c2e81830152820152919050565b60ff815160ff811115610a9857610a986121fd565b03610ac057604051806060016040528060238152602001612a32602391396020820152919050565b8051610adc9060ff811115610ad757610ad76121fd565b6110bb565b6002835111610b0457604051806040016040528060018152602001601760f91b815250610b35565b610b15600184516104c49190612674565b604051602001610b259190612687565b6040516020818303038152906040525b6040516020016102449291906126c4565b919050565b60606000610b58836111ad565b90506100d8816100df565b60608160048060ff16826040015160ff1614610ba357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b6000610bb7856000015186606001516111cb565b9050610bc4816001612715565b6001600160401b03166001600160401b03811115610be457610be4611fae565b604051908082528060200260200182016040528015610c1d57816020015b610c0a611f46565b815260200190600190039081610c025790505b50935060005b816001600160401b0316811015610ced57610c3d86611293565b9550610c48866112bb565b858281518110610c5a57610c5a6122e5565b6020026020010181905250600460ff16866040015160ff1603610cb3576000610c8287610b63565b90508060018251610c939190612674565b81518110610ca357610ca36122e5565b6020026020010151965050610cdb565b600560ff16866040015160ff1603610cd0576000610c8287611353565b610cd986611547565b505b80610ce581612735565b915050610c23565b508484826001600160401b031681518110610d0a57610d0a6122e5565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff1614610d5d57604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b610d6f846000015185606001516111cb565b6001600160401b031692505b5050919050565b60608160038060ff16826040015160ff1614610dc257604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b610dd4846000015185606001516111cb565b6001600160401b03166080850181905267fffffffffffffffe1901610e715760005b80610e6b576000610e0f8660000151876040015161170c565b90506001600160401b038082161015610e605784610e39610e3160048461274e565b8851906117b9565b604051602001610e4a929190612774565b6040516020818303038152906040529450610e65565b600191505b50610df6565b50610d7b565b60808401518451610e81916117b9565b9250610d7b565b60408051606480825260a08201909252606091906000908260208201818036833701905050905060005b6000610ebf600a876127a3565b9050610ecc600a876127b7565b9550610ed98160306127cb565b60f81b8383610ee781612735565b945081518110610ef957610ef96122e5565b60200101906001600160f81b031916908160001a9053505084600003610eb2576000816001600160401b03811115610f3357610f33611fae565b6040519080825280601f01601f191660200182016040528015610f5d576020820181803683370190505b50905060015b828111610fd95783610f758285612674565b81518110610f8557610f856122e5565b01602001516001600160f81b03191682610fa0600184612674565b81518110610fb057610fb06122e5565b60200101906001600160f81b031916908160001a90535080610fd181612735565b915050610f63565b5095945050505050565b60008160078060ff16826040015160ff161461102357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b836060015160ff16601b0361103d578351610e8190611940565b6060840151604051630c0304c160e21b815260ff9091166004820152602401610119565b60008160078060ff16826040015160ff16146110a157604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b836060015160ff1660190361103d578351610e8190611aa2565b6040805160028082528183019092526060916000919060208201818036833701905050905060006110ed6010856127e4565b6110f89060306127cb565b90506000611107601086612806565b6111129060306127cb565b905060398260ff16111561112e5761112b6007836127cb565b91505b60398160ff161115611148576111456007826127cb565b90505b8160f81b8360008151811061115f5761115f6122e5565b60200101906001600160f81b031916908160001a9053508060f81b8360018151811061118d5761118d6122e5565b60200101906001600160f81b031916908160001a90535091949350505050565b6111b5611f8d565b60006111c083611bd4565b90506100d881611bf9565b600060188260ff1610156111e3575060ff81166100a7565b8160ff16601803611201576111f783611c2d565b60ff1690506100a7565b8160ff166019036112205761121583611c8f565b61ffff1690506100a7565b8160ff16601a036112415761123483611cfb565b63ffffffff1690506100a7565b8160ff16601b0361125c5761125583611d5a565b90506100a7565b8160ff16601f0361127557506001600160401b036100a7565b604051636d785b1360e01b815260ff83166004820152602401610119565b61129b611f46565b815180515160209091015110156112b75781516100a790611db9565b5090565b6112c3611f46565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff161461139357604080830151905161800560e51b815260ff91821660048201529082166024820152604401610119565b60006113a7856000015186606001516111cb565b6113b2906002612828565b90506113bf816001612715565b6001600160401b03166001600160401b038111156113df576113df611fae565b60405190808252806020026020018201604052801561141857816020015b611405611f46565b8152602001906001900390816113fd5790505b50935060005b816001600160401b0316811015610ced5761143886611293565b9550611443866112bb565b858281518110611455576114556122e5565b602090810291909101015261146b6002826127a3565b1580156114805750604086015160ff16600314155b156114ae57604080870151905161800560e51b815260ff909116600482015260036024820152604401610119565b604086015160ff16600414806114cb5750604086015160ff166005145b1561152a57604086015160009060ff166004146114f0576114eb87611353565b6114f9565b6114f987610b63565b9050806001825161150a9190612674565b8151811061151a5761151a6122e5565b6020026020010151965050611535565b61153386611547565b505b8061153f81612735565b91505061141e565b61154f611f46565b604082015160ff16158061156a5750604082015160ff166001145b806115a35750604082015160ff16600714801561158f57506019826060015160ff1610155b80156115a35750601b826060015160ff1611155b156115d6576115b182611ed9565b6001600160401b031682600001516020018181516115cf9190612853565b9052505090565b604082015160ff16600314806115f35750604082015160ff166002145b1561163757600061160c836000015184606001516111cb565b9050806001600160401b0316836000015160200181815161162d9190612853565b9052506112b79050565b604082015160ff16600414806116545750604082015160ff166005145b1561167d5761166b826000015183606001516111cb565b6001600160401b031660808301525090565b604082015160ff1660071415806116af5750816060015160ff166014141580156116af5750816060015160ff16601514155b156112b75760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b6064820152608401610119565b60008061171884611c2d565b90508060ff1660ff03611735576001600160401b039150506100a7565b6117428482601f166111cb565b91506001600160401b038083161061177857604051636d785b1360e01b81526001600160401b0383166004820152602401610119565b60ff83166007600583901c16146117b25760405161800560e51b81526007600583901c16600482015260ff84166024820152604401610119565b5092915050565b6060816001600160401b03166001600160401b038111156117dc576117dc611fae565b6040519080825280601f01601f191660200182016040528015611806576020820181803683370190505b50905060005b826001600160401b0316816001600160401b0316101561193757600061183185611c2d565b905060808116156118f85760e08160ff16101561186d5761185185611c2d565b603f16600682601f1660ff16901b1790506001840393506118f8565b60f08160ff1610156118b25761188285611c2d565b603f16600661189087611c2d565b603f1660ff16901b600c83600f1660ff16901b171790506002840393506118f8565b6118bb85611c2d565b603f1660066118c987611c2d565b603f16901b600c6118d988611c2d565b603f1660ff16901b601284600f1660ff16901b17171790506003840393505b8060f81b83836001600160401b031681518110611917576119176122e5565b60200101906001600160f81b031916908160001a9053505060010161180c565b50908152919050565b60008061194c83611d5a565b6001600160401b0381169150678000000000000000811690600090611981906103ff90677ff00000000000001660341d612866565b9050660fffffffffffff83166103fe1982146119a557661000000000000017611a23565b8161040003611a2357826000036119cb57604051806020016040528060008152506119ed565b604051806040016040528060088152602001676e6567617469766560c01b8152505b6040516020016119fd9190612886565b60408051601f198184030181529082905262461bcd60e51b8252610119916004016128de565b60008212611a5557603481611a426001851b66038d7ea4c680006128f1565b611a4c91906128f1565b901d9450611a84565b6034611a6083612921565b6001901b611a758366038d7ea4c680006128f1565b611a7f9190612402565b901d94505b8215611a9957611a96600019866128f1565b94505b50505050919050565b600080611aae83611c8f565b61ffff81169150618000811690600090611ad490600f90617c001660030b600a1d61293d565b90506103ff8316600e19600383900b14611af15761040017611b51565b8160030b601003611b51578263ffffffff16600003611b1f5760405180602001604052806000815250611b41565b604051806040016040528060088152602001676e6567617469766560c01b8152505b6040516020016119fd9190612964565b60008260030b12611b8a57600a8160030b8360030b6001901b612710611b7791906128f1565b611b8191906128f1565b901d9450611bbc565b600a611b958361299c565b60030b6001901b8260030b612710611bad91906128f1565b611bb79190612402565b901d94505b63ffffffff831615611a9957611a96600019866129bf565b611bdc611f46565b60408051808201909152828152600060208201526100d881611db9565b611c01611f8d565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b6000816020015182600001515180821115611c65576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051808301600101519550908190611c8282612735565b8152505050505050919050565b600081602001516002611ca29190612853565b82515180821115611cd0576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600281840181015196509091611cee8284612853565b9052509395945050505050565b600081602001516004611d0e9190612853565b82515180821115611d3c576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600481840181015196509091611cee8284612853565b600081602001516008611d6d9190612853565b82515180821115611d9b576040516363a056dd60e01b81526004810183905260248101829052604401610119565b8351602085018051600881840181015196509091611cee8284612853565b611dc1611f46565b8151518290600003611de6576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611e6957611e0689611c2d565b955081611e1281612735565b6007600589901c169650601f881695509250506005198501611e61576020890151611e3d8a866111cb565b9350808a60200151611e4f9190612674565b611e599084612853565b925050611df7565b506000611df7565b600760ff86161115611e935760405163bd2ac87960e01b815260ff86166004820152602401610119565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b60006018826060015160ff161015611ef357506000919050565b601c826060015160ff161015611f225760188260600151611f1491906129df565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff9091166004820152602401610119565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b6040518060400160405280600015158152602001611fa9611f46565b905290565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715611fe657611fe6611fae565b60405290565b60405160c081016001600160401b0381118282101715611fe657611fe6611fae565b600082601f83011261201f57600080fd5b81356001600160401b038082111561203957612039611fae565b604051601f8301601f19908116603f0116810190828211818310171561206157612061611fae565b8160405283815286602085880101111561207a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b803560ff81168114610b4657600080fd5b80356001600160401b0381168114610b4657600080fd5b600060208083850312156120d557600080fd5b82356001600160401b03808211156120ec57600080fd5b908401906040828703121561210057600080fd5b612108611fc4565b8235801515811461211857600080fd5b8152828401358281111561212b57600080fd5b929092019160c0838803121561214057600080fd5b612148611fec565b83358381111561215757600080fd5b84016040818a03121561216957600080fd5b612171611fc4565b81358581111561218057600080fd5b61218c8b82850161200e565b825250908601358682015281526121a484860161209a565b858201526121b46040850161209a565b60408201526121c56060850161209a565b60608201526121d6608085016120ab565b60808201526121e760a085016120ab565b60a0820152938101939093525090949350505050565b634e487b7160e01b600052602160045260246000fd5b60005b8381101561222e578181015183820152602001612216565b50506000910152565b6000815180845261224f816020860160208601612213565b601f01601f19169290920160200192915050565b6020815260008251610100811061228a57634e487b7160e01b600052602160045260246000fd5b8060208401525060208301516040808401526122a96060840182612237565b949350505050565b6000602082840312156122c357600080fd5b81356001600160401b038111156122d957600080fd5b6122a98482850161200e565b634e487b7160e01b600052603260045260246000fd5b7f5769746e65743a205261646f6e3a20756e737570706f7274656420270000000081526000835161233381601c850160208801612213565b712720666f7220696e7075742074797065202760701b601c91840191820152835161236581602e840160208801612213565b61139760f11b602e9290910191820152603001949350505050565b7f5769746e65743a2052657472696576616c3a20485454502f00000000000000008152600082516123b8816018850160208701612213565b661032b93937b91760c91b6018939091019283015250601f01919050565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600082612411576124116123d6565b600160ff1b82146000198414161561242b5761242b6123ec565b500590565b60008160030b8360030b80612447576124476123d6565b637fffffff19821460001982141615612462576124626123ec565b90059392505050565b7f5769746e65743a2054616c6c793a20696e73756666696369656e7420636f6e73815266032b739bab99d160cd1b6020820152600083516124b3816027850160208801612213565b64012901e1e960dd1b60279184019182015283516124d881602c840160208801612213565b61129760f11b602c9290910191820152602e01949350505050565b7f5769746e65743a2054616c6c793a20657865637574696f6e206572726f723a2081526000825161252b816020850160208701612213565b601760f91b6020939091019283015250602101919050565b7f5769746e65743a204167677265676174696f6e3a20747269656420746f20616381527f6365737320612076616c75652066726f6d20616e2061727261792077697468206020820152690c2dc40d2dcc8caf040560b31b6040820152600082516125b481604a850160208701612213565b6f149037baba1037b3103137bab732399760811b604a939091019283015250605a01919050565b7f5769746e65743a204167677265676174696f6e3a20747269656420746f20616381527f6365737320612076616c75652066726f6d2061206d617020776974682061206b60208201526432bc90141160d91b604082015260008251612647816045850160208701612213565b751114903a3430ba103bb0b9903737ba103337bab7321760511b6045939091019283015250605b01919050565b818103818111156100a7576100a76123ec565b61040560f31b8152600082516126a4816002850160208701612213565b68103830b930b6b9949760b91b6002939091019283015250600b01919050565b720aadcd0c2dcc8d8cac840cae4e4dee4744060f606b1b8152600083516126f2816013850160208801612213565b835190830190612709816013840160208801612213565b01601301949350505050565b6001600160401b038181168382160190808211156117b2576117b26123ec565b600060018201612747576127476123ec565b5060010190565b60006001600160401b0380841680612768576127686123d6565b92169190910492915050565b60008351612786818460208801612213565b83519083019061279a818360208801612213565b01949350505050565b6000826127b2576127b26123d6565b500690565b6000826127c6576127c66123d6565b500490565b60ff81811683821601908111156100a7576100a76123ec565b600060ff8316806127f7576127f76123d6565b8060ff84160491505092915050565b600060ff831680612819576128196123d6565b8060ff84160691505092915050565b6001600160401b0381811683821602808216919082811461284b5761284b6123ec565b505092915050565b808201808211156100a7576100a76123ec565b81810360008312801583831316838312821617156117b2576117b26123ec565b7f5769746e65744275666665722e72656164466c6f617436343a200000000000008152600082516128be81601a850160208701612213565b6820696e66696e69747960b81b601a939091019283015250602301919050565b6020815260006100d86020830184612237565b80820260008212600160ff1b8414161561290d5761290d6123ec565b81810583148215176100a7576100a76123ec565b6000600160ff1b8201612936576129366123ec565b5060000390565b600382810b9082900b03637fffffff198112637fffffff821317156100a7576100a76123ec565b7f5769746e65744275666665722e72656164466c6f617431363a200000000000008152600082516128be81601a850160208701612213565b60008160030b637fffffff1981036129b6576129b66123ec565b60000392915050565b60008260030b8260030b028060030b91508082146117b2576117b26123ec565b60ff82811682821603908111156100a7576100a76123ec56fe5769746e65743a204272696467653a2072656a65637465642064756520746f20706f6f72206272696467696e6720696e63656e74697665732e5769746e65743a2054616c6c793a20756e68616e646c656420696e746572636570742e5769746e65743a204272696467653a206d616c666f726d6564206461746120726571756573742063616e6e6f742062652070726f6365737365642e556e6b6e6f776e206572726f723a206e6f206572726f7220636f64652077617320666f756e642e5769746e65743a204272696467653a2072656a65637465642064756520746f20706f6f72207769746e657373696e6720696e63656e74697665732e5769746e65743a2054616c6c793a20696e73756666696369656e7420636f6d6d6974732ea264697066735822122008d88e8641f5b05bf9e2d6bb4ec96e521a3415ba6fe58014e76ec99a217fb51864736f6c63430008110033