Moonbase Alpha Testnet

Contract

0xcE68F9D657C5B8931a1Baceb77Dc0e71499F7855

Overview

DEV Balance

Moonbase Alpha LogoMoonbase Alpha LogoMoonbase Alpha Logo0 DEV

Multichain Info

N/A
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Latest 25 internal transactions (View All)

Parent Transaction Hash Block From To
73519602024-06-07 10:14:1898 days ago1717755258
0xcE68F9D6...1499F7855
0 DEV
73519602024-06-07 10:14:1898 days ago1717755258
0xcE68F9D6...1499F7855
0 DEV
73519602024-06-07 10:14:1898 days ago1717755258
0xcE68F9D6...1499F7855
0 DEV
73519542024-06-07 10:13:3098 days ago1717755210
0xcE68F9D6...1499F7855
0 DEV
73519112024-06-07 10:08:0698 days ago1717754886
0xcE68F9D6...1499F7855
0 DEV
73519112024-06-07 10:08:0698 days ago1717754886
0xcE68F9D6...1499F7855
0.00002681 DEV
73519112024-06-07 10:08:0698 days ago1717754886
0xcE68F9D6...1499F7855
0 DEV
73519112024-06-07 10:08:0698 days ago1717754886
0xcE68F9D6...1499F7855
0 DEV
73519112024-06-07 10:08:0698 days ago1717754886
0xcE68F9D6...1499F7855
0 DEV
73514962024-06-07 9:24:0098 days ago1717752240
0xcE68F9D6...1499F7855
0.00002681 DEV
73514962024-06-07 9:24:0098 days ago1717752240
0xcE68F9D6...1499F7855
0 DEV
73514522024-06-07 9:19:3098 days ago1717751970
0xcE68F9D6...1499F7855
0 DEV
73514522024-06-07 9:19:3098 days ago1717751970
0xcE68F9D6...1499F7855
0.00002681 DEV
73514522024-06-07 9:19:3098 days ago1717751970
0xcE68F9D6...1499F7855
0 DEV
73514522024-06-07 9:19:3098 days ago1717751970
0xcE68F9D6...1499F7855
0 DEV
73514522024-06-07 9:19:3098 days ago1717751970
0xcE68F9D6...1499F7855
0 DEV
73510052024-06-07 8:31:4898 days ago1717749108
0xcE68F9D6...1499F7855
0.00002681 DEV
73510052024-06-07 8:31:4898 days ago1717749108
0xcE68F9D6...1499F7855
0 DEV
73509682024-06-07 8:28:0098 days ago1717748880
0xcE68F9D6...1499F7855
0 DEV
73509682024-06-07 8:28:0098 days ago1717748880
0xcE68F9D6...1499F7855
0.00002681 DEV
73509682024-06-07 8:28:0098 days ago1717748880
0xcE68F9D6...1499F7855
0 DEV
73509682024-06-07 8:28:0098 days ago1717748880
0xcE68F9D6...1499F7855
0 DEV
73509682024-06-07 8:28:0098 days ago1717748880
0xcE68F9D6...1499F7855
0 DEV
73499702024-06-07 6:34:0098 days ago1717742040
0xcE68F9D6...1499F7855
0.00002681 DEV
73499702024-06-07 6:34:0098 days ago1717742040
0xcE68F9D6...1499F7855
0 DEV
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
WitnetOracleTrustableDefault

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 34 : WitnetOracleTrustableDefault.sol
// SPDX-License-Identifier: MIT

/* solhint-disable var-name-mixedcase */

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

import "./WitnetOracleTrustableBase.sol";

/// @title Witnet Request Board "trustable" implementation contract.
/// @notice Contract to bridge requests to Witnet Decentralized Oracle Network.
/// @dev This contract enables posting requests that Witnet bridges will insert into the Witnet network.
/// The result of the requests will be posted back to this contract by the bridge nodes too.
/// @author The Witnet Foundation
contract WitnetOracleTrustableDefault
    is 
        WitnetOracleTrustableBase
{
    function class() virtual override public view returns (string memory) {
        return type(WitnetOracleTrustableDefault).name;
    }

    uint256 internal immutable __reportResultGasBase;
    uint256 internal immutable __reportResultWithCallbackGasBase;
    uint256 internal immutable __reportResultWithCallbackRevertGasBase;
    uint256 internal immutable __sstoreFromZeroGas;

    constructor(
            WitnetRequestFactory _factory,
            WitnetRequestBytecodes _registry,
            bool _upgradable,
            bytes32 _versionTag,
            uint256 _reportResultGasBase,
            uint256 _reportResultWithCallbackGasBase,
            uint256 _reportResultWithCallbackRevertGasBase,
            uint256 _sstoreFromZeroGas
        )
        WitnetOracleTrustableBase(
            _factory, 
            _registry,
            _upgradable, 
            _versionTag, 
            address(0)
        )
    {   
        __reportResultGasBase = _reportResultGasBase;
        __reportResultWithCallbackGasBase = _reportResultWithCallbackGasBase;
        __reportResultWithCallbackRevertGasBase = _reportResultWithCallbackRevertGasBase;
        __sstoreFromZeroGas = _sstoreFromZeroGas;
    }


    // ================================================================================================================
    // --- Overrides 'IWitnetOracle' ----------------------------------------------------------------------------

    /// @notice Estimate the minimum reward required for posting a data request.
    /// @dev Underestimates if the size of returned data is greater than `_resultMaxSize`. 
    /// @param _gasPrice Expected gas price to pay upon posting the data request.
    /// @param _resultMaxSize Maximum expected size of returned data (in bytes).
    function estimateBaseFee(uint256 _gasPrice, uint16 _resultMaxSize)
        public view
        virtual override
        returns (uint256)
    {
        return _gasPrice * (
            __reportResultGasBase
                + __sstoreFromZeroGas * (
                    4 + (_resultMaxSize == 0 ? 0 : _resultMaxSize - 1) / 32
                )
        );
    }

    /// @notice Estimate the minimum reward required for posting a data request with a callback.
    /// @param _gasPrice Expected gas price to pay upon posting the data request.
    /// @param _callbackGasLimit Maximum gas to be spent when reporting the data request result.
    function estimateBaseFeeWithCallback(uint256 _gasPrice, uint24 _callbackGasLimit)
        public view
        virtual override
        returns (uint256)
    {
        uint _reportResultWithCallbackGasThreshold = (
            __reportResultWithCallbackRevertGasBase
                + 3 * __sstoreFromZeroGas
        );
        if (
            _callbackGasLimit < _reportResultWithCallbackGasThreshold
                || __reportResultWithCallbackGasBase + _callbackGasLimit < _reportResultWithCallbackGasThreshold
        ) {
            return (
                _gasPrice
                    * _reportResultWithCallbackGasThreshold
            );
        } else {
            return (
                _gasPrice 
                    * (
                        __reportResultWithCallbackGasBase
                            + _callbackGasLimit
                    )
            );
        }
    }


    // ================================================================================================================
    // --- Overrides 'Payable' ----------------------------------------------------------------------------------------

    /// Gets current transaction price.
    function _getGasPrice()
        internal view
        virtual override
        returns (uint256)
    {
        return tx.gasprice;
    }

    /// Gets current payment value.
    function _getMsgValue()
        internal view
        virtual override
        returns (uint256)
    {
        return msg.value;
    }

    /// Transfers ETHs to given address.
    /// @param _to Recipient address.
    /// @param _amount Amount of ETHs to transfer.
    function __safeTransferTo(address payable _to, uint256 _amount)
        internal
        virtual override
    {
        payable(_to).transfer(_amount);
    }   
}

File 2 of 34 : Upgradeable.sol
// SPDX-License-Identifier: MIT

/* solhint-disable var-name-mixedcase */

pragma solidity >=0.6.0 <0.9.0;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import "./Initializable.sol";
import "./Proxiable.sol";

abstract contract Upgradeable is Initializable, Proxiable {

    address internal immutable _BASE;
    bytes32 internal immutable _CODEHASH;
    bool internal immutable _UPGRADABLE;

    modifier onlyDelegateCalls virtual {
        require(
            address(this) != _BASE,
            "Upgradeable: not a delegate call"
        );
        _;
    }

    /// Emitted every time the contract gets upgraded.
    /// @param from The address who ordered the upgrading. Namely, the WRB operator in "trustable" implementations.
    /// @param baseAddr The address of the new implementation contract.
    /// @param baseCodehash The EVM-codehash of the new implementation contract.
    /// @param versionTag Ascii-encoded version literal with which the implementation deployer decided to tag it.
    event Upgraded(
        address indexed from,
        address indexed baseAddr,
        bytes32 indexed baseCodehash,
        string  versionTag
    );

    constructor (bool _isUpgradable) {
        address _base = address(this);
        _BASE = _base;
        _UPGRADABLE = _isUpgradable;
    }

    /// @dev Retrieves base contract. Differs from address(this) when called via delegate-proxy pattern.
    function base() public view returns (address) {
        return _BASE;
    }

    /// @dev Retrieves the immutable codehash of this contract, even if invoked as delegatecall.
    function codehash() public view returns (bytes32 _codehash) {
        address _base = _BASE;
        assembly {
            _codehash := extcodehash(_base)
        }
    }

    /// @dev Determines whether the logic of this contract is potentially upgradable.
    function isUpgradable() public view returns (bool) {
        return _UPGRADABLE;
    }

    /// @dev Tells whether provided address could eventually upgrade the contract.
    function isUpgradableFrom(address from) virtual external view returns (bool);

    /// @notice Re-initialize contract's storage context upon a new upgrade from a proxy.    
    /// @dev Must fail when trying to upgrade to same logic contract more than once.
    function initialize(bytes memory) virtual external;

    /// @dev Retrieves human-redable named version of current implementation.
    function version() virtual public view returns (string memory); 
}

File 3 of 34 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

File 4 of 34 : Proxiable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

abstract contract Proxiable {
    /// @dev Complying with EIP-1822: Universal Upgradeable Proxy Standard (UUPS)
    /// @dev See https://eips.ethereum.org/EIPS/eip-1822.
    function proxiableUUID() virtual external view returns (bytes32);

    struct ProxiableSlot {
        address implementation;
        address proxy;
        bytes32 codehash;
    }

    function __implementation() internal view returns (address) {
        return __proxiable().implementation;
    }

    function __proxy() internal view returns (address) {
        return __proxiable().proxy;
    }

    function __proxiable() internal pure returns (ProxiableSlot storage proxiable) {
        assembly {
            // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
            proxiable.slot := 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
        }
    }
}

File 5 of 34 : Payable.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

abstract contract Payable {
    IERC20 public immutable currency;

    event Received(address from, uint256 value);
    event Transfer(address to, uint256 value);

    constructor(address _currency) {
        currency = IERC20(_currency);
    }

    /// Gets current transaction price.
    function _getGasPrice() internal view virtual returns (uint256);

    /// Gets current payment value.
    function _getMsgValue() internal view virtual returns (uint256);

    /// Perform safe transfer or whatever token is used for paying rewards.
    function __safeTransferTo(address payable, uint256) internal virtual;
}

File 6 of 34 : Ownable2Step.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert("Ownable2Step: caller is not the new owner");
        }
        _transferOwnership(sender);
    }
}

File 7 of 34 : Ownable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

File 8 of 34 : Initializable.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

File 9 of 34 : WitnetV2.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./Witnet.sol";

library WitnetV2 {

    /// Struct containing both request and response data related to every query posted to the Witnet Request Board
    struct Query {
        Request request;
        Response response;
    }

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

    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct Request {
        address requester;              // EVM address from which the request was posted.
        uint24  gasCallback;            // Max callback gas limit upon response, if a callback is required.
        uint72  evmReward;              // EVM amount in wei eventually to be paid to the legit result reporter.
        bytes   witnetBytecode;         // Optional: Witnet Data Request bytecode to be solved by the Witnet blockchain.
        bytes32 witnetRAD;              // Optional: Previously verified hash of the Witnet Data Request to be solved.
        WitnetV2.RadonSLA witnetSLA;    // Minimum Service-Level parameters to be committed by the Witnet blockchain. 
    }

    /// Response metadata and result as resolved by the Witnet blockchain.
    struct Response {
        address reporter;               // EVM address from which the Data Request result was reported.
        uint64  finality;               // EVM block number at which the reported data will be considered to be finalized.
        uint32  resultTimestamp;        // Unix timestamp (seconds) at which the data request was resolved in the Witnet blockchain.
        bytes32 resultTallyHash;        // Unique hash of the commit/reveal act in the Witnet blockchain that resolved the data request.
        bytes   resultCborBytes;        // CBOR-encode result to the request, as resolved in the Witnet blockchain.
    }

    /// Response status from a requester's point of view.
    enum ResponseStatus {
        Void,
        Awaiting,
        Ready,
        Error,
        Finalizing,
        Delivered
    }

    struct RadonSLA {
        /// @notice Number of nodes in the Witnet blockchain that will take part in solving the data request. 
        uint8   committeeSize;
        
        /// @notice Fee in $nanoWIT paid to every node in the Witnet blockchain involved in solving the data request.
        /// @dev Witnet nodes participating as witnesses will have to stake as collateral 100x this amount.
        uint64  witnessingFeeNanoWit;
    }

    
    /// ===============================================================================================================
    /// --- 'WitnetV2.RadonSLA' helper methods ------------------------------------------------------------------------

    function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b) 
        internal pure returns (bool)
    {
        return (a.committeeSize >= b.committeeSize);
    }
     
    function isValid(RadonSLA calldata sla) internal pure returns (bool) {
        return (
            sla.witnessingFeeNanoWit > 0 
                && sla.committeeSize > 0 && sla.committeeSize <= 127
                // v1.7.x requires witnessing collateral to be greater or equal to 20 WIT:
                && sla.witnessingFeeNanoWit * 100 >= 20 * 10 ** 9 
        );
    }

    function toV1(RadonSLA memory self) internal pure returns (Witnet.RadonSLA memory) {
        return Witnet.RadonSLA({
            numWitnesses: self.committeeSize,
            minConsensusPercentage: 51,
            witnessReward: self.witnessingFeeNanoWit,
            witnessCollateral: self.witnessingFeeNanoWit * 100,
            minerCommitRevealFee: self.witnessingFeeNanoWit / self.committeeSize
        });
    }

    function nanoWitTotalFee(RadonSLA storage self) internal view returns (uint64) {
        return self.witnessingFeeNanoWit * (self.committeeSize + 3);
    }


    /// ===============================================================================================================
    /// --- P-RNG generators ------------------------------------------------------------------------------------------

    /// Generates a pseudo-random uint32 number uniformly distributed within the range `[0 .. range)`, based on
    /// the given `nonce` and `seed` values. 
    function randomUniformUint32(uint32 range, uint256 nonce, bytes32 seed)
        internal pure 
        returns (uint32) 
    {
        uint256 _number = uint256(
            keccak256(
                abi.encode(seed, nonce)
            )
        ) & uint256(2 ** 224 - 1);
        return uint32((_number * range) >> 224);
    }
}

File 10 of 34 : WitnetErrorsLib.sol
// SPDX-License-Identifier: MIT

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

import "./WitnetV2.sol";

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

    using Witnet for bytes;
    using Witnet for uint8;
    using Witnet for uint256;
    using Witnet for Witnet.ResultErrorCodes;
    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)
        );
    }

    function asResultError(WitnetV2.ResponseStatus _status, bytes memory _cborBytes)
        public pure
        returns (Witnet.ResultError memory)
    {
        if (
            _status == WitnetV2.ResponseStatus.Error
                || _status == WitnetV2.ResponseStatus.Ready
        ) {
            return resultErrorFromCborBytes(_cborBytes);
        } else if (_status == WitnetV2.ResponseStatus.Finalizing) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetErrorsLib: not yet finalized"
            });
        } if (_status == WitnetV2.ResponseStatus.Awaiting) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetErrorsLib: not yet reported"
            });
        } else {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetErrorsLib: unknown query"
            });
        }
    }

    function resultErrorCodesFromCborBytes(bytes memory cborBytes)
        public pure
        returns (
            Witnet.ResultErrorCodes _code, 
            Witnet.ResultErrorCodes _subcode
        )
    {
        WitnetCBOR.CBOR[] memory _errors = _errorsFromResult(cborBytes.toWitnetResult());
        if (_errors.length > 1) {
            _code = Witnet.ResultErrorCodes(_errors[0].readUint());
            if (_errors.length > 2) {
                _subcode = Witnet.ResultErrorCodes(_errors[1].readUint());
            } 
        }
    }

    /// @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)
    {
        return _errorsFromResult(cborBytes.toWitnetResult());
    }

    /// @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: "Critical: no error code was found."
            });
        } else {
            _error.code = Witnet.ResultErrorCodes(errors[0].readUint());
        }
        string memory _prefix;
        if (_error.code.isCircumstantial()) {
            _prefix = "Circumstantial: ";
        } else if (_error.code.poorIncentives()) {
            _prefix = "Poor incentives: ";
        } else if (_error.code.lackOfConsensus()) {
            _prefix = "Consensual: ";
        } else {
            _prefix = "Critical: ";
        } 
        _error.reason = string(abi.encodePacked(_prefix, _stringify(_error.code, errors)));
    }

    function _stringify(Witnet.ResultErrorCodes code, WitnetCBOR.CBOR[] memory args)
        private pure
        returns (string memory)
    {
        if (code == Witnet.ResultErrorCodes.InsufficientCommits) {
            return "insufficient commits.";

        } else if (
            code == Witnet.ResultErrorCodes.CircumstantialFailure
                && args.length > 2
        ) {
            return _stringify(args[1].readUint(), args);
        
        } else if (code == Witnet.ResultErrorCodes.InsufficientMajority) {
            return "insufficient majority.";

        } else if (code == Witnet.ResultErrorCodes.InsufficientReveals) {
            return "insufficient reveals.";

        } else if (code == Witnet.ResultErrorCodes.BridgePoorIncentives) {
            return "as for the bridge.";

        } else if (
            code == Witnet.ResultErrorCodes.OversizedTallyResult
                || code == Witnet.ResultErrorCodes.BridgeOversizedTallyResult
        ) {
            return "oversized result.";

        } else if (code == Witnet.ResultErrorCodes.InconsistentSources) {
            return "inconsistent sources.";

        } else if (
            code == Witnet.ResultErrorCodes.MalformedResponses
                && args.length > 2
        ) {
            return string(abi.encodePacked(
                "malformed response: ",
                _stringify(args[1].readUint(), args)
            ));

        } else if (
            code == Witnet.ResultErrorCodes.MalformedDataRequest 
                || code == Witnet.ResultErrorCodes.BridgeMalformedDataRequest

        ) {
            if (args.length > 2) {
                return string(abi.encodePacked(
                    "malformed request: ",
                    _stringify(args[1].readUint(), args)
                ));
            } else {
                return "malformed request.";
            }

        } else if (code == Witnet.ResultErrorCodes.UnhandledIntercept) {
            if (args.length > 2) {
                return string(abi.encodePacked(
                    "unhandled intercept on tally (+",
                    (args.length - 2).toString(),
                    " args)."
                ));
            } else {
                return "unhandled intercept on tally.";
            }
        
        } else {
            return string(abi.encodePacked(
                "0x",
                uint8(code).toHexString()
            ));
        }
    }

    function _stringify(uint subcode, WitnetCBOR.CBOR[] memory args)
        private pure 
        returns (string memory)
    {
        Witnet.ResultErrorCodes _code = Witnet.ResultErrorCodes(subcode);

        // circumstantial subcodes:
        if (_code == Witnet.ResultErrorCodes.HttpErrors) {
            if (args.length > 3) {
                return string(abi.encodePacked(
                    "http/",
                    args[2].readUint().toString()
                ));
            } else {
                return "unspecific http status code.";
            }

        } else if (_code == Witnet.ResultErrorCodes.RetrievalsTimeout) {
            return "response timeout.";

        } else if (_code == Witnet.ResultErrorCodes.ArrayIndexOutOfBounds) {
            if (args.length > 3) {
                return string(abi.encodePacked(
                    "array index out of bounds: ",
                    args[2].readUint().toString()
                ));
            } else {
                return "array index out of bounds.";
            }

        } else if (_code == Witnet.ResultErrorCodes.MapKeyNotFound) {
            if (args.length > 3) {
                return string(abi.encodePacked(
                    "map key not found: ",
                    args[2].readString()
                ));
            } else {
                return "map key not found.";
            }

        } else if (_code == Witnet.ResultErrorCodes.JsonPathNotFound) {
            if (args.length > 3) {
                return string(abi.encodePacked(
                    "json path returned no values: ",
                    args[2].readString()
                ));
            } else {
                return "json path returned no values.";
            }
        
        } else {
            return string(abi.encodePacked(
                "0x",
                Witnet.toHexString(uint8(_code)),
                args.length > 3
                    ? string(abi.encodePacked(" (+", uint(args.length - 3).toString(), " args)"))
                    : ""
            ));
        }
    }

    /// @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)";
        }
    }
}

File 11 of 34 : 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);
    }
  }
 
}

File 12 of 34 : 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))
        }
      }
    }
  }

}

File 13 of 34 : Witnet.sol
// SPDX-License-Identifier: MIT

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

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 (deprecated) 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 the Witnet-provided response metadata and CBOR-encoded 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, 
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Source-specific format error sub-codes ============================================================================
        /// 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,
        /// 0x04: The request body of at least one data source was not properly formated.
        SourceRequestBody,
        /// 0x05: The request headers of at least one data source was not properly formated.
        SourceRequestHeaders,
        /// 0x06: The request URL of at least one data source was not properly formated.
        SourceRequestURL,
        /// Unallocated
        SourceFormat0x07, SourceFormat0x08, SourceFormat0x09, SourceFormat0x0A, SourceFormat0x0B, SourceFormat0x0C,
        SourceFormat0x0D, SourceFormat0x0E, SourceFormat0x0F, 
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Complexity error sub-codes ========================================================================================
        /// 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,

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Lack of support error sub-codes ===================================================================================
        /// 0x20: Some Radon operator code was found that is not supported (1+ args).
        UnsupportedOperator,
        /// 0x21: Some Radon filter opcode is not currently supported (1+ args).
        UnsupportedFilter,
        /// 0x22: Some Radon request type is not currently supported (1+ args).
        UnsupportedHashFunction,
        /// 0x23: Some Radon reducer opcode is not currently supported (1+ args)
        UnsupportedReducer,
        /// 0x24: Some Radon hash function is not currently supported (1+ args).
        UnsupportedRequestType, 
        /// 0x25: Some Radon encoding function is not currently supported (1+ args).
        UnsupportedEncodingFunction,
        /// Unallocated
        Operator0x26, Operator0x27, 
        /// 0x28: Wrong number (or type) of arguments were passed to some Radon operator.
        WrongArguments,
        /// Unallocated
        Operator0x29, Operator0x2A, Operator0x2B, Operator0x2C, Operator0x2D, Operator0x2E, Operator0x2F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Retrieve-specific circumstantial error sub-codes ================================================================================
        /// 0x30: A majority of data sources returned an HTTP status code other than 200 (1+ args):
        HttpErrors,
        /// 0x31: A majority of data sources timed out:
        RetrievalsTimeout,
        /// Unallocated
        RetrieveCircumstance0x32, RetrieveCircumstance0x33, RetrieveCircumstance0x34, RetrieveCircumstance0x35,
        RetrieveCircumstance0x36, RetrieveCircumstance0x37, RetrieveCircumstance0x38, RetrieveCircumstance0x39,
        RetrieveCircumstance0x3A, RetrieveCircumstance0x3B, RetrieveCircumstance0x3C, RetrieveCircumstance0x3D,
        RetrieveCircumstance0x3E, RetrieveCircumstance0x3F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Scripting-specific runtime error sub-code =========================================================================
        /// 0x40: Math operator caused an underflow.
        MathUnderflow,
        /// 0x41: Math operator caused an overflow.
        MathOverflow,
        /// 0x42: Math operator tried to divide by zero.
        MathDivisionByZero,            
        /// 0x43:Wrong input to subscript call.
        WrongSubscriptInput,
        /// 0x44: Value cannot be extracted from input binary buffer.
        BufferIsNotValue,
        /// 0x45: Value cannot be decoded from expected type.
        Decode,
        /// 0x46: Unexpected empty array.
        EmptyArray,
        /// 0x47: Value cannot be encoded to expected type.
        Encode,
        /// 0x48: Failed to filter input values (1+ args).
        Filter,
        /// 0x49: Failed to hash input value.
        Hash,
        /// 0x4A: Mismatching array ranks.
        MismatchingArrays,
        /// 0x4B: Failed to process non-homogenous array.
        NonHomegeneousArray,
        /// 0x4C: Failed to parse syntax of some input value, or argument.
        Parse,
        /// 0x4E: Parsing logic limits were exceeded.
        ParseOverflow,
        /// 0x4F: Unallocated
        ScriptError0x4F,
    
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Actual first-order result error codes =============================================================================
        /// 0x50: Not enough reveals were received in due time:
        InsufficientReveals,
        /// 0x51: No actual reveal majority was reached on tally stage:
        InsufficientMajority,
        /// 0x52: Not enough commits were received before tally stage:
        InsufficientCommits,
        /// 0x53: Generic error during tally execution (to be deprecated after WIP #0028)
        TallyExecution,
        /// 0x54: A majority of data sources could either be temporarily unresponsive or failing to report the requested data:
        CircumstantialFailure,
        /// 0x55: At least one data source is inconsistent when queried through multiple transports at once:
        InconsistentSources,
        /// 0x56: Any one of the (multiple) Retrieve, Aggregate or Tally scripts were badly formated:
        MalformedDataRequest,
        /// 0x57: Values returned from a majority of data sources don't match the expected schema:
        MalformedResponses,
        /// Unallocated:    
        OtherError0x58, OtherError0x59, OtherError0x5A, OtherError0x5B, OtherError0x5C, OtherError0x5D, OtherError0x5E, 
        /// 0x5F: Size of serialized tally result exceeds allowance:
        OversizedTallyResult,

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Inter-stage runtime error sub-codes ===============================================================================
        /// 0x60: Data aggregation reveals could not get decoded on the tally stage:
        MalformedReveals,
        /// 0x61: The result to data aggregation could not get encoded:
        EncodeReveals,  
        /// 0x62: A mode tie ocurred when calculating some mode value on the aggregation or the tally stage:
        ModeTie, 
        /// Unallocated:
        OtherError0x63, OtherError0x64, OtherError0x65, OtherError0x66, OtherError0x67, OtherError0x68, OtherError0x69, 
        OtherError0x6A, OtherError0x6B, OtherError0x6C, OtherError0x6D, OtherError0x6E, OtherError0x6F,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Runtime access error sub-codes ====================================================================================
        /// 0x70: Tried to access a value from an array using an index that is out of bounds (1+ args):
        ArrayIndexOutOfBounds,
        /// 0x71: Tried to access a value from a map using a key that does not exist (1+ args):
        MapKeyNotFound,
        /// 0X72: Tried to extract value from a map using a JSON Path that returns no values (+1 args):
        JsonPathNotFound,
        /// Unallocated:
        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,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Inter-client generic error codes ==================================================================================
        /// Data requests that cannot be relayed into the Witnet blockchain should be reported
        /// with one of these errors. 
        /// 0xE0: Requests that cannot be parsed must always get this error as their result.
        BridgeMalformedDataRequest,
        /// 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
        BridgeOversizedTallyResult,
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// 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 it should (0+ args)
        UnhandledIntercept
    }

    function isCircumstantial(ResultErrorCodes self) internal pure returns (bool) {
        return (self == ResultErrorCodes.CircumstantialFailure);
    }

    function lackOfConsensus(ResultErrorCodes self) internal pure returns (bool) {
        return (
            self == ResultErrorCodes.InsufficientCommits
                || self == ResultErrorCodes.InsufficientMajority
                || self == ResultErrorCodes.InsufficientReveals
        );
    }

    function isRetriable(ResultErrorCodes self) internal pure returns (bool) {
        return (
            lackOfConsensus(self)
                || isCircumstantial(self)
                || poorIncentives(self)
        );
    }

    function poorIncentives(ResultErrorCodes self) internal pure returns (bool) {
        return (
            self == ResultErrorCodes.OversizedTallyResult
                || self == ResultErrorCodes.InsufficientCommits
                || self == ResultErrorCodes.BridgePoorIncentives
                || self == ResultErrorCodes.BridgeOversizedTallyResult
        );
    }
    

    /// Possible Radon data request methods that can be used within a Radon Retrieval. 
    enum RadonDataRequestMethods {
        /* 0 */ Unknown,
        /* 1 */ HttpGet,
        /* 2 */ RNG,
        /* 3 */ HttpPost,
        /* 4 */ HttpHead
    }

    /// Possible types either processed by Witnet Radon Scripts or included within results to Witnet Data Requests.
    enum RadonDataTypes {
        /* 0x00 */ Any, 
        /* 0x01 */ Array,
        /* 0x02 */ Bool,
        /* 0x03 */ Bytes,
        /* 0x04 */ Integer,
        /* 0x05 */ Float,
        /* 0x06 */ Map,
        /* 0x07 */ String,
        Unused0x08, Unused0x09, Unused0x0A, Unused0x0B,
        Unused0x0C, Unused0x0D, Unused0x0E, Unused0x0F,
        /* 0x10 */ Same,
        /* 0x11 */ Inner,
        /* 0x12 */ Match,
        /* 0x13 */ Subscript
    }

    /// Structure defining some data filtering that can be applied at the Aggregation or the Tally stages
    /// within a Witnet Data Request resolution workflow.
    struct RadonFilter {
        RadonFilterOpcodes opcode;
        bytes args;
    }

    /// Filtering methods currently supported on the Witnet blockchain. 
    enum RadonFilterOpcodes {
        /* 0x00 */ Reserved0x00, //GreaterThan,
        /* 0x01 */ Reserved0x01, //LessThan,
        /* 0x02 */ Reserved0x02, //Equals,
        /* 0x03 */ Reserved0x03, //AbsoluteDeviation,
        /* 0x04 */ Reserved0x04, //RelativeDeviation
        /* 0x05 */ StandardDeviation,
        /* 0x06 */ Reserved0x06, //Top,
        /* 0x07 */ Reserved0x07, //Bottom,
        /* 0x08 */ Mode,
        /* 0x09 */ Reserved0x09  //LessOrEqualThan
    }

    /// Structure defining the array of filters and reducting function to be applied at either the Aggregation
    /// or the Tally stages within a Witnet Data Request resolution workflow.
    struct RadonReducer {
        RadonReducerOpcodes opcode;
        RadonFilter[] filters;
    }

    /// Reducting functions currently supported on the Witnet blockchain.
    enum RadonReducerOpcodes {
        /* 0x00 */ Reserved0x00, //Minimum,
        /* 0x01 */ Reserved0x01, //Maximum,
        /* 0x02 */ Mode,
        /* 0x03 */ AverageMean,
        /* 0x04 */ Reserved0x04, //AverageMeanWeighted,
        /* 0x05 */ AverageMedian,
        /* 0x06 */ Reserved0x06, //AverageMedianWeighted,
        /* 0x07 */ StandardDeviation,
        /* 0x08 */ Reserved0x08, //AverageDeviation,
        /* 0x09 */ Reserved0x09, //MedianDeviation,
        /* 0x0A */ Reserved0x10, //MaximumDeviation,
        /* 0x0B */ ConcatenateAndHash
    }

    /// Structure containing all the parameters that fully describe a Witnet Radon Retrieval within a Witnet Data Request.
    struct RadonRetrieval {
        uint8 argsCount;
        RadonDataRequestMethods method;
        RadonDataTypes resultDataType;
        string url;
        string body;
        string[2][] headers;
        bytes script;
    }

    /// Structure containing the Retrieve-Attestation-Delivery parts of a Witnet Data Request.
    struct RadonRAD {
        RadonRetrieval[] retrieve;
        RadonReducer aggregate;
        RadonReducer tally;
    }

    /// Structure containing the Service Level Aggreement parameters of a Witnet Data Request.
    struct RadonSLA {
        uint8 numWitnesses;
        uint8 minConsensusPercentage;
        uint64 witnessReward;
        uint64 witnessCollateral;
        uint64 minerCommitRevealFee;
    }


    /// ===============================================================================================================
    /// --- 'uint*' 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);
    }


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

    /// @dev Transform given bytes into a Witnet.Result instance.
    /// @param cborBytes Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function toWitnetResult(bytes memory cborBytes)
        internal pure
        returns (Witnet.Result memory)
    {
        WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(cborBytes);
        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);
        }
    }
    

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

    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();
    }


    /// ===============================================================================================================
    /// --- 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 ++;
            }
        }
    }
}

File 14 of 34 : IWitnetRequestFactory.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

interface IWitnetRequestFactory {
    
    event WitnetRequestTemplateBuilt(address template, bool parameterized);
    
    function buildRequestTemplate(
            bytes32[] memory sourcesIds,
            bytes32 aggregatorId,
            bytes32 tallyId,
            uint16  resultDataMaxSize
        ) external returns (address template);

}

File 15 of 34 : IWitnetRequestBytecodes.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "../libs/WitnetV2.sol";

interface IWitnetRequestBytecodes {

    error UnknownRadonRetrieval(bytes32 hash);
    error UnknownRadonReducer(bytes32 hash);
    error UnknownRadonRequest(bytes32 hash);

    event NewDataProvider(uint256 index);
    event NewRadonRetrievalHash(bytes32 hash);
    event NewRadonReducerHash(bytes32 hash);
    event NewRadHash(bytes32 hash);

    function bytecodeOf(bytes32 radHash) external view returns (bytes memory);
    function bytecodeOf(bytes32 radHash, WitnetV2.RadonSLA calldata sla) external view returns (bytes memory);
    function bytecodeOf(bytes calldata radBytecode, WitnetV2.RadonSLA calldata sla) external view returns (bytes memory);
    
    function hashOf(bytes calldata) external view returns (bytes32);

    function lookupDataProvider(uint256 index) external view returns (string memory, uint);
    function lookupDataProviderIndex(string calldata authority) external view returns (uint);
    function lookupDataProviderSources(uint256 index, uint256 offset, uint256 length) external view returns (bytes32[] memory);

    function lookupRadonReducer(bytes32 hash) external view returns (Witnet.RadonReducer memory);
    
    function lookupRadonRetrieval(bytes32 hash) external view returns (Witnet.RadonRetrieval memory);
    function lookupRadonRetrievalArgsCount(bytes32 hash) external view returns (uint8);
    function lookupRadonRetrievalResultDataType(bytes32 hash) external view returns (Witnet.RadonDataTypes);
    
    function lookupRadonRequestAggregator(bytes32 radHash) external view returns (Witnet.RadonReducer memory);
    function lookupRadonRequestResultMaxSize(bytes32 radHash) external view returns (uint16);
    function lookupRadonRequestResultDataType(bytes32 radHash) external view returns (Witnet.RadonDataTypes);
    function lookupRadonRequestSources(bytes32 radHash) external view returns (bytes32[] memory);
    function lookupRadonRequestSourcesCount(bytes32 radHash) external view returns (uint);
    function lookupRadonRequestTally(bytes32 radHash) external view returns (Witnet.RadonReducer memory);
        
    function verifyRadonRetrieval(
            Witnet.RadonDataRequestMethods requestMethod,
            string calldata requestURL,
            string calldata requestBody,
            string[2][] calldata requestHeaders,
            bytes calldata requestRadonScript
        ) external returns (bytes32 hash);
    
    function verifyRadonReducer(Witnet.RadonReducer calldata reducer)
        external returns (bytes32 hash);
    
    function verifyRadonRequest(
            bytes32[] calldata sources,
            bytes32 aggregator,
            bytes32 tally,
            uint16 resultMaxSize,
            string[][] calldata args
        ) external returns (bytes32 radHash);

    function totalDataProviders() external view returns (uint);
}

File 16 of 34 : IWitnetRequestBoardAdminACLs.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title Witnet Request Board ACLs administration interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardAdminACLs {
    
    event ReportersSet(address[] reporters);
    event ReportersUnset(address[] reporters);

    /// Tells whether given address is included in the active reporters control list.
    function isReporter(address) external view returns (bool);

    /// Adds given addresses to the active reporters control list.
    /// @dev Can only be called from the owner address.
    /// @dev Emits the `ReportersSet` event. 
    function setReporters(address[] calldata reporters) external;

    /// Removes given addresses from the active reporters control list.
    /// @dev Can only be called from the owner address.
    /// @dev Emits the `ReportersUnset` event. 
    function unsetReporters(address[] calldata reporters) external;
}

File 17 of 34 : IWitnetOracleReporter.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "../libs/WitnetV2.sol";

/// @title The Witnet Request Board Reporter interface.
/// @author The Witnet Foundation.
interface IWitnetOracleReporter {

    /// @notice Estimates the actual earnings in WEI, that a reporter would get by reporting result to given query,
    /// @notice based on the gas price of the calling transaction. Data requesters should consider upgrading the reward on 
    /// @notice queries providing no actual earnings.
    function estimateReportEarnings(
            uint256[] calldata witnetQueryIds, 
            bytes calldata reportTxMsgData,
            uint256 reportTxGasPrice,
            uint256 nanoWitPrice
        ) external view returns (uint256, uint256);

    /// @notice Retrieves the Witnet Data Request bytecodes and SLAs of previously posted queries.
    /// @dev Returns empty buffer if the query does not exist.
    /// @param queryIds Query identifiers.
    function extractWitnetDataRequests(uint256[] calldata queryIds) 
        external view returns (bytes[] memory drBytecodes);

    /// @notice Reports the Witnet-provided result to a previously posted request. 
    /// @dev Will assume `block.timestamp` as the timestamp at which the request was solved.
    /// @dev Fails if:
    /// @dev - the `_witnetQueryId` is not in 'Posted' status.
    /// @dev - provided `_tallyHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param witnetQueryId The unique identifier of the data request.
    /// @param witnetQueryResultTallyHash The hash of the corresponding data request transaction in Witnet.
    /// @param witnetQueryResultCborBytes The result itself as bytes.
    function reportResult(
            uint256 witnetQueryId,
            bytes32 witnetQueryResultTallyHash,
            bytes calldata witnetQueryResultCborBytes
        ) external returns (uint256);

    /// @notice Reports the Witnet-provided result to a previously posted request.
    /// @dev Fails if:
    /// @dev - called from unauthorized address;
    /// @dev - the `_witnetQueryId` is not in 'Posted' status.
    /// @dev - provided `_tallyHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param witnetQueryId The unique query identifier
    /// @param witnetQueryResultTimestamp The timestamp of the solving tally transaction in Witnet.
    /// @param witnetQueryResultTallyHash The hash of the corresponding data request transaction in Witnet.
    /// @param witnetQueryResultCborBytes The result itself as bytes.
    function reportResult(
            uint256 witnetQueryId,
            uint32  witnetQueryResultTimestamp,
            bytes32 witnetQueryResultTallyHash,
            bytes calldata witnetQueryResultCborBytes
        ) external returns (uint256);

    /// @notice Reports Witnet-provided results to multiple requests within a single EVM tx.
    /// @notice Emits either a WitnetQueryResponse* or a BatchReportError event per batched report.
    /// @dev Fails only if called from unauthorized address.
    /// @param _batchResults Array of BatchResult structs, every one containing:
    ///         - unique query identifier;
    ///         - timestamp of the solving tally txs in Witnet. If zero is provided, EVM-timestamp will be used instead;
    ///         - hash of the corresponding data request tx at the Witnet side-chain level;
    ///         - data request result in raw bytes.
    function reportResultBatch(BatchResult[] calldata _batchResults) external returns (uint256);
        
        struct BatchResult {
            uint256 queryId;
            uint32  queryResultTimestamp;
            bytes32 queryResultTallyHash;
            bytes   queryResultCborBytes;
        }

        event BatchReportError(uint256 queryId, string reason);
}

File 18 of 34 : IWitnetOracleEvents.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

import "../libs/WitnetV2.sol";

interface IWitnetOracleEvents {
    
    /// Emitted every time a new query containing some verified data request is posted to the WRB.
    event WitnetQuery(
        uint256 id, 
        uint256 evmReward,
        WitnetV2.RadonSLA witnetSLA
    );

    /// Emitted when a query with no callback gets reported into the WRB.
    event WitnetQueryResponse(
        uint256 id, 
        uint256 evmGasPrice
    );

    /// Emitted when a query with a callback gets successfully reported into the WRB.
    event WitnetQueryResponseDelivered(
        uint256 id, 
        uint256 evmGasPrice, 
        uint256 evmCallbackGas
    );

    /// Emitted when a query with a callback cannot get reported into the WRB.
    event WitnetQueryResponseDeliveryFailed(
        uint256 id, 
        bytes   resultCborBytes,
        uint256 evmGasPrice, 
        uint256 evmCallbackActualGas, 
        string  evmCallbackRevertReason
    );

    /// Emitted when the reward of some not-yet reported query is upgraded.
    event WitnetQueryRewardUpgraded(
        uint256 id, 
        uint256 evmReward
    );

}

File 19 of 34 : IWitnetOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

import "../libs/WitnetV2.sol";

interface IWitnetOracle {

    /// @notice Estimate the minimum reward required for posting a data request.
    /// @dev Underestimates if the size of returned data is greater than `resultMaxSize`. 
    /// @param gasPrice Expected gas price to pay upon posting the data request.
    /// @param resultMaxSize Maximum expected size of returned data (in bytes).  
    function estimateBaseFee(uint256 gasPrice, uint16 resultMaxSize) external view returns (uint256);

    /// @notice Estimate the minimum reward required for posting a data request.
    /// @dev Fails if the RAD hash was not previously verified on the WitnetRequestBytecodes registry.
    /// @param gasPrice Expected gas price to pay upon posting the data request.
    /// @param radHash The RAD hash of the data request to be solved by Witnet.
    function estimateBaseFee(uint256 gasPrice, bytes32 radHash) external view returns (uint256);
    
    /// @notice Estimate the minimum reward required for posting a data request with a callback.
    /// @param gasPrice Expected gas price to pay upon posting the data request.
    /// @param callbackGasLimit Maximum gas to be spent when reporting the data request result.
    function estimateBaseFeeWithCallback(uint256 gasPrice, uint24 callbackGasLimit) external view returns (uint256);
       
    /// @notice Retrieves a copy of all Witnet-provable data related to a previously posted request, 
    /// removing the whole query from the WRB storage.
    /// @dev Fails if the query was not in 'Reported' status, or called from an address different to
    /// @dev the one that actually posted the given request.
    /// @param queryId The unique query identifier.
    function fetchQueryResponse(uint256 queryId) external returns (WitnetV2.Response memory);
   
    /// @notice Gets the whole Query data contents, if any, no matter its current status.
    function getQuery(uint256 queryId) external view returns (WitnetV2.Query memory);

    /// @notice Gets the current EVM reward the report can claim, if not done yet.
    function getQueryEvmReward(uint256 queryId) external view returns (uint256);

    /// @notice Retrieves the RAD hash and SLA parameters of the given query.
    /// @param queryId The unique query identifier.
    function getQueryRequest(uint256 queryId) external view returns (WitnetV2.Request memory);

    /// @notice Retrieves the whole `Witnet.Response` record referred to a previously posted Witnet Data Request.
    /// @param queryId The unique query identifier.
    function getQueryResponse(uint256 queryId) external view returns (WitnetV2.Response memory);

    /// @notice Returns query's result current status from a requester's point of view:
    /// @notice   - 0 => Void: the query is either non-existent or deleted;
    /// @notice   - 1 => Awaiting: the query has not yet been reported;
    /// @notice   - 2 => Ready: the query response was finalized, and contains a result with no erros.
    /// @notice   - 3 => Error: the query response was finalized, and contains a result with errors.
    /// @param queryId The unique query identifier.
    function getQueryResponseStatus(uint256 queryId) external view returns (WitnetV2.ResponseStatus);

    /// @notice Retrieves the CBOR-encoded buffer containing the Witnet-provided result to the given query.
    /// @param queryId The unique query identifier.
    function getQueryResultCborBytes(uint256 queryId) external view returns (bytes memory);

    /// @notice Gets error code identifying some possible failure on the resolution of the given query.
    /// @param queryId The unique query identifier.
    function getQueryResultError(uint256 queryId) external view returns (Witnet.ResultError memory);

    /// @notice Gets current status of given query.
    function getQueryStatus(uint256 queryId) external view returns (WitnetV2.QueryStatus);
    
    /// @notice Get current status of all given query ids.
    function getQueryStatusBatch(uint256[] calldata queryIds) external view returns (WitnetV2.QueryStatus[] memory);

    /// @notice Returns next query id to be generated by the Witnet Request Board.
    function getNextQueryId() external view returns (uint256);

    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and 
    /// @notice solved by the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be 
    /// @notice transferred to the reporter who relays back the Witnet-provable result to this request.
    /// @dev Reasons to fail:
    /// @dev - the RAD hash was not previously verified by the WitnetRequestBytecodes registry;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - insufficient value is paid as reward.
    /// @param queryRAD The RAD hash of the data request to be solved by Witnet.
    /// @param querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @return queryId Unique query identifier.
    function postRequest(
            bytes32 queryRAD, 
            WitnetV2.RadonSLA calldata querySLA
        ) external payable returns (uint256 queryId);

    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and solved by 
    /// @notice the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be transferred to the 
    /// @notice reporter who relays back the Witnet-provable result to this request. The Witnet-provable result will be reported
    /// @notice directly to the requesting contract. If the report callback fails for any reason, an `WitnetQueryResponseDeliveryFailed`
    /// @notice will be triggered, and the Witnet audit trail will be saved in storage, but not so the actual CBOR-encoded result.
    /// @dev Reasons to fail:
    /// @dev - the caller is not a contract implementing the IWitnetConsumer interface;
    /// @dev - the RAD hash was not previously verified by the WitnetRequestBytecodes registry;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - insufficient value is paid as reward.
    /// @param queryRAD The RAD hash of the data request to be solved by Witnet.
    /// @param querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @param queryCallbackGasLimit Maximum gas to be spent when reporting the data request result.
    /// @return queryId Unique query identifier.
    function postRequestWithCallback(
            bytes32 queryRAD, 
            WitnetV2.RadonSLA calldata querySLA, 
            uint24 queryCallbackGasLimit
        ) external payable returns (uint256 queryId);

    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and solved by 
    /// @notice the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be transferred to the 
    /// @notice reporter who relays back the Witnet-provable result to this request. The Witnet-provable result will be reported
    /// @notice directly to the requesting contract. If the report callback fails for any reason, a `WitnetQueryResponseDeliveryFailed`
    /// @notice event will be triggered, and the Witnet audit trail will be saved in storage, but not so the CBOR-encoded result.
    /// @dev Reasons to fail:
    /// @dev - the caller is not a contract implementing the IWitnetConsumer interface;
    /// @dev - the provided bytecode is empty;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - insufficient value is paid as reward.
    /// @param queryUnverifiedBytecode The (unverified) bytecode containing the actual data request to be solved by the Witnet blockchain.
    /// @param querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @param queryCallbackGasLimit Maximum gas to be spent when reporting the data request result.
    /// @return queryId Unique query identifier.
    function postRequestWithCallback(
            bytes calldata queryUnverifiedBytecode,
            WitnetV2.RadonSLA calldata querySLA, 
            uint24 queryCallbackGasLimit
        ) external payable returns (uint256 queryId);

    /// @notice Increments the reward of a previously posted request by adding the transaction value to it.
    /// @param queryId The unique query identifier.
    function upgradeQueryEvmReward(uint256 queryId) external payable;

}

File 20 of 34 : IWitnetConsumer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../libs/Witnet.sol";

interface IWitnetConsumer {

    /// @notice Method to be called from the WitnetOracle contract as soon as the given Witnet `queryId`
    /// @notice gets reported, if reported with no errors.
    /// @dev It should revert if called from any other address different to the WitnetOracle being used
    /// @dev by the WitnetConsumer contract. 
    /// @param witnetQueryId The unique identifier of the Witnet query being reported.
    /// @param witnetResultTallyHash Hash of the commit/reveal witnessing act that took place in the Witnet blockahin.
    /// @param witnetResultTimestamp Timestamp at which the reported value was captured by the Witnet blockchain. 
    /// @param witnetEvmFinalityBlock EVM block at which the provided data can be considered to be final.
    /// @param witnetResultCborValue The CBOR-encoded resulting value of the Witnet query being reported.
    function reportWitnetQueryResult(
            uint256 witnetQueryId, 
            uint64  witnetResultTimestamp,
            bytes32 witnetResultTallyHash,
            uint256 witnetEvmFinalityBlock,
            WitnetCBOR.CBOR calldata witnetResultCborValue
        ) external;

    /// @notice Method to be called from the WitnetOracle contract as soon as the given Witnet `queryId`
    /// @notice gets reported, if reported WITH errors.
    /// @dev It should revert if called from any other address different to the WitnetOracle being used
    /// @dev by the WitnetConsumer contract. 
    /// @param witnetQueryId The unique identifier of the Witnet query being reported.
    /// @param witnetResultTallyHash Hash of the commit/reveal witnessing act that took place in the Witnet blockahin.
    /// @param witnetResultTimestamp Timestamp at which the reported value was captured by the Witnet blockchain. 
    /// @param witnetEvmFinalityBlock EVM block at which the provided data can be considered to be final.
    /// @param errorCode The error code enum identifying the error produced during resolution on the Witnet blockchain.
    /// @param errorArgs Error arguments, if any. An empty buffer is to be passed if no error arguments apply.
    function reportWitnetQueryError(
            uint256 witnetQueryId, 
            uint64  witnetResultTimestamp,
            bytes32 witnetResultTallyHash,
            uint256 witnetEvmFinalityBlock,
            Witnet.ResultErrorCodes errorCode, 
            WitnetCBOR.CBOR calldata errorArgs
        ) external;

    /// @notice Determines if Witnet queries can be reported from given address.
    /// @dev In practice, must only be true on the WitnetOracle address that's being used by
    /// @dev the WitnetConsumer to post queries. 
    function reportableFrom(address) external view returns (bool);
}

File 21 of 34 : WitnetOracleDataLib.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "../WitnetRequestBytecodes.sol";
import "../libs/WitnetV2.sol";

/// @title Witnet Request Board base data model library
/// @author The Witnet Foundation.
library WitnetOracleDataLib {  

    using WitnetV2 for WitnetV2.Request;

    bytes32 internal constant _WITNET_ORACLE_DATA_SLOTHASH =
        /* keccak256("io.witnet.boards.data") */
        0xf595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e183;

    struct Storage {
        uint256 nonce;
        mapping (uint => WitnetV2.Query) queries;
        mapping (address => bool) reporters;
    }

    // ================================================================================================================
    // --- Internal functions -----------------------------------------------------------------------------------------

    /// Returns storage pointer to contents of 'WitnetBoardState' struct.
    function data() internal pure returns (Storage storage _ptr)
    {
        assembly {
            _ptr.slot := _WITNET_ORACLE_DATA_SLOTHASH
        }
    }

    function isReporter(address addr) internal view returns (bool) {
        return data().reporters[addr];
    }

    /// Gets query storage by query id.
    function seekQuery(uint256 _queryId) internal view returns (WitnetV2.Query storage) {
      return data().queries[_queryId];
    }

    /// Gets the Witnet.Request part of a given query.
    function seekQueryRequest(uint256 _queryId) internal view returns (WitnetV2.Request storage) {
        return data().queries[_queryId].request;
    }   

    /// Gets the Witnet.Result part of a given query.
    function seekQueryResponse(uint256 _queryId) internal view returns (WitnetV2.Response storage) {
        return data().queries[_queryId].response;
    }

    function seekQueryStatus(uint256 queryId) internal view returns (WitnetV2.QueryStatus) {
        WitnetV2.Query storage __query = data().queries[queryId];
        if (__query.response.resultTimestamp != 0) {
            if (block.number >= __query.response.finality) {
                return WitnetV2.QueryStatus.Finalized;
            } else {
                return WitnetV2.QueryStatus.Reported;
            }
        } else if (__query.request.requester != address(0)) {
            return WitnetV2.QueryStatus.Posted;
        } else {
            return WitnetV2.QueryStatus.Unknown;
        }
    }

    function seekQueryResponseStatus(uint256 queryId) internal view returns (WitnetV2.ResponseStatus) {
        WitnetV2.QueryStatus _queryStatus = seekQueryStatus(queryId);
        if (_queryStatus == WitnetV2.QueryStatus.Finalized) {
            bytes storage __cborValues = data().queries[queryId].response.resultCborBytes;
            if (__cborValues.length > 0) {
                // determine whether stored result is an error by peeking the first byte
                return (__cborValues[0] == bytes1(0xd8)
                    ? WitnetV2.ResponseStatus.Error 
                    : WitnetV2.ResponseStatus.Ready
                );
            } else {
                // the result is final but delivered to the requesting address
                return WitnetV2.ResponseStatus.Delivered;
            }
        } else if (_queryStatus == WitnetV2.QueryStatus.Posted) {
            return WitnetV2.ResponseStatus.Awaiting;
        } else if (_queryStatus == WitnetV2.QueryStatus.Reported) {
            return WitnetV2.ResponseStatus.Finalizing;
        } else {
            return WitnetV2.ResponseStatus.Void;
        }
    }

    // ================================================================================================================
    // --- Public functions -------------------------------------------------------------------------------------------

    function extractWitnetDataRequests(WitnetRequestBytecodes registry, uint256[] calldata queryIds)
        public view
        returns (bytes[] memory bytecodes)
    {
        bytecodes = new bytes[](queryIds.length);
        for (uint _ix = 0; _ix < queryIds.length; _ix ++) {
            if (seekQueryStatus(queryIds[_ix]) != WitnetV2.QueryStatus.Unknown) {
                WitnetV2.Request storage __request = data().queries[queryIds[_ix]].request;
                if (__request.witnetRAD != bytes32(0)) {
                    bytecodes[_ix] = registry.bytecodeOf(
                        __request.witnetRAD,
                        __request.witnetSLA
                    );
                } else {
                    bytecodes[_ix] = registry.bytecodeOf(
                        __request.witnetBytecode,
                        __request.witnetSLA 
                    );
                }
            }
        }
    }

    function notInStatusRevertMessage(WitnetV2.QueryStatus self) public pure returns (string memory) {
        if (self == WitnetV2.QueryStatus.Posted) {
            return "query not in Posted status";
        } else if (self == WitnetV2.QueryStatus.Reported) {
            return "query not in Reported status";
        } else if (self == WitnetV2.QueryStatus.Finalized) {
            return "query not in Finalized status";
        } else {
            return "bad mood";
        }
    }
}

File 22 of 34 : WitnetOracleTrustableBase.sol
// SPDX-License-Identifier: MIT

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

import "../WitnetUpgradableBase.sol";
import "../../WitnetOracle.sol";
import "../../WitnetRequestFactory.sol";
import "../../data/WitnetOracleDataLib.sol";
import "../../interfaces/IWitnetOracleReporter.sol";
import "../../interfaces/IWitnetRequestBoardAdminACLs.sol";
import "../../interfaces/IWitnetConsumer.sol";
import "../../libs/WitnetErrorsLib.sol";
import "../../patterns/Payable.sol";

/// @title Witnet Request Board "trustable" base implementation contract.
/// @notice Contract to bridge requests to Witnet Decentralized Oracle Network.
/// @dev This contract enables posting requests that Witnet bridges will insert into the Witnet network.
/// The result of the requests will be posted back to this contract by the bridge nodes too.
/// @author The Witnet Foundation
abstract contract WitnetOracleTrustableBase
    is 
        WitnetUpgradableBase,
        WitnetOracle,
        IWitnetOracleReporter,
        IWitnetRequestBoardAdminACLs,
        Payable 
{
    using Witnet for bytes;
    using Witnet for Witnet.Result;
    using WitnetCBOR for WitnetCBOR.CBOR;
    using WitnetV2 for WitnetV2.RadonSLA;
    using WitnetV2 for WitnetV2.Request;
    using WitnetV2 for WitnetV2.Response;

    bytes4 public immutable override specs = type(IWitnetOracle).interfaceId;
    WitnetRequestBytecodes immutable public override registry;
    
    WitnetRequestFactory immutable private __factory;

    modifier checkCallbackRecipient(address _addr, uint24 _callbackGasLimit) {
        _require(
            _addr.code.length > 0 && IWitnetConsumer(_addr).reportableFrom(address(this)) && _callbackGasLimit > 0,
            "invalid callback"
        ); _;
    }

    modifier checkReward(uint256 _baseFee) {
        _require(
            _getMsgValue() >= _baseFee, 
            "insufficient reward"
        ); 
        _require(
            _getMsgValue() <= _baseFee * 10,
            "too much reward"
        );
        _;
    }

    modifier checkSLA(WitnetV2.RadonSLA calldata sla) {
        _require(
            WitnetV2.isValid(sla), 
            "invalid SLA"
        ); _;
    }

    /// Asserts the given query is currently in the given status.
    modifier inStatus(uint256 _queryId, WitnetV2.QueryStatus _status) {
      if (WitnetOracleDataLib.seekQueryStatus(_queryId) != _status) {
        _revert(WitnetOracleDataLib.notInStatusRevertMessage(_status));
      } else {
        _;
      }
    }

    /// Asserts the caller actually posted the referred query.
    modifier onlyRequester(uint256 _queryId) {
        _require(
            msg.sender == WitnetOracleDataLib.seekQueryRequest(_queryId).requester, 
            "not the requester"
        ); _;
    }

    /// Asserts the caller is authorized as a reporter
    modifier onlyReporters {
        _require(
            __storage().reporters[msg.sender],
            "unauthorized reporter"
        );
        _;
    } 
    
    constructor(
            WitnetRequestFactory _factory,
            WitnetRequestBytecodes _registry,
            bool _upgradable,
            bytes32 _versionTag,
            address _currency
        )
        Ownable(address(msg.sender))
        Payable(_currency)
        WitnetUpgradableBase(
            _upgradable,
            _versionTag,
            "io.witnet.proxiable.board"
        )
    {
        __factory = _factory;
        registry = _registry;
    }

    receive() external payable { 
        _revert("no transfers accepted");
    }

    /// @dev Provide backwards compatibility for dapps bound to versions <= 0.6.1
    /// @dev (i.e. calling methods in IWitnetOracle)
    /// @dev (Until 'function ... abi(...)' modifier is allegedly supported in solc versions >= 0.9.1)
    /* solhint-disable payable-fallback */
    /* solhint-disable no-complex-fallback */
    fallback() override external { 
        _revert(string(abi.encodePacked(
            "not implemented: 0x",
            Witnet.toHexString(uint8(bytes1(msg.sig))),
            Witnet.toHexString(uint8(bytes1(msg.sig << 8))),
            Witnet.toHexString(uint8(bytes1(msg.sig << 16))),
            Witnet.toHexString(uint8(bytes1(msg.sig << 24)))
        )));
    }

    function channel() virtual override public view returns (bytes4) {
        return bytes4(keccak256(abi.encode(address(this), block.chainid)));
    }

    function class()
        public view
        virtual override(WitnetOracle, WitnetUpgradableBase) 
        returns (string memory)
    {
        return type(WitnetOracleTrustableBase).name;
    }

    function factory() virtual override public view returns (WitnetRequestFactory) {
        return __factory;
    }

    
    // ================================================================================================================
    // --- Yet to be implemented virtual methods ----------------------------------------------------------------------

    /// @notice Estimate the minimum reward required for posting a data request.
    /// @dev Underestimates if the size of returned data is greater than `_resultMaxSize`. 
    /// @param _gasPrice Expected gas price to pay upon posting the data request.
    /// @param _resultMaxSize Maximum expected size of returned data (in bytes).
    function estimateBaseFee(uint256 _gasPrice, uint16 _resultMaxSize) virtual public view returns (uint256); 

    /// @notice Estimate the minimum reward required for posting a data request with a callback.
    /// @param _gasPrice Expected gas price to pay upon posting the data request.
    /// @param _callbackGasLimit Maximum gas to be spent when reporting the data request result.
    function estimateBaseFeeWithCallback(uint256 _gasPrice, uint24 _callbackGasLimit) virtual public view returns (uint256);

    
    // ================================================================================================================
    // --- Overrides 'Upgradeable' ------------------------------------------------------------------------------------

    /// @notice Re-initialize contract's storage context upon a new upgrade from a proxy.
    /// @dev Must fail when trying to upgrade to same logic contract more than once.
    function initialize(bytes memory _initData)
        public
        override
    {
        address _owner = owner();
        address[] memory _newReporters;

        if (_owner == address(0)) {
            // get owner (and reporters) from _initData
            bytes memory _newReportersRaw;
            (_owner, _newReportersRaw) = abi.decode(_initData, (address, bytes));
            _transferOwnership(_owner);
            _newReporters = abi.decode(_newReportersRaw, (address[]));
        } else {
            // only owner can initialize:
            _require(
                msg.sender == _owner,
                "not the owner"
            );
            // get reporters from _initData
            _newReporters = abi.decode(_initData, (address[]));
        }

        if (
            __proxiable().codehash != bytes32(0)
                && __proxiable().codehash == codehash()
        ) {
            _revert("already upgraded");
        }
        __proxiable().codehash = codehash();

        _require(
            address(__factory).code.length > 0,
            "inexistent factory"
        );
        _require(
            __factory.specs() == type(IWitnetRequestFactory).interfaceId, 
            "uncompliant factory"
        );
        _require(
            address(__factory.witnet()) == address(this) 
                && address(__factory.registry()) == address(registry),
            "discordant factory"
        );

        // Set reporters, if any
        __setReporters(_newReporters);

        emit Upgraded(_owner, base(), codehash(), version());
    }

    /// Tells whether provided address could eventually upgrade the contract.
    function isUpgradableFrom(address _from) external view override returns (bool) {
        return (
            // false if the WRB is intrinsically not upgradable, or `_from` is no owner
            isUpgradable()
                && owner() == _from
        );
    }


    // ================================================================================================================
    // --- Partial implementation of IWitnetOracle --------------------------------------------------------------

    /// @notice Estimate the minimum reward required for posting a data request.
    /// @dev Underestimates if the size of returned data is greater than `resultMaxSize`. 
    /// @param gasPrice Expected gas price to pay upon posting the data request.
    /// @param radHash The hash of some Witnet Data Request previously posted in the WitnetRequestBytecodes registry.
    function estimateBaseFee(uint256 gasPrice, bytes32 radHash)
        public view
        virtual override
        returns (uint256)
    {
        uint16 _resultMaxSize = registry.lookupRadonRequestResultMaxSize(radHash);
        _require(
            _resultMaxSize > 0, 
            "invalid RAD"
        );
        return estimateBaseFee(
            gasPrice,
            _resultMaxSize
        );
    }

    /// Retrieves copy of all response data related to a previously posted request, removing the whole query from storage.
    /// @dev Fails if the `_witnetQueryId` is not in 'Reported' status, or called from an address different to
    /// @dev the one that actually posted the given request.
    /// @param _witnetQueryId The unique query identifier.
    function fetchQueryResponse(uint256 _witnetQueryId)
        virtual override
        external
        inStatus(_witnetQueryId, WitnetV2.QueryStatus.Finalized)
        onlyRequester(_witnetQueryId)
        returns (WitnetV2.Response memory _response)
    {
        _response = WitnetOracleDataLib.seekQuery(_witnetQueryId).response;
        delete __storage().queries[_witnetQueryId];
    }

    /// Gets the whole Query data contents, if any, no matter its current status.
    function getQuery(uint256 _witnetQueryId)
      public view
      virtual override
      returns (WitnetV2.Query memory)
    {
        return __storage().queries[_witnetQueryId];
    }

    /// @notice Gets the current EVM reward the report can claim, if not done yet.
    function getQueryEvmReward(uint256 _witnetQueryId) 
        external view 
        virtual override
        returns (uint256)
    {
        return __storage().queries[_witnetQueryId].request.evmReward;
    }

    /// @notice Retrieves the RAD hash and SLA parameters of the given query.
    /// @param _witnetQueryId The unique query identifier.
    function getQueryRequest(uint256 _witnetQueryId)
        external view 
        override
        returns (WitnetV2.Request memory)
    {
        return WitnetOracleDataLib.seekQueryRequest(_witnetQueryId);
    }

    /// Retrieves the Witnet-provable result, and metadata, to a previously posted request.    
    /// @dev Fails if the `_witnetQueryId` is not in 'Reported' status.
    /// @param _witnetQueryId The unique query identifier
    function getQueryResponse(uint256 _witnetQueryId)
        public view
        virtual override
        returns (WitnetV2.Response memory)
    {
        return WitnetOracleDataLib.seekQueryResponse(_witnetQueryId);
    }

    /// @notice Returns query's result current status from a requester's point of view:
    /// @notice   - 0 => Void: the query is either non-existent or deleted;
    /// @notice   - 1 => Awaiting: the query has not yet been reported;
    /// @notice   - 2 => Ready: the query has been succesfully solved;
    /// @notice   - 3 => Error: the query couldn't get solved due to some issue.
    /// @param _witnetQueryId The unique query identifier.
    function getQueryResponseStatus(uint256 _witnetQueryId)
        virtual override public view
        returns (WitnetV2.ResponseStatus)
    {
        return WitnetOracleDataLib.seekQueryResponseStatus(_witnetQueryId);
    }

    /// @notice Retrieves the CBOR-encoded buffer containing the Witnet-provided result to the given query.
    /// @param _witnetQueryId The unique query identifier.
    function getQueryResultCborBytes(uint256 _witnetQueryId) 
        external view 
        virtual override
        returns (bytes memory)
    {
        return WitnetOracleDataLib.seekQueryResponse(_witnetQueryId).resultCborBytes;
    }

    /// @notice Gets error code identifying some possible failure on the resolution of the given query.
    /// @param _witnetQueryId The unique query identifier.
    function getQueryResultError(uint256 _witnetQueryId)
        virtual override 
        public view
        returns (Witnet.ResultError memory)
    {
        WitnetV2.ResponseStatus _status = WitnetOracleDataLib.seekQueryResponseStatus(_witnetQueryId);
        try WitnetErrorsLib.asResultError(_status, WitnetOracleDataLib.seekQueryResponse(_witnetQueryId).resultCborBytes)
            returns (Witnet.ResultError memory _resultError)
        {
            return _resultError;
        } 
        catch Error(string memory _reason) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: string(abi.encodePacked("WitnetErrorsLib: ", _reason))
            });
        }
        catch (bytes memory) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetErrorsLib: assertion failed"
            });
        }
    }

    /// Gets current status of given query.
    function getQueryStatus(uint256 _witnetQueryId)
        external view
        override
        returns (WitnetV2.QueryStatus)
    {
        return WitnetOracleDataLib.seekQueryStatus(_witnetQueryId);
    }

    function getQueryStatusBatch(uint256[] calldata _witnetQueryIds)
        external view
        override
        returns (WitnetV2.QueryStatus[] memory _status)
    {
        _status = new WitnetV2.QueryStatus[](_witnetQueryIds.length);
        for (uint _ix = 0; _ix < _witnetQueryIds.length; _ix ++) {
            _status[_ix] = WitnetOracleDataLib.seekQueryStatus(_witnetQueryIds[_ix]);
        }
    }

    /// @notice Returns next query id to be generated by the Witnet Request Board.
    function getNextQueryId()
        external view
        override
        returns (uint256)
    {
        return __storage().nonce + 1;
    }

    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and 
    /// @notice solved by the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be 
    /// @notice transferred to the reporter who relays back the Witnet-provable result to this request.
    /// @dev Reasons to fail:
    /// @dev - the RAD hash was not previously verified by the WitnetRequestBytecodes registry;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - insufficient value is paid as reward.
    /// @param _queryRAD The RAD hash of the data request to be solved by Witnet.
    /// @param _querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @return _witnetQueryId Unique query identifier.
    function postRequest(
            bytes32 _queryRAD, 
            WitnetV2.RadonSLA calldata _querySLA
        )
        virtual override
        external payable
        checkReward(estimateBaseFee(_getGasPrice(), _queryRAD))
        checkSLA(_querySLA)
        returns (uint256 _witnetQueryId)
    {
        _witnetQueryId = __postRequest(_queryRAD, _querySLA, 0);
        // Let Web3 observers know that a new request has been posted
        emit WitnetQuery(
            _witnetQueryId, 
            _getMsgValue(),
            _querySLA
        );
    }
   
    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and solved by 
    /// @notice the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be transferred to the 
    /// @notice reporter who relays back the Witnet-provable result to this request. The Witnet-provable result will be reported
    /// @notice directly to the requesting contract. If the report callback fails for any reason, an `WitnetQueryResponseDeliveryFailed`
    /// @notice will be triggered, and the Witnet audit trail will be saved in storage, but not so the actual CBOR-encoded result.
    /// @dev Reasons to fail:
    /// @dev - the caller is not a contract implementing the IWitnetConsumer interface;
    /// @dev - the RAD hash was not previously verified by the WitnetRequestBytecodes registry;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - zero callback gas limit is provided;
    /// @dev - insufficient value is paid as reward.
    /// @param _queryRAD The RAD hash of the data request to be solved by Witnet.
    /// @param _querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @param _queryCallbackGasLimit Maximum gas to be spent when reporting the data request result.
    /// @return _witnetQueryId Unique query identifier.
    function postRequestWithCallback(
            bytes32 _queryRAD, 
            WitnetV2.RadonSLA calldata _querySLA,
            uint24 _queryCallbackGasLimit
        )
        virtual override
        external payable 
        checkCallbackRecipient(msg.sender, _queryCallbackGasLimit)
        checkReward(estimateBaseFeeWithCallback(_getGasPrice(),  _queryCallbackGasLimit))
        checkSLA(_querySLA)
        returns (uint256 _witnetQueryId)
    {
        _witnetQueryId = __postRequest(
            _queryRAD,
            _querySLA,
            _queryCallbackGasLimit
        );
        emit WitnetQuery(
            _witnetQueryId, 
            _getMsgValue(),
            _querySLA
        );
    }

    /// @notice Requests the execution of the given Witnet Data Request, in expectation that it will be relayed and solved by 
    /// @notice the Witnet blockchain. A reward amount is escrowed by the Witnet Request Board that will be transferred to the 
    /// @notice reporter who relays back the Witnet-provable result to this request. The Witnet-provable result will be reported
    /// @notice directly to the requesting contract. If the report callback fails for any reason, a `WitnetQueryResponseDeliveryFailed`
    /// @notice event will be triggered, and the Witnet audit trail will be saved in storage, but not so the CBOR-encoded result.
    /// @dev Reasons to fail:
    /// @dev - the caller is not a contract implementing the IWitnetConsumer interface;
    /// @dev - the provided bytecode is empty;
    /// @dev - invalid SLA parameters were provided;
    /// @dev - zero callback gas limit is provided;
    /// @dev - insufficient value is paid as reward.
    /// @param _queryUnverifiedBytecode The (unverified) bytecode containing the actual data request to be solved by the Witnet blockchain.
    /// @param _querySLA The data query SLA to be fulfilled on the Witnet blockchain.
    /// @param _queryCallbackGasLimit Maximum gas to be spent when reporting the data request result.
    /// @return _witnetQueryId Unique query identifier.
    function postRequestWithCallback(
            bytes calldata _queryUnverifiedBytecode,
            WitnetV2.RadonSLA calldata _querySLA, 
            uint24 _queryCallbackGasLimit
        )
        virtual override
        external payable 
        checkCallbackRecipient(msg.sender, _queryCallbackGasLimit)
        checkReward(estimateBaseFeeWithCallback(_getGasPrice(),  _queryCallbackGasLimit))
        checkSLA(_querySLA)
        returns (uint256 _witnetQueryId)
    {
        _witnetQueryId = __postRequest(
            bytes32(0),
            _querySLA,
            _queryCallbackGasLimit
        );
        WitnetOracleDataLib.seekQueryRequest(_witnetQueryId).witnetBytecode = _queryUnverifiedBytecode;
        emit WitnetQuery(
            _witnetQueryId,
            _getMsgValue(),
            _querySLA
        );
    }
  
    /// Increments the reward of a previously posted request by adding the transaction value to it.
    /// @dev Fails if the `_witnetQueryId` is not in 'Posted' status.
    /// @param _witnetQueryId The unique query identifier.
    function upgradeQueryEvmReward(uint256 _witnetQueryId)
        external payable
        virtual override      
        inStatus(_witnetQueryId, WitnetV2.QueryStatus.Posted)
    {
        WitnetV2.Request storage __request = WitnetOracleDataLib.seekQueryRequest(_witnetQueryId);
        __request.evmReward += uint72(_getMsgValue());
        emit WitnetQueryRewardUpgraded(_witnetQueryId, __request.evmReward);
    }

    
    // ================================================================================================================
    // --- Full implementation of IWitnetOracleReporter ---------------------------------------------------------

    /// @notice Estimates the actual earnings (or loss), in WEI, that a reporter would get by reporting result to given query,
    /// @notice based on the gas price of the calling transaction. Data requesters should consider upgrading the reward on 
    /// @notice queries providing no actual earnings.
    function estimateReportEarnings(
            uint256[] calldata _witnetQueryIds, 
            bytes calldata,
            uint256 _txGasPrice,
            uint256 _nanoWitPrice
        )
        external view
        virtual override
        returns (uint256 _revenues, uint256 _expenses)
    {
        for (uint _ix = 0; _ix < _witnetQueryIds.length; _ix ++) {
            if (WitnetOracleDataLib.seekQueryStatus(_witnetQueryIds[_ix]) == WitnetV2.QueryStatus.Posted) {
                WitnetV2.Request storage __request = WitnetOracleDataLib.seekQueryRequest(_witnetQueryIds[_ix]);
                _revenues += __request.evmReward;
                if (__request.gasCallback > 0) {
                    _expenses += estimateBaseFeeWithCallback(_txGasPrice, __request.gasCallback);
                } else {
                    if (__request.witnetRAD != bytes32(0)) {
                        _expenses += estimateBaseFee(_txGasPrice, __request.witnetRAD);
                    } else {
                        // todo: improve profit estimation accuracy if reporting on deleted query
                        _expenses += estimateBaseFee(_txGasPrice, uint16(0)); 
                    }
                }
                _expenses +=  __request.witnetSLA.nanoWitTotalFee() * _nanoWitPrice;
            }
        }
    }

    /// @notice Retrieves the Witnet Data Request bytecodes and SLAs of previously posted queries.
    /// @dev Returns empty buffer if the query does not exist.
    /// @param _queryIds Query identifies.
    function extractWitnetDataRequests(uint256[] calldata _queryIds)
        external view 
        virtual override
        returns (bytes[] memory _bytecodes)
    {
        return WitnetOracleDataLib.extractWitnetDataRequests(registry, _queryIds);
    }

    /// Reports the Witnet-provable result to a previously posted request. 
    /// @dev Will assume `block.timestamp` as the timestamp at which the request was solved.
    /// @dev Fails if:
    /// @dev - the `_witnetQueryId` is not in 'Posted' status.
    /// @dev - provided `_witnetQueryResultTallyHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _witnetQueryId The unique identifier of the data request.
    /// @param _witnetQueryResultTallyHash Hash of the commit/reveal witnessing act that took place in the Witnet blockahin.
    /// @param _witnetQueryResultCborBytes The result itself as bytes.
    function reportResult(
            uint256 _witnetQueryId,
            bytes32 _witnetQueryResultTallyHash,
            bytes calldata _witnetQueryResultCborBytes
        )
        external override
        onlyReporters
        inStatus(_witnetQueryId, WitnetV2.QueryStatus.Posted)
        returns (uint256)
    {
        // results cannot be empty:
        _require(
            _witnetQueryResultCborBytes.length != 0, 
            "result cannot be empty"
        );
        // do actual report and return reward transfered to the reproter:
        // solhint-disable not-rely-on-time
        return __reportResultAndReward(
            _witnetQueryId,
            uint32(block.timestamp),
            _witnetQueryResultTallyHash,
            _witnetQueryResultCborBytes
        );
    }

    /// Reports the Witnet-provable result to a previously posted request.
    /// @dev Fails if:
    /// @dev - called from unauthorized address;
    /// @dev - the `_witnetQueryId` is not in 'Posted' status.
    /// @dev - provided `_witnetQueryResultTallyHash` is zero;
    /// @dev - length of provided `_witnetQueryResultCborBytes` is zero.
    /// @param _witnetQueryId The unique query identifier
    /// @param _witnetQueryResultTimestamp Timestamp at which the reported value was captured by the Witnet blockchain. 
    /// @param _witnetQueryResultTallyHash Hash of the commit/reveal witnessing act that took place in the Witnet blockahin.
    /// @param _witnetQueryResultCborBytes The result itself as bytes.
    function reportResult(
            uint256 _witnetQueryId,
            uint32  _witnetQueryResultTimestamp,
            bytes32 _witnetQueryResultTallyHash,
            bytes calldata _witnetQueryResultCborBytes
        )
        external
        override
        onlyReporters
        inStatus(_witnetQueryId, WitnetV2.QueryStatus.Posted)
        returns (uint256)
    {
        // validate timestamp
        _require(
            _witnetQueryResultTimestamp > 0 
                && _witnetQueryResultTimestamp <= block.timestamp, 
            "bad timestamp"
        );
        // results cannot be empty
        _require(
            _witnetQueryResultCborBytes.length != 0, 
            "result cannot be empty"
        );
        // do actual report and return reward transfered to the reproter:
        return  __reportResultAndReward(
            _witnetQueryId,
            _witnetQueryResultTimestamp,
            _witnetQueryResultTallyHash,
            _witnetQueryResultCborBytes
        );
    }

    /// @notice Reports Witnet-provided results to multiple requests within a single EVM tx.
    /// @notice Emits either a WitnetQueryResponse* or a BatchReportError event per batched report.
    /// @dev Fails only if called from unauthorized address.
    /// @param _batchResults Array of BatchResult structs, every one containing:
    ///         - unique query identifier;
    ///         - timestamp of the solving tally txs in Witnet. If zero is provided, EVM-timestamp will be used instead;
    ///         - hash of the corresponding data request tx at the Witnet side-chain level;
    ///         - data request result in raw bytes.
    function reportResultBatch(IWitnetOracleReporter.BatchResult[] calldata _batchResults)
        external override
        onlyReporters
        returns (uint256 _batchReward)
    {
        for ( uint _i = 0; _i < _batchResults.length; _i ++) {
            if (
                WitnetOracleDataLib.seekQueryStatus(_batchResults[_i].queryId)
                    != WitnetV2.QueryStatus.Posted
            ) {
                emit BatchReportError(
                    _batchResults[_i].queryId,
                    WitnetOracleDataLib.notInStatusRevertMessage(WitnetV2.QueryStatus.Posted)
                );
            } else if (
                uint256(_batchResults[_i].queryResultTimestamp) > block.timestamp
                    || _batchResults[_i].queryResultTimestamp == 0
                    || _batchResults[_i].queryResultCborBytes.length == 0
            ) {
                emit BatchReportError(
                    _batchResults[_i].queryId, 
                    string(abi.encodePacked(
                        class(),
                        "invalid report data"
                    ))
                );
            } else {
                _batchReward += __reportResult(
                    _batchResults[_i].queryId,
                    _batchResults[_i].queryResultTimestamp,
                    _batchResults[_i].queryResultTallyHash,
                    _batchResults[_i].queryResultCborBytes
                );
            }
        }   
        // Transfer rewards to all reported results in one single transfer to the reporter:
        if (_batchReward > 0) {
            __safeTransferTo(
                payable(msg.sender),
                _batchReward
            );
        }
    }


    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardAdminACLs' ------------------------------------------------------

    /// Tells whether given address is included in the active reporters control list.
    /// @param _reporter The address to be checked.
    function isReporter(address _reporter) public view override returns (bool) {
        return WitnetOracleDataLib.isReporter(_reporter);
    }

    /// Adds given addresses to the active reporters control list.
    /// @dev Can only be called from the owner address.
    /// @dev Emits the `ReportersSet` event. 
    /// @param _reporters List of addresses to be added to the active reporters control list.
    function setReporters(address[] memory _reporters)
        public
        override
        onlyOwner
    {
        __setReporters(_reporters);
    }

    /// Removes given addresses from the active reporters control list.
    /// @dev Can only be called from the owner address.
    /// @dev Emits the `ReportersUnset` event. 
    /// @param _exReporters List of addresses to be added to the active reporters control list.
    function unsetReporters(address[] memory _exReporters)
        public
        override
        onlyOwner
    {
        for (uint ix = 0; ix < _exReporters.length; ix ++) {
            address _reporter = _exReporters[ix];
            __storage().reporters[_reporter] = false;
        }
        emit ReportersUnset(_exReporters);
    }


    // ================================================================================================================
    // --- Internal functions -----------------------------------------------------------------------------------------

    function __newQueryId(bytes32 _queryRAD, bytes32 _querySLA)
        virtual internal view
        returns (uint256)
    {
        return uint(keccak256(abi.encode(
            channel(),
            block.number,
            msg.sender,
            _queryRAD,
            _querySLA
        )));
    }

    function __postRequest(bytes32 _radHash, WitnetV2.RadonSLA calldata _sla, uint24 _callbackGasLimit)
        virtual internal
        returns (uint256 _witnetQueryId)
    {
        _witnetQueryId = ++ __storage().nonce; //__newQueryId(_radHash, _packedSLA);
        WitnetV2.Request storage __request = WitnetOracleDataLib.seekQueryRequest(_witnetQueryId);
        _require(__request.requester == address(0), "already posted");
        {
            __request.requester = msg.sender;
            __request.gasCallback = _callbackGasLimit;
            __request.evmReward = uint72(_getMsgValue());
            __request.witnetRAD = _radHash;
            __request.witnetSLA = _sla;
        }
    }

    function __reportResult(
            uint256 _witnetQueryId,
            uint32  _witnetQueryResultTimestamp,
            bytes32 _witnetQueryResultTallyHash,
            bytes calldata _witnetQueryResultCborBytes
        )
        virtual internal
        returns (uint256 _evmReward)
    {
        // read requester address and whether a callback was requested:
        WitnetV2.Request storage __request = WitnetOracleDataLib.seekQueryRequest(_witnetQueryId);
                
        // read query EVM reward:
        _evmReward = __request.evmReward;
        
        // set EVM reward right now as to avoid re-entrancy attacks:
        __request.evmReward = 0; 

        // determine whether a callback is required
        if (__request.gasCallback > 0) {
            (
                uint256 _evmCallbackActualGas,
                bool _evmCallbackSuccess,
                string memory _evmCallbackRevertMessage
            ) = __reportResultCallback(
                _witnetQueryId,
                _witnetQueryResultTimestamp,
                _witnetQueryResultTallyHash,
                _witnetQueryResultCborBytes,
                __request.requester,
                __request.gasCallback
            );
            if (_evmCallbackSuccess) {
                // => the callback run successfully
                emit WitnetQueryResponseDelivered(
                    _witnetQueryId,
                    _getGasPrice(),
                    _evmCallbackActualGas
                );
            } else {
                // => the callback reverted
                emit WitnetQueryResponseDeliveryFailed(
                    _witnetQueryId,
                    _witnetQueryResultCborBytes,
                    _getGasPrice(),
                    _evmCallbackActualGas,
                    bytes(_evmCallbackRevertMessage).length > 0 
                        ? _evmCallbackRevertMessage
                        : "WitnetOracle: callback exceeded gas limit"
                );
            }
            // upon delivery, successfull or not, the audit trail is saved into storage, 
            // but not the actual result which was intended to be passed over to the requester:
            __writeQueryResponse(
                _witnetQueryId, 
                _witnetQueryResultTimestamp, 
                _witnetQueryResultTallyHash, 
                hex""
            );
        } else {
            // => no callback is involved
            emit WitnetQueryResponse(
                _witnetQueryId, 
                _getGasPrice()
            );
            // write query result and audit trail data into storage 
            __writeQueryResponse(
                _witnetQueryId,
                _witnetQueryResultTimestamp,
                _witnetQueryResultTallyHash,
                _witnetQueryResultCborBytes
            );
        }
    }

    function __reportResultAndReward(
            uint256 _witnetQueryId,
            uint32  _witnetQueryResultTimestamp,
            bytes32 _witnetQueryResultTallyHash,
            bytes calldata _witnetQueryResultCborBytes
        )
        virtual internal
        returns (uint256 _evmReward)
    {
        _evmReward = __reportResult(
            _witnetQueryId, 
            _witnetQueryResultTimestamp, 
            _witnetQueryResultTallyHash, 
            _witnetQueryResultCborBytes
        );
        // transfer reward to reporter
        __safeTransferTo(
            payable(msg.sender),
            _evmReward
        );
    }

    function __reportResultCallback(
            uint256 _witnetQueryId,
            uint64  _witnetQueryResultTimestamp,
            bytes32 _witnetQueryResultTallyHash,
            bytes calldata _witnetQueryResultCborBytes,
            address _evmRequester,
            uint256 _evmCallbackGasLimit
        )
        virtual internal
        returns (
            uint256 _evmCallbackActualGas, 
            bool _evmCallbackSuccess, 
            string memory _evmCallbackRevertMessage
        )
    {
        _evmCallbackActualGas = gasleft();
        if (_witnetQueryResultCborBytes[0] == bytes1(0xd8)) {
            WitnetCBOR.CBOR[] memory _errors = WitnetCBOR.fromBytes(_witnetQueryResultCborBytes).readArray();
            if (_errors.length < 2) {
                // try to report result with unknown error:
                try IWitnetConsumer(_evmRequester).reportWitnetQueryError{gas: _evmCallbackGasLimit}(
                    _witnetQueryId,
                    _witnetQueryResultTimestamp,
                    _witnetQueryResultTallyHash,
                    block.number,
                    Witnet.ResultErrorCodes.Unknown,
                    WitnetCBOR.CBOR({
                        buffer: WitnetBuffer.Buffer({ data: hex"", cursor: 0}),
                        initialByte: 0,
                        majorType: 0,
                        additionalInformation: 0,
                        len: 0,
                        tag: 0
                    })
                ) {
                    _evmCallbackSuccess = true;
                } catch Error(string memory err) {
                    _evmCallbackRevertMessage = err;
                }
            } else {
                // try to report result with parsable error:
                try IWitnetConsumer(_evmRequester).reportWitnetQueryError{gas: _evmCallbackGasLimit}(
                    _witnetQueryId,
                    _witnetQueryResultTimestamp,
                    _witnetQueryResultTallyHash,
                    block.number,
                    Witnet.ResultErrorCodes(_errors[0].readUint()),
                    _errors[0]
                ) {
                    _evmCallbackSuccess = true;
                } catch Error(string memory err) {
                    _evmCallbackRevertMessage = err; 
                }
            }
        } else {
            // try to report result result with no error :
            try IWitnetConsumer(_evmRequester).reportWitnetQueryResult{gas: _evmCallbackGasLimit}(
                _witnetQueryId,
                _witnetQueryResultTimestamp,
                _witnetQueryResultTallyHash,
                block.number,
                WitnetCBOR.fromBytes(_witnetQueryResultCborBytes)
            ) {
                _evmCallbackSuccess = true;
            } catch Error(string memory err) {
                _evmCallbackRevertMessage = err;
            } catch (bytes memory) {}
        }
        _evmCallbackActualGas -= gasleft();
    }

    function __setReporters(address[] memory _reporters)
        virtual internal
    {
        for (uint ix = 0; ix < _reporters.length; ix ++) {
            address _reporter = _reporters[ix];
            __storage().reporters[_reporter] = true;
        }
        emit ReportersSet(_reporters);
    }

    /// Returns storage pointer to contents of 'WitnetBoardState' struct.
    function __storage() virtual internal pure returns (WitnetOracleDataLib.Storage storage _ptr) {
      return WitnetOracleDataLib.data();
    }

    function __writeQueryResponse(
            uint256 _witnetQueryId, 
            uint32  _witnetQueryResultTimestamp, 
            bytes32 _witnetQueryResultTallyHash, 
            bytes memory _witnetQueryResultCborBytes
        )
        virtual internal
    {
        WitnetOracleDataLib.seekQuery(_witnetQueryId).response = WitnetV2.Response({
            reporter: msg.sender,
            finality: uint64(block.number),
            resultTimestamp: _witnetQueryResultTimestamp,
            resultTallyHash: _witnetQueryResultTallyHash,
            resultCborBytes: _witnetQueryResultCborBytes
        });
    }

}

File 23 of 34 : WitnetUpgradableBase.sol
// SPDX-License-Identifier: MIT
// solhint-disable var-name-mixedcase
// solhint-disable payable-fallback

pragma solidity >=0.8.0 <0.9.0;

import "../patterns/Ownable2Step.sol";
import "../patterns/ReentrancyGuard.sol";
import "../patterns/Upgradeable.sol";

import "./WitnetProxy.sol";

/// @title Witnet Request Board base contract, with an Upgradeable (and Destructible) touch.
/// @author Guillermo Díaz <[email protected]>
abstract contract WitnetUpgradableBase
    is
        Ownable2Step,
        Upgradeable, 
        ReentrancyGuard
{
    bytes32 internal immutable _WITNET_UPGRADABLE_VERSION;

    address public immutable deployer = msg.sender;

    constructor(
            bool _upgradable,
            bytes32 _versionTag,
            string memory _proxiableUUID
        )
        Upgradeable(_upgradable)
    {
        _WITNET_UPGRADABLE_VERSION = _versionTag;
        proxiableUUID = keccak256(bytes(_proxiableUUID));
    }
    
    /// @dev Reverts if proxy delegatecalls to unexistent method.
    fallback() virtual external {
        _revert("not implemented");
    }


    function class() virtual public view returns (string memory) {
        return type(WitnetUpgradableBase).name;
    }
   
    // ================================================================================================================
    // --- Overrides 'Proxiable' --------------------------------------------------------------------------------------

    /// @dev Gets immutable "heritage blood line" (ie. genotype) as a Proxiable, and eventually Upgradeable, contract.
    ///      If implemented as an Upgradeable touch, upgrading this contract to another one with a different 
    ///      `proxiableUUID()` value should fail.
    bytes32 public immutable override proxiableUUID;


    // ================================================================================================================
    // --- Overrides 'Upgradeable' --------------------------------------------------------------------------------------

    /// Retrieves human-readable version tag of current implementation.
    function version() public view virtual override returns (string memory) {
        return _toString(_WITNET_UPGRADABLE_VERSION);
    }


    // ================================================================================================================
    // --- Internal methods -------------------------------------------------------------------------------------------

    function _require(
            bool _condition, 
            string memory _message
        )
        internal view
    {
        if (!_condition) {
            _revert(_message);
        }
    }

    function _revert(string memory _message)
        internal view
    {
        revert(
            string(abi.encodePacked(
                class(),
                ": ",
                _message
            ))
        );
    }

    /// 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);
    }

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

}

File 24 of 34 : WitnetProxy.sol
// SPDX-License-Identifier: MIT

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

import "../patterns/Upgradeable.sol";

/// @title WitnetProxy: upgradable delegate-proxy contract. 
/// @author Guillermo Díaz <[email protected]>
contract WitnetProxy {

    /// Event emitted every time the implementation gets updated.
    event Upgraded(address indexed implementation);  

    /// Constructor with no params as to ease eventual support of Singleton pattern (i.e. ERC-2470).
    constructor () {}

    receive() virtual external payable {}

    /// Payable fallback accepts delegating calls to payable functions.  
    fallback() external payable { /* solhint-disable no-complex-fallback */
        address _implementation = implementation();
        assembly { /* solhint-disable avoid-low-level-calls */
            // Gas optimized delegate call to 'implementation' contract.
            // Note: `msg.data`, `msg.sender` and `msg.value` will be passed over 
            //       to actual implementation of `msg.sig` within `implementation` contract.
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize())
            let result := delegatecall(gas(), _implementation, ptr, calldatasize(), 0, 0)
            let size := returndatasize()
            returndatacopy(ptr, 0, size)
            switch result
                case 0  { 
                    // pass back revert message:
                    revert(ptr, size) 
                }
                default {
                  // pass back same data as returned by 'implementation' contract:
                  return(ptr, size) 
                }
        }
    }

    /// Returns proxy's current implementation address.
    function implementation() public view returns (address) {
        return __proxySlot().implementation;
    }

    /// Upgrades the `implementation` address.
    /// @param _newImplementation New implementation address.
    /// @param _initData Raw data with which new implementation will be initialized.
    /// @return Returns whether new implementation would be further upgradable, or not.
    function upgradeTo(address _newImplementation, bytes memory _initData)
        public returns (bool)
    {
        // New implementation cannot be null:
        require(_newImplementation != address(0), "WitnetProxy: null implementation");

        address _oldImplementation = implementation();
        if (_oldImplementation != address(0)) {
            // New implementation address must differ from current one:
            require(_newImplementation != _oldImplementation, "WitnetProxy: nothing to upgrade");

            // Assert whether current implementation is intrinsically upgradable:
            try Upgradeable(_oldImplementation).isUpgradable() returns (bool _isUpgradable) {
                require(_isUpgradable, "WitnetProxy: not upgradable");
            } catch {
                revert("WitnetProxy: unable to check upgradability");
            }

            // Assert whether current implementation allows `msg.sender` to upgrade the proxy:
            (bool _wasCalled, bytes memory _result) = _oldImplementation.delegatecall(
                abi.encodeWithSignature(
                    "isUpgradableFrom(address)",
                    msg.sender
                )
            );
            require(_wasCalled, "WitnetProxy: uncompliant implementation");
            require(abi.decode(_result, (bool)), "WitnetProxy: not authorized");
            require(
                Upgradeable(_oldImplementation).proxiableUUID() == Upgradeable(_newImplementation).proxiableUUID(),
                "WitnetProxy: proxiableUUIDs mismatch"
            );
        }

        // Initialize new implementation within proxy-context storage:
        (bool _wasInitialized, bytes memory _returnData) = _newImplementation.delegatecall(
            abi.encodeWithSignature(
                "initialize(bytes)",
                _initData
            )
        );
        if (!_wasInitialized) {
            if (_returnData.length < 68) {
                revert("WitnetProxy: initialization failed");
            } else {
                assembly {
                    _returnData := add(_returnData, 0x04)
                }
                revert(abi.decode(_returnData, (string)));
            }
        }

        // If all checks and initialization pass, update implementation address:
        __proxySlot().implementation = _newImplementation;
    
        emit Upgraded(_newImplementation);

        // Asserts new implementation complies w/ minimal implementation of Upgradeable interface:
        try Upgradeable(_newImplementation).isUpgradable() returns (bool _isUpgradable) {
            return _isUpgradable;
        }
        catch {
            revert ("WitnetProxy: uncompliant implementation");
        }
    }

    /// @dev Complying with EIP-1967, retrieves storage struct containing proxy's current implementation address.
    function __proxySlot() private pure returns (Proxiable.ProxiableSlot storage _slot) {
        assembly {
            // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
            _slot.slot := 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
        }
    }

}

File 25 of 34 : WitnetRequestFactory.sol
// SPDX-License-Identifier: MIT

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

import "./WitnetRequestBytecodes.sol";
import "./WitnetOracle.sol";
import "./interfaces/IWitnetRequestFactory.sol";

abstract contract WitnetRequestFactory
    is
        IWitnetRequestFactory
{
    function class() virtual external view returns (string memory);
    function registry() virtual external view returns (WitnetRequestBytecodes);
    function specs() virtual external view returns (bytes4);
    function witnet() virtual external view returns (WitnetOracle);
}

File 26 of 34 : WitnetRequestBytecodes.sol
// SPDX-License-Identifier: MIT

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

import "./interfaces/IWitnetRequestBytecodes.sol";

abstract contract WitnetRequestBytecodes
    is
        IWitnetRequestBytecodes
{
    function class() virtual external view returns (string memory) {
        return type(WitnetRequestBytecodes).name;
    }   
    function specs() virtual external view returns (bytes4);
}

File 27 of 34 : WitnetOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "./WitnetRequestBytecodes.sol";
import "./WitnetRequestFactory.sol";
import "./interfaces/IWitnetOracle.sol";
import "./interfaces/IWitnetOracleEvents.sol";

/// @title Witnet Request Board functionality base contract.
/// @author The Witnet Foundation.
abstract contract WitnetOracle
    is
        IWitnetOracle,
        IWitnetOracleEvents
{
    function class() virtual external view returns (string memory) {
        return type(WitnetOracle).name;
    }
    function channel() virtual external view returns (bytes4);
    function factory() virtual external view returns (WitnetRequestFactory);
    function registry() virtual external view returns (WitnetRequestBytecodes);
    function specs() virtual external view returns (bytes4);
}

File 28 of 34 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 29 of 34 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 30 of 34 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

File 31 of 34 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 32 of 34 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

File 33 of 34 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 34 of 34 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

Settings
{
  "remappings": [],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "libraries": {
    "/contracts/libs/WitnetErrorsLib.sol": {
      "WitnetErrorsLib": "0xa57B9dd8420631248c3DFB535f4FC9f7E2f02B4B"
    },
    "/contracts/data/WitnetOracleDataLib.sol": {
      "WitnetOracleDataLib": "0x561A6c8F9C9D6e7EbAEcd4963A8f27Ae13568676"
    }
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"contract WitnetRequestFactory","name":"_factory","type":"address"},{"internalType":"contract WitnetRequestBytecodes","name":"_registry","type":"address"},{"internalType":"bool","name":"_upgradable","type":"bool"},{"internalType":"bytes32","name":"_versionTag","type":"bytes32"},{"internalType":"uint256","name":"_reportResultGasBase","type":"uint256"},{"internalType":"uint256","name":"_reportResultWithCallbackGasBase","type":"uint256"},{"internalType":"uint256","name":"_reportResultWithCallbackRevertGasBase","type":"uint256"},{"internalType":"uint256","name":"_sstoreFromZeroGas","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EmptyBuffer","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"range","type":"uint256"}],"name":"IndexOutOfBounds","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"InvalidLengthEncoding","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"read","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"UnexpectedMajorType","type":"error"},{"inputs":[{"internalType":"uint256","name":"unexpected","type":"uint256"}],"name":"UnsupportedMajorType","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"queryId","type":"uint256"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"BatchReportError","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"reporters","type":"address[]"}],"name":"ReportersSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"reporters","type":"address[]"}],"name":"ReportersUnset","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"baseAddr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"baseCodehash","type":"bytes32"},{"indexed":false,"internalType":"string","name":"versionTag","type":"string"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmReward","type":"uint256"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"indexed":false,"internalType":"struct WitnetV2.RadonSLA","name":"witnetSLA","type":"tuple"}],"name":"WitnetQuery","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmGasPrice","type":"uint256"}],"name":"WitnetQueryResponse","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmGasPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmCallbackGas","type":"uint256"}],"name":"WitnetQueryResponseDelivered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"resultCborBytes","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"evmGasPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmCallbackActualGas","type":"uint256"},{"indexed":false,"internalType":"string","name":"evmCallbackRevertReason","type":"string"}],"name":"WitnetQueryResponseDeliveryFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"evmReward","type":"uint256"}],"name":"WitnetQueryRewardUpgraded","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"base","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"channel","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"class","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"codehash","outputs":[{"internalType":"bytes32","name":"_codehash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currency","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deployer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_gasPrice","type":"uint256"},{"internalType":"uint16","name":"_resultMaxSize","type":"uint16"}],"name":"estimateBaseFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"bytes32","name":"radHash","type":"bytes32"}],"name":"estimateBaseFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_gasPrice","type":"uint256"},{"internalType":"uint24","name":"_callbackGasLimit","type":"uint24"}],"name":"estimateBaseFeeWithCallback","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_witnetQueryIds","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"uint256","name":"_txGasPrice","type":"uint256"},{"internalType":"uint256","name":"_nanoWitPrice","type":"uint256"}],"name":"estimateReportEarnings","outputs":[{"internalType":"uint256","name":"_revenues","type":"uint256"},{"internalType":"uint256","name":"_expenses","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_queryIds","type":"uint256[]"}],"name":"extractWitnetDataRequests","outputs":[{"internalType":"bytes[]","name":"_bytecodes","type":"bytes[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract WitnetRequestFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"fetchQueryResponse","outputs":[{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint64","name":"finality","type":"uint64"},{"internalType":"uint32","name":"resultTimestamp","type":"uint32"},{"internalType":"bytes32","name":"resultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"resultCborBytes","type":"bytes"}],"internalType":"struct WitnetV2.Response","name":"_response","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getNextQueryId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQuery","outputs":[{"components":[{"components":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"uint24","name":"gasCallback","type":"uint24"},{"internalType":"uint72","name":"evmReward","type":"uint72"},{"internalType":"bytes","name":"witnetBytecode","type":"bytes"},{"internalType":"bytes32","name":"witnetRAD","type":"bytes32"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"internalType":"struct WitnetV2.RadonSLA","name":"witnetSLA","type":"tuple"}],"internalType":"struct WitnetV2.Request","name":"request","type":"tuple"},{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint64","name":"finality","type":"uint64"},{"internalType":"uint32","name":"resultTimestamp","type":"uint32"},{"internalType":"bytes32","name":"resultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"resultCborBytes","type":"bytes"}],"internalType":"struct WitnetV2.Response","name":"response","type":"tuple"}],"internalType":"struct WitnetV2.Query","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryEvmReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryRequest","outputs":[{"components":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"uint24","name":"gasCallback","type":"uint24"},{"internalType":"uint72","name":"evmReward","type":"uint72"},{"internalType":"bytes","name":"witnetBytecode","type":"bytes"},{"internalType":"bytes32","name":"witnetRAD","type":"bytes32"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"internalType":"struct WitnetV2.RadonSLA","name":"witnetSLA","type":"tuple"}],"internalType":"struct WitnetV2.Request","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryResponse","outputs":[{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint64","name":"finality","type":"uint64"},{"internalType":"uint32","name":"resultTimestamp","type":"uint32"},{"internalType":"bytes32","name":"resultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"resultCborBytes","type":"bytes"}],"internalType":"struct WitnetV2.Response","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryResponseStatus","outputs":[{"internalType":"enum WitnetV2.ResponseStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryResultCborBytes","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryResultError","outputs":[{"components":[{"internalType":"enum Witnet.ResultErrorCodes","name":"code","type":"uint8"},{"internalType":"string","name":"reason","type":"string"}],"internalType":"struct Witnet.ResultError","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"getQueryStatus","outputs":[{"internalType":"enum WitnetV2.QueryStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_witnetQueryIds","type":"uint256[]"}],"name":"getQueryStatusBatch","outputs":[{"internalType":"enum WitnetV2.QueryStatus[]","name":"_status","type":"uint8[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_initData","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_reporter","type":"address"}],"name":"isReporter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isUpgradable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"}],"name":"isUpgradableFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_queryRAD","type":"bytes32"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"internalType":"struct WitnetV2.RadonSLA","name":"_querySLA","type":"tuple"}],"name":"postRequest","outputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_queryUnverifiedBytecode","type":"bytes"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"internalType":"struct WitnetV2.RadonSLA","name":"_querySLA","type":"tuple"},{"internalType":"uint24","name":"_queryCallbackGasLimit","type":"uint24"}],"name":"postRequestWithCallback","outputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_queryRAD","type":"bytes32"},{"components":[{"internalType":"uint8","name":"committeeSize","type":"uint8"},{"internalType":"uint64","name":"witnessingFeeNanoWit","type":"uint64"}],"internalType":"struct WitnetV2.RadonSLA","name":"_querySLA","type":"tuple"},{"internalType":"uint24","name":"_queryCallbackGasLimit","type":"uint24"}],"name":"postRequestWithCallback","outputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract WitnetRequestBytecodes","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"},{"internalType":"bytes32","name":"_witnetQueryResultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"_witnetQueryResultCborBytes","type":"bytes"}],"name":"reportResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"},{"internalType":"uint32","name":"_witnetQueryResultTimestamp","type":"uint32"},{"internalType":"bytes32","name":"_witnetQueryResultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"_witnetQueryResultCborBytes","type":"bytes"}],"name":"reportResult","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"queryId","type":"uint256"},{"internalType":"uint32","name":"queryResultTimestamp","type":"uint32"},{"internalType":"bytes32","name":"queryResultTallyHash","type":"bytes32"},{"internalType":"bytes","name":"queryResultCborBytes","type":"bytes"}],"internalType":"struct IWitnetOracleReporter.BatchResult[]","name":"_batchResults","type":"tuple[]"}],"name":"reportResultBatch","outputs":[{"internalType":"uint256","name":"_batchReward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_reporters","type":"address[]"}],"name":"setReporters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"specs","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_exReporters","type":"address[]"}],"name":"unsetReporters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_witnetQueryId","type":"uint256"}],"name":"upgradeQueryEvmReward","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

610240604052336101005263baeca88b60e01b6101605234801561002257600080fd5b50604051615cb3380380615cb3833981016040819052610041916101a6565b8787878760008083836040518060400160405280601981526020017f696f2e7769746e65742e70726f786961626c652e626f61726400000000000000815250823360006001600160a01b0316816001600160a01b0316036100bc57604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b6100c581610125565b5030608052151560c052600160025560e091909152805160209091012061012052506001600160a01b03908116610140529485166101a05250505016610180526101c0939093526101e09190915261020052610220525061022892505050565b600180546001600160a01b031916905561013e81610141565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b038116811461013e57600080fd5b600080600080600080600080610100898b0312156101c357600080fd5b88516101ce81610191565b60208a01519098506101df81610191565b60408a015190975080151581146101f557600080fd5b60608a015160808b015160a08c015160c08d015160e0909d01519b9e9a9d50929b919a9099929850909650945092505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e051610200516102205161597e61033560003960008181610bad0152611ea701526000610bd9015260008181610c190152610c6101526000611ed1015260008181610903015281816117d60152818161181e015281816118e901526119a60152600081816106c50152818161197c01528181611b3401526120ef01526000610870015260006109a00152600061052e0152600061094e01526000611bc701526000818161055f0152611d7f015260005050600081816104e4015281816108390152818161170b0152818161176501528181611a6c0152611a8e015261597e6000f3fe6080604052600436106102765760003560e01c80637b1039991161014f578063aeb2ffc1116100c1578063e30c39781161007a578063e30c397814610970578063e5a6b10f1461098e578063e900aa33146109c2578063ec5946db146109d5578063f2fde38b146109e8578063f61921b214610a08576102b3565b8063aeb2ffc114610892578063b207e730146108bf578063bff852fa146108df578063c45a0155146108f4578063c805dd0f14610927578063d5f394881461093c576102b3565b806393d5185c1161011357806393d5185c146107955780639cc56e67146107ca578063a3ff5b00146107ea578063a77fc1a4146107fd578063a9e954b91461082a578063adb7c3f71461085e576102b3565b80637b103999146106b35780637bbdb96e146106e75780637bd88218146107375780638d3d8b38146107575780638da5cb5b14610777576102b3565b80635001f3b5116101e85780636280bce8116101ac5780636280bce8146105d25780636b58960a146105f25780636f07abcc146106125780636fdaab7e1461063f578063715018a61461068957806379ba50971461069e576102b3565b80635001f3b5146104d557806352d1902d1461051c5780635479d9401461055057806354fd4d5014610583578063581f5094146105a5576102b3565b8063234fe6e31161023a578063234fe6e31461040857806328a78d9b146104355780633dc2b7a214610455578063439fab911461046857806345ea6c17146104885780634c9f72e3146104b5576102b3565b8063044ad7be1461032b57806305e742ef1461036057806306eb2c421461038e57806308b7e85e146103ae5780630aa4112a146103db576102b3565b366102b3576102b1604051806040016040528060158152602001741b9bc81d1c985b9cd9995c9cc81858d8d95c1d1959605a1b815250610a28565b005b3480156102bf57600080fd5b506102b16102d160003560f81c610a71565b6102e260ff60003560f01c16610a71565b6102f360ff60003560e81c16610a71565b61030460ff60003560e01c16610a71565b6040516020016103179493929190614363565b604051602081830303815290604052610a28565b34801561033757600080fd5b5061034b6103463660046143f7565b610b63565b60405190151581526020015b60405180910390f35b34801561036c57600080fd5b5061038061037b366004614427565b610ba5565b604051908152602001610357565b34801561039a57600080fd5b506103806103a936600461449e565b610c96565b3480156103ba57600080fd5b506103ce6103c93660046144df565b611044565b6040516103579190614578565b3480156103e757600080fd5b506103fb6103f63660046144df565b6112db565b604051610357919061460d565b34801561041457600080fd5b506104286104233660046144df565b611441565b604051610357919061464a565b34801561044157600080fd5b506102b16104503660046146bd565b61144c565b610380610463366004614773565b611505565b34801561047457600080fd5b506102b16104833660046147be565b61160f565b34801561049457600080fd5b506104a86104a336600461449e565b611b03565b6040516103579190614843565b3480156104c157600080fd5b506102b16104d03660046146bd565b611bac565b3480156104e157600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b039091168152602001610357565b34801561052857600080fd5b506103807f000000000000000000000000000000000000000000000000000000000000000081565b34801561055c57600080fd5b507f000000000000000000000000000000000000000000000000000000000000000061034b565b34801561058f57600080fd5b50610598611bc0565b60405161035791906148a7565b3480156105b157600080fd5b506105c56105c036600461449e565b611bf0565b60405161035791906148ca565b3480156105de57600080fd5b506103806105ed366004614956565b611cab565b3480156105fe57600080fd5b5061034b61060d3660046143f7565b611d7b565b34801561061e57600080fd5b5061063261062d3660046144df565b611dd1565b60405161035791906149a8565b34801561064b57600080fd5b5061038061065a3660046144df565b60009081526000805160206159298339815191526020526040902054600160b81b90046001600160481b031690565b34801561069557600080fd5b506102b1611ddc565b3480156106aa57600080fd5b506102b1611df0565b3480156106bf57600080fd5b506105047f000000000000000000000000000000000000000000000000000000000000000081565b3480156106f357600080fd5b5060408051306020808301919091524682840152825180830384018152606090920190925280519101205b6040516001600160e01b03199091168152602001610357565b34801561074357600080fd5b506103806107523660046149c6565b611e67565b34801561076357600080fd5b506105986107723660046144df565b611eff565b34801561078357600080fd5b506000546001600160a01b0316610504565b3480156107a157600080fd5b506107b56107b03660046149f6565b611f9d565b60408051928352602083019190915201610357565b3480156107d657600080fd5b506103806107e5366004614a73565b6120cc565b6103806107f8366004614a95565b6121a2565b34801561080957600080fd5b5061081d6108183660046144df565b6122fc565b6040516103579190614b0a565b34801561083657600080fd5b507f00000000000000000000000000000000000000000000000000000000000000003f610380565b34801561086a57600080fd5b5061071e7f000000000000000000000000000000000000000000000000000000000000000081565b34801561089e57600080fd5b506108b26108ad3660046144df565b612475565b6040516103579190614b36565b3480156108cb57600080fd5b506103806108da366004614b83565b6126ab565b3480156108eb57600080fd5b506105986127c6565b34801561090057600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610504565b34801561093357600080fd5b506103806127fd565b34801561094857600080fd5b506105047f000000000000000000000000000000000000000000000000000000000000000081565b34801561097c57600080fd5b506001546001600160a01b0316610504565b34801561099a57600080fd5b506105047f000000000000000000000000000000000000000000000000000000000000000081565b6103806109d0366004614bea565b61281a565b6102b16109e33660046144df565b6128d9565b3480156109f457600080fd5b506102b1610a033660046143f7565b6129d7565b348015610a1457600080fd5b506103ce610a233660046144df565b612a48565b610a306127c6565b81604051602001610a42929190614c27565b60408051601f198184030181529082905262461bcd60e51b8252610a68916004016148a7565b60405180910390fd5b604080516002808252818301909252606091600091906020820181803683370190505090506000610aa3601085614c90565b610aae906030614cb2565b90506000610abd601086614ccb565b610ac8906030614cb2565b905060398260ff161115610ae457610ae1600783614cb2565b91505b60398160ff161115610afe57610afb600782614cb2565b90505b8160f81b83600081518110610b1557610b15614ced565b60200101906001600160f81b031916908160001a9053508060f81b83600181518110610b4357610b43614ced565b60200101906001600160f81b031916908160001a90535091949350505050565b6001600160a01b03811660009081527ff595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e185602052604081205460ff165b92915050565b600080610bd37f00000000000000000000000000000000000000000000000000000000000000006003614d03565b610bfd907f0000000000000000000000000000000000000000000000000000000000000000614d1a565b9050808362ffffff161080610c3f575080610c3d62ffffff85167f0000000000000000000000000000000000000000000000000000000000000000614d1a565b105b15610c5657610c4e8185614d03565b915050610b9f565b610c8562ffffff84167f0000000000000000000000000000000000000000000000000000000000000000614d1a565b610c4e9085614d03565b5092915050565b6000610cf86000805160206159098339815191525b336000908152600291909101602090815260409182902054825180840190935260158352743ab730baba3437b934bd32b2103932b837b93a32b960591b9183019190915260ff1690612b6a565b60005b82811015611033576001610d32858584818110610d1a57610d1a614ced565b9050602002810190610d2c9190614d2d565b35612b7c565b6003811115610d4357610d43614620565b14610e28577f4df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f848483818110610d7b57610d7b614ced565b9050602002810190610d8d9190614d2d565b6040516353e8875160e11b815290359073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea290610dc8906001906004016149a8565b600060405180830381865af4158015610de5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e0d9190810190614d9c565b604051610e1b929190614dd0565b60405180910390a161102b565b42848483818110610e3b57610e3b614ced565b9050602002810190610e4d9190614d2d565b610e5e906040810190602001614de9565b63ffffffff161180610ea85750838382818110610e7d57610e7d614ced565b9050602002810190610e8f9190614d2d565b610ea0906040810190602001614de9565b63ffffffff16155b80610ee45750838382818110610ec057610ec0614ced565b9050602002810190610ed29190614d2d565b610ee0906060810190614e04565b1590505b15610f62577f4df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f848483818110610f1c57610f1c614ced565b9050602002810190610f2e9190614d2d565b35610f376127c6565b604051602001610f479190614e4a565b60408051601f1981840301815290829052610e1b9291614dd0565b61101e848483818110610f7757610f77614ced565b9050602002810190610f899190614d2d565b35858584818110610f9c57610f9c614ced565b9050602002810190610fae9190614d2d565b610fbf906040810190602001614de9565b868685818110610fd157610fd1614ced565b9050602002810190610fe39190614d2d565b60400135878786818110610ff957610ff9614ced565b905060200281019061100b9190614d2d565b611019906060810190614e04565b612bfd565b6110289083614d1a565b91505b600101610cfb565b508015610b9f57610b9f3382612ddc565b6040805160a08101825260008082526020820181905291810182905260608082019290925260808101919091528160038061107e83612b7c565b600381111561108f5761108f614620565b1461111e576040516353e8875160e11b81526111199073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b600060405180830381865af41580156110ec573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111149190810190614d9c565b610a28565b6112d4565b8361116761112b82612e12565b546040805180820190915260118152703737ba103a3432903932b8bab2b9ba32b960791b60208201526001600160a01b03909116331490612b6a565b61117085612e12565b6040805160a0810182526004830180546001600160a01b0381168352600160a01b81046001600160401b03166020840152600160e01b900463ffffffff169282019290925260058301546060820152600690920180546080840191906111d590614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461120190614e81565b801561124e5780601f106112235761010080835404028352916020019161124e565b820191906000526020600020905b81548152906001019060200180831161123157829003601f168201915b505050505081525050935061126e60008051602061590983398151915290565b6000868152600191820160205260408120818155918290829061129390830182614227565b506000600282018190556003909101805468ffffffffffffffffff191690556004830181815560058401829055906112ce6006850182614227565b50505050505b5050919050565b61131f6040805160c081018252600080825260208083018290528284018290526060808401526080830182905283518085019094528184528301529060a082015290565b61132882612e12565b6040805160c08101825282546001600160a01b0381168252600160a01b810462ffffff166020830152600160b81b90046001600160481b03169181019190915260018201805491929160608401919061138090614e81565b80601f01602080910402602001604051908101604052809291908181526020018280546113ac90614e81565b80156113f95780601f106113ce576101008083540402835291602001916113f9565b820191906000526020600020905b8154815290600101906020018083116113dc57829003601f168201915b5050509183525050600282015460208083019190915260408051808201825260039094015460ff8116855261010090046001600160401b031691840191909152015292915050565b6000610b9f82612e30565b611454612f48565b60005b81518110156114ca57600082828151811061147457611474614ced565b60200260200101519050600061149560008051602061590983398151915290565b6001600160a01b0392909216600090815260029092016020526040909120805460ff1916911515919091179055600101611457565b507f646436560d9757cb3c0f01da0f62642c6040b00c9a80685f94ef1a7725cad5f1816040516114fa9190614eb5565b60405180910390a150565b60006115113a846120cc565b61154a81345b1015604051806040016040528060138152602001721a5b9cdd59999a58da595b9d081c995dd85c99606a1b815250612b6a565b61158861155882600a614d03565b3411156040518060400160405280600f81526020016e1d1bdbc81b5d58da081c995dd85c99608a1b815250612b6a565b826115be61159582612f75565b6040518060400160405280600b81526020016a696e76616c696420534c4160a81b815250612b6a565b6115ca85856000613002565b92507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168334866040516115ff93929190614f1a565b60405180910390a1505092915050565b6000546001600160a01b0316606081611662576060838060200190518101906116389190614f61565b9093509050611646836130d6565b8080602001905181019061165a9190614fb1565b9150506116bc565b6116a5826001600160a01b0316336001600160a01b0316146040518060400160405280600d81526020016c3737ba103a34329037bbb732b960991b815250612b6a565b828060200190518101906116b99190614fb1565b90505b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe541580159061172d57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe547f00000000000000000000000000000000000000000000000000000000000000003f145b15611763576117636040518060400160405280601081526020016f185b1c9958591e481d5c19dc9859195960821b815250610a28565b7f00000000000000000000000000000000000000000000000000000000000000003f7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe55604080518082019091526012815271696e6578697374656e7420666163746f727960701b6020820152611807907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b151590612b6a565b6118da630db7c58b60e41b6001600160e01b0319167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663adb7c3f76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e919061504a565b6001600160e01b0319161460405180604001604052806013815260200172756e636f6d706c69616e7420666163746f727960681b815250612b6a565b611a61306001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166346d1d21a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611945573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119699190615074565b6001600160a01b0316148015611a3157507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637b1039996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a269190615074565b6001600160a01b0316145b60405180604001604052806012815260200171646973636f7264616e7420666163746f727960701b815250612b6a565b611a6a816130ef565b7f00000000000000000000000000000000000000000000000000000000000000003f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03167fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f6611ae9611bc0565b604051611af691906148a7565b60405180910390a4505050565b6040516251ca3160e21b815260609073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063014728c490611b60907f00000000000000000000000000000000000000000000000000000000000000009087908790600401615091565b600060405180830381865af4158015611b7d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ba591908101906150db565b9392505050565b611bb4612f48565b611bbd816130ef565b50565b6060611beb7f0000000000000000000000000000000000000000000000000000000000000000613195565b905090565b6060816001600160401b03811115611c0a57611c0a614658565b604051908082528060200260200182016040528015611c33578160200160208202803683370190505b50905060005b82811015610c8f57611c62848483818110611c5657611c56614ced565b90506020020135612b7c565b828281518110611c7457611c74614ced565b60200260200101906003811115611c8d57611c8d614620565b90816003811115611ca057611ca0614620565b905250600101611c39565b6000611cc4600080516020615909833981519152610cab565b84600180611cd183612b7c565b6003811115611ce257611ce2614620565b14611d27576040516353e8875160e11b8152611d229073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b611d71565b604080518082019091526016815275726573756c742063616e6e6f7420626520656d70747960501b6020820152611d619085151590612b6a565b611d6e8742888888613239565b92505b5050949350505050565b60007f00000000000000000000000000000000000000000000000000000000000000008015610b9f5750816001600160a01b0316611dc16000546001600160a01b031690565b6001600160a01b03161492915050565b6000610b9f82612b7c565b611de4612f48565b611dee60006130d6565b565b60015433906001600160a01b03168114611e5e5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610a68565b611bbd816130d6565b6000602061ffff831615611e8557611e80600184615196565b611e88565b60005b611e9291906151b1565b611e9d9060046151d2565b611ecb9061ffff167f0000000000000000000000000000000000000000000000000000000000000000614d03565b611ef5907f0000000000000000000000000000000000000000000000000000000000000000614d1a565b611ba59084614d03565b6060611f0a8261325d565b6002018054611f1890614e81565b80601f0160208091040260200160405190810160405280929190818152602001828054611f4490614e81565b8015611f915780601f10611f6657610100808354040283529160200191611f91565b820191906000526020600020905b815481529060010190602001808311611f7457829003601f168201915b50505050509050919050565b60008060005b878110156120c0576001611fc28a8a84818110611c5657611c56614ced565b6003811115611fd357611fd3614620565b036120b8576000611ffb8a8a84818110611fef57611fef614ced565b90506020020135612e12565b805490915061201a90600160b81b90046001600160481b031685614d1a565b8154909450600160a01b900462ffffff161561205a578054612049908790600160a01b900462ffffff16610ba5565b6120539084614d1a565b925061208a565b600281015415612072576120498682600201546120cc565b61207d866000611e67565b6120879084614d1a565b92505b846120978260030161327e565b6001600160401b03166120aa9190614d03565b6120b49084614d1a565b9250505b600101611fa3565b50965096945050505050565b604051633b5bc50360e11b81526004810182905260009081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906376b78a0690602401602060405180830381865afa158015612136573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061215a91906151ed565b905061219060008261ffff16116040518060400160405280600b81526020016a1a5b9d985b1a590814905160aa1b815250612b6a565b61219a8482611e67565b949350505050565b6000338261225c823b1580159061221d57506040516323d0872b60e11b81523060048201526001600160a01b038416906347a10e56906024015b602060405180830381865afa1580156121f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221d919061520a565b801561222e575060008262ffffff16115b6040518060400160405280601081526020016f696e76616c69642063616c6c6261636b60801b815250612b6a565b6122673a5b85610ba5565b6122718134611517565b61227f61155882600a614d03565b8561228c61159582612f75565b61229860008888613002565b945088886122a587612e12565b600101916122b491908361527c565b507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168534896040516122e893929190614f1a565b60405180910390a150505050949350505050565b604080518082019091526000815260606020820152600061231c83612e30565b905073a57b9dd8420631248c3dfb535f4fc9f7e2f02b4b63a62b8462826123428661325d565b6002016040518363ffffffff1660e01b815260040161236292919061533c565b600060405180830381865af49250505080156123a057506040513d6000823e601f3d908101601f1916820160405261239d91908101906153db565b60015b611ba5576123ac615474565b806308c379a00361240857506123c0615490565b806123cb575061240a565b604080518082019091528060008152602001826040516020016123ee9190615519565b60408051601f198184030181529190529052949350505050565b505b3d808015612434576040519150601f19603f3d011682016040523d82523d6000602084013e612439565b606091505b506040805180820190915280600081526020016040518060600160405280602181526020016158e8602191399052949350505050565b50919050565b61247d614261565b600082815260008051602061592983398151915260205260409081902081516101008101835281546001600160a01b038116938201938452600160a01b810462ffffff166060830152600160b81b90046001600160481b03166080820152600182018054919384929091849160a0850191906124f890614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461252490614e81565b80156125715780601f1061254657610100808354040283529160200191612571565b820191906000526020600020905b81548152906001019060200180831161255457829003601f168201915b5050509183525050600282015460208083019190915260408051808201825260039094015460ff8116855261010090046001600160401b039081168584015292810193909352928452815160a0810183526004860180546001600160a01b0381168352600160a01b810490931682860152600160e01b90920463ffffffff16928101929092526005850154606083015260068501805494909301939192909160808401919061261f90614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461264b90614e81565b80156126985780601f1061266d57610100808354040283529160200191612698565b820191906000526020600020905b81548152906001019060200180831161267b57829003601f168201915b5050509190925250505090525092915050565b60006126c4600080516020615909833981519152610cab565b856001806126d183612b7c565b60038111156126e2576126e2614620565b14612727576040516353e8875160e11b81526127229073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b6127bb565b61277160008863ffffffff161180156127465750428863ffffffff1611155b6040518060400160405280600d81526020016c06261642074696d657374616d7609c1b815250612b6a565b604080518082019091526016815275726573756c742063616e6e6f7420626520656d70747960501b60208201526127ab9085151590612b6a565b6127b88888888888613239565b92505b505095945050505050565b60408051808201909152601c81527f5769746e65744f7261636c65547275737461626c6544656661756c7400000000602082015290565b600060008051602061590983398151915254611beb906001614d1a565b60003382612858823b1580159061221d57506040516323d0872b60e11b81523060048201526001600160a01b038416906347a10e56906024016121dc565b6128613a612261565b61286b8134611517565b61287961155882600a614d03565b8561288661159582612f75565b612891888888613002565b94507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168534896040516128c693929190614f1a565b60405180910390a1505050509392505050565b806001806128e683612b7c565b60038111156128f7576128f7614620565b1461293c576040516353e8875160e11b81526129379073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b505050565b600061294784612e12565b9050348154829060179061296c908490600160b81b90046001600160481b0316615552565b82546101009290920a6001600160481b03818102199093169183160217909155825460408051888152600160b81b90920490921660208201527fdcced240139c3504c690fc16a776a5a4da3d5d1c139539e75037554ddc21e55b92500160405180910390a150505050565b6129df612f48565b600180546001600160a01b0383166001600160a01b03199091168117909155612a106000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6040805160a0810182526000808252602082018190529181018290526060808201929092526080810191909152612a7e8261325d565b6040805160a08101825282546001600160a01b0381168252600160a01b81046001600160401b03166020830152600160e01b900463ffffffff169181019190915260018201546060820152600282018054919291608084019190612ae190614e81565b80601f0160208091040260200160405190810160405280929190818152602001828054612b0d90614e81565b8015612b5a5780601f10612b2f57610100808354040283529160200191612b5a565b820191906000526020600020905b815481529060010190602001808311612b3d57829003601f168201915b5050505050815250509050919050565b81612b7857612b7881610a28565b5050565b6000818152600080516020615929833981519152602052604081206004810154600160e01b900463ffffffff1615612bdb576004810154600160a01b90046001600160401b03164310612bd25750600392915050565b50600292915050565b80546001600160a01b031615612bf45750600192915050565b50600092915050565b600080612c0987612e12565b80546001600160b81b038116808355600160b81b9091046001600160481b03169350909150600160a01b900462ffffff1615612d5557805460009081908190612c78908b9063ffffffff8c16908b908b908b906001600160a01b03811690600160a01b900462ffffff166132ae565b9250925092508115612cc857604080518b81523a602082015280820185905290517f37fc320f2d5c58a36c657d3b047384d42550bcc0d9781d13a7d97f8a97c2370c9181900360600190a1612d32565b7f794f0625cb473a6fc2bbc46c87577b8e719f074c42f7fe02abdf08e7435b1d8d8a88883a876000875111612d15576040518060600160405280602981526020016158bf60299139612d17565b865b604051612d2996959493929190615572565b60405180910390a15b612d4d8a8a8a60405180602001604052806000815250613644565b505050612dd2565b7f1fd7bc07c18ac1c4f6d3111c704cd1b4c29b9f7980b7c5a9a2fddeef29d6c277873a6040805192835260208301919091520160405180910390a1612dd287878787878080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061364492505050565b5095945050505050565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015612937573d6000803e3d6000fd5b60009081526000805160206159298339815191526020526040902090565b600080612e3c83612b7c565b90506003816003811115612e5257612e52614620565b03612f045760008381526000805160206159298339815191526020526040812060060180549091908290612e8590614e81565b90501115612efa578054601b60fb1b908290600090612ea390614e81565b8110612eb157612eb1614ced565b815460011615612ed05790600052602060002090602091828204019190065b9054901a600160f81b026001600160f81b03191614612ef057600261219a565b6003949350505050565b5060059392505050565b6001816003811115612f1857612f18614620565b03612f265750600192915050565b6002816003811115612f3a57612f3a614620565b03612bf45750600492915050565b6000546001600160a01b03163314611dee5760405163118cdaa760e01b8152336004820152602401610a68565b600080612f8860408401602085016155cf565b6001600160401b0316118015612fad57506000612fa860208401846155ec565b60ff16115b8015612fc95750607f612fc360208401846155ec565b60ff1611155b8015610b9f57506404a817c800612fe660408401602085016155cf565b612ff1906064615609565b6001600160401b0316101592915050565b6000600080516020615909833981519152805460009061302190615634565b91829055509050600061303382612e12565b805460408051808201909152600e81526d185b1c9958591e481c1bdcdd195960921b6020820152919250613073916001600160a01b039091161590612b6a565b8054346001600160481b0316600160b81b026001600160b81b03199091163362ffffff60a01b191617600160a01b62ffffff861602176001600160b81b03161781556002810185905583600382016130cb828261564d565b905050509392505050565b600180546001600160a01b0319169055611bbd81613711565b60005b815181101561316557600082828151811061310f5761310f614ced565b60200260200101519050600161313060008051602061590983398151915290565b6001600160a01b0392909216600090815260029092016020526040909120805460ff19169115159190911790556001016130f2565b507f4d570ee36dec878006609360d34ac8d6a0b68d521871ae15a407b6340877ca01816040516114fa9190614eb5565b606060006131a283613761565b6001600160401b038111156131b9576131b9614658565b6040519080825280601f01601f1916602001820160405280156131e3576020820181803683370190505b50905060005b8151811015610c8f5783816020811061320457613204614ced565b1a60f81b82828151811061321a5761321a614ced565b60200101906001600160f81b031916908160001a9053506001016131e9565b60006132488686868686612bfd565b90506132543382612ddc565b95945050505050565b60009081526000805160206159298339815191526020526040902060040190565b80546000906132919060ff166003614cb2565b8254610b9f9160ff169061010090046001600160401b0316615609565b60008060605a9250601b60fb1b87876000816132cc576132cc614ced565b9050013560f81c60f81b6001600160f81b0319160361351c57600061332e61332989898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061379f92505050565b6137c4565b905060028151101561345557856001600160a01b03166363febc9c868d8d8d4360006040518060c00160405280604051806040016040528060405180602001604052806000815250815260200160008152508152602001600060ff168152602001600060ff168152602001600060ff16815260200160006001600160401b0316815260200160006001600160401b03168152506040518863ffffffff1660e01b81526004016133e29695949392919061571e565b600060405180830381600088803b1580156133fc57600080fd5b5087f19350505050801561340e575060015b61344c5761341a615474565b806308c379a003613440575061342e615490565b806134395750613442565b9150613516565b505b3d6000803e3d6000fd5b60019250613516565b856001600160a01b03166363febc9c868d8d8d4361348c8860008151811061347f5761347f614ced565b6020026020010151613974565b60fe81111561349d5761349d614620565b886000815181106134b0576134b0614ced565b60200260200101516040518863ffffffff1660e01b81526004016134d99695949392919061571e565b600060405180830381600088803b1580156134f357600080fd5b5087f193505050508015613505575060015b6135115761341a615474565b600192505b5061362a565b846001600160a01b031663bcc6307b858c8c8c4361356f8e8e8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061379f92505050565b6040518763ffffffff1660e01b815260040161358f95949392919061576b565b600060405180830381600088803b1580156135a957600080fd5b5087f1935050505080156135bb575060015b613625576135c7615474565b806308c379a0036135ed57506135db615490565b806135e657506135ef565b905061362a565b505b3d808015613619576040519150601f19603f3d011682016040523d82523d6000602084013e61361e565b606091505b505061362a565b600191505b5a613635908461579f565b92509750975097945050505050565b6040518060a00160405280336001600160a01b03168152602001436001600160401b031681526020018463ffffffff1681526020018381526020018281525061368c85612e12565b81516004820180546020850151604086015163ffffffff16600160e01b026001600160e01b036001600160401b03909216600160a01b026001600160e01b03199093166001600160a01b0390951694909417919091171691909117815560608301516005830155608083015190916006019061370890826157b2565b50505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60005b602081101561379a5781816020811061377f5761377f614ced565b1a60f81b6001600160f81b0319161561379a57600101613764565b919050565b6137a76142e3565b6040805180820190915282815260006020820152611ba5816139d7565b60608160048060ff16826040015160ff161461380457604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b600061381885600001518660600151613af7565b9050613825816001615871565b6001600160401b03166001600160401b0381111561384557613845614658565b60405190808252806020026020018201604052801561387e57816020015b61386b6142e3565b8152602001906001900390816138635790505b50935060005b816001600160401b03168110156139445761389e86613bbf565b95506138a986613be7565b8582815181106138bb576138bb614ced565b6020026020010181905250600460ff16866040015160ff16036139145760006138e3876137c4565b905080600182516138f4919061579f565b8151811061390457613904614ced565b602002602001015196505061393c565b600560ff16866040015160ff16036139315760006138e387613c7f565b61393a86613e69565b505b600101613884565b508484826001600160401b03168151811061396157613961614ced565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff16146139b457604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b6139c684600001518560600151613af7565b6001600160401b0316949350505050565b6139df6142e3565b8151518290600003613a04576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015613a8757613a248961402e565b955081613a3081615634565b6007600589901c169650601f881695509250506005198501613a7f576020890151613a5b8a86613af7565b9350808a60200151613a6d919061579f565b613a779084614d1a565b925050613a15565b506000613a15565b600760ff86161115613ab15760405163bd2ac87960e01b815260ff86166004820152602401610a68565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b600060188260ff161015613b0f575060ff8116610b9f565b8160ff16601803613b2d57613b238361402e565b60ff169050610b9f565b8160ff16601903613b4c57613b4183614090565b61ffff169050610b9f565b8160ff16601a03613b6d57613b60836140fc565b63ffffffff169050610b9f565b8160ff16601b03613b8857613b818361415b565b9050610b9f565b8160ff16601f03613ba157506001600160401b03610b9f565b604051636d785b1360e01b815260ff83166004820152602401610a68565b613bc76142e3565b81518051516020909101511015613be3578151610b9f906139d7565b5090565b613bef6142e3565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff1614613cbf57604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b6000613cd385600001518660600151613af7565b613cde906002615609565b9050613ceb816001615871565b6001600160401b03166001600160401b03811115613d0b57613d0b614658565b604051908082528060200260200182016040528015613d4457816020015b613d316142e3565b815260200190600190039081613d295790505b50935060005b816001600160401b031681101561394457613d6486613bbf565b9550613d6f86613be7565b858281518110613d8157613d81614ced565b6020908102919091010152613d97600282615891565b158015613dac5750604086015160ff16600314155b15613dda57604080870151905161800560e51b815260ff909116600482015260036024820152604401610a68565b604086015160ff1660041480613df75750604086015160ff166005145b15613e5657604086015160009060ff16600414613e1c57613e1787613c7f565b613e25565b613e25876137c4565b90508060018251613e36919061579f565b81518110613e4657613e46614ced565b6020026020010151965050613e61565b613e5f86613e69565b505b600101613d4a565b613e716142e3565b604082015160ff161580613e8c5750604082015160ff166001145b80613ec55750604082015160ff166007148015613eb157506019826060015160ff1610155b8015613ec55750601b826060015160ff1611155b15613ef857613ed3826141ba565b6001600160401b03168260000151602001818151613ef19190614d1a565b9052505090565b604082015160ff1660031480613f155750604082015160ff166002145b15613f59576000613f2e83600001518460600151613af7565b9050806001600160401b03168360000151602001818151613f4f9190614d1a565b905250613be39050565b604082015160ff1660041480613f765750604082015160ff166005145b15613f9f57613f8d82600001518360600151613af7565b6001600160401b031660808301525090565b604082015160ff166007141580613fd15750816060015160ff16601414158015613fd15750816060015160ff16601514155b15613be35760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b6064820152608401610a68565b6000816020015182600001515180821115614066576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b835160208501805180830160010151955090819061408382615634565b8152505050505050919050565b6000816020015160026140a39190614d1a565b825151808211156140d1576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516002818401810151965090916140ef8284614d1a565b9052509395945050505050565b60008160200151600461410f9190614d1a565b8251518082111561413d576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516004818401810151965090916140ef8284614d1a565b60008160200151600861416e9190614d1a565b8251518082111561419c576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516008818401810151965090916140ef8284614d1a565b60006018826060015160ff1610156141d457506000919050565b601c826060015160ff16101561420357601882606001516141f591906158a5565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff9091166004820152602401610a68565b50805461423390614e81565b6000825580601f10614243575050565b601f016020900490600052602060002090810190611bbd919061432a565b60405180604001604052806142b06040805160c081018252600080825260208083018290528284018290526060808401526080830182905283518085019094528184528301529060a082015290565b81526040805160a08101825260008082526020828101829052928201819052606080830191909152608082015291015290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b5b80821115613be3576000815560010161432b565b60005b8381101561435a578181015183820152602001614342565b50506000910152565b720dcdee840d2dae0d8cadacadce8cac8744060f606b1b815260008551614391816013850160208a0161433f565b8551908301906143a8816013840160208a0161433f565b85519101906143be81601384016020890161433f565b84519101906143d481601384016020880161433f565b016013019695505050505050565b6001600160a01b0381168114611bbd57600080fd5b60006020828403121561440957600080fd5b8135611ba5816143e2565b803562ffffff8116811461379a57600080fd5b6000806040838503121561443a57600080fd5b8235915061444a60208401614414565b90509250929050565b60008083601f84011261446557600080fd5b5081356001600160401b0381111561447c57600080fd5b6020830191508360208260051b850101111561449757600080fd5b9250929050565b600080602083850312156144b157600080fd5b82356001600160401b038111156144c757600080fd5b6144d385828601614453565b90969095509350505050565b6000602082840312156144f157600080fd5b5035919050565b6000815180845261451081602086016020860161433f565b601f01601f19169290920160200192915050565b60018060a01b0381511682526001600160401b03602082015116602083015263ffffffff6040820151166040830152606081015160608301526000608082015160a0608085015261219a60a08501826144f8565b602081526000611ba56020830184614524565b60018060a01b03815116825262ffffff60208201511660208301526001600160481b0360408201511660408301526000606082015160e060608501526145d460e08501826144f8565b90506080830151608085015260a083015160ff81511660a08601526001600160401b0360208201511660c0860152508091505092915050565b602081526000611ba5602083018461458b565b634e487b7160e01b600052602160045260246000fd5b6006811061464657614646614620565b9052565b60208101610b9f8284614636565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561469357614693614658565b6040525050565b60006001600160401b038211156146b3576146b3614658565b5060051b60200190565b600060208083850312156146d057600080fd5b82356001600160401b038111156146e657600080fd5b8301601f810185136146f757600080fd5b80356147028161469a565b60405161470f828261466e565b82815260059290921b830184019184810191508783111561472f57600080fd5b928401925b82841015614756578335614747816143e2565b82529284019290840190614734565b979650505050505050565b60006040828403121561246f57600080fd5b6000806060838503121561478657600080fd5b8235915061444a8460208501614761565b60006001600160401b038211156147b0576147b0614658565b50601f01601f191660200190565b6000602082840312156147d057600080fd5b81356001600160401b038111156147e657600080fd5b8201601f810184136147f757600080fd5b803561480281614797565b60405161480f828261466e565b82815286602084860101111561482457600080fd5b8260208501602083013760009281016020019290925250949350505050565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b8281101561489a57603f198886030184526148888583516144f8565b9450928501929085019060010161486c565b5092979650505050505050565b602081526000611ba560208301846144f8565b6004811061464657614646614620565b6020808252825182820181905260009190848201906040850190845b81811015614909576148f98385516148ba565b92840192918401916001016148e6565b50909695505050505050565b60008083601f84011261492757600080fd5b5081356001600160401b0381111561493e57600080fd5b60208301915083602082850101111561449757600080fd5b6000806000806060858703121561496c57600080fd5b843593506020850135925060408501356001600160401b0381111561499057600080fd5b61499c87828801614915565b95989497509550505050565b60208101610b9f82846148ba565b61ffff81168114611bbd57600080fd5b600080604083850312156149d957600080fd5b8235915060208301356149eb816149b6565b809150509250929050565b60008060008060008060808789031215614a0f57600080fd5b86356001600160401b0380821115614a2657600080fd5b614a328a838b01614453565b90985096506020890135915080821115614a4b57600080fd5b50614a5889828a01614915565b979a9699509760408101359660609091013595509350505050565b60008060408385031215614a8657600080fd5b50508035926020909101359150565b60008060008060808587031215614aab57600080fd5b84356001600160401b03811115614ac157600080fd5b614acd87828801614915565b9095509350614ae190508660208701614761565b9150614aef60608601614414565b905092959194509250565b60ff811061464657614646614620565b60208152614b1c602082018351614afa565b6000602083015160408084015261219a60608401826144f8565b602081526000825160406020840152614b52606084018261458b565b90506020840151601f198483030160408501526132548282614524565b803563ffffffff8116811461379a57600080fd5b600080600080600060808688031215614b9b57600080fd5b85359450614bab60208701614b6f565b93506040860135925060608601356001600160401b03811115614bcd57600080fd5b614bd988828901614915565b969995985093965092949392505050565b600080600060808486031215614bff57600080fd5b83359250614c108560208601614761565b9150614c1e60608501614414565b90509250925092565b60008351614c3981846020880161433f565b6101d160f51b9083019081528351614c5881600284016020880161433f565b01600201949350505050565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060ff831680614ca357614ca3614c64565b8060ff84160491505092915050565b60ff8181168382160190811115610b9f57610b9f614c7a565b600060ff831680614cde57614cde614c64565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b8082028115828204841417610b9f57610b9f614c7a565b80820180821115610b9f57610b9f614c7a565b60008235607e19833603018112614d4357600080fd5b9190910192915050565b600082601f830112614d5e57600080fd5b8151614d6981614797565b604051614d76828261466e565b828152856020848701011115614d8b57600080fd5b61325483602083016020880161433f565b600060208284031215614dae57600080fd5b81516001600160401b03811115614dc457600080fd5b61219a84828501614d4d565b82815260406020820152600061219a60408301846144f8565b600060208284031215614dfb57600080fd5b611ba582614b6f565b6000808335601e19843603018112614e1b57600080fd5b8301803591506001600160401b03821115614e3557600080fd5b60200191503681900382131561449757600080fd5b60008251614e5c81846020870161433f565b72696e76616c6964207265706f7274206461746160681b920191825250601301919050565b600181811c90821680614e9557607f821691505b60208210810361246f57634e487b7160e01b600052602260045260246000fd5b6020808252825182820181905260009190848201906040850190845b818110156149095783516001600160a01b031683529284019291840191600101614ed1565b60ff81168114611bbd57600080fd5b6001600160401b0381168114611bbd57600080fd5b83815260208101839052608081018235614f3381614ef6565b60ff1660408301526020830135614f4981614f05565b6001600160401b038116606084015250949350505050565b60008060408385031215614f7457600080fd5b8251614f7f816143e2565b60208401519092506001600160401b03811115614f9b57600080fd5b614fa785828601614d4d565b9150509250929050565b60006020808385031215614fc457600080fd5b82516001600160401b03811115614fda57600080fd5b8301601f81018513614feb57600080fd5b8051614ff68161469a565b604051615003828261466e565b82815260059290921b830184019184810191508783111561502357600080fd5b928401925b8284101561475657835161503b816143e2565b82529284019290840190615028565b60006020828403121561505c57600080fd5b81516001600160e01b031981168114611ba557600080fd5b60006020828403121561508657600080fd5b8151611ba5816143e2565b6001600160a01b0384168152604060208201819052810182905260006001600160fb1b038311156150c157600080fd5b8260051b8085606085013791909101606001949350505050565b600060208083850312156150ee57600080fd5b82516001600160401b038082111561510557600080fd5b818501915085601f83011261511957600080fd5b81516151248161469a565b604051615131828261466e565b82815260059290921b840185019185810191508883111561515157600080fd5b8585015b838110156151895780518581111561516d5760008081fd5b61517b8b89838a0101614d4d565b845250918601918601615155565b5098975050505050505050565b61ffff828116828216039080821115610c8f57610c8f614c7a565b600061ffff808416806151c6576151c6614c64565b92169190910492915050565b61ffff818116838216019080821115610c8f57610c8f614c7a565b6000602082840312156151ff57600080fd5b8151611ba5816149b6565b60006020828403121561521c57600080fd5b81518015158114611ba557600080fd5b601f821115612937576000816000526020600020601f850160051c810160208610156152555750805b601f850160051c820191505b8181101561527457828155600101615261565b505050505050565b6001600160401b0383111561529357615293614658565b6152a7836152a18354614e81565b8361522c565b6000601f8411600181146152db57600085156152c35750838201355b600019600387901b1c1916600186901b178355615335565b600083815260209020601f19861690835b8281101561530c57868501358255602094850194600190920191016152ec565b50868210156153295760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b6153468184614636565b60006020604060208401526000845461535e81614e81565b8060408701526060600180841660008114615380576001811461539c576153cc565b60ff19851660608a0152606084151560051b8a010195506153cc565b89600052602060002060005b858110156153c35781548b82018601529083019088016153a8565b8a016060019650505b50939998505050505050505050565b6000602082840312156153ed57600080fd5b81516001600160401b038082111561540457600080fd5b908301906040828603121561541857600080fd5b60405160408101818110838211171561543357615433614658565b604052825160ff811061544557600080fd5b815260208301518281111561545957600080fd5b61546587828601614d4d565b60208301525095945050505050565b600060033d111561548d5760046000803e5060005160e01c5b90565b600060443d101561549e5790565b6040516003193d81016004833e81513d6001600160401b0381602484011181841117156154cd57505050505090565b82850191508151818111156154e55750505050505090565b843d87010160208285010111156154ff5750505050505090565b61550e6020828601018761466e565b509095945050505050565b7002bb4ba3732ba22b93937b939a634b11d1607d1b81526000825161554581601185016020870161433f565b9190910160110192915050565b6001600160481b03818116838216019080821115610c8f57610c8f614c7a565b86815260a060208201528460a0820152848660c0830137600060c086830101526000601f19601f870116820185604084015284606084015260c08382030160808401526155c260c08201856144f8565b9998505050505050505050565b6000602082840312156155e157600080fd5b8135611ba581614f05565b6000602082840312156155fe57600080fd5b8135611ba581614ef6565b6001600160401b0381811683821602808216919082811461562c5761562c614c7a565b505092915050565b60006001820161564657615646614c7a565b5060010190565b813561565881614ef6565b60ff8116905081548160ff198216178355602084013561567781614f05565b68ffffffffffffffff008160081b16836001600160481b03198416171784555050505050565b6000815160c084528051604060c08601526156bc6101008601826144f8565b9050602082015160e086015260ff602085015116602086015260ff604085015116604086015260ff6060850151166060860152608084015191506001600160401b0380831660808701528060a08601511660a087015250809250505092915050565b8681526001600160401b03861660208201528460408201528360608201526157496080820184614afa565b60c060a0820152600061575f60c083018461569d565b98975050505050505050565b8581526001600160401b038516602082015283604082015282606082015260a06080820152600061475660a083018461569d565b81810381811115610b9f57610b9f614c7a565b81516001600160401b038111156157cb576157cb614658565b6157df816157d98454614e81565b8461522c565b602080601f83116001811461581457600084156157fc5750858301515b600019600386901b1c1916600185901b178555615274565b600085815260208120601f198616915b8281101561584357888601518255948401946001909101908401615824565b50858210156158615787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160401b03818116838216019080821115610c8f57610c8f614c7a565b6000826158a0576158a0614c64565b500690565b60ff8281168282160390811115610b9f57610b9f614c7a56fe5769746e65744f7261636c653a2063616c6c6261636b20657863656564656420676173206c696d69745769746e65744572726f72734c69623a20617373657274696f6e206661696c6564f595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e183f595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e184a2646970667358221220231c7a4228d1a9ad53fdce58161530dc9dc2c1b7ee5d7903e434ae0f96fd0b3364736f6c63430008190033000000000000000000000000000db36997af1f02209a6f995883b9b699900000000000000000000000000000000b61fe075f545fd37767f403916582759000000000000000000000000000000000000000000000000000000000000000000001322e302e31342d34386336646436000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c138000000000000000000000000000000000000000000000000000000000000fef90000000000000000000000000000000000000000000000000000000000010faa0000000000000000000000000000000000000000000000000000000000004e20

Deployed Bytecode

0x6080604052600436106102765760003560e01c80637b1039991161014f578063aeb2ffc1116100c1578063e30c39781161007a578063e30c397814610970578063e5a6b10f1461098e578063e900aa33146109c2578063ec5946db146109d5578063f2fde38b146109e8578063f61921b214610a08576102b3565b8063aeb2ffc114610892578063b207e730146108bf578063bff852fa146108df578063c45a0155146108f4578063c805dd0f14610927578063d5f394881461093c576102b3565b806393d5185c1161011357806393d5185c146107955780639cc56e67146107ca578063a3ff5b00146107ea578063a77fc1a4146107fd578063a9e954b91461082a578063adb7c3f71461085e576102b3565b80637b103999146106b35780637bbdb96e146106e75780637bd88218146107375780638d3d8b38146107575780638da5cb5b14610777576102b3565b80635001f3b5116101e85780636280bce8116101ac5780636280bce8146105d25780636b58960a146105f25780636f07abcc146106125780636fdaab7e1461063f578063715018a61461068957806379ba50971461069e576102b3565b80635001f3b5146104d557806352d1902d1461051c5780635479d9401461055057806354fd4d5014610583578063581f5094146105a5576102b3565b8063234fe6e31161023a578063234fe6e31461040857806328a78d9b146104355780633dc2b7a214610455578063439fab911461046857806345ea6c17146104885780634c9f72e3146104b5576102b3565b8063044ad7be1461032b57806305e742ef1461036057806306eb2c421461038e57806308b7e85e146103ae5780630aa4112a146103db576102b3565b366102b3576102b1604051806040016040528060158152602001741b9bc81d1c985b9cd9995c9cc81858d8d95c1d1959605a1b815250610a28565b005b3480156102bf57600080fd5b506102b16102d160003560f81c610a71565b6102e260ff60003560f01c16610a71565b6102f360ff60003560e81c16610a71565b61030460ff60003560e01c16610a71565b6040516020016103179493929190614363565b604051602081830303815290604052610a28565b34801561033757600080fd5b5061034b6103463660046143f7565b610b63565b60405190151581526020015b60405180910390f35b34801561036c57600080fd5b5061038061037b366004614427565b610ba5565b604051908152602001610357565b34801561039a57600080fd5b506103806103a936600461449e565b610c96565b3480156103ba57600080fd5b506103ce6103c93660046144df565b611044565b6040516103579190614578565b3480156103e757600080fd5b506103fb6103f63660046144df565b6112db565b604051610357919061460d565b34801561041457600080fd5b506104286104233660046144df565b611441565b604051610357919061464a565b34801561044157600080fd5b506102b16104503660046146bd565b61144c565b610380610463366004614773565b611505565b34801561047457600080fd5b506102b16104833660046147be565b61160f565b34801561049457600080fd5b506104a86104a336600461449e565b611b03565b6040516103579190614843565b3480156104c157600080fd5b506102b16104d03660046146bd565b611bac565b3480156104e157600080fd5b507f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78555b6040516001600160a01b039091168152602001610357565b34801561052857600080fd5b506103807f9969c6aff411c5e5f0807500693e8f819ce88529615cfa6cab569b24788a101881565b34801561055c57600080fd5b507f000000000000000000000000000000000000000000000000000000000000000161034b565b34801561058f57600080fd5b50610598611bc0565b60405161035791906148a7565b3480156105b157600080fd5b506105c56105c036600461449e565b611bf0565b60405161035791906148ca565b3480156105de57600080fd5b506103806105ed366004614956565b611cab565b3480156105fe57600080fd5b5061034b61060d3660046143f7565b611d7b565b34801561061e57600080fd5b5061063261062d3660046144df565b611dd1565b60405161035791906149a8565b34801561064b57600080fd5b5061038061065a3660046144df565b60009081526000805160206159298339815191526020526040902054600160b81b90046001600160481b031690565b34801561069557600080fd5b506102b1611ddc565b3480156106aa57600080fd5b506102b1611df0565b3480156106bf57600080fd5b506105047f000000000000000000000000000b61fe075f545fd37767f4039165827590000081565b3480156106f357600080fd5b5060408051306020808301919091524682840152825180830384018152606090920190925280519101205b6040516001600160e01b03199091168152602001610357565b34801561074357600080fd5b506103806107523660046149c6565b611e67565b34801561076357600080fd5b506105986107723660046144df565b611eff565b34801561078357600080fd5b506000546001600160a01b0316610504565b3480156107a157600080fd5b506107b56107b03660046149f6565b611f9d565b60408051928352602083019190915201610357565b3480156107d657600080fd5b506103806107e5366004614a73565b6120cc565b6103806107f8366004614a95565b6121a2565b34801561080957600080fd5b5061081d6108183660046144df565b6122fc565b6040516103579190614b0a565b34801561083657600080fd5b507f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78553f610380565b34801561086a57600080fd5b5061071e7fbaeca88b0000000000000000000000000000000000000000000000000000000081565b34801561089e57600080fd5b506108b26108ad3660046144df565b612475565b6040516103579190614b36565b3480156108cb57600080fd5b506103806108da366004614b83565b6126ab565b3480156108eb57600080fd5b506105986127c6565b34801561090057600080fd5b507f000000000000000000000000000db36997af1f02209a6f995883b9b699900000610504565b34801561093357600080fd5b506103806127fd565b34801561094857600080fd5b506105047f00000000000000000000000003232abe800d1638b30432feef300581de323a4e81565b34801561097c57600080fd5b506001546001600160a01b0316610504565b34801561099a57600080fd5b506105047f000000000000000000000000000000000000000000000000000000000000000081565b6103806109d0366004614bea565b61281a565b6102b16109e33660046144df565b6128d9565b3480156109f457600080fd5b506102b1610a033660046143f7565b6129d7565b348015610a1457600080fd5b506103ce610a233660046144df565b612a48565b610a306127c6565b81604051602001610a42929190614c27565b60408051601f198184030181529082905262461bcd60e51b8252610a68916004016148a7565b60405180910390fd5b604080516002808252818301909252606091600091906020820181803683370190505090506000610aa3601085614c90565b610aae906030614cb2565b90506000610abd601086614ccb565b610ac8906030614cb2565b905060398260ff161115610ae457610ae1600783614cb2565b91505b60398160ff161115610afe57610afb600782614cb2565b90505b8160f81b83600081518110610b1557610b15614ced565b60200101906001600160f81b031916908160001a9053508060f81b83600181518110610b4357610b43614ced565b60200101906001600160f81b031916908160001a90535091949350505050565b6001600160a01b03811660009081527ff595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e185602052604081205460ff165b92915050565b600080610bd37f0000000000000000000000000000000000000000000000000000000000004e206003614d03565b610bfd907f0000000000000000000000000000000000000000000000000000000000010faa614d1a565b9050808362ffffff161080610c3f575080610c3d62ffffff85167f000000000000000000000000000000000000000000000000000000000000fef9614d1a565b105b15610c5657610c4e8185614d03565b915050610b9f565b610c8562ffffff84167f000000000000000000000000000000000000000000000000000000000000fef9614d1a565b610c4e9085614d03565b5092915050565b6000610cf86000805160206159098339815191525b336000908152600291909101602090815260409182902054825180840190935260158352743ab730baba3437b934bd32b2103932b837b93a32b960591b9183019190915260ff1690612b6a565b60005b82811015611033576001610d32858584818110610d1a57610d1a614ced565b9050602002810190610d2c9190614d2d565b35612b7c565b6003811115610d4357610d43614620565b14610e28577f4df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f848483818110610d7b57610d7b614ced565b9050602002810190610d8d9190614d2d565b6040516353e8875160e11b815290359073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea290610dc8906001906004016149a8565b600060405180830381865af4158015610de5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e0d9190810190614d9c565b604051610e1b929190614dd0565b60405180910390a161102b565b42848483818110610e3b57610e3b614ced565b9050602002810190610e4d9190614d2d565b610e5e906040810190602001614de9565b63ffffffff161180610ea85750838382818110610e7d57610e7d614ced565b9050602002810190610e8f9190614d2d565b610ea0906040810190602001614de9565b63ffffffff16155b80610ee45750838382818110610ec057610ec0614ced565b9050602002810190610ed29190614d2d565b610ee0906060810190614e04565b1590505b15610f62577f4df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f848483818110610f1c57610f1c614ced565b9050602002810190610f2e9190614d2d565b35610f376127c6565b604051602001610f479190614e4a565b60408051601f1981840301815290829052610e1b9291614dd0565b61101e848483818110610f7757610f77614ced565b9050602002810190610f899190614d2d565b35858584818110610f9c57610f9c614ced565b9050602002810190610fae9190614d2d565b610fbf906040810190602001614de9565b868685818110610fd157610fd1614ced565b9050602002810190610fe39190614d2d565b60400135878786818110610ff957610ff9614ced565b905060200281019061100b9190614d2d565b611019906060810190614e04565b612bfd565b6110289083614d1a565b91505b600101610cfb565b508015610b9f57610b9f3382612ddc565b6040805160a08101825260008082526020820181905291810182905260608082019290925260808101919091528160038061107e83612b7c565b600381111561108f5761108f614620565b1461111e576040516353e8875160e11b81526111199073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b600060405180830381865af41580156110ec573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111149190810190614d9c565b610a28565b6112d4565b8361116761112b82612e12565b546040805180820190915260118152703737ba103a3432903932b8bab2b9ba32b960791b60208201526001600160a01b03909116331490612b6a565b61117085612e12565b6040805160a0810182526004830180546001600160a01b0381168352600160a01b81046001600160401b03166020840152600160e01b900463ffffffff169282019290925260058301546060820152600690920180546080840191906111d590614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461120190614e81565b801561124e5780601f106112235761010080835404028352916020019161124e565b820191906000526020600020905b81548152906001019060200180831161123157829003601f168201915b505050505081525050935061126e60008051602061590983398151915290565b6000868152600191820160205260408120818155918290829061129390830182614227565b506000600282018190556003909101805468ffffffffffffffffff191690556004830181815560058401829055906112ce6006850182614227565b50505050505b5050919050565b61131f6040805160c081018252600080825260208083018290528284018290526060808401526080830182905283518085019094528184528301529060a082015290565b61132882612e12565b6040805160c08101825282546001600160a01b0381168252600160a01b810462ffffff166020830152600160b81b90046001600160481b03169181019190915260018201805491929160608401919061138090614e81565b80601f01602080910402602001604051908101604052809291908181526020018280546113ac90614e81565b80156113f95780601f106113ce576101008083540402835291602001916113f9565b820191906000526020600020905b8154815290600101906020018083116113dc57829003601f168201915b5050509183525050600282015460208083019190915260408051808201825260039094015460ff8116855261010090046001600160401b031691840191909152015292915050565b6000610b9f82612e30565b611454612f48565b60005b81518110156114ca57600082828151811061147457611474614ced565b60200260200101519050600061149560008051602061590983398151915290565b6001600160a01b0392909216600090815260029092016020526040909120805460ff1916911515919091179055600101611457565b507f646436560d9757cb3c0f01da0f62642c6040b00c9a80685f94ef1a7725cad5f1816040516114fa9190614eb5565b60405180910390a150565b60006115113a846120cc565b61154a81345b1015604051806040016040528060138152602001721a5b9cdd59999a58da595b9d081c995dd85c99606a1b815250612b6a565b61158861155882600a614d03565b3411156040518060400160405280600f81526020016e1d1bdbc81b5d58da081c995dd85c99608a1b815250612b6a565b826115be61159582612f75565b6040518060400160405280600b81526020016a696e76616c696420534c4160a81b815250612b6a565b6115ca85856000613002565b92507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168334866040516115ff93929190614f1a565b60405180910390a1505092915050565b6000546001600160a01b0316606081611662576060838060200190518101906116389190614f61565b9093509050611646836130d6565b8080602001905181019061165a9190614fb1565b9150506116bc565b6116a5826001600160a01b0316336001600160a01b0316146040518060400160405280600d81526020016c3737ba103a34329037bbb732b960991b815250612b6a565b828060200190518101906116b99190614fb1565b90505b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe541580159061172d57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe547f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78553f145b15611763576117636040518060400160405280601081526020016f185b1c9958591e481d5c19dc9859195960821b815250610a28565b7f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78553f7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbe55604080518082019091526012815271696e6578697374656e7420666163746f727960701b6020820152611807907f000000000000000000000000000db36997af1f02209a6f995883b9b6999000006001600160a01b03163b151590612b6a565b6118da630db7c58b60e41b6001600160e01b0319167f000000000000000000000000000db36997af1f02209a6f995883b9b6999000006001600160a01b031663adb7c3f76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e919061504a565b6001600160e01b0319161460405180604001604052806013815260200172756e636f6d706c69616e7420666163746f727960681b815250612b6a565b611a61306001600160a01b03167f000000000000000000000000000db36997af1f02209a6f995883b9b6999000006001600160a01b03166346d1d21a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611945573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119699190615074565b6001600160a01b0316148015611a3157507f000000000000000000000000000b61fe075f545fd37767f403916582759000006001600160a01b03167f000000000000000000000000000db36997af1f02209a6f995883b9b6999000006001600160a01b0316637b1039996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a269190615074565b6001600160a01b0316145b60405180604001604052806012815260200171646973636f7264616e7420666163746f727960701b815250612b6a565b611a6a816130ef565b7f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78553f7f000000000000000000000000ce68f9d657c5b8931a1baceb77dc0e71499f78556001600160a01b0316836001600160a01b03167fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f6611ae9611bc0565b604051611af691906148a7565b60405180910390a4505050565b6040516251ca3160e21b815260609073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063014728c490611b60907f000000000000000000000000000b61fe075f545fd37767f403916582759000009087908790600401615091565b600060405180830381865af4158015611b7d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ba591908101906150db565b9392505050565b611bb4612f48565b611bbd816130ef565b50565b6060611beb7f322e302e31342d34386336646436000000000000000000000000000000000000613195565b905090565b6060816001600160401b03811115611c0a57611c0a614658565b604051908082528060200260200182016040528015611c33578160200160208202803683370190505b50905060005b82811015610c8f57611c62848483818110611c5657611c56614ced565b90506020020135612b7c565b828281518110611c7457611c74614ced565b60200260200101906003811115611c8d57611c8d614620565b90816003811115611ca057611ca0614620565b905250600101611c39565b6000611cc4600080516020615909833981519152610cab565b84600180611cd183612b7c565b6003811115611ce257611ce2614620565b14611d27576040516353e8875160e11b8152611d229073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b611d71565b604080518082019091526016815275726573756c742063616e6e6f7420626520656d70747960501b6020820152611d619085151590612b6a565b611d6e8742888888613239565b92505b5050949350505050565b60007f00000000000000000000000000000000000000000000000000000000000000018015610b9f5750816001600160a01b0316611dc16000546001600160a01b031690565b6001600160a01b03161492915050565b6000610b9f82612b7c565b611de4612f48565b611dee60006130d6565b565b60015433906001600160a01b03168114611e5e5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610a68565b611bbd816130d6565b6000602061ffff831615611e8557611e80600184615196565b611e88565b60005b611e9291906151b1565b611e9d9060046151d2565b611ecb9061ffff167f0000000000000000000000000000000000000000000000000000000000004e20614d03565b611ef5907f000000000000000000000000000000000000000000000000000000000001c138614d1a565b611ba59084614d03565b6060611f0a8261325d565b6002018054611f1890614e81565b80601f0160208091040260200160405190810160405280929190818152602001828054611f4490614e81565b8015611f915780601f10611f6657610100808354040283529160200191611f91565b820191906000526020600020905b815481529060010190602001808311611f7457829003601f168201915b50505050509050919050565b60008060005b878110156120c0576001611fc28a8a84818110611c5657611c56614ced565b6003811115611fd357611fd3614620565b036120b8576000611ffb8a8a84818110611fef57611fef614ced565b90506020020135612e12565b805490915061201a90600160b81b90046001600160481b031685614d1a565b8154909450600160a01b900462ffffff161561205a578054612049908790600160a01b900462ffffff16610ba5565b6120539084614d1a565b925061208a565b600281015415612072576120498682600201546120cc565b61207d866000611e67565b6120879084614d1a565b92505b846120978260030161327e565b6001600160401b03166120aa9190614d03565b6120b49084614d1a565b9250505b600101611fa3565b50965096945050505050565b604051633b5bc50360e11b81526004810182905260009081906001600160a01b037f000000000000000000000000000b61fe075f545fd37767f4039165827590000016906376b78a0690602401602060405180830381865afa158015612136573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061215a91906151ed565b905061219060008261ffff16116040518060400160405280600b81526020016a1a5b9d985b1a590814905160aa1b815250612b6a565b61219a8482611e67565b949350505050565b6000338261225c823b1580159061221d57506040516323d0872b60e11b81523060048201526001600160a01b038416906347a10e56906024015b602060405180830381865afa1580156121f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221d919061520a565b801561222e575060008262ffffff16115b6040518060400160405280601081526020016f696e76616c69642063616c6c6261636b60801b815250612b6a565b6122673a5b85610ba5565b6122718134611517565b61227f61155882600a614d03565b8561228c61159582612f75565b61229860008888613002565b945088886122a587612e12565b600101916122b491908361527c565b507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168534896040516122e893929190614f1a565b60405180910390a150505050949350505050565b604080518082019091526000815260606020820152600061231c83612e30565b905073a57b9dd8420631248c3dfb535f4fc9f7e2f02b4b63a62b8462826123428661325d565b6002016040518363ffffffff1660e01b815260040161236292919061533c565b600060405180830381865af49250505080156123a057506040513d6000823e601f3d908101601f1916820160405261239d91908101906153db565b60015b611ba5576123ac615474565b806308c379a00361240857506123c0615490565b806123cb575061240a565b604080518082019091528060008152602001826040516020016123ee9190615519565b60408051601f198184030181529190529052949350505050565b505b3d808015612434576040519150601f19603f3d011682016040523d82523d6000602084013e612439565b606091505b506040805180820190915280600081526020016040518060600160405280602181526020016158e8602191399052949350505050565b50919050565b61247d614261565b600082815260008051602061592983398151915260205260409081902081516101008101835281546001600160a01b038116938201938452600160a01b810462ffffff166060830152600160b81b90046001600160481b03166080820152600182018054919384929091849160a0850191906124f890614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461252490614e81565b80156125715780601f1061254657610100808354040283529160200191612571565b820191906000526020600020905b81548152906001019060200180831161255457829003601f168201915b5050509183525050600282015460208083019190915260408051808201825260039094015460ff8116855261010090046001600160401b039081168584015292810193909352928452815160a0810183526004860180546001600160a01b0381168352600160a01b810490931682860152600160e01b90920463ffffffff16928101929092526005850154606083015260068501805494909301939192909160808401919061261f90614e81565b80601f016020809104026020016040519081016040528092919081815260200182805461264b90614e81565b80156126985780601f1061266d57610100808354040283529160200191612698565b820191906000526020600020905b81548152906001019060200180831161267b57829003601f168201915b5050509190925250505090525092915050565b60006126c4600080516020615909833981519152610cab565b856001806126d183612b7c565b60038111156126e2576126e2614620565b14612727576040516353e8875160e11b81526127229073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b6127bb565b61277160008863ffffffff161180156127465750428863ffffffff1611155b6040518060400160405280600d81526020016c06261642074696d657374616d7609c1b815250612b6a565b604080518082019091526016815275726573756c742063616e6e6f7420626520656d70747960501b60208201526127ab9085151590612b6a565b6127b88888888888613239565b92505b505095945050505050565b60408051808201909152601c81527f5769746e65744f7261636c65547275737461626c6544656661756c7400000000602082015290565b600060008051602061590983398151915254611beb906001614d1a565b60003382612858823b1580159061221d57506040516323d0872b60e11b81523060048201526001600160a01b038416906347a10e56906024016121dc565b6128613a612261565b61286b8134611517565b61287961155882600a614d03565b8561288661159582612f75565b612891888888613002565b94507ffb94adf28ab7e538d2691d90927f622cbc1100eae6afec58052efdee6c98a6168534896040516128c693929190614f1a565b60405180910390a1505050509392505050565b806001806128e683612b7c565b60038111156128f7576128f7614620565b1461293c576040516353e8875160e11b81526129379073561a6c8f9c9d6e7ebaecd4963a8f27ae135686769063a7d10ea2906110cf9085906004016149a8565b505050565b600061294784612e12565b9050348154829060179061296c908490600160b81b90046001600160481b0316615552565b82546101009290920a6001600160481b03818102199093169183160217909155825460408051888152600160b81b90920490921660208201527fdcced240139c3504c690fc16a776a5a4da3d5d1c139539e75037554ddc21e55b92500160405180910390a150505050565b6129df612f48565b600180546001600160a01b0383166001600160a01b03199091168117909155612a106000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6040805160a0810182526000808252602082018190529181018290526060808201929092526080810191909152612a7e8261325d565b6040805160a08101825282546001600160a01b0381168252600160a01b81046001600160401b03166020830152600160e01b900463ffffffff169181019190915260018201546060820152600282018054919291608084019190612ae190614e81565b80601f0160208091040260200160405190810160405280929190818152602001828054612b0d90614e81565b8015612b5a5780601f10612b2f57610100808354040283529160200191612b5a565b820191906000526020600020905b815481529060010190602001808311612b3d57829003601f168201915b5050505050815250509050919050565b81612b7857612b7881610a28565b5050565b6000818152600080516020615929833981519152602052604081206004810154600160e01b900463ffffffff1615612bdb576004810154600160a01b90046001600160401b03164310612bd25750600392915050565b50600292915050565b80546001600160a01b031615612bf45750600192915050565b50600092915050565b600080612c0987612e12565b80546001600160b81b038116808355600160b81b9091046001600160481b03169350909150600160a01b900462ffffff1615612d5557805460009081908190612c78908b9063ffffffff8c16908b908b908b906001600160a01b03811690600160a01b900462ffffff166132ae565b9250925092508115612cc857604080518b81523a602082015280820185905290517f37fc320f2d5c58a36c657d3b047384d42550bcc0d9781d13a7d97f8a97c2370c9181900360600190a1612d32565b7f794f0625cb473a6fc2bbc46c87577b8e719f074c42f7fe02abdf08e7435b1d8d8a88883a876000875111612d15576040518060600160405280602981526020016158bf60299139612d17565b865b604051612d2996959493929190615572565b60405180910390a15b612d4d8a8a8a60405180602001604052806000815250613644565b505050612dd2565b7f1fd7bc07c18ac1c4f6d3111c704cd1b4c29b9f7980b7c5a9a2fddeef29d6c277873a6040805192835260208301919091520160405180910390a1612dd287878787878080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061364492505050565b5095945050505050565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015612937573d6000803e3d6000fd5b60009081526000805160206159298339815191526020526040902090565b600080612e3c83612b7c565b90506003816003811115612e5257612e52614620565b03612f045760008381526000805160206159298339815191526020526040812060060180549091908290612e8590614e81565b90501115612efa578054601b60fb1b908290600090612ea390614e81565b8110612eb157612eb1614ced565b815460011615612ed05790600052602060002090602091828204019190065b9054901a600160f81b026001600160f81b03191614612ef057600261219a565b6003949350505050565b5060059392505050565b6001816003811115612f1857612f18614620565b03612f265750600192915050565b6002816003811115612f3a57612f3a614620565b03612bf45750600492915050565b6000546001600160a01b03163314611dee5760405163118cdaa760e01b8152336004820152602401610a68565b600080612f8860408401602085016155cf565b6001600160401b0316118015612fad57506000612fa860208401846155ec565b60ff16115b8015612fc95750607f612fc360208401846155ec565b60ff1611155b8015610b9f57506404a817c800612fe660408401602085016155cf565b612ff1906064615609565b6001600160401b0316101592915050565b6000600080516020615909833981519152805460009061302190615634565b91829055509050600061303382612e12565b805460408051808201909152600e81526d185b1c9958591e481c1bdcdd195960921b6020820152919250613073916001600160a01b039091161590612b6a565b8054346001600160481b0316600160b81b026001600160b81b03199091163362ffffff60a01b191617600160a01b62ffffff861602176001600160b81b03161781556002810185905583600382016130cb828261564d565b905050509392505050565b600180546001600160a01b0319169055611bbd81613711565b60005b815181101561316557600082828151811061310f5761310f614ced565b60200260200101519050600161313060008051602061590983398151915290565b6001600160a01b0392909216600090815260029092016020526040909120805460ff19169115159190911790556001016130f2565b507f4d570ee36dec878006609360d34ac8d6a0b68d521871ae15a407b6340877ca01816040516114fa9190614eb5565b606060006131a283613761565b6001600160401b038111156131b9576131b9614658565b6040519080825280601f01601f1916602001820160405280156131e3576020820181803683370190505b50905060005b8151811015610c8f5783816020811061320457613204614ced565b1a60f81b82828151811061321a5761321a614ced565b60200101906001600160f81b031916908160001a9053506001016131e9565b60006132488686868686612bfd565b90506132543382612ddc565b95945050505050565b60009081526000805160206159298339815191526020526040902060040190565b80546000906132919060ff166003614cb2565b8254610b9f9160ff169061010090046001600160401b0316615609565b60008060605a9250601b60fb1b87876000816132cc576132cc614ced565b9050013560f81c60f81b6001600160f81b0319160361351c57600061332e61332989898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061379f92505050565b6137c4565b905060028151101561345557856001600160a01b03166363febc9c868d8d8d4360006040518060c00160405280604051806040016040528060405180602001604052806000815250815260200160008152508152602001600060ff168152602001600060ff168152602001600060ff16815260200160006001600160401b0316815260200160006001600160401b03168152506040518863ffffffff1660e01b81526004016133e29695949392919061571e565b600060405180830381600088803b1580156133fc57600080fd5b5087f19350505050801561340e575060015b61344c5761341a615474565b806308c379a003613440575061342e615490565b806134395750613442565b9150613516565b505b3d6000803e3d6000fd5b60019250613516565b856001600160a01b03166363febc9c868d8d8d4361348c8860008151811061347f5761347f614ced565b6020026020010151613974565b60fe81111561349d5761349d614620565b886000815181106134b0576134b0614ced565b60200260200101516040518863ffffffff1660e01b81526004016134d99695949392919061571e565b600060405180830381600088803b1580156134f357600080fd5b5087f193505050508015613505575060015b6135115761341a615474565b600192505b5061362a565b846001600160a01b031663bcc6307b858c8c8c4361356f8e8e8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061379f92505050565b6040518763ffffffff1660e01b815260040161358f95949392919061576b565b600060405180830381600088803b1580156135a957600080fd5b5087f1935050505080156135bb575060015b613625576135c7615474565b806308c379a0036135ed57506135db615490565b806135e657506135ef565b905061362a565b505b3d808015613619576040519150601f19603f3d011682016040523d82523d6000602084013e61361e565b606091505b505061362a565b600191505b5a613635908461579f565b92509750975097945050505050565b6040518060a00160405280336001600160a01b03168152602001436001600160401b031681526020018463ffffffff1681526020018381526020018281525061368c85612e12565b81516004820180546020850151604086015163ffffffff16600160e01b026001600160e01b036001600160401b03909216600160a01b026001600160e01b03199093166001600160a01b0390951694909417919091171691909117815560608301516005830155608083015190916006019061370890826157b2565b50505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60005b602081101561379a5781816020811061377f5761377f614ced565b1a60f81b6001600160f81b0319161561379a57600101613764565b919050565b6137a76142e3565b6040805180820190915282815260006020820152611ba5816139d7565b60608160048060ff16826040015160ff161461380457604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b600061381885600001518660600151613af7565b9050613825816001615871565b6001600160401b03166001600160401b0381111561384557613845614658565b60405190808252806020026020018201604052801561387e57816020015b61386b6142e3565b8152602001906001900390816138635790505b50935060005b816001600160401b03168110156139445761389e86613bbf565b95506138a986613be7565b8582815181106138bb576138bb614ced565b6020026020010181905250600460ff16866040015160ff16036139145760006138e3876137c4565b905080600182516138f4919061579f565b8151811061390457613904614ced565b602002602001015196505061393c565b600560ff16866040015160ff16036139315760006138e387613c7f565b61393a86613e69565b505b600101613884565b508484826001600160401b03168151811061396157613961614ced565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff16146139b457604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b6139c684600001518560600151613af7565b6001600160401b0316949350505050565b6139df6142e3565b8151518290600003613a04576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015613a8757613a248961402e565b955081613a3081615634565b6007600589901c169650601f881695509250506005198501613a7f576020890151613a5b8a86613af7565b9350808a60200151613a6d919061579f565b613a779084614d1a565b925050613a15565b506000613a15565b600760ff86161115613ab15760405163bd2ac87960e01b815260ff86166004820152602401610a68565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b600060188260ff161015613b0f575060ff8116610b9f565b8160ff16601803613b2d57613b238361402e565b60ff169050610b9f565b8160ff16601903613b4c57613b4183614090565b61ffff169050610b9f565b8160ff16601a03613b6d57613b60836140fc565b63ffffffff169050610b9f565b8160ff16601b03613b8857613b818361415b565b9050610b9f565b8160ff16601f03613ba157506001600160401b03610b9f565b604051636d785b1360e01b815260ff83166004820152602401610a68565b613bc76142e3565b81518051516020909101511015613be3578151610b9f906139d7565b5090565b613bef6142e3565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff1614613cbf57604080830151905161800560e51b815260ff91821660048201529082166024820152604401610a68565b6000613cd385600001518660600151613af7565b613cde906002615609565b9050613ceb816001615871565b6001600160401b03166001600160401b03811115613d0b57613d0b614658565b604051908082528060200260200182016040528015613d4457816020015b613d316142e3565b815260200190600190039081613d295790505b50935060005b816001600160401b031681101561394457613d6486613bbf565b9550613d6f86613be7565b858281518110613d8157613d81614ced565b6020908102919091010152613d97600282615891565b158015613dac5750604086015160ff16600314155b15613dda57604080870151905161800560e51b815260ff909116600482015260036024820152604401610a68565b604086015160ff1660041480613df75750604086015160ff166005145b15613e5657604086015160009060ff16600414613e1c57613e1787613c7f565b613e25565b613e25876137c4565b90508060018251613e36919061579f565b81518110613e4657613e46614ced565b6020026020010151965050613e61565b613e5f86613e69565b505b600101613d4a565b613e716142e3565b604082015160ff161580613e8c5750604082015160ff166001145b80613ec55750604082015160ff166007148015613eb157506019826060015160ff1610155b8015613ec55750601b826060015160ff1611155b15613ef857613ed3826141ba565b6001600160401b03168260000151602001818151613ef19190614d1a565b9052505090565b604082015160ff1660031480613f155750604082015160ff166002145b15613f59576000613f2e83600001518460600151613af7565b9050806001600160401b03168360000151602001818151613f4f9190614d1a565b905250613be39050565b604082015160ff1660041480613f765750604082015160ff166005145b15613f9f57613f8d82600001518360600151613af7565b6001600160401b031660808301525090565b604082015160ff166007141580613fd15750816060015160ff16601414158015613fd15750816060015160ff16601514155b15613be35760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b6064820152608401610a68565b6000816020015182600001515180821115614066576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b835160208501805180830160010151955090819061408382615634565b8152505050505050919050565b6000816020015160026140a39190614d1a565b825151808211156140d1576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516002818401810151965090916140ef8284614d1a565b9052509395945050505050565b60008160200151600461410f9190614d1a565b8251518082111561413d576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516004818401810151965090916140ef8284614d1a565b60008160200151600861416e9190614d1a565b8251518082111561419c576040516363a056dd60e01b81526004810183905260248101829052604401610a68565b83516020850180516008818401810151965090916140ef8284614d1a565b60006018826060015160ff1610156141d457506000919050565b601c826060015160ff16101561420357601882606001516141f591906158a5565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff9091166004820152602401610a68565b50805461423390614e81565b6000825580601f10614243575050565b601f016020900490600052602060002090810190611bbd919061432a565b60405180604001604052806142b06040805160c081018252600080825260208083018290528284018290526060808401526080830182905283518085019094528184528301529060a082015290565b81526040805160a08101825260008082526020828101829052928201819052606080830191909152608082015291015290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b5b80821115613be3576000815560010161432b565b60005b8381101561435a578181015183820152602001614342565b50506000910152565b720dcdee840d2dae0d8cadacadce8cac8744060f606b1b815260008551614391816013850160208a0161433f565b8551908301906143a8816013840160208a0161433f565b85519101906143be81601384016020890161433f565b84519101906143d481601384016020880161433f565b016013019695505050505050565b6001600160a01b0381168114611bbd57600080fd5b60006020828403121561440957600080fd5b8135611ba5816143e2565b803562ffffff8116811461379a57600080fd5b6000806040838503121561443a57600080fd5b8235915061444a60208401614414565b90509250929050565b60008083601f84011261446557600080fd5b5081356001600160401b0381111561447c57600080fd5b6020830191508360208260051b850101111561449757600080fd5b9250929050565b600080602083850312156144b157600080fd5b82356001600160401b038111156144c757600080fd5b6144d385828601614453565b90969095509350505050565b6000602082840312156144f157600080fd5b5035919050565b6000815180845261451081602086016020860161433f565b601f01601f19169290920160200192915050565b60018060a01b0381511682526001600160401b03602082015116602083015263ffffffff6040820151166040830152606081015160608301526000608082015160a0608085015261219a60a08501826144f8565b602081526000611ba56020830184614524565b60018060a01b03815116825262ffffff60208201511660208301526001600160481b0360408201511660408301526000606082015160e060608501526145d460e08501826144f8565b90506080830151608085015260a083015160ff81511660a08601526001600160401b0360208201511660c0860152508091505092915050565b602081526000611ba5602083018461458b565b634e487b7160e01b600052602160045260246000fd5b6006811061464657614646614620565b9052565b60208101610b9f8284614636565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561469357614693614658565b6040525050565b60006001600160401b038211156146b3576146b3614658565b5060051b60200190565b600060208083850312156146d057600080fd5b82356001600160401b038111156146e657600080fd5b8301601f810185136146f757600080fd5b80356147028161469a565b60405161470f828261466e565b82815260059290921b830184019184810191508783111561472f57600080fd5b928401925b82841015614756578335614747816143e2565b82529284019290840190614734565b979650505050505050565b60006040828403121561246f57600080fd5b6000806060838503121561478657600080fd5b8235915061444a8460208501614761565b60006001600160401b038211156147b0576147b0614658565b50601f01601f191660200190565b6000602082840312156147d057600080fd5b81356001600160401b038111156147e657600080fd5b8201601f810184136147f757600080fd5b803561480281614797565b60405161480f828261466e565b82815286602084860101111561482457600080fd5b8260208501602083013760009281016020019290925250949350505050565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b8281101561489a57603f198886030184526148888583516144f8565b9450928501929085019060010161486c565b5092979650505050505050565b602081526000611ba560208301846144f8565b6004811061464657614646614620565b6020808252825182820181905260009190848201906040850190845b81811015614909576148f98385516148ba565b92840192918401916001016148e6565b50909695505050505050565b60008083601f84011261492757600080fd5b5081356001600160401b0381111561493e57600080fd5b60208301915083602082850101111561449757600080fd5b6000806000806060858703121561496c57600080fd5b843593506020850135925060408501356001600160401b0381111561499057600080fd5b61499c87828801614915565b95989497509550505050565b60208101610b9f82846148ba565b61ffff81168114611bbd57600080fd5b600080604083850312156149d957600080fd5b8235915060208301356149eb816149b6565b809150509250929050565b60008060008060008060808789031215614a0f57600080fd5b86356001600160401b0380821115614a2657600080fd5b614a328a838b01614453565b90985096506020890135915080821115614a4b57600080fd5b50614a5889828a01614915565b979a9699509760408101359660609091013595509350505050565b60008060408385031215614a8657600080fd5b50508035926020909101359150565b60008060008060808587031215614aab57600080fd5b84356001600160401b03811115614ac157600080fd5b614acd87828801614915565b9095509350614ae190508660208701614761565b9150614aef60608601614414565b905092959194509250565b60ff811061464657614646614620565b60208152614b1c602082018351614afa565b6000602083015160408084015261219a60608401826144f8565b602081526000825160406020840152614b52606084018261458b565b90506020840151601f198483030160408501526132548282614524565b803563ffffffff8116811461379a57600080fd5b600080600080600060808688031215614b9b57600080fd5b85359450614bab60208701614b6f565b93506040860135925060608601356001600160401b03811115614bcd57600080fd5b614bd988828901614915565b969995985093965092949392505050565b600080600060808486031215614bff57600080fd5b83359250614c108560208601614761565b9150614c1e60608501614414565b90509250925092565b60008351614c3981846020880161433f565b6101d160f51b9083019081528351614c5881600284016020880161433f565b01600201949350505050565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060ff831680614ca357614ca3614c64565b8060ff84160491505092915050565b60ff8181168382160190811115610b9f57610b9f614c7a565b600060ff831680614cde57614cde614c64565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b8082028115828204841417610b9f57610b9f614c7a565b80820180821115610b9f57610b9f614c7a565b60008235607e19833603018112614d4357600080fd5b9190910192915050565b600082601f830112614d5e57600080fd5b8151614d6981614797565b604051614d76828261466e565b828152856020848701011115614d8b57600080fd5b61325483602083016020880161433f565b600060208284031215614dae57600080fd5b81516001600160401b03811115614dc457600080fd5b61219a84828501614d4d565b82815260406020820152600061219a60408301846144f8565b600060208284031215614dfb57600080fd5b611ba582614b6f565b6000808335601e19843603018112614e1b57600080fd5b8301803591506001600160401b03821115614e3557600080fd5b60200191503681900382131561449757600080fd5b60008251614e5c81846020870161433f565b72696e76616c6964207265706f7274206461746160681b920191825250601301919050565b600181811c90821680614e9557607f821691505b60208210810361246f57634e487b7160e01b600052602260045260246000fd5b6020808252825182820181905260009190848201906040850190845b818110156149095783516001600160a01b031683529284019291840191600101614ed1565b60ff81168114611bbd57600080fd5b6001600160401b0381168114611bbd57600080fd5b83815260208101839052608081018235614f3381614ef6565b60ff1660408301526020830135614f4981614f05565b6001600160401b038116606084015250949350505050565b60008060408385031215614f7457600080fd5b8251614f7f816143e2565b60208401519092506001600160401b03811115614f9b57600080fd5b614fa785828601614d4d565b9150509250929050565b60006020808385031215614fc457600080fd5b82516001600160401b03811115614fda57600080fd5b8301601f81018513614feb57600080fd5b8051614ff68161469a565b604051615003828261466e565b82815260059290921b830184019184810191508783111561502357600080fd5b928401925b8284101561475657835161503b816143e2565b82529284019290840190615028565b60006020828403121561505c57600080fd5b81516001600160e01b031981168114611ba557600080fd5b60006020828403121561508657600080fd5b8151611ba5816143e2565b6001600160a01b0384168152604060208201819052810182905260006001600160fb1b038311156150c157600080fd5b8260051b8085606085013791909101606001949350505050565b600060208083850312156150ee57600080fd5b82516001600160401b038082111561510557600080fd5b818501915085601f83011261511957600080fd5b81516151248161469a565b604051615131828261466e565b82815260059290921b840185019185810191508883111561515157600080fd5b8585015b838110156151895780518581111561516d5760008081fd5b61517b8b89838a0101614d4d565b845250918601918601615155565b5098975050505050505050565b61ffff828116828216039080821115610c8f57610c8f614c7a565b600061ffff808416806151c6576151c6614c64565b92169190910492915050565b61ffff818116838216019080821115610c8f57610c8f614c7a565b6000602082840312156151ff57600080fd5b8151611ba5816149b6565b60006020828403121561521c57600080fd5b81518015158114611ba557600080fd5b601f821115612937576000816000526020600020601f850160051c810160208610156152555750805b601f850160051c820191505b8181101561527457828155600101615261565b505050505050565b6001600160401b0383111561529357615293614658565b6152a7836152a18354614e81565b8361522c565b6000601f8411600181146152db57600085156152c35750838201355b600019600387901b1c1916600186901b178355615335565b600083815260209020601f19861690835b8281101561530c57868501358255602094850194600190920191016152ec565b50868210156153295760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b6153468184614636565b60006020604060208401526000845461535e81614e81565b8060408701526060600180841660008114615380576001811461539c576153cc565b60ff19851660608a0152606084151560051b8a010195506153cc565b89600052602060002060005b858110156153c35781548b82018601529083019088016153a8565b8a016060019650505b50939998505050505050505050565b6000602082840312156153ed57600080fd5b81516001600160401b038082111561540457600080fd5b908301906040828603121561541857600080fd5b60405160408101818110838211171561543357615433614658565b604052825160ff811061544557600080fd5b815260208301518281111561545957600080fd5b61546587828601614d4d565b60208301525095945050505050565b600060033d111561548d5760046000803e5060005160e01c5b90565b600060443d101561549e5790565b6040516003193d81016004833e81513d6001600160401b0381602484011181841117156154cd57505050505090565b82850191508151818111156154e55750505050505090565b843d87010160208285010111156154ff5750505050505090565b61550e6020828601018761466e565b509095945050505050565b7002bb4ba3732ba22b93937b939a634b11d1607d1b81526000825161554581601185016020870161433f565b9190910160110192915050565b6001600160481b03818116838216019080821115610c8f57610c8f614c7a565b86815260a060208201528460a0820152848660c0830137600060c086830101526000601f19601f870116820185604084015284606084015260c08382030160808401526155c260c08201856144f8565b9998505050505050505050565b6000602082840312156155e157600080fd5b8135611ba581614f05565b6000602082840312156155fe57600080fd5b8135611ba581614ef6565b6001600160401b0381811683821602808216919082811461562c5761562c614c7a565b505092915050565b60006001820161564657615646614c7a565b5060010190565b813561565881614ef6565b60ff8116905081548160ff198216178355602084013561567781614f05565b68ffffffffffffffff008160081b16836001600160481b03198416171784555050505050565b6000815160c084528051604060c08601526156bc6101008601826144f8565b9050602082015160e086015260ff602085015116602086015260ff604085015116604086015260ff6060850151166060860152608084015191506001600160401b0380831660808701528060a08601511660a087015250809250505092915050565b8681526001600160401b03861660208201528460408201528360608201526157496080820184614afa565b60c060a0820152600061575f60c083018461569d565b98975050505050505050565b8581526001600160401b038516602082015283604082015282606082015260a06080820152600061475660a083018461569d565b81810381811115610b9f57610b9f614c7a565b81516001600160401b038111156157cb576157cb614658565b6157df816157d98454614e81565b8461522c565b602080601f83116001811461581457600084156157fc5750858301515b600019600386901b1c1916600185901b178555615274565b600085815260208120601f198616915b8281101561584357888601518255948401946001909101908401615824565b50858210156158615787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160401b03818116838216019080821115610c8f57610c8f614c7a565b6000826158a0576158a0614c64565b500690565b60ff8281168282160390811115610b9f57610b9f614c7a56fe5769746e65744f7261636c653a2063616c6c6261636b20657863656564656420676173206c696d69745769746e65744572726f72734c69623a20617373657274696f6e206661696c6564f595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e183f595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e184a2646970667358221220231c7a4228d1a9ad53fdce58161530dc9dc2c1b7ee5d7903e434ae0f96fd0b3364736f6c63430008190033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000000db36997af1f02209a6f995883b9b699900000000000000000000000000000000b61fe075f545fd37767f403916582759000000000000000000000000000000000000000000000000000000000000000000001322e302e31342d34386336646436000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c138000000000000000000000000000000000000000000000000000000000000fef90000000000000000000000000000000000000000000000000000000000010faa0000000000000000000000000000000000000000000000000000000000004e20

-----Decoded View---------------
Arg [0] : _factory (address): 0x000DB36997AF1F02209A6F995883B9B699900000
Arg [1] : _registry (address): 0x000B61Fe075F545fd37767f40391658275900000
Arg [2] : _upgradable (bool): True
Arg [3] : _versionTag (bytes32): 0x322e302e31342d34386336646436000000000000000000000000000000000000
Arg [4] : _reportResultGasBase (uint256): 115000
Arg [5] : _reportResultWithCallbackGasBase (uint256): 65273
Arg [6] : _reportResultWithCallbackRevertGasBase (uint256): 69546
Arg [7] : _sstoreFromZeroGas (uint256): 20000

-----Encoded View---------------
8 Constructor Arguments found :
Arg [0] : 000000000000000000000000000db36997af1f02209a6f995883b9b699900000
Arg [1] : 000000000000000000000000000b61fe075f545fd37767f40391658275900000
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [3] : 322e302e31342d34386336646436000000000000000000000000000000000000
Arg [4] : 000000000000000000000000000000000000000000000000000000000001c138
Arg [5] : 000000000000000000000000000000000000000000000000000000000000fef9
Arg [6] : 0000000000000000000000000000000000000000000000000000000000010faa
Arg [7] : 0000000000000000000000000000000000000000000000000000000000004e20


Block Transaction Gas Used Reward
view all blocks collator

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.