Moonbase Alpha Testnet

Contract

0xCA9e7861643febcEa7C657eA8F012645D6acceC4
Source Code

Overview

DEV Balance

Moonbase Alpha LogoMoonbase Alpha LogoMoonbase Alpha Logo0 DEV

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Value
0x6101a06051818702023-09-26 10:01:36158 days 10 hrs ago1695722496IN
 Create: WitnetRequestBoardTrustableDefault
0 DEV0.000915730.12500074

Latest 25 internal transactions (View All)

Parent Txn Hash Block From To Value
61850252024-03-02 20:49:123 mins ago1709412552
0xCA9e78...D6acceC4
0.00001437 DEV
61850252024-03-02 20:49:123 mins ago1709412552
0xCA9e78...D6acceC4
0 DEV
61850252024-03-02 20:49:123 mins ago1709412552
0xCA9e78...D6acceC4
0 DEV
61850252024-03-02 20:49:123 mins ago1709412552
0xCA9e78...D6acceC4
0 DEV
61845892024-03-02 19:16:001 hr 36 mins ago1709406960
0xCA9e78...D6acceC4
0.00001437 DEV
61845892024-03-02 19:16:001 hr 36 mins ago1709406960
0xCA9e78...D6acceC4
0 DEV
61845762024-03-02 19:13:061 hr 39 mins ago1709406786
0xCA9e78...D6acceC4
0.00001437 DEV
61845762024-03-02 19:13:061 hr 39 mins ago1709406786
0xCA9e78...D6acceC4
0 DEV
61845762024-03-02 19:13:061 hr 39 mins ago1709406786
0xCA9e78...D6acceC4
0 DEV
61845762024-03-02 19:13:061 hr 39 mins ago1709406786
0xCA9e78...D6acceC4
0 DEV
61838552024-03-02 16:38:364 hrs 13 mins ago1709397516
0xCA9e78...D6acceC4
0.00001437 DEV
61838552024-03-02 16:38:364 hrs 13 mins ago1709397516
0xCA9e78...D6acceC4
0 DEV
61838402024-03-02 16:35:304 hrs 16 mins ago1709397330
0xCA9e78...D6acceC4
0.00001437 DEV
61838402024-03-02 16:35:304 hrs 16 mins ago1709397330
0xCA9e78...D6acceC4
0 DEV
61838402024-03-02 16:35:304 hrs 16 mins ago1709397330
0xCA9e78...D6acceC4
0 DEV
61838402024-03-02 16:35:304 hrs 16 mins ago1709397330
0xCA9e78...D6acceC4
0 DEV
61836962024-03-02 16:04:484 hrs 47 mins ago1709395488
0xCA9e78...D6acceC4
0.00001437 DEV
61836962024-03-02 16:04:484 hrs 47 mins ago1709395488
0xCA9e78...D6acceC4
0 DEV
61836862024-03-02 16:01:484 hrs 50 mins ago1709395308
0xCA9e78...D6acceC4
0.00001437 DEV
61836862024-03-02 16:01:484 hrs 50 mins ago1709395308
0xCA9e78...D6acceC4
0 DEV
61836862024-03-02 16:01:484 hrs 50 mins ago1709395308
0xCA9e78...D6acceC4
0 DEV
61836862024-03-02 16:01:484 hrs 50 mins ago1709395308
0xCA9e78...D6acceC4
0 DEV
61836652024-03-02 15:57:124 hrs 55 mins ago1709395032
0xCA9e78...D6acceC4
0.00001437 DEV
61836652024-03-02 15:57:124 hrs 55 mins ago1709395032
0xCA9e78...D6acceC4
0 DEV
61836512024-03-02 15:54:124 hrs 58 mins ago1709394852
0xCA9e78...D6acceC4
0.00001437 DEV
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
WitnetRequestBoardTrustableDefault

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 43 : WitnetRequestBoardTrustableDefault.sol
// SPDX-License-Identifier: MIT

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

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

import "./customs/WitnetRequestBoardTrustableBase.sol";
import "../../patterns/Destructible.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 WitnetRequestBoardTrustableDefault
    is 
        Destructible,
        WitnetRequestBoardTrustableBase
{
    uint256 internal immutable _ESTIMATED_REPORT_RESULT_GAS;

    constructor(
            WitnetRequestFactory _factory,
            bool _upgradable,
            bytes32 _versionTag,
            uint256 _reportResultGasLimit
        )
        WitnetRequestBoardTrustableBase(
            _factory, 
            _upgradable, 
            _versionTag, 
            address(0)
        )
    {   
        _ESTIMATED_REPORT_RESULT_GAS = _reportResultGasLimit;
    }


    // ================================================================================================================
    // --- Overrides implementation of 'IWitnetRequestBoardView' ------------------------------------------------------

    /// Estimates the amount of reward we need to insert for a given gas price.
    /// @param _gasPrice The gas price for which we need to calculate the rewards.
    function estimateReward(uint256 _gasPrice)
        public view
        virtual override
        returns (uint256)
    {
        return _gasPrice * _ESTIMATED_REPORT_RESULT_GAS;
    }


    // ================================================================================================================
    // --- Overrides 'Destructible' -----------------------------------------------------------------------------------

    /// Destroys current instance. Only callable by the owner.
    function destruct() external override onlyOwner {
        selfdestruct(payable(msg.sender));
    }


    // ================================================================================================================
    // --- 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 43 : Upgradeable.sol
// SPDX-License-Identifier: MIT

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

pragma solidity >=0.6.0 <0.9.0;

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);
        bytes32 _codehash;        
        assembly {
            _codehash := extcodehash(_base)
        }
        _BASE = _base;
        _CODEHASH = _codehash;
        _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) {
        return _CODEHASH;
    }

    /// @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 43 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

File 4 of 43 : 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;
    }

    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 43 : Payable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

import "../interfaces/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 43 : 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 43 : Ownable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

File 8 of 43 : 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 43 : ERC165.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

File 10 of 43 : Destructible.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

interface Destructible {
    /// @dev Self-destruct the whole contract.
    function destruct() external;
}

File 11 of 43 : WitnetV2.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./Witnet.sol";

library WitnetV2 {

    error IndexOutOfBounds(uint256 index, uint256 range);
    error InsufficientBalance(uint256 weiBalance, uint256 weiExpected);
    error InsufficientFee(uint256 weiProvided, uint256 weiExpected);
    error Unauthorized(address violator);

    error RadonFilterMissingArgs(uint8 opcode);

    error RadonRequestNoSources();
    error RadonRequestSourcesArgsMismatch(uint expected, uint actual);
    error RadonRequestMissingArgs(uint index, uint expected, uint actual);
    error RadonRequestResultsMismatch(uint index, uint8 read, uint8 expected);
    error RadonRequestTooHeavy(bytes bytecode, uint weight);

    error RadonSlaNoReward();
    error RadonSlaNoWitnesses();
    error RadonSlaTooManyWitnesses(uint256 numWitnesses);
    error RadonSlaConsensusOutOfRange(uint256 percentage);
    error RadonSlaLowCollateral(uint256 witnessCollateral);

    error UnsupportedDataRequestMethod(uint8 method, string schema, string body, string[2][] headers);
    error UnsupportedRadonDataType(uint8 datatype, uint256 maxlength);
    error UnsupportedRadonFilterOpcode(uint8 opcode);
    error UnsupportedRadonFilterArgs(uint8 opcode, bytes args);
    error UnsupportedRadonReducerOpcode(uint8 opcode);
    error UnsupportedRadonReducerScript(uint8 opcode, bytes script, uint256 offset);
    error UnsupportedRadonScript(bytes script, uint256 offset);
    error UnsupportedRadonScriptOpcode(bytes script, uint256 cursor, uint8 opcode);
    error UnsupportedRadonTallyScript(bytes32 hash);

    function toEpoch(uint _timestamp) internal pure returns (uint) {
        return 1 + (_timestamp - 11111) / 15;
    }

    function toTimestamp(uint _epoch) internal pure returns (uint) {
        return 111111+ _epoch * 15;
    }

    struct Beacon {
        uint256 escrow;
        uint256 evmBlock;
        uint256 gasprice;
        address relayer;
        address slasher;
        uint256 superblockIndex;
        uint256 superblockRoot;        
    }

    enum BeaconStatus {
        Idle
    }

    struct Block {
        bytes32 blockHash;
        bytes32 drTxsRoot;
        bytes32 drTallyTxsRoot;
    }
    
    enum BlockStatus {
        Idle
    }

    struct DrPost {
        uint256 block;
        DrPostStatus status;
        DrPostRequest request;
        DrPostResponse response;
    }
    
    /// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
    struct DrPostRequest {
        uint256 epoch;
        address requester;
        address reporter;
        bytes32 radHash;
        bytes32 slaHash;
        uint256 weiReward;
    }

    /// Data kept in EVM-storage containing Witnet-provided response metadata and result.
    struct DrPostResponse {
        address disputer;
        address reporter;
        uint256 escrowed;
        uint256 drCommitTxEpoch;
        uint256 drTallyTxEpoch;
        bytes32 drTallyTxHash;
        bytes   drTallyResultCborBytes;
    }

    enum DrPostStatus {
        Void,
        Deleted,
        Expired,
        Posted,
        Disputed,
        Reported,
        Finalized,
        Accepted,
        Rejected
    }

    struct DataProvider {
        string  authority;
        uint256 totalEndpoints;
        mapping (uint256 => bytes32) endpoints;
    }

    enum DataRequestMethods {
        /* 0 */ Unknown,
        /* 1 */ HttpGet,
        /* 2 */ Rng,
        /* 3 */ HttpPost
    }

    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
    }

    struct RadonFilter {
        RadonFilterOpcodes opcode;
        bytes args;
    }

    enum RadonFilterOpcodes {
        /* 0x00 */ GreaterThan,
        /* 0x01 */ LessThan,
        /* 0x02 */ Equals,
        /* 0x03 */ AbsoluteDeviation,
        /* 0x04 */ RelativeDeviation,
        /* 0x05 */ StandardDeviation,
        /* 0x06 */ Top,
        /* 0x07 */ Bottom,
        /* 0x08 */ Mode,
        /* 0x09 */ LessOrEqualThan
    }

    struct RadonReducer {
        RadonReducerOpcodes opcode;
        RadonFilter[] filters;
        bytes script;
    }

    enum RadonReducerOpcodes {
        /* 0x00 */ Minimum,
        /* 0x01 */ Maximum,
        /* 0x02 */ Mode,
        /* 0x03 */ AverageMean,
        /* 0x04 */ AverageMeanWeighted,
        /* 0x05 */ AverageMedian,
        /* 0x06 */ AverageMedianWeighted,
        /* 0x07 */ StandardDeviation,
        /* 0x08 */ AverageDeviation,
        /* 0x09 */ MedianDeviation,
        /* 0x0A */ MaximumDeviation,
        /* 0x0B */ ConcatenateAndHash
    }

    struct RadonRetrieval {
        uint8 argsCount;
        DataRequestMethods method;
        RadonDataTypes resultDataType;
        string url;
        string body;
        string[2][] headers;
        bytes script;
    }

    struct RadonSLA {
        uint numWitnesses;
        uint minConsensusPercentage;
        uint witnessReward;
        uint witnessCollateral;
        uint minerCommitRevealFee;
    }

    /// @notice Returns `true` if all witnessing parameters in `b` have same
    /// @notice value or greater than the ones in `a`.
    function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b)
        internal pure
        returns (bool)
    {
        return (
            a.numWitnesses >= b.numWitnesses
                && a.minConsensusPercentage >= b.minConsensusPercentage
                && a.witnessReward >= b.witnessReward
                && a.witnessCollateral >= b.witnessCollateral
                && a.minerCommitRevealFee >= b.minerCommitRevealFee
        );
    }

}

File 12 of 43 : WitnetErrorsLib.sol
// SPDX-License-Identifier: MIT

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

import "./Witnet.sol";

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

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

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

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


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

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

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

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

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

File 13 of 43 : 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 14 of 43 : 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 15 of 43 : Witnet.sol
// SPDX-License-Identifier: MIT

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

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

library Witnet {

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

File 16 of 43 : IWitnetRequestFactory.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "../../WitnetBytecodes.sol";

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

File 17 of 43 : IWitnetBytecodesEvents.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

interface IWitnetBytecodesEvents {    
    event NewDataProvider(uint256 index);
    event NewRadonRetrievalHash(bytes32 hash);
    event NewRadonReducerHash(bytes32 hash);
    event NewRadHash(bytes32 hash);
    event NewSlaHash(bytes32 hash);
}

File 18 of 43 : IWitnetBytecodesErrors.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

interface IWitnetBytecodesErrors {
    error UnknownRadonRetrieval(bytes32 hash);
    error UnknownRadonReducer(bytes32 hash);
    error UnknownRadonRequest(bytes32 hash);
    error UnknownRadonSLA(bytes32 hash);  
}

File 19 of 43 : IWitnetBytecodes.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

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

interface IWitnetBytecodes {

    function bytecodeOf(bytes32 radHash) external view returns (bytes memory);
    function bytecodeOf(bytes32 radHash, bytes32 slahHash) external view returns (bytes memory);

    function hashOf(
            bytes32[] calldata sources,
            bytes32 aggregator,
            bytes32 tally,
            uint16 resultMaxSize,
            string[][] calldata args
        ) external pure returns (bytes32);
    function hashOf(bytes32 radHash, bytes32 slaHash) external pure returns (bytes32 drQueryHash);
    function hashWeightWitsOf(bytes32 radHash, bytes32 slaHash) external view returns (
            bytes32 drQueryHash,
            uint32  drQueryWeight,
            uint256 drQueryWits
        );

    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 (WitnetV2.RadonReducer memory);
    
    function lookupRadonRetrieval(bytes32 hash) external view returns (WitnetV2.RadonRetrieval memory);
    function lookupRadonRetrievalArgsCount(bytes32 hash) external view returns (uint8);
    function lookupRadonRetrievalResultDataType(bytes32 hash) external view returns (WitnetV2.RadonDataTypes);
    
    function lookupRadonRequestAggregator(bytes32 radHash) external view returns (WitnetV2.RadonReducer memory);
    function lookupRadonRequestResultMaxSize(bytes32 radHash) external view returns (uint256);
    function lookupRadonRequestResultDataType(bytes32 radHash) external view returns (WitnetV2.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 (WitnetV2.RadonReducer memory);
    
    function lookupRadonSLA(bytes32 slaHash) external view returns (WitnetV2.RadonSLA memory);
    function lookupRadonSLAReward(bytes32 slaHash) external view returns (uint);
    
    function verifyRadonRetrieval(
            WitnetV2.DataRequestMethods requestMethod,
            string calldata requestSchema,
            string calldata requestAuthority,
            string calldata requestPath,
            string calldata requestQuery,
            string calldata requestBody,
            string[2][] calldata requestHeaders,
            bytes calldata requestRadonScript
        ) external returns (bytes32 hash);
    
    function verifyRadonRetrieval(
            WitnetV2.DataRequestMethods requestMethod,
            string calldata requestURL,
            string calldata requestBody,
            string[2][] calldata requestHeaders,
            bytes calldata requestRadonScript
        ) external returns (bytes32 hash);
    
    function verifyRadonReducer(WitnetV2.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 verifyRadonSLA(WitnetV2.RadonSLA calldata sla)
        external returns (bytes32 slaHash);

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

File 20 of 43 : IWitnetRequestBoardView.sol
// SPDX-License-Identifier: MIT

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

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

/// @title Witnet Request Board info interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardView {

    /// @notice Estimates the amount of reward we need to insert for a given gas price.
    /// @param _gasPrice The gas price for which we need to calculate the rewards.
    function estimateReward(uint256 _gasPrice) external view returns (uint256);

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

    /// @notice Gets the whole Query data contents, if any, no matter its current status.
    function getQueryData(uint256 _queryId) external view returns (Witnet.Query memory);

    /// @notice Gets current status of given query.
    function getQueryStatus(uint256 _queryId) external view returns (Witnet.QueryStatus);

    /// @notice Retrieves the whole Request record posted to the Witnet Request Board.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been reported
    /// @dev or deleted.
    /// @param _queryId The unique identifier of a previously posted query.
    function readRequest(uint256 _queryId) external view returns (Witnet.Request memory);

    /// @notice Retrieves the serialized bytecode of a previously posted Witnet Data Request.
    /// @dev Fails if the `_queryId` is not valid, or if the related script bytecode 
    /// @dev got changed after being posted. Returns empty array once it gets reported, 
    /// @dev or deleted.
    /// @param _queryId The unique query identifier.
    function readRequestBytecode(uint256 _queryId) external view returns (bytes memory);

    /// @notice Retrieves the gas price that any assigned reporter will have to pay when reporting 
    /// result to a previously posted Witnet data request.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifie
    function readRequestGasPrice(uint256 _queryId) external view returns (uint256);

    /// @notice Retrieves the reward currently set for the referred query.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifier.
    function readRequestReward(uint256 _queryId) external view returns (uint256);

    /// @notice Retrieves the whole `Witnet.Response` record referred to a previously posted Witnet Data Request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponse(uint256 _queryId) external view returns (Witnet.Response memory);

    /// @notice Retrieves error codes of given query.
    /// @dev Fails if the `_queryId` is not in 'Reported' status, or if no actual error.
    /// @param _queryId The unique query identifier.
    function readResponseDrTxHash(uint256 _queryId) external view returns (bytes32);

    /// @notice Retrieves the address that reported the result to a previously-posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseReporter(uint256 _queryId) external view returns (address);

    /// @notice Retrieves the Witnet-provided CBOR-bytes result of a previously posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseResult(uint256 _queryId) external view returns (Witnet.Result memory);

    /// @notice Retrieves the timestamp in which the result to the referred query was solved by the Witnet DON.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseTimestamp(uint256 _queryId) external view returns (uint256);
}

File 21 of 43 : IWitnetRequestBoardRequestor.sol
// SPDX-License-Identifier: MIT

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

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

/// @title Witnet Requestor Interface
/// @notice It defines how to interact with the Witnet Request Board in order to:
///   - request the execution of Witnet Radon scripts (data request);
///   - upgrade the resolution reward of any previously posted request, in case gas price raises in mainnet;
///   - read the result of any previously posted request, eventually reported by the Witnet DON.
///   - remove from storage all data related to past and solved data requests, and results.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardRequestor {

    /// @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 _queryId The unique query identifier.
    function checkResultStatus(uint256 _queryId) external view returns (Witnet.ResultStatus);

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

    /// @notice Retrieves a copy of all Witnet-provided data related to a previously posted request, removing the whole query from the WRB storage.
    /// @dev Fails if the `_queryId` is 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 deleteQuery(uint256 _queryId) external returns (Witnet.Response memory);

    /// @notice Requests the execution of the given Witnet Data Request in expectation that it will be relayed and solved by the Witnet DON.
    /// @notice A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// @notice result to this request.
    /// @dev Fails if:
    /// @dev - provided reward is too low.
    /// @dev - provided script is zero address.
    /// @dev - provided script bytecode is empty.
    /// @param addr The address of the IWitnetRequest contract that can provide the actual Data Request bytecode.
    /// @return _queryId Unique query identifier.
    function postRequest(IWitnetRequest addr) 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 the Witnet DON.
    /// @notice A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// @notice result to this request.
    /// @dev Fails if, provided reward is too low.
    /// @param radHash The RAD hash of the data request to be solved by Witnet.
    /// @param slaHash The SLA hash of the data request to be solved by Witnet.
    /// @return _queryId Unique query identifier.
    function postRequest(bytes32 radHash, bytes32 slaHash) 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 the Witnet DON.
    /// @notice A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// @notice result to this request.
    /// @dev Fails if, provided reward is too low.
    /// @param radHash The RAD hash of the data request to be solved by Witnet.
    /// @param slaParams The SLA params of the data request to be solved by Witnet.
    /// @return _queryId Unique query identifier.
    function postRequest(bytes32 radHash, WitnetV2.RadonSLA calldata slaParams) external payable returns (uint256 _queryId);

    /// @notice Increments the reward of a previously posted request by adding the transaction value to it.
    /// @dev Updates request `gasPrice` in case this method is called with a higher 
    /// @dev gas price value than the one used in previous calls to `postRequest` or
    /// @dev `upgradeReward`. 
    /// @dev Fails if the `_queryId` is not in 'Posted' status.
    /// @dev Fails also in case the request `gasPrice` is increased, and the new 
    /// @dev reward value gets below new recalculated threshold. 
    /// @param _queryId The unique query identifier.
    function upgradeReward(uint256 _queryId) external payable;
}

File 22 of 43 : IWitnetRequestBoardReporter.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

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

    /// @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 `_queryId` is not in 'Posted' status.
    /// @dev - provided `_drTxHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _queryId The unique identifier of the data request.
    /// @param _drTxHash The hash of the corresponding data request transaction in Witnet.
    /// @param _result The result itself as bytes.
    function reportResult(
            uint256 _queryId,
            bytes32 _drTxHash,
            bytes calldata _result
        ) external;

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

    /// @notice Reports Witnet-provided results to multiple requests within a single EVM tx.
    /// @dev Must emit a PostedResult event for every succesfully reported result.
    /// @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.
    /// @param _verbose If true, must emit a BatchReportError event for every failing report, if any. 
    function reportResultBatch(BatchResult[] calldata _batchResults, bool _verbose) external;
        
        struct BatchResult {
            uint256 queryId;
            uint256 timestamp;
            bytes32 drTxHash;
            bytes   cborBytes;
        }

        event BatchReportError(uint256 queryId, string reason);
}

File 23 of 43 : IWitnetRequestBoardEvents.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/// @title Witnet Request Board emitting events interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardEvents {
    
    /// Emitted when a Witnet Data Request is posted to the WRB.
    event PostedRequest(uint256 queryId, address from);

    /// Emitted when a Witnet-solved result is reported to the WRB.
    event PostedResult(uint256 queryId, address from);

    /// Emitted when all data related to given query is deleted from the WRB.
    event DeletedQuery(uint256 queryId, address from);
}

File 24 of 43 : IWitnetRequestBoardDeprecating.sol
// SPDX-License-Identifier: MIT

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

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

/// @title Witnet Request Board info interface.
/// @author The Witnet Foundation.
interface IWitnetRequestBoardDeprecating {

    /// ===============================================================================================================
    /// --- Deprecating funcionality v0.5 -----------------------------------------------------------------------------
    
    /// Tell if a Witnet.Result is successful.
    /// @param _result An instance of Witnet.Result.
    /// @return `true` if successful, `false` if errored.
    function isOk(Witnet.Result memory _result) external pure returns (bool);

    /// Decode a bytes value from a Witnet.Result as a `bytes32` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `bytes32` decoded from the Witnet.Result.
    function asBytes32(Witnet.Result memory _result) external pure returns (bytes32);

    /// Generate a suitable error message for a member of `Witnet.ResultErrorCodes` and its corresponding arguments.
    /// @dev WARN: Note that client contracts should wrap this function into a try-catch foreseing potential errors generated in this function
    /// @param _result An instance of `Witnet.Result`.
    /// @return A tuple containing the `CBORValue.Error memory` decoded from the `Witnet.Result`, plus a loggable error message.
    function asErrorMessage(Witnet.Result memory _result) external pure returns (Witnet.ResultErrorCodes, string memory);

    /// Decode a natural numeric value from a Witnet.Result as a `uint` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `uint` decoded from the Witnet.Result.
    function asUint64(Witnet.Result memory _result) external pure returns (uint64);

    /// Decode raw CBOR bytes into a Witnet.Result instance.
    /// @param _cborBytes Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory _cborBytes) external pure returns (Witnet.Result memory);

}

File 25 of 43 : 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 26 of 43 : IWitnetRequest.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

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

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

File 27 of 43 : IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

File 28 of 43 : WitnetRequestBoardTrustableBase.sol
// SPDX-License-Identifier: MIT

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

import "../../WitnetUpgradableBase.sol";
import "../../../WitnetRequestBoard.sol";
import "../../../data/WitnetBoardDataACLs.sol";
import "../../../interfaces/IWitnetRequestBoardAdminACLs.sol";
import "../../../patterns/Payable.sol";

import "../../../libs/WitnetErrorsLib.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 WitnetRequestBoardTrustableBase
    is 
        WitnetUpgradableBase,
        WitnetRequestBoard,
        WitnetBoardDataACLs,
        IWitnetRequestBoardAdminACLs,
        Payable 
{
    using Witnet for bytes;
    using Witnet for Witnet.Result;
    
    constructor(
            WitnetRequestFactory _factory,
            bool _upgradable,
            bytes32 _versionTag,
            address _currency
        )
        Payable(_currency)
        WitnetUpgradableBase(
            _upgradable,
            _versionTag,
            "io.witnet.proxiable.board"
        )
        WitnetRequestBoard(_factory)
    {}

    receive() external payable { 
        revert("WitnetRequestBoardTrustableBase: no transfers accepted");
    }

    /// @dev Provide backwards compatibility for dapps bound to versions <= 0.6.1
    /// @dev (i.e. calling methods in IWitnetRequestBoardDeprecating)
    /// @dev (Until 'function ... abi(...)' modifier is allegedly supported in solc versions >= 0.9.1)
    // solhint-disable-next-line payable-fallback
    fallback() override external { /* solhint-disable no-complex-fallback */
        bytes4 _newSig = msg.sig;
        if (msg.sig == 0xA8604C1A) {
            // IWitnetRequestParser.isOk({bool,CBOR}) --> IWitnetRequestBoardDeprecating.isOk({bool,WitnetCBOR.CBOR})
            _newSig = IWitnetRequestBoardDeprecating.isOk.selector;
        } else if (msg.sig == 0xCF62D115) {
            // IWitnetRequestParser.asBytes32({bool,CBOR}) --> IWitnetRequestBoardDeprecating.asBytes32({bool,WitnetCBOR.CBOR})
            _newSig = IWitnetRequestBoardDeprecating.asBytes32.selector;
        } else if (msg.sig == 0xBC7E25FF) {
            // IWitnetRequestParser.asUint64({bool,CBOR}) --> IWitnetRequestBoardDeprecating.asUint64({bool,WitnetCBOR.CBOR})
            _newSig = IWitnetRequestBoardDeprecating.asUint64.selector;
        } else if (msg.sig == 0xD74803BE) {
            // IWitnetRequestParser.asErrorMessage({bool,CBOR}) --> IWitnetRequestBoardDeprecating.asErrorMessage({bool,WitnetCBOR.CBOR})
            _newSig = IWitnetRequestBoardDeprecating.asErrorMessage.selector;
        }
        if (_newSig != msg.sig) {
            address _self = address(this);
            assembly {
                let ptr := mload(0x40)
                calldatacopy(ptr, 0, calldatasize())
                mstore(ptr, or(and(mload(ptr), 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff), _newSig))
                let result := delegatecall(gas(), _self, ptr, calldatasize(), 0, 0)
                let size := returndatasize()
                returndatacopy(ptr, 0, size)
                switch result
                    case 0 { revert(ptr, size) }
                    default { return(ptr, size) }
            }
        } else {
            revert(string(abi.encodePacked(
                "WitnetRequestBoardTrustableBase: 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)))
            )));
        }
    }


    // ================================================================================================================
    // --- Overrides IERC165 interface --------------------------------------------------------------------------------

    /// @dev See {IERC165-supportsInterface}.
    function supportsInterface(bytes4 _interfaceId)
      public view
      virtual override
      returns (bool)
    {
        return _interfaceId == type(WitnetRequestBoard).interfaceId
            || _interfaceId == type(IWitnetRequestBoardAdminACLs).interfaceId
            || super.supportsInterface(_interfaceId);
    }


    // ================================================================================================================
    // --- 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 = __storage().owner;
        if (_owner == address(0)) {
            // set owner if none set yet
            _owner = msg.sender;
            __storage().owner = _owner;
        } else {
            // only owner can initialize:
            require(
                msg.sender == _owner,
                "WitnetRequestBoardTrustableBase: only owner"
            );
        }

        if (__storage().base != address(0)) {
            // current implementation cannot be initialized more than once:
            require(
                __storage().base != base(),
                "WitnetRequestBoardTrustableBase: already upgraded"
            );
        }        
        __storage().base = base();

        emit Upgraded(msg.sender, base(), codehash(), version());

        // Do actual base initialization:
        setReporters(abi.decode(_initData, (address[])));
    }

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


    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardAdmin' ----------------------------------------------------------

    /// Gets admin/owner address.
    function owner()
        public view
        override
        returns (address)
    {
        return __storage().owner;
    }

    /// Transfers ownership.
    function transferOwnership(address _newOwner)
        public
        virtual override
        onlyOwner
    {
        address _owner = __storage().owner;
        if (_newOwner != _owner) {
            __storage().owner = _newOwner;
            emit OwnershipTransferred(_owner, _newOwner);
        }
    }


    // ================================================================================================================
    // --- 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 _acls().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
    {
        for (uint ix = 0; ix < _reporters.length; ix ++) {
            address _reporter = _reporters[ix];
            _acls().isReporter_[_reporter] = true;
        }
        emit ReportersSet(_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];
            _acls().isReporter_[_reporter] = false;
        }
        emit ReportersUnset(_exReporters);
    }


    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardReporter' -------------------------------------------------------

    /// 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 `_queryId` is not in 'Posted' status.
    /// @dev - provided `_drTxHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _queryId The unique identifier of the data request.
    /// @param _drTxHash The hash of the solving tally transaction in Witnet.
    /// @param _cborBytes The result itself as bytes.
    function reportResult(
            uint256 _queryId,
            bytes32 _drTxHash,
            bytes calldata _cborBytes
        )
        external
        override
        onlyReporters
        inStatus(_queryId, Witnet.QueryStatus.Posted)
    {
        require(_drTxHash != 0, "WitnetRequestBoardTrustableDefault: Witnet drTxHash cannot be zero");
        // Ensures the result bytes do not have zero length
        // This would not be a valid encoding with CBOR and could trigger a reentrancy attack
        require(_cborBytes.length != 0, "WitnetRequestBoardTrustableDefault: result cannot be empty");
        // solhint-disable not-rely-on-time
        _safeTransferTo(
            payable(msg.sender),
            __reportResult(
                _queryId,
                block.timestamp,
                _drTxHash,
                _cborBytes
            )
        );
        emit PostedResult(_queryId, msg.sender);
    }

    /// Reports the Witnet-provided result to a previously posted request.
    /// @dev Fails if:
    /// @dev - called from unauthorized address;
    /// @dev - the `_queryId` is not in 'Posted' status.
    /// @dev - provided `_drTxHash` is zero;
    /// @dev - length of provided `_result` is zero.
    /// @param _queryId The unique query identifier
    /// @param _timestamp The timestamp of the solving tally transaction in Witnet.
    /// @param _drTxHash The hash of the solving tally transaction in Witnet.
    /// @param _cborBytes The result itself as bytes.
    function reportResult(
            uint256 _queryId,
            uint256 _timestamp,
            bytes32 _drTxHash,
            bytes calldata _cborBytes
        )
        external
        override
        onlyReporters
        inStatus(_queryId, Witnet.QueryStatus.Posted)
    {
        require(_timestamp <= block.timestamp, "WitnetRequestBoardTrustableDefault: bad timestamp");
        require(_drTxHash != 0, "WitnetRequestBoardTrustableDefault: Witnet drTxHash cannot be zero");
        // Ensures the result bytes do not have zero length
        // This would not be a valid encoding with CBOR and could trigger a reentrancy attack
        require(_cborBytes.length != 0, "WitnetRequestBoardTrustableDefault: result cannot be empty");
        _safeTransferTo(
            payable(msg.sender),
            __reportResult(
                _queryId,
                _timestamp,
                _drTxHash,
                _cborBytes
            )
        );
        emit PostedResult(_queryId, msg.sender);
    }

    /// Reports Witnet-provided results to multiple requests within a single EVM tx.
    /// @dev Fails if called from unauthorized address.
    /// @dev Emits a PostedResult event for every succesfully reported result, if any.
    /// @param _batchResults Array of BatchedResult 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.
    /// @param _verbose If true, emits a BatchReportError event for every failing report, if any. 
    function reportResultBatch(
            IWitnetRequestBoardReporter.BatchResult[] memory _batchResults,
            bool _verbose
        )
        external
        override
        onlyReporters
    {
        uint _batchReward;
        uint _batchSize = _batchResults.length;
        for ( uint _i = 0; _i < _batchSize; _i ++) {
            BatchResult memory _result = _batchResults[_i];
            if (_statusOf(_result.queryId) != Witnet.QueryStatus.Posted) {
                if (_verbose) {
                    emit BatchReportError(
                        _result.queryId,
                        "WitnetRequestBoardTrustableBase: bad queryId"
                    );
                }
            } else if (_result.drTxHash == 0) {
                if (_verbose) {
                    emit BatchReportError(
                        _result.queryId,
                        "WitnetRequestBoardTrustableBase: bad drTxHash"
                    );
                }
            } else if (_result.cborBytes.length == 0) {
                if (_verbose) {
                    emit BatchReportError(
                        _result.queryId, 
                        "WitnetRequestBoardTrustableBase: bad cborBytes"
                    );
                }
            } else if (_result.timestamp > 0 && _result.timestamp > block.timestamp) {
                if (_verbose) {
                    emit BatchReportError(
                        _result.queryId,
                        "WitnetRequestBoardTrustableBase: bad timestamp"
                    );
                }
            } else {
                _batchReward += __reportResult(
                    _result.queryId,
                    _result.timestamp == 0 ? block.timestamp : _result.timestamp,
                    _result.drTxHash,
                    _result.cborBytes
                );
                emit PostedResult(
                    _result.queryId,
                    msg.sender
                );
            }
        }   
        // Transfer all successful rewards in one single shot to the authorized reporter, if any:
        if (_batchReward > 0) {
            _safeTransferTo(
                payable(msg.sender),
                _batchReward
            );
        }
    }
    

    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardRequestor' ------------------------------------------------------

    /// @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 _queryId The unique query identifier.
    function checkResultStatus(uint256 _queryId)
        virtual public view
        returns (Witnet.ResultStatus)
    {
        Witnet.QueryStatus _queryStatus = _statusOf(_queryId);
        if (_queryStatus == Witnet.QueryStatus.Reported) {
            bytes storage __cborValues = __response(_queryId).cborBytes;
            // determine whether reported result is an error by peeking the first byte
            return (__cborValues[0] == bytes1(0xd8) 
                ? Witnet.ResultStatus.Error
                : Witnet.ResultStatus.Ready
            );
        } else if (_queryStatus == Witnet.QueryStatus.Posted) {
            return Witnet.ResultStatus.Awaiting;
        } else {
            return Witnet.ResultStatus.Void;
        }
    }

    /// @notice Gets error code identifying some possible failure on the resolution of the given query.
    /// @param _queryId The unique query identifier.
    function checkResultError(uint256 _queryId)
        override external view
        returns (Witnet.ResultError memory)
    {
        Witnet.ResultStatus _status = checkResultStatus(_queryId);
        if (_status == Witnet.ResultStatus.Awaiting) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetRequestBoardTrustableBase: not yet solved"
            });
        } else if (_status == Witnet.ResultStatus.Void) {
            return Witnet.ResultError({
                code: Witnet.ResultErrorCodes.Unknown,
                reason: "WitnetRequestBoardTrustableBase: unknown query"
            });
        } else {
            try WitnetErrorsLib.resultErrorFromCborBytes(__response(_queryId).cborBytes)
                returns (Witnet.ResultError memory _error)
            {
                return _error;
            }
            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"
                });
            }
        }
    }

    /// Retrieves copy of all response data related to a previously posted request, removing the whole query from storage.
    /// @dev Fails if the `_queryId` is 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 deleteQuery(uint256 _queryId)
        public
        virtual override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (Witnet.Response memory _response)
    {
        Witnet.Query storage __query = __storage().queries[_queryId];
        require(
            msg.sender == __query.from,
            "WitnetRequestBoardTrustableBase: only requester"
        );
        _response = __query.response;
        delete __storage().queries[_queryId];
        emit DeletedQuery(_queryId, msg.sender);
    }

    /// Requests the execution of the given Witnet Data Request in expectation that it will be relayed and solved by the Witnet DON.
    /// A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// result to this request.
    /// @dev Fails if:
    /// @dev - provided reward is too low.
    /// @dev - provided address is zero.
    /// @param _requestInterface The address of a IWitnetRequest contract, containing the actual Data Request seralized bytecode.
    /// @return _queryId An unique query identifier.
    function postRequest(IWitnetRequest _requestInterface)
        virtual override
        public payable
        returns (uint256 _queryId)
    {
        uint256 _value = _getMsgValue();
        uint256 _gasPrice = _getGasPrice();

        // check base reward
        uint256 _baseReward = estimateReward(_gasPrice);
        require(_value >= _baseReward, "WitnetRequestBoardTrustableBase: reward too low");

        // Validates provided script:
        require(_requestInterface.hash() != bytes32(0), "WitnetRequestBoardTrustableBase: no precompiled request");

        _queryId = ++ __storage().numQueries;
        __storage().queries[_queryId].from = msg.sender;

        Witnet.Request storage _request = __request(_queryId);
        _request.addr = address(_requestInterface);
        _request.gasprice = _gasPrice;
        _request.reward = _value;

        // Let observers know that a new request has been posted
        emit PostedRequest(_queryId, msg.sender);
    }

    /// Requests the execution of the given Witnet Data Request in expectation that it will be relayed and solved by the Witnet DON.
    /// A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// result to this request.
    /// @dev Fails if:
    /// @dev - provided reward is too low.
    /// @param _radHash The radHash of the Witnet Data Request.
    /// @param _slaHash The slaHash of the Witnet Data Request.
    function postRequest(bytes32 _radHash, bytes32 _slaHash)
        virtual override
        public payable
        returns (uint256 _queryId)
    {
        uint256 _value = _getMsgValue();
        uint256 _gasPrice = _getGasPrice();

        // check base reward
        uint256 _baseReward = estimateReward(_gasPrice);
        require(
            _value >= _baseReward,
            "WitnetRequestBoardTrustableBase: reward too low"
        );

        _queryId = ++ __storage().numQueries;
        __storage().queries[_queryId].from = msg.sender;

        Witnet.Request storage _request = __request(_queryId);
        _request.radHash = _radHash;
        _request.slaHash = _slaHash;
        _request.gasprice = _gasPrice;
        _request.reward = _value;

        // Let observers know that a new request has been posted
        emit PostedRequest(_queryId, msg.sender);
    }

    /// Requests the execution of the given Witnet Data Request in expectation that it will be relayed and solved by the Witnet DON.
    /// A reward amount is escrowed by the Witnet Request Board that will be transferred to the reporter who relays back the Witnet-provided 
    /// result to this request.
    /// @dev Fails if:
    /// @dev - provided reward is too low.
    /// @param _radHash The RAD hash of the data tequest to be solved by Witnet.
    /// @param _slaParams The SLA param of the data request to be solved by Witnet.
    function postRequest(bytes32 _radHash, WitnetV2.RadonSLA calldata _slaParams)
        virtual override
        public payable
        returns (uint256 _queryId)
    {
        return postRequest(
            _radHash,
            registry.verifyRadonSLA(_slaParams)
        );
    }
    
    
    /// Increments the reward of a previously posted request by adding the transaction value to it.
    /// @dev Updates request `gasPrice` in case this method is called with a higher 
    /// @dev gas price value than the one used in previous calls to `postRequest` or
    /// @dev `upgradeReward`. 
    /// @dev Fails if the `_queryId` is not in 'Posted' status.
    /// @dev Fails also in case the request `gasPrice` is increased, and the new 
    /// @dev reward value gets below new recalculated threshold. 
    /// @param _queryId The unique query identifier.
    function upgradeReward(uint256 _queryId)
        public payable
        virtual override      
        inStatus(_queryId, Witnet.QueryStatus.Posted)
    {
        Witnet.Request storage _request = __request(_queryId);

        uint256 _newReward = _request.reward + _getMsgValue();
        uint256 _newGasPrice = _getGasPrice();

        // If gas price is increased, then check if new rewards cover gas costs
        if (_newGasPrice > _request.gasprice) {
            // Checks the reward is covering gas cost
            uint256 _minResultReward = estimateReward(_newGasPrice);
            require(
                _newReward >= _minResultReward,
                "WitnetRequestBoardTrustableBase: reward too low"
            );
            _request.gasprice = _newGasPrice;
        }
        _request.reward = _newReward;
    }


    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardView' -----------------------------------------------------------

    /// Estimates the amount of reward we need to insert for a given gas price.
    /// @param _gasPrice The gas price for which we need to calculate the rewards.
    function estimateReward(uint256 _gasPrice)
        public view
        virtual override
        returns (uint256);

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

    /// Gets the whole Query data contents, if any, no matter its current status.
    function getQueryData(uint256 _queryId)
      external view
      override
      returns (Witnet.Query memory)
    {
        return __storage().queries[_queryId];
    }

    /// Gets current status of given query.
    function getQueryStatus(uint256 _queryId)
        external view
        override
        returns (Witnet.QueryStatus)
    {
        return _statusOf(_queryId);

    }

    /// Retrieves the whole Request record posted to the Witnet Request Board.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been reported
    /// @dev or deleted.
    /// @param _queryId The unique identifier of a previously posted query.
    function readRequest(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Posted)
        returns (Witnet.Request memory _request)
    {
        return __request(_queryId);
    }
    
    /// Retrieves the serialized bytecode of a previously posted Witnet Data Request.
    /// @dev Fails if the `_queryId` is not valid, or if the related script bytecode 
    /// @dev got changed after being posted. Returns empty array once it gets reported, 
    /// @dev or deleted.
    /// @param _queryId The unique query identifier.
    function readRequestBytecode(uint256 _queryId)
        external view
        virtual override
        returns (bytes memory _bytecode)
    {
        require(
            _statusOf(_queryId) != Witnet.QueryStatus.Unknown,
            "WitnetRequestBoardTrustableBase: not yet posted"
        );
        Witnet.Request storage _request = __request(_queryId);
        if (_request.addr != address(0)) {
            _bytecode = IWitnetRequest(_request.addr).bytecode();
        } else if (_request.radHash != bytes32(0)) {
            _bytecode = registry.bytecodeOf(
                _request.radHash,
                _request.slaHash
            );
        }
    }

    /// Retrieves the gas price that any assigned reporter will have to pay when reporting 
    /// result to a previously posted Witnet data request.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifier
    function readRequestGasPrice(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Posted)
        returns (uint256)
    {
        return __storage().queries[_queryId].request.gasprice;
    }

    /// Retrieves the reward currently set for a previously posted request.
    /// @dev Fails if the `_queryId` is not valid or, if it has already been 
    /// @dev reported, or deleted. 
    /// @param _queryId The unique query identifier
    function readRequestReward(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Posted)
        returns (uint256)
    {
        return __storage().queries[_queryId].request.reward;
    }

    /// Retrieves the Witnet-provided result, and metadata, to a previously posted request.    
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier
    function readResponse(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (Witnet.Response memory _response)
    {
        return __response(_queryId);
    }

    /// Retrieves the hash of the Witnet transaction that actually solved the referred query.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseDrTxHash(uint256 _queryId)
        external view        
        override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (bytes32)
    {
        return __response(_queryId).drTxHash;
    }

    /// Retrieves the address that reported the result to a previously-posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier
    function readResponseReporter(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (address)
    {
        return __response(_queryId).reporter;
    }

    /// Retrieves the Witnet-provided CBOR-bytes result of a previously posted request.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier
    function readResponseResult(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (Witnet.Result memory)
    {
        Witnet.Response storage _response = __response(_queryId);
        return _response.cborBytes.resultFromCborBytes();
    }

    /// Retrieves the timestamp in which the result to the referred query was solved by the Witnet DON.
    /// @dev Fails if the `_queryId` is not in 'Reported' status.
    /// @param _queryId The unique query identifier.
    function readResponseTimestamp(uint256 _queryId)
        external view
        override
        inStatus(_queryId, Witnet.QueryStatus.Reported)
        returns (uint256)
    {
        return __response(_queryId).timestamp;
    }


    // ================================================================================================================
    // --- Full implementation of 'IWitnetRequestBoardDeprecating' interface ------------------------------------------

    /// Tell if a Witnet.Result is successful.
    /// @param _result An instance of Witnet.Result.
    /// @return `true` if successful, `false` if errored.
    function isOk(Witnet.Result memory _result)
        external pure
        override
        returns (bool)
    {
        return _result.success;
    }

    /// Decode a bytes value from a Witnet.Result as a `bytes32` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `bytes32` decoded from the Witnet.Result.
    function asBytes32(Witnet.Result memory _result)
        external pure
        override
        returns (bytes32)
    {
        return _result.asBytes32();
    }

    /// Generate a suitable error message for a member of `Witnet.ResultErrorCodes` and its corresponding arguments.
    /// @dev WARN: Note that client contracts should wrap this function into a try-catch foreseing potential errors generated in this function
    /// @param _result An instance of `Witnet.Result`.
    /// @return A tuple containing the `CBORValue.Error memory` decoded from the `Witnet.Result`, plus a loggable error message.
    function asErrorMessage(Witnet.Result memory _result)
        external pure
        override
        returns (Witnet.ResultErrorCodes, string memory)
    {
        Witnet.ResultError memory _resultError = WitnetErrorsLib.asError(_result);
        return (
            _resultError.code,
            _resultError.reason
        );
    }
    
    /// Decode a natural numeric value from a Witnet.Result as a `uint` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `uint` decoded from the Witnet.Result.
    function asUint64(Witnet.Result memory _result)
        external pure 
        override
        returns (uint64)
    {
        return uint64(_result.asUint());
    }

    /// Decode raw CBOR bytes into a Witnet.Result instance.
    /// @param _cborBytes Raw bytes representing a CBOR-encoded value.
    /// @return A `Witnet.Result` instance.
    function resultFromCborBytes(bytes memory _cborBytes)
        external pure
        override
        returns (Witnet.Result memory)
    {
        return Witnet.resultFromCborBytes(_cborBytes);
    }


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

    function __reportResult(
            uint256 _queryId,
            uint256 _timestamp,
            bytes32 _drTxHash,
            bytes memory _cborBytes
        )
        internal
        returns (uint256 _reward)
    {
        Witnet.Query storage _query = __query(_queryId);
        Witnet.Request storage _request = _query.request;
        Witnet.Response storage _response = _query.response;

        // solhint-disable not-rely-on-time
        _response.timestamp = _timestamp;
        _response.drTxHash = _drTxHash;
        _response.reporter = msg.sender;
        _response.cborBytes = _cborBytes;

        // return request latest reward
        _reward = _request.reward;

        // Request data won't be needed anymore, so it can just get deleted right now:  
        delete _query.request;
    }
}

File 29 of 43 : 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/ERC165.sol";
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 The Witnet Foundation.
abstract contract WitnetUpgradableBase
    is
        ERC165,
        Ownable2Step,
        Upgradeable, 
        ReentrancyGuard
{
    bytes32 internal immutable _WITNET_UPGRADABLE_VERSION;

    error AlreadyUpgraded(address implementation);
    error NotCompliant(bytes4 interfaceId);
    error NotUpgradable(address self);
    error OnlyOwner(address owner);

    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("WitnetUpgradableBase: not implemented");
    }


    // ================================================================================================================
    // --- Overrides IERC165 interface --------------------------------------------------------------------------------

    /// @dev See {IERC165-supportsInterface}.
    function supportsInterface(bytes4 _interfaceId)
      public view
      virtual override
      returns (bool)
    {
        return _interfaceId == type(Ownable2Step).interfaceId
            || _interfaceId == type(Upgradeable).interfaceId
            || super.supportsInterface(_interfaceId);
    }

    
    // ================================================================================================================
    // --- 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 -------------------------------------------------------------------------------------------

    /// 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 30 of 43 : 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 The Witnet Foundation.
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: not compliant");
            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,) = _newImplementation.delegatecall(
            abi.encodeWithSignature(
                "initialize(bytes)",
                _initData
            )
        );
        require(_wasInitialized, "WitnetProxy: unable to initialize");

        // 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: not compliant");
        }
    }

    /// @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 31 of 43 : WitnetBoardDataACLs.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

import "./WitnetBoardData.sol";

/// @title Witnet Access Control Lists storage layout, for Witnet-trusted request boards.
/// @author The Witnet Foundation.
abstract contract WitnetBoardDataACLs
    is
        WitnetBoardData
{
    bytes32 internal constant _WITNET_BOARD_ACLS_SLOTHASH =
        /* keccak256("io.witnet.boards.data.acls") */
        0xa6db7263983f337bae2c9fb315730227961d1c1153ae1e10a56b5791465dd6fd;

    struct WitnetBoardACLs {
        mapping (address => bool) isReporter_;
    }

    constructor() {
        _acls().isReporter_[msg.sender] = true;
    }

    modifier onlyReporters {
        require(
            _acls().isReporter_[msg.sender],
            "WitnetRequestBoard: unauthorized reporter"
        );
        _;
    } 

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

    function _acls() internal pure returns (WitnetBoardACLs storage _struct) {
        assembly {
            _struct.slot := _WITNET_BOARD_ACLS_SLOTHASH
        }
    }
}

File 32 of 43 : WitnetBoardData.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

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

/// @title Witnet Request Board base data model. 
/// @author The Witnet Foundation.
abstract contract WitnetBoardData {  

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

    struct WitnetBoardState {
        address base;
        address owner;    
        uint256 numQueries;
        mapping (uint => Witnet.Query) queries;
    }

    constructor() {
        __storage().owner = msg.sender;
    }

    /// Asserts the given query is currently in the given status.
    modifier inStatus(uint256 _queryId, Witnet.QueryStatus _status) {
      require(
          _statusOf(_queryId) == _status,
          _statusOfRevertMessage(_status)
        );
      _;
    }

    /// Asserts the given query was previously posted and that it was not yet deleted.
    modifier notDeleted(uint256 _queryId) {
        require(_queryId > 0 && _queryId <= __storage().numQueries, "WitnetRequestBoard: not yet posted");
        require(__query(_queryId).from  != address(0), "WitnetRequestBoard: deleted");
        _;
    }

    /// Asserts the give query was actually posted before calling this method.
    modifier wasPosted(uint256 _queryId) {
        require(_queryId > 0 && _queryId <= __storage().numQueries, "WitnetRequestBoard: not yet posted");
        _;
    }

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

    /// Gets query storage by query id.
    function __query(uint256 _queryId) internal view returns (Witnet.Query storage) {
      return __storage().queries[_queryId];
    }

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

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

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

    /// Gets current status of given query.
    function _statusOf(uint256 _queryId)
      internal view
      returns (Witnet.QueryStatus)
    {
      Witnet.Query storage _query = __storage().queries[_queryId];
      if (_query.response.drTxHash != 0) {
        // Query is in "Reported" status as soon as the hash of the
        // Witnet transaction that solved the query is reported
        // back from a Witnet bridge:
        return Witnet.QueryStatus.Reported;
      }
      else if (_query.from != address(0)) {
        // Otherwise, while address from which the query was posted
        // is kept in storage, the query remains in "Posted" status:
        return Witnet.QueryStatus.Posted;
      }
      else if (_queryId > __storage().numQueries) {
        // Requester's address is removed from storage only if
        // the query gets "Deleted" by its requester.
        return Witnet.QueryStatus.Deleted;
      } else {
        return Witnet.QueryStatus.Unknown;
      }
    }

    function _statusOfRevertMessage(Witnet.QueryStatus _status)
      internal pure
      returns (string memory)
    {
      if (_status == Witnet.QueryStatus.Posted) {
        return "WitnetRequestBoard: not in Posted status";
      } else if (_status == Witnet.QueryStatus.Reported) {
        return "WitnetRequestBoard: not in Reported status";
      } else if (_status == Witnet.QueryStatus.Deleted) {
        return "WitnetRequestBoard: not in Deleted status";
      } else {
        return "WitnetRequestBoard: bad mood";
      }
    }
}

File 33 of 43 : WitnetRequestFactory.sol
// SPDX-License-Identifier: MIT

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

import "./interfaces/V2/IWitnetRequestFactory.sol";

abstract contract WitnetRequestFactory
    is
        IWitnetRequestFactory
{}

File 34 of 43 : WitnetRequestBoard.sol
// SPDX-License-Identifier: MIT

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

import "./WitnetBytecodes.sol";
import "./WitnetRequestFactory.sol";

import "./interfaces/IWitnetRequestBoardEvents.sol";
import "./interfaces/IWitnetRequestBoardReporter.sol";
import "./interfaces/IWitnetRequestBoardRequestor.sol";
import "./interfaces/IWitnetRequestBoardView.sol";

import "./interfaces/IWitnetRequestBoardDeprecating.sol";

/// @title Witnet Request Board functionality base contract.
/// @author The Witnet Foundation.
abstract contract WitnetRequestBoard is
    IWitnetRequestBoardDeprecating,
    IWitnetRequestBoardEvents,
    IWitnetRequestBoardReporter,
    IWitnetRequestBoardRequestor,
    IWitnetRequestBoardView
{
    WitnetRequestFactory immutable public factory;
    WitnetBytecodes immutable public registry;
    constructor (WitnetRequestFactory _factory) {
        require(
            _factory.class() == type(WitnetRequestFactory).interfaceId,
            "WitnetRequestBoard: uncompliant factory"
        );
        factory = _factory;
        registry = _factory.registry();
    }
}

File 35 of 43 : WitnetBytecodes.sol
// SPDX-License-Identifier: MIT

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

import "./interfaces/V2/IWitnetBytecodes.sol";
import "./interfaces/V2/IWitnetBytecodesErrors.sol";
import "./interfaces/V2/IWitnetBytecodesEvents.sol";

abstract contract WitnetBytecodes
    is
        IWitnetBytecodes,
        IWitnetBytecodesErrors,
        IWitnetBytecodesEvents
{}

File 36 of 43 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @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 37 of 43 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./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);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 38 of 43 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

File 39 of 43 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}

File 40 of 43 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @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;

    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
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

File 41 of 43 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @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 {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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 {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _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 42 of 43 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 43 of 43 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @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]
 * ```
 * 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 Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _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 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _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() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @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 {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"contract WitnetRequestFactory","name":"_factory","type":"address"},{"internalType":"bool","name":"_upgradable","type":"bool"},{"internalType":"bytes32","name":"_versionTag","type":"bytes32"},{"internalType":"uint256","name":"_reportResultGasLimit","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"AlreadyUpgraded","type":"error"},{"inputs":[],"name":"EmptyBuffer","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"range","type":"uint256"}],"name":"IndexOutOfBounds","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"InvalidLengthEncoding","type":"error"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"NotCompliant","type":"error"},{"inputs":[{"internalType":"address","name":"self","type":"address"}],"name":"NotUpgradable","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OnlyOwner","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":"uint256","name":"queryId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"}],"name":"DeletedQuery","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"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":"uint256","name":"queryId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"}],"name":"PostedRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"queryId","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"}],"name":"PostedResult","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"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"_result","type":"tuple"}],"name":"asBytes32","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"_result","type":"tuple"}],"name":"asErrorMessage","outputs":[{"internalType":"enum Witnet.ResultErrorCodes","name":"","type":"uint8"},{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"_result","type":"tuple"}],"name":"asUint64","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"base","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"checkResultError","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":"_queryId","type":"uint256"}],"name":"checkResultStatus","outputs":[{"internalType":"enum Witnet.ResultStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"codehash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currency","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"deleteQuery","outputs":[{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"drTxHash","type":"bytes32"},{"internalType":"bytes","name":"cborBytes","type":"bytes"}],"internalType":"struct Witnet.Response","name":"_response","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"destruct","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_gasPrice","type":"uint256"}],"name":"estimateReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract WitnetRequestFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNextQueryId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"getQueryData","outputs":[{"components":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bytes32","name":"slaHash","type":"bytes32"},{"internalType":"bytes32","name":"radHash","type":"bytes32"},{"internalType":"uint256","name":"gasprice","type":"uint256"},{"internalType":"uint256","name":"reward","type":"uint256"}],"internalType":"struct Witnet.Request","name":"request","type":"tuple"},{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"drTxHash","type":"bytes32"},{"internalType":"bytes","name":"cborBytes","type":"bytes"}],"internalType":"struct Witnet.Response","name":"response","type":"tuple"},{"internalType":"address","name":"from","type":"address"}],"internalType":"struct Witnet.Query","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"getQueryStatus","outputs":[{"internalType":"enum Witnet.QueryStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_initData","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"_result","type":"tuple"}],"name":"isOk","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","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":"_radHash","type":"bytes32"},{"internalType":"bytes32","name":"_slaHash","type":"bytes32"}],"name":"postRequest","outputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IWitnetRequest","name":"_requestInterface","type":"address"}],"name":"postRequest","outputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_radHash","type":"bytes32"},{"components":[{"internalType":"uint256","name":"numWitnesses","type":"uint256"},{"internalType":"uint256","name":"minConsensusPercentage","type":"uint256"},{"internalType":"uint256","name":"witnessReward","type":"uint256"},{"internalType":"uint256","name":"witnessCollateral","type":"uint256"},{"internalType":"uint256","name":"minerCommitRevealFee","type":"uint256"}],"internalType":"struct WitnetV2.RadonSLA","name":"_slaParams","type":"tuple"}],"name":"postRequest","outputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readRequest","outputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bytes32","name":"slaHash","type":"bytes32"},{"internalType":"bytes32","name":"radHash","type":"bytes32"},{"internalType":"uint256","name":"gasprice","type":"uint256"},{"internalType":"uint256","name":"reward","type":"uint256"}],"internalType":"struct Witnet.Request","name":"_request","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readRequestBytecode","outputs":[{"internalType":"bytes","name":"_bytecode","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readRequestGasPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readRequestReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readResponse","outputs":[{"components":[{"internalType":"address","name":"reporter","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"drTxHash","type":"bytes32"},{"internalType":"bytes","name":"cborBytes","type":"bytes"}],"internalType":"struct Witnet.Response","name":"_response","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readResponseDrTxHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readResponseReporter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readResponseResult","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"}],"name":"readResponseTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract WitnetBytecodes","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"},{"internalType":"bytes32","name":"_drTxHash","type":"bytes32"},{"internalType":"bytes","name":"_cborBytes","type":"bytes"}],"name":"reportResult","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryId","type":"uint256"},{"internalType":"uint256","name":"_timestamp","type":"uint256"},{"internalType":"bytes32","name":"_drTxHash","type":"bytes32"},{"internalType":"bytes","name":"_cborBytes","type":"bytes"}],"name":"reportResult","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"queryId","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"drTxHash","type":"bytes32"},{"internalType":"bytes","name":"cborBytes","type":"bytes"}],"internalType":"struct IWitnetRequestBoardReporter.BatchResult[]","name":"_batchResults","type":"tuple[]"},{"internalType":"bool","name":"_verbose","type":"bool"}],"name":"reportResultBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_cborBytes","type":"bytes"}],"name":"resultFromCborBytes","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"}],"internalType":"struct WitnetBuffer.Buffer","name":"buffer","type":"tuple"},{"internalType":"uint8","name":"initialByte","type":"uint8"},{"internalType":"uint8","name":"majorType","type":"uint8"},{"internalType":"uint8","name":"additionalInformation","type":"uint8"},{"internalType":"uint64","name":"len","type":"uint64"},{"internalType":"uint64","name":"tag","type":"uint64"}],"internalType":"struct WitnetCBOR.CBOR","name":"value","type":"tuple"}],"internalType":"struct Witnet.Result","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address[]","name":"_reporters","type":"address[]"}],"name":"setReporters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":"_queryId","type":"uint256"}],"name":"upgradeReward","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101a06040523480156200001257600080fd5b50604051620050623803806200506283398101604081905262000035916200032c565b8383836000808484846040518060400160405280601981526020017f696f2e7769746e65742e70726f786961626c652e626f61726400000000000000815250826200008f620000896200029860201b60201c565b6200029c565b3060808190523f60a052151560c052600160025560e09190915280516020918201206101005260408051635ffc297d60e11b81529051600093506001600160a01b0385169263bff852fa92600480820193918290030181865afa158015620000fb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200012191906200037d565b6001600160e01b031916146200018d5760405162461bcd60e51b815260206004820152602760248201527f5769746e657452657175657374426f6172643a20756e636f6d706c69616e7420604482015266666163746f727960c81b606482015260840160405180910390fd5b6001600160a01b03811661012081905260408051637b10399960e01b81529051637b103999916004808201926020929091908290030181865afa158015620001d9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001ff9190620003b0565b6001600160a01b03908116610140527ff595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e18480546001600160a01b0319163390811790915560009081527fa6db7263983f337bae2c9fb315730227961d1c1153ae1e10a56b5791465dd6fd60205260409020805460ff1916600117905591909116610160525050506101809290925250620003d09350505050565b3390565b600180546001600160a01b0319169055620002c381620002c6602090811b62002b0317901c565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0381168114620002c357600080fd5b600080600080608085870312156200034357600080fd5b8451620003508162000316565b602086015190945080151581146200036757600080fd5b6040860151606090960151949790965092505050565b6000602082840312156200039057600080fd5b81516001600160e01b031981168114620003a957600080fd5b9392505050565b600060208284031215620003c357600080fd5b8151620003a98162000316565b60805160a05160c05160e0516101005161012051610140516101605161018051614bf06200047260003960006128f001526000610af601526000818161084e015281816110a101526124f601526000610a02015260006106d6015260006116ba01526000818161070701526119fd015260008181610941015261135601526000818161068c015281816112820152818161131301526113780152614bf06000f3fe6080604052600436106102975760003560e01c8063754e5bea1161015a578063b545e2b3116100c1578063d4da69ac1161007a578063d4da69ac14610a79578063dc3c71cd14610aa6578063e30c397814610ac6578063e5a6b10f14610ae4578063e99e47f314610b18578063f2fde38b14610b38576102f6565b8063b545e2b3146109b0578063c2485ebd146109c3578063c45a0155146109f0578063c805dd0f14610a24578063c8f5cdd514610a39578063d2e8756114610a59576102f6565b80638da5cb5b116101135780638da5cb5b146108d057806399f65804146108e55780639d96fced14610912578063a9e954b914610932578063b20321b414610965578063b281a7bd1461099d576102f6565b8063754e5bea146107fa57806379ba5097146108275780637b1039991461083c5780637c1fbda3146108705780637d52e6501461089057806381a398b5146108b0576102f6565b80634c9f72e3116101fe5780636280bce8116101b75780636280bce81461075f57806366822a441461077f57806366bfdc75146107925780636b58960a146107a55780636f07abcc146107c5578063715018a6146107e5576102f6565b80634c9f72e31461065d5780635001f3b51461067d57806352d1902d146106c45780635479d940146106f857806354fd4d501461072b578063578d630514610740576102f6565b80632b68b9c6116102505780632b68b9c6146105805780633ae97295146105955780633b885f2a146105b55780633e1c2183146105e2578063439fab9114610610578063483377bf14610630576102f6565b806301ffc9a71461046a578063044ad7be1461049f5780631dd27daf146104e5578063200e83771461051357806320f9241e1461054057806328a78d9b14610560576102f6565b366102f65760405162461bcd60e51b81526020600482015260366024820152600080516020614b7b833981519152604482015275081b9bc81d1c985b9cd9995c9cc81858d8d95c1d195960521b60648201526084015b60405180910390fd5b34801561030257600080fd5b506001600160e01b031960003516635430260d60e11b81900361032d575063578d630560e01b6103a1565b6001600160e01b03196000351663cf62d11560e01b0361035557506307d52e6560e41b6103a1565b6001600160e01b03196000351663bc7e25ff60e01b0361037d5750632c80c86d60e21b6103a1565b6001600160e01b031960003516636ba401df60e11b036103a15750633e1c218360e01b5b6000356001600160e01b0319908116908216146103ee5760405130903660008237826001600160e01b038251161781526000803683855af43d806000843e8180156103ea578184f35b8184fd5b6103fc60003560f81c610b58565b61040d60ff60003560f01c16610b58565b61041e60ff60003560e81c16610b58565b61042f60ff60003560e01c16610b58565b604051602001610442949392919061390a565b60408051601f198184030181529082905262461bcd60e51b82526102ed916004016139ca565b005b34801561047657600080fd5b5061048a6104853660046139dd565b610c4a565b60405190151581526020015b60405180910390f35b3480156104ab57600080fd5b5061048a6104ba366004613a1c565b6001600160a01b03166000908152600080516020614b9b833981519152602052604090205460ff1690565b3480156104f157600080fd5b50610505610500366004613a39565b610c90565b604051908152602001610496565b34801561051f57600080fd5b5061053361052e366004613a39565b610d01565b6040516104969190613a78565b34801561054c57600080fd5b5061050561055b366004613a39565b610dd8565b34801561056c57600080fd5b5061046861057b366004613b53565b610e36565b34801561058c57600080fd5b50610468610ef7565b3480156105a157600080fd5b506105056105b0366004613a39565b610f02565b3480156105c157600080fd5b506105d56105d0366004613a39565b610f6f565b60405161049691906139ca565b3480156105ee57600080fd5b506106026105fd366004613cb2565b611129565b604051610496929190613e04565b34801561061c57600080fd5b5061046861062b366004613e24565b6111be565b34801561063c57600080fd5b5061065061064b366004613a39565b6113f2565b6040516104969190613e58565b34801561066957600080fd5b50610468610678366004613b53565b6115fd565b34801561068957600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b039091168152602001610496565b3480156106d057600080fd5b506105057f000000000000000000000000000000000000000000000000000000000000000081565b34801561070457600080fd5b507f000000000000000000000000000000000000000000000000000000000000000061048a565b34801561073757600080fd5b506105d56116b3565b34801561074c57600080fd5b5061048a61075b366004613cb2565b5190565b34801561076b57600080fd5b5061046861077a366004613ecc565b6116e3565b61050561078d366004613f1e565b611832565b6104686107a0366004613a39565b611928565b3480156107b157600080fd5b5061048a6107c0366004613a1c565b6119e1565b3480156107d157600080fd5b506105336107e0366004613a39565b611a3f565b3480156107f157600080fd5b50610468611a4a565b34801561080657600080fd5b5061081a610815366004613a39565b611a5e565b6040516104969190613f7b565b34801561083357600080fd5b50610468611ba1565b34801561084857600080fd5b506106ac7f000000000000000000000000000000000000000000000000000000000000000081565b34801561087c57600080fd5b5061081a61088b366004613a39565b611c1b565b34801561089c57600080fd5b506105056108ab366004613cb2565b611e93565b3480156108bc57600080fd5b506104686108cb366004613f8e565b611e9e565b3480156108dc57600080fd5b506106ac612190565b3480156108f157600080fd5b50610905610900366004613a39565b6121ac565b60405161049691906140ac565b34801561091e57600080fd5b506106ac61092d366004613a39565b612271565b34801561093e57600080fd5b507f0000000000000000000000000000000000000000000000000000000000000000610505565b34801561097157600080fd5b50610985610980366004613cb2565b6122d5565b6040516001600160401b039091168152602001610496565b6105056109ab366004613a1c565b6122e0565b6105056109be3660046140ea565b6124a7565b3480156109cf57600080fd5b506109e36109de366004613a39565b612563565b6040516104969190614122565b3480156109fc57600080fd5b506106ac7f000000000000000000000000000000000000000000000000000000000000000081565b348015610a3057600080fd5b5061050561271b565b348015610a4557600080fd5b50610468610a543660046141a2565b612734565b348015610a6557600080fd5b50610505610a74366004613a39565b6128e9565b348015610a8557600080fd5b50610a99610a94366004613a39565b612915565b6040516104969190614202565b348015610ab257600080fd5b50610505610ac1366004613a39565b612a0f565b348015610ad257600080fd5b506001546001600160a01b03166106ac565b348015610af057600080fd5b506106ac7f000000000000000000000000000000000000000000000000000000000000000081565b348015610b2457600080fd5b50610a99610b33366004613e24565b612a6d565b348015610b4457600080fd5b50610468610b53366004613a1c565b612a7e565b604080516002808252818301909252606091600091906020820181803683370190505090506000610b8a6010856142cf565b610b959060306142f1565b90506000610ba460108661430a565b610baf9060306142f1565b905060398260ff161115610bcb57610bc86007836142f1565b91505b60398160ff161115610be557610be26007826142f1565b90505b8160f81b83600081518110610bfc57610bfc61432c565b60200101906001600160f81b031916908160001a9053508060f81b83600181518110610c2a57610c2a61432c565b60200101906001600160f81b031916908160001a90535091949350505050565b60006001600160e01b03198216632fd28e3360e21b1480610c7b57506001600160e01b03198216633039146360e11b145b80610c8a5750610c8a82612b53565b92915050565b600081600180610c9f83612ba3565b6003811115610cb057610cb0613a52565b14610cba82612c0e565b90610cd85760405162461bcd60e51b81526004016102ed91906139ca565b50610ce1612cf6565b6000858152600391909101602052604090206004015492505b5050919050565b600080610d0d83612ba3565b90506002816003811115610d2357610d23613a52565b03610da7576000610d3384612d1a565b6003018054909150601b60fb1b908290600090610d4f90614342565b8110610d5d57610d5d61432c565b815460011615610d7c5790600052602060002090602091828204019190065b9054901a600160f81b026001600160f81b03191614610d9c576002610d9f565b60035b949350505050565b6001816003811115610dbb57610dbb613a52565b03610dc95750600192915050565b50600092915050565b50919050565b600081600280610de783612ba3565b6003811115610df857610df8613a52565b14610e0282612c0e565b90610e205760405162461bcd60e51b81526004016102ed91906139ca565b50610e2a84612d1a565b60010154949350505050565b610e3e612d3a565b60005b8151811015610ebc576000828281518110610e5e57610e5e61432c565b602002602001015190506000610e7f600080516020614b9b83398151915290565b6001600160a01b039290921660009081526020929092526040909120805460ff191691151591909117905580610eb481614376565b915050610e41565b507f646436560d9757cb3c0f01da0f62642c6040b00c9a80685f94ef1a7725cad5f181604051610eec919061438f565b60405180910390a150565b610eff612d3a565b33ff5b600081600180610f1183612ba3565b6003811115610f2257610f22613a52565b14610f2c82612c0e565b90610f4a5760405162461bcd60e51b81526004016102ed91906139ca565b50610f53612cf6565b6000858152600391820160205260409020015492505050919050565b60606000610f7c83612ba3565b6003811115610f8d57610f8d613a52565b03610fe05760405162461bcd60e51b815260206004820152602f6024820152600080516020614b7b83398151915260448201526e081b9bdd081e595d081c1bdcdd1959608a1b60648201526084016102ed565b6000610feb83612d99565b80549091506001600160a01b0316156110765780546040805163784a000160e11b815290516001600160a01b039092169163f0940002916004808201926000929091908290030181865afa158015611047573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261106f9190810190614417565b9150610dd2565b600281015415610dd25760028101546001820154604051630565c45f60e31b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001692632b2e22f8926110dd92600401918252602082015260400190565b600060405180830381865afa1580156110fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111229190810190614417565b9392505050565b600060606000732163dbcbdbbec066ef8d8adab75af8b0b9a5cfaa63059c737f856040518263ffffffff1660e01b81526004016111669190614202565b600060405180830381865af4158015611183573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111ab919081019061445f565b8051602090910151909590945092505050565b60006111c8612cf6565b600101546001600160a01b031690508061120d575033806111e7612cf6565b60010180546001600160a01b0319166001600160a01b0392909216919091179055611267565b336001600160a01b038216146112675760405162461bcd60e51b815260206004820152602b6024820152600080516020614b7b83398151915260448201526a1037b7363c9037bbb732b960a91b60648201526084016102ed565b6000611271612cf6565b546001600160a01b031614611311577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166112b2612cf6565b546001600160a01b0316036113115760405162461bcd60e51b81526020600482015260316024820152600080516020614b7b83398151915260448201527008185b1c9958591e481d5c19dc98591959607a1b60648201526084016102ed565b7f000000000000000000000000000000000000000000000000000000000000000061133a612cf6565b80546001600160a01b0319166001600160a01b039283161790557f0000000000000000000000000000000000000000000000000000000000000000907f000000000000000000000000000000000000000000000000000000000000000016337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f66113c26116b3565b6040516113cf91906139ca565b60405180910390a46113ee8280602001905181019061067891906144fe565b5050565b604080518082019091526000815260606020820152600061141283610d01565b9050600181600381111561142857611428613a52565b03611461576040805180820190915280600081526020016040518060600160405280602f8152602001614af4602f913990529392505050565b600081600381111561147557611475613a52565b036114ae576040805180820190915280600081526020016040518060600160405280602e8152602001614b23602e913990529392505050565b732163dbcbdbbec066ef8d8adab75af8b0b9a5cfaa637e1a92b76114d185612d1a565b6003016040518263ffffffff1660e01b81526004016114f09190614597565b600060405180830381865af492505050801561152e57506040513d6000823e601f3d908101601f1916820160405261152b919081019061445f565b60015b6111225761153a614622565b806308c379a003611596575061154e61463e565b806115595750611598565b6040805180820190915280600081526020018260405160200161157c91906146c7565b60408051601f198184030181529190529052949350505050565b505b3d8080156115c2576040519150601f19603f3d011682016040523d82523d6000602084013e6115c7565b606091505b50604080518082019091528060008152602001604051806060016040528060218152602001614a8b602191399052949350505050565b611605612d3a565b60005b81518110156116835760008282815181106116255761162561432c565b602002602001015190506001611646600080516020614b9b83398151915290565b6001600160a01b039290921660009081526020929092526040909120805460ff19169115159190911790558061167b81614376565b915050611608565b507f4d570ee36dec878006609360d34ac8d6a0b68d521871ae15a407b6340877ca0181604051610eec919061438f565b60606116de7f0000000000000000000000000000000000000000000000000000000000000000612db6565b905090565b336000908152600080516020614b9b833981519152602052604090205460ff1661171f5760405162461bcd60e51b81526004016102ed90614700565b8360018061172c83612ba3565b600381111561173d5761173d613a52565b1461174782612c0e565b906117655760405162461bcd60e51b81526004016102ed91906139ca565b5060008590036117875760405162461bcd60e51b81526004016102ed90614749565b60008390036117a85760405162461bcd60e51b81526004016102ed906147b1565b6117f3336117ee88428989898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612e6192505050565b612ee0565b604080518781523360208201527ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a1505050505050565b6000343a82611840826128e9565b9050808310156118625760405162461bcd60e51b81526004016102ed9061480e565b61186a612cf6565b6002016000815461187a90614376565b918290555093503361188a612cf6565b60008681526003919091016020526040812060090180546001600160a01b0319166001600160a01b0393909316929092179091556118c785612d99565b60028101889055600181018790556003810184905560048101859055604080518781523360208201529192507fcabaf9c102f83746b27ae932f638eebfaf5ea7d014edd20ab14dec3768a8f55c910160405180910390a15050505092915050565b8060018061193583612ba3565b600381111561194657611946613a52565b1461195082612c0e565b9061196e5760405162461bcd60e51b81526004016102ed91906139ca565b50600061197a84612d99565b9050600034826004015461198e919061484b565b60038301549091503a908111156119d55760006119aa826128e9565b9050808310156119cc5760405162461bcd60e51b81526004016102ed9061480e565b50600383018190555b50600490910155505050565b6000806119ec612cf6565b600101546001600160a01b031690507f000000000000000000000000000000000000000000000000000000000000000080156111225750826001600160a01b0316816001600160a01b0316149392505050565b6000610c8a82612ba3565b611a52612d3a565b611a5c6000612f1b565b565b604080516080810182526000808252602082018190529181019190915260608082015281600280611a8e83612ba3565b6003811115611a9f57611a9f613a52565b14611aa982612c0e565b90611ac75760405162461bcd60e51b81526004016102ed91906139ca565b50611ad184612d1a565b6040805160808101825282546001600160a01b0316815260018301546020820152600283015491810191909152600382018054919291606084019190611b1690614342565b80601f0160208091040260200160405190810160405280929190818152602001828054611b4290614342565b8015611b8f5780601f10611b6457610100808354040283529160200191611b8f565b820191906000526020600020905b815481529060010190602001808311611b7257829003601f168201915b50505050508152505092505050919050565b60015433906001600160a01b03168114611c0f5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b60648201526084016102ed565b611c1881612f1b565b50565b604080516080810182526000808252602082018190529181019190915260608082015281600280611c4b83612ba3565b6003811115611c5c57611c5c613a52565b14611c6682612c0e565b90611c845760405162461bcd60e51b81526004016102ed91906139ca565b506000611c8f612cf6565b60008681526003919091016020526040902060098101549091506001600160a01b03163314611d065760405162461bcd60e51b815260206004820152602f6024820152600080516020614b7b83398151915260448201526e1037b7363c903932b8bab2b9ba32b960891b60648201526084016102ed565b604080516080810182526005830180546001600160a01b0316825260068401546020830152600784015492820192909252600883018054919291606084019190611d4f90614342565b80601f0160208091040260200160405190810160405280929190818152602001828054611d7b90614342565b8015611dc85780601f10611d9d57610100808354040283529160200191611dc8565b820191906000526020600020905b815481529060010190602001808311611dab57829003601f168201915b5050505050815250509350611ddb612cf6565b600086815260039182016020526040812080546001600160a01b03199081168255600182018390556002820183905592810182905560048101829055600581018054909316835560068101829055600781018290559181611e3f600885018261382b565b50505060090180546001600160a01b0319169055604080518681523360208201527fdec847db058c9c012e0f3dbe2b99e05cfa4c693f61a7d8bc64652a68913cbfff910160405180910390a1505050919050565b6000610c8a82612f34565b336000908152600080516020614b9b833981519152602052604090205460ff16611eda5760405162461bcd60e51b81526004016102ed90614700565b8151600090815b81811015612179576000858281518110611efd57611efd61432c565b6020026020010151905060016003811115611f1a57611f1a613a52565b8151611f2590612ba3565b6003811115611f3657611f36613a52565b14611fa2578415611f9d5780516040805191825260208201819052602c90820152600080516020614b7b83398151915260608201526b08189859081c5d595c9e525960a21b6080820152600080516020614ad48339815191529060a0015b60405180910390a15b612166565b604081015160000361200c578415611f9d5780516040805191825260208201819052602d90820152600080516020614b7b83398151915260608201526c040c4c2c840c8e4a8f090c2e6d609b1b6080820152600080516020614ad48339815191529060a001611f94565b806060015151600003612078578415611f9d5780516040805191825260208201819052602e90820152600080516020614b7b83398151915260608201526d206261642063626f72427974657360901b6080820152600080516020614ad48339815191529060a001611f94565b6000816020015111801561208f5750428160200151115b156120f3578415611f9d5780516040805191825260208201819052602e90820152600080516020614b7b83398151915260608201526d0206261642074696d657374616d760941b6080820152600080516020614ad48339815191529060a001611f94565b8051602082015161211f91901561210e578260200151612110565b425b83604001518460600151612e61565b612129908561484b565b8151604080519182523360208301529195507ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a15b508061217181614376565b915050611ee1565b50811561218a5761218a3383612ee0565b50505050565b600061219a612cf6565b600101546001600160a01b0316919050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152816001806121e483612ba3565b60038111156121f5576121f5613a52565b146121ff82612c0e565b9061221d5760405162461bcd60e51b81526004016102ed91906139ca565b5061222784612d99565b6040805160a08101825282546001600160a01b0316815260018301546020820152600283015491810191909152600382015460608201526004909101546080820152949350505050565b60008160028061228083612ba3565b600381111561229157612291613a52565b1461229b82612c0e565b906122b95760405162461bcd60e51b81526004016102ed91906139ca565b506122c384612d1a565b546001600160a01b0316949350505050565b6000610c8a82612f69565b6000343a826122ee826128e9565b9050808310156123105760405162461bcd60e51b81526004016102ed9061480e565b6000801b856001600160a01b03166309bd5a606040518163ffffffff1660e01b8152600401602060405180830381865afa158015612352573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612376919061485e565b036123d75760405162461bcd60e51b81526020600482015260376024820152600080516020614b7b83398151915260448201527f206e6f20707265636f6d70696c6564207265717565737400000000000000000060648201526084016102ed565b6123df612cf6565b600201600081546123ef90614376565b91829055509350336123ff612cf6565b60008681526003919091016020526040812060090180546001600160a01b0319166001600160a01b03939093169290921790915561243c85612d99565b80546001600160a01b0319166001600160a01b0388161781556003810184905560048101859055604080518781523360208201529192507fcabaf9c102f83746b27ae932f638eebfaf5ea7d014edd20ab14dec3768a8f55c910160405180910390a150505050919050565b60408051638fadabeb60e01b8152823560048201526020830135602482015290820135604482015260608201356064820152608082013560848201526000906111229084906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690638fadabeb9060a4016020604051808303816000875af115801561253f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078d919061485e565b6125cd6040805161010081019091526000606082018181526080830182905260a0830182905260c0830182905260e0830191909152819081526040805160808101825260008082526020828101829052928201526060808201529101908152600060209091015290565b6125d5612cf6565b60008381526003918201602090815260409182902082516101008101845281546001600160a01b0390811660608084019182526001850154608080860191909152600286015460a08601529785015460c0850152600485015460e0850152908352855196870186526005840180549092168752600684015487860152600784015495870195909552600883018054929693959487019491929184019161267a90614342565b80601f01602080910402602001604051908101604052809291908181526020018280546126a690614342565b80156126f35780601f106126c8576101008083540402835291602001916126f3565b820191906000526020600020905b8154815290600101906020018083116126d657829003601f168201915b505050919092525050508152600991909101546001600160a01b031660209091015292915050565b6000612725612cf6565b600201546116de90600161484b565b336000908152600080516020614b9b833981519152602052604090205460ff166127705760405162461bcd60e51b81526004016102ed90614700565b8460018061277d83612ba3565b600381111561278e5761278e613a52565b1461279882612c0e565b906127b65760405162461bcd60e51b81526004016102ed91906139ca565b50428611156128215760405162461bcd60e51b815260206004820152603160248201527f5769746e657452657175657374426f617264547275737461626c65446566617560448201527006c743a206261642074696d657374616d7607c1b60648201526084016102ed565b60008590036128425760405162461bcd60e51b81526004016102ed90614749565b60008390036128635760405162461bcd60e51b81526004016102ed906147b1565b6128a9336117ee89898989898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612e6192505050565b604080518881523360208201527ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a150505050505050565b6000610c8a7f000000000000000000000000000000000000000000000000000000000000000083614877565b61291d613865565b8160028061292a83612ba3565b600381111561293b5761293b613a52565b1461294582612c0e565b906129635760405162461bcd60e51b81526004016102ed91906139ca565b50600061296f85612d1a565b9050612a0681600301805461298390614342565b80601f01602080910402602001604051908101604052809291908181526020018280546129af90614342565b80156129fc5780601f106129d1576101008083540402835291602001916129fc565b820191906000526020600020905b8154815290600101906020018083116129df57829003601f168201915b5050505050612f9a565b95945050505050565b600081600280612a1e83612ba3565b6003811115612a2f57612a2f613a52565b14612a3982612c0e565b90612a575760405162461bcd60e51b81526004016102ed91906139ca565b50612a6184612d1a565b60020154949350505050565b612a75613865565b610c8a82612f9a565b612a86612d3a565b6000612a90612cf6565b600101546001600160a01b039081169150821681146113ee5781612ab2612cf6565b60010180546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006001600160e01b03198216631a12e29960e21b1480612b8457506001600160e01b0319821663d1ab0e8760e01b145b80610c8a57506301ffc9a760e01b6001600160e01b0319831614610c8a565b600080612bae612cf6565b600084815260039190910160205260409020600781015490915015612bd65750600292915050565b60098101546001600160a01b031615612bf25750600192915050565b612bfa612cf6565b60020154831115610dc95750600392915050565b60606001826003811115612c2457612c24613a52565b03612c4857604051806060016040528060288152602001614aac6028913992915050565b6002826003811115612c5c57612c5c613a52565b03612c80576040518060600160405280602a8152602001614b51602a913992915050565b6003826003811115612c9457612c94613a52565b03612cb857604051806060016040528060298152602001614a626029913992915050565b505060408051808201909152601c81527f5769746e657452657175657374426f6172643a20626164206d6f6f6400000000602082015290565b919050565b7ff595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e18390565b6000612d24612cf6565b6000928352600301602052506040902060050190565b33612d43612190565b6001600160a01b031614611a5c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016102ed565b6000612da3612cf6565b6000928352600301602052506040902090565b60606000612dc383612fb8565b6001600160401b03811115612dda57612dda613a8b565b6040519080825280601f01601f191660200182016040528015612e04576020820181803683370190505b50905060005b8151811015612e5a57838160208110612e2557612e2561432c565b1a60f81b828281518110612e3b57612e3b61432c565b60200101906001600160f81b031916908160001a905350600101612e0a565b5092915050565b600080612e6d86612d99565b60068101869055600781018590556005810180546001600160a01b03191633178155909150819060088201612ea286826148dc565b505060049081015482546001600160a01b03191683556000600184018190556002840181905560038401819055929091019190915595945050505050565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015612f16573d6000803e3d6000fd5b505050565b600180546001600160a01b0319169055611c1881612b03565b6000818060000151612f585760405162461bcd60e51b81526004016102ed9061499b565b611122612f6484612ff1565b613022565b6000818060000151612f8d5760405162461bcd60e51b81526004016102ed9061499b565b611122836020015161302f565b612fa2613865565b6000612fad83613092565b9050611122816130b7565b60005b6020811015612cf157818160208110612fd657612fd661432c565b1a60f81b6001600160f81b03191615612cf157600101612fbb565b60608180600001516130155760405162461bcd60e51b81526004016102ed9061499b565b61112283602001516130eb565b6000610c8a826020613235565b60008160008060ff16826040015160ff161461306f57604080830151905161800560e51b815260ff918216600482015290821660248201526044016102ed565b613081846000015185606001516132ad565b6001600160401b0316949350505050565b61309a613886565b604080518082019091528281526000602082015261112281613375565b6130bf613865565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b60608160028060ff16826040015160ff161461312b57604080830151905161800560e51b815260ff918216600482015290821660248201526044016102ed565b61313d846000015185606001516132ad565b6001600160401b03166080850181905263fffffffe190161321457600061316c85600001518660400151613495565b905063ffffffff808216101561320e5784516131919063ffffffff8084169061353b16565b6040516020016131a191906149ed565b60405160208183030381529060405293506131c485600001518660400151613495565b905063ffffffff808216101561320e57845184906131eb9063ffffffff8085169061353b16565b6040516020016131fc929190614a09565b60405160208183030381529060405293505b50610cfa565b6080840151845161322e9163ffffffff9081169061353b16565b9250610cfa565b600060208260ff16111561324b5761324b614a38565b60008260ff1684511161325f578351613264565b8260ff165b905060005b818110156132a557806008028582815181106132875761328761432c565b01602001516001600160f81b031916901c9290921791600101613269565b505092915050565b600060188260ff1610156132c5575060ff8116610c8a565b8160ff166018036132e3576132d9836135fb565b60ff169050610c8a565b8160ff16601903613302576132f78361365d565b61ffff169050610c8a565b8160ff16601a0361332357613316836136c9565b63ffffffff169050610c8a565b8160ff16601b0361333e5761333783613728565b9050610c8a565b8160ff16601f0361335757506001600160401b03610c8a565b604051636d785b1360e01b815260ff831660048201526024016102ed565b61337d613886565b81515182906000036133a2576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015613425576133c2896135fb565b9550816133ce81614376565b6007600589901c169650601f88169550925050600519850161341d5760208901516133f98a866132ad565b9350808a6020015161340b9190614a4e565b613415908461484b565b9250506133b3565b5060006133b3565b600760ff8616111561344f5760405163bd2ac87960e01b815260ff861660048201526024016102ed565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b6000806134a1846135fb565b90508060ff1660ff036134be576001600160401b03915050610c8a565b6134cb8482601f166132ad565b91506001600160401b038083161061350157604051636d785b1360e01b81526001600160401b03831660048201526024016102ed565b60ff83166007600583901c1614612e5a5760405161800560e51b81526007600583901c16600482015260ff841660248201526044016102ed565b606081836020015161354d919061484b565b8351518082111561357b576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b836001600160401b0381111561359357613593613a8b565b6040519080825280601f01601f1916602001820160405280156135bd576020820181803683370190505b50925083156132a55784516020808701519081830181019086016135e281838a613787565b6135ee898960016137cb565b5050505050505092915050565b6000816020015182600001515180821115613633576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b835160208501805180830160010151955090819061365082614376565b8152505050505050919050565b600081602001516002613670919061484b565b8251518082111561369e576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516002818401810151965090916136bc828461484b565b9052509395945050505050565b6000816020015160046136dc919061484b565b8251518082111561370a576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516004818401810151965090916136bc828461484b565b60008160200151600861373b919061484b565b82515180821115613769576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516008818401810151965090916136bc828461484b565b5b602081106137a7578151835260209283019290910190601f1901613788565b8015612f1657905182516020929092036101000a6000190180199091169116179052565b600082846000015151808211156137ff576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b8315613817576020860151613814908661484b565b94505b602086018590528492505b50509392505050565b50805461383790614342565b6000825580601f10613847575050565b601f016020900490600052602060002090810190611c1891906138cd565b6040518060400160405280600015158152602001613881613886565b905290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b5b808211156138e257600081556001016138ce565b5090565b60005b838110156139015781810151838201526020016138e9565b50506000910152565b600080516020614b7b833981519152815273040dcdee840d2dae0d8cadacadce8cac8744060f60631b60208201526000855161394d816034850160208a016138e6565b855190830190613964816034840160208a016138e6565b855191019061397a8160348401602089016138e6565b84519101906139908160348401602088016138e6565b016034019695505050505050565b600081518084526139b68160208601602086016138e6565b601f01601f19169290920160200192915050565b602081526000611122602083018461399e565b6000602082840312156139ef57600080fd5b81356001600160e01b03198116811461112257600080fd5b6001600160a01b0381168114611c1857600080fd5b600060208284031215613a2e57600080fd5b813561112281613a07565b600060208284031215613a4b57600080fd5b5035919050565b634e487b7160e01b600052602160045260246000fd5b60048110611c1857611c18613a52565b60208101613a8583613a68565b91905290565b634e487b7160e01b600052604160045260246000fd5b604081018181106001600160401b0382111715613ac057613ac0613a8b565b60405250565b60c081018181106001600160401b0382111715613ac057613ac0613a8b565b608081018181106001600160401b0382111715613ac057613ac0613a8b565b601f8201601f191681016001600160401b0381118282101715613b2957613b29613a8b565b6040525050565b60006001600160401b03821115613b4957613b49613a8b565b5060051b60200190565b60006020808385031215613b6657600080fd5b82356001600160401b03811115613b7c57600080fd5b8301601f81018513613b8d57600080fd5b8035613b9881613b30565b604051613ba58282613b04565b82815260059290921b8301840191848101915087831115613bc557600080fd5b928401925b82841015613bec578335613bdd81613a07565b82529284019290840190613bca565b979650505050505050565b80358015158114612cf157600080fd5b60006001600160401b03821115613c2057613c20613a8b565b50601f01601f191660200190565b600082601f830112613c3f57600080fd5b8135613c4a81613c07565b604051613c578282613b04565b828152856020848701011115613c6c57600080fd5b82602086016020830137600092810160200192909252509392505050565b803560ff81168114612cf157600080fd5b80356001600160401b0381168114612cf157600080fd5b60006020808385031215613cc557600080fd5b82356001600160401b0380821115613cdc57600080fd5b81850191506040808388031215613cf257600080fd5b8051613cfd81613aa1565b613d0684613bf7565b81528484013583811115613d1957600080fd5b939093019260c08489031215613d2e57600080fd5b8151613d3981613ac6565b843584811115613d4857600080fd5b8501808a03841315613d5957600080fd5b8351613d6481613aa1565b813586811115613d7357600080fd5b613d7f8c828501613c2e565b82525090870135878201528152613d97858701613c8a565b86820152613da6838601613c8a565b83820152613db660608601613c8a565b6060820152613dc760808601613c9b565b6080820152613dd860a08601613c9b565b60a082015294810194909452509195945050505050565b6101008110613e0057613e00613a52565b9052565b613e0e8184613def565b604060208201526000610d9f604083018461399e565b600060208284031215613e3657600080fd5b81356001600160401b03811115613e4c57600080fd5b610d9f84828501613c2e565b60208152613e6a602082018351613def565b60006020830151604080840152610d9f606084018261399e565b60008083601f840112613e9657600080fd5b5081356001600160401b03811115613ead57600080fd5b602083019150836020828501011115613ec557600080fd5b9250929050565b60008060008060608587031215613ee257600080fd5b843593506020850135925060408501356001600160401b03811115613f0657600080fd5b613f1287828801613e84565b95989497509550505050565b60008060408385031215613f3157600080fd5b50508035926020909101359150565b60018060a01b03815116825260208101516020830152604081015160408301526000606082015160806060850152610d9f608085018261399e565b6020815260006111226020830184613f40565b6000806040808486031215613fa257600080fd5b83356001600160401b0380821115613fb957600080fd5b818601915086601f830112613fcd57600080fd5b81356020613fda82613b30565b8551613fe68282613b04565b83815260059390931b850182019282810191508a84111561400657600080fd5b8286015b8481101561408e5780358681111561402157600080fd5b87016080818e03601f1901121561403757600080fd5b885161404281613ae5565b858201358152898201358682015260608201358a82015260808201358881111561406c5760008081fd5b61407a8f8883860101613c2e565b60608301525084525091830191830161400a565b50975061409e9050888201613bf7565b955050505050509250929050565b81516001600160a01b031681526020808301519082015260408083015190820152606080830151908201526080808301519082015260a08101610c8a565b60008082840360c08112156140fe57600080fd5b8335925060a0601f198201121561411457600080fd5b506020830190509250929050565b6020815261416560208201835180516001600160a01b03168252602080820151908301526040808201519083015260608082015190830152608090810151910152565b6000602083015160e060c0840152614181610100840182613f40565b604094909401516001600160a01b031660e093909301929092525090919050565b6000806000806000608086880312156141ba57600080fd5b85359450602086013593506040860135925060608601356001600160401b038111156141e557600080fd5b6141f188828901613e84565b969995985093965092949392505050565b6020815281511515602082015260006020830151604080840152805160c060608501528051604061012086015261423d61016086018261399e565b6020928301516101408701529183015160ff1660808601525060408201519061426b60a086018360ff169052565b606083015160ff1660c086015260808301516001600160401b0380821660e088015260a0909401519384166101008701529150612a06565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060ff8316806142e2576142e26142a3565b8060ff84160491505092915050565b60ff8181168382160190811115610c8a57610c8a6142b9565b600060ff83168061431d5761431d6142a3565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b600181811c9082168061435657607f821691505b602082108103610dd257634e487b7160e01b600052602260045260246000fd5b600060018201614388576143886142b9565b5060010190565b6020808252825182820181905260009190848201906040850190845b818110156143d05783516001600160a01b0316835292840192918401916001016143ab565b50909695505050505050565b60006143e783613c07565b6040516143f48282613b04565b80925084815285858501111561440957600080fd5b6138228560208301866138e6565b60006020828403121561442957600080fd5b81516001600160401b0381111561443f57600080fd5b8201601f8101841361445057600080fd5b610d9f848251602084016143dc565b60006020828403121561447157600080fd5b81516001600160401b038082111561448857600080fd5b908301906040828603121561449c57600080fd5b6040516144a881613aa1565b825161010081106144b857600080fd5b81526020830151828111156144cc57600080fd5b80840193505085601f8401126144e157600080fd5b6144f0868451602086016143dc565b602082015295945050505050565b6000602080838503121561451157600080fd5b82516001600160401b0381111561452757600080fd5b8301601f8101851361453857600080fd5b805161454381613b30565b6040516145508282613b04565b82815260059290921b830184019184810191508783111561457057600080fd5b928401925b82841015613bec57835161458881613a07565b82529284019290840190614575565b60006020808352600084546145ab81614342565b808487015260406001808416600081146145cc57600181146145e657614614565b60ff1985168984015283151560051b890183019550614614565b896000528660002060005b8581101561460c5781548b82018601529083019088016145f1565b8a0184019650505b509398975050505050505050565b600060033d111561463b5760046000803e5060005160e01c5b90565b600060443d101561464c5790565b6040516003193d81016004833e81513d6001600160401b03816024840111818411171561467b57505050505090565b82850191508151818111156146935750505050505090565b843d87010160208285010111156146ad5750505050505090565b6146bc60208286010187613b04565b509095945050505050565b7002bb4ba3732ba22b93937b939a634b11d1607d1b8152600082516146f38160118501602087016138e6565b9190910160110192915050565b60208082526029908201527f5769746e657452657175657374426f6172643a20756e617574686f72697a6564604082015268103932b837b93a32b960b91b606082015260800190565b60208082526042908201527f5769746e657452657175657374426f617264547275737461626c65446566617560408201527f6c743a205769746e65742064725478486173682063616e6e6f74206265207a65606082015261726f60f01b608082015260a00190565b6020808252603a908201527f5769746e657452657175657374426f617264547275737461626c65446566617560408201527f6c743a20726573756c742063616e6e6f7420626520656d707479000000000000606082015260800190565b6020808252602f90820152600080516020614b7b83398151915260408201526e2072657761726420746f6f206c6f7760881b606082015260800190565b80820180821115610c8a57610c8a6142b9565b60006020828403121561487057600080fd5b5051919050565b8082028115828204841417610c8a57610c8a6142b9565b601f821115612f1657600081815260208120601f850160051c810160208610156148b55750805b601f850160051c820191505b818110156148d4578281556001016148c1565b505050505050565b81516001600160401b038111156148f5576148f5613a8b565b614909816149038454614342565b8461488e565b602080601f83116001811461493e57600084156149265750858301515b600019600386901b1c1916600185901b1785556148d4565b600085815260208120601f198616915b8281101561496d5788860151825594840194600190910190840161494e565b508582101561498b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60208082526032908201527f5769746e65743a20747269656420746f206465636f64652076616c756520667260408201527137b69032b93937b932b2103932b9bab63a1760711b606082015260800190565b600082516149ff8184602087016138e6565b9190910192915050565b60008351614a1b8184602088016138e6565b835190830190614a2f8183602088016138e6565b01949350505050565b634e487b7160e01b600052600160045260246000fd5b81810381811115610c8a57610c8a6142b956fe5769746e657452657175657374426f6172643a206e6f7420696e2044656c65746564207374617475735769746e65744572726f72734c69623a20617373657274696f6e206661696c65645769746e657452657175657374426f6172643a206e6f7420696e20506f73746564207374617475734df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f5769746e657452657175657374426f617264547275737461626c65426173653a206e6f742079657420736f6c7665645769746e657452657175657374426f617264547275737461626c65426173653a20756e6b6e6f776e2071756572795769746e657452657175657374426f6172643a206e6f7420696e205265706f72746564207374617475735769746e657452657175657374426f617264547275737461626c65426173653aa6db7263983f337bae2c9fb315730227961d1c1153ae1e10a56b5791465dd6fda26469706673582212205afe0f5db767084abd2c77df81db387107cb0230a3996be72f017f76595cff9864736f6c634300081100330000000000000000000000001111111fde7dc956e3d7922bc779d9e2349afb630000000000000000000000000000000000000000000000000000000000000001302e372e31342d39386133373737000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c138

Deployed Bytecode

0x6080604052600436106102975760003560e01c8063754e5bea1161015a578063b545e2b3116100c1578063d4da69ac1161007a578063d4da69ac14610a79578063dc3c71cd14610aa6578063e30c397814610ac6578063e5a6b10f14610ae4578063e99e47f314610b18578063f2fde38b14610b38576102f6565b8063b545e2b3146109b0578063c2485ebd146109c3578063c45a0155146109f0578063c805dd0f14610a24578063c8f5cdd514610a39578063d2e8756114610a59576102f6565b80638da5cb5b116101135780638da5cb5b146108d057806399f65804146108e55780639d96fced14610912578063a9e954b914610932578063b20321b414610965578063b281a7bd1461099d576102f6565b8063754e5bea146107fa57806379ba5097146108275780637b1039991461083c5780637c1fbda3146108705780637d52e6501461089057806381a398b5146108b0576102f6565b80634c9f72e3116101fe5780636280bce8116101b75780636280bce81461075f57806366822a441461077f57806366bfdc75146107925780636b58960a146107a55780636f07abcc146107c5578063715018a6146107e5576102f6565b80634c9f72e31461065d5780635001f3b51461067d57806352d1902d146106c45780635479d940146106f857806354fd4d501461072b578063578d630514610740576102f6565b80632b68b9c6116102505780632b68b9c6146105805780633ae97295146105955780633b885f2a146105b55780633e1c2183146105e2578063439fab9114610610578063483377bf14610630576102f6565b806301ffc9a71461046a578063044ad7be1461049f5780631dd27daf146104e5578063200e83771461051357806320f9241e1461054057806328a78d9b14610560576102f6565b366102f65760405162461bcd60e51b81526020600482015260366024820152600080516020614b7b833981519152604482015275081b9bc81d1c985b9cd9995c9cc81858d8d95c1d195960521b60648201526084015b60405180910390fd5b34801561030257600080fd5b506001600160e01b031960003516635430260d60e11b81900361032d575063578d630560e01b6103a1565b6001600160e01b03196000351663cf62d11560e01b0361035557506307d52e6560e41b6103a1565b6001600160e01b03196000351663bc7e25ff60e01b0361037d5750632c80c86d60e21b6103a1565b6001600160e01b031960003516636ba401df60e11b036103a15750633e1c218360e01b5b6000356001600160e01b0319908116908216146103ee5760405130903660008237826001600160e01b038251161781526000803683855af43d806000843e8180156103ea578184f35b8184fd5b6103fc60003560f81c610b58565b61040d60ff60003560f01c16610b58565b61041e60ff60003560e81c16610b58565b61042f60ff60003560e01c16610b58565b604051602001610442949392919061390a565b60408051601f198184030181529082905262461bcd60e51b82526102ed916004016139ca565b005b34801561047657600080fd5b5061048a6104853660046139dd565b610c4a565b60405190151581526020015b60405180910390f35b3480156104ab57600080fd5b5061048a6104ba366004613a1c565b6001600160a01b03166000908152600080516020614b9b833981519152602052604090205460ff1690565b3480156104f157600080fd5b50610505610500366004613a39565b610c90565b604051908152602001610496565b34801561051f57600080fd5b5061053361052e366004613a39565b610d01565b6040516104969190613a78565b34801561054c57600080fd5b5061050561055b366004613a39565b610dd8565b34801561056c57600080fd5b5061046861057b366004613b53565b610e36565b34801561058c57600080fd5b50610468610ef7565b3480156105a157600080fd5b506105056105b0366004613a39565b610f02565b3480156105c157600080fd5b506105d56105d0366004613a39565b610f6f565b60405161049691906139ca565b3480156105ee57600080fd5b506106026105fd366004613cb2565b611129565b604051610496929190613e04565b34801561061c57600080fd5b5061046861062b366004613e24565b6111be565b34801561063c57600080fd5b5061065061064b366004613a39565b6113f2565b6040516104969190613e58565b34801561066957600080fd5b50610468610678366004613b53565b6115fd565b34801561068957600080fd5b507f000000000000000000000000ca9e7861643febcea7c657ea8f012645d6accec45b6040516001600160a01b039091168152602001610496565b3480156106d057600080fd5b506105057f9969c6aff411c5e5f0807500693e8f819ce88529615cfa6cab569b24788a101881565b34801561070457600080fd5b507f000000000000000000000000000000000000000000000000000000000000000161048a565b34801561073757600080fd5b506105d56116b3565b34801561074c57600080fd5b5061048a61075b366004613cb2565b5190565b34801561076b57600080fd5b5061046861077a366004613ecc565b6116e3565b61050561078d366004613f1e565b611832565b6104686107a0366004613a39565b611928565b3480156107b157600080fd5b5061048a6107c0366004613a1c565b6119e1565b3480156107d157600080fd5b506105336107e0366004613a39565b611a3f565b3480156107f157600080fd5b50610468611a4a565b34801561080657600080fd5b5061081a610815366004613a39565b611a5e565b6040516104969190613f7b565b34801561083357600080fd5b50610468611ba1565b34801561084857600080fd5b506106ac7f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc881565b34801561087c57600080fd5b5061081a61088b366004613a39565b611c1b565b34801561089c57600080fd5b506105056108ab366004613cb2565b611e93565b3480156108bc57600080fd5b506104686108cb366004613f8e565b611e9e565b3480156108dc57600080fd5b506106ac612190565b3480156108f157600080fd5b50610905610900366004613a39565b6121ac565b60405161049691906140ac565b34801561091e57600080fd5b506106ac61092d366004613a39565b612271565b34801561093e57600080fd5b507fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470610505565b34801561097157600080fd5b50610985610980366004613cb2565b6122d5565b6040516001600160401b039091168152602001610496565b6105056109ab366004613a1c565b6122e0565b6105056109be3660046140ea565b6124a7565b3480156109cf57600080fd5b506109e36109de366004613a39565b612563565b6040516104969190614122565b3480156109fc57600080fd5b506106ac7f0000000000000000000000001111111fde7dc956e3d7922bc779d9e2349afb6381565b348015610a3057600080fd5b5061050561271b565b348015610a4557600080fd5b50610468610a543660046141a2565b612734565b348015610a6557600080fd5b50610505610a74366004613a39565b6128e9565b348015610a8557600080fd5b50610a99610a94366004613a39565b612915565b6040516104969190614202565b348015610ab257600080fd5b50610505610ac1366004613a39565b612a0f565b348015610ad257600080fd5b506001546001600160a01b03166106ac565b348015610af057600080fd5b506106ac7f000000000000000000000000000000000000000000000000000000000000000081565b348015610b2457600080fd5b50610a99610b33366004613e24565b612a6d565b348015610b4457600080fd5b50610468610b53366004613a1c565b612a7e565b604080516002808252818301909252606091600091906020820181803683370190505090506000610b8a6010856142cf565b610b959060306142f1565b90506000610ba460108661430a565b610baf9060306142f1565b905060398260ff161115610bcb57610bc86007836142f1565b91505b60398160ff161115610be557610be26007826142f1565b90505b8160f81b83600081518110610bfc57610bfc61432c565b60200101906001600160f81b031916908160001a9053508060f81b83600181518110610c2a57610c2a61432c565b60200101906001600160f81b031916908160001a90535091949350505050565b60006001600160e01b03198216632fd28e3360e21b1480610c7b57506001600160e01b03198216633039146360e11b145b80610c8a5750610c8a82612b53565b92915050565b600081600180610c9f83612ba3565b6003811115610cb057610cb0613a52565b14610cba82612c0e565b90610cd85760405162461bcd60e51b81526004016102ed91906139ca565b50610ce1612cf6565b6000858152600391909101602052604090206004015492505b5050919050565b600080610d0d83612ba3565b90506002816003811115610d2357610d23613a52565b03610da7576000610d3384612d1a565b6003018054909150601b60fb1b908290600090610d4f90614342565b8110610d5d57610d5d61432c565b815460011615610d7c5790600052602060002090602091828204019190065b9054901a600160f81b026001600160f81b03191614610d9c576002610d9f565b60035b949350505050565b6001816003811115610dbb57610dbb613a52565b03610dc95750600192915050565b50600092915050565b50919050565b600081600280610de783612ba3565b6003811115610df857610df8613a52565b14610e0282612c0e565b90610e205760405162461bcd60e51b81526004016102ed91906139ca565b50610e2a84612d1a565b60010154949350505050565b610e3e612d3a565b60005b8151811015610ebc576000828281518110610e5e57610e5e61432c565b602002602001015190506000610e7f600080516020614b9b83398151915290565b6001600160a01b039290921660009081526020929092526040909120805460ff191691151591909117905580610eb481614376565b915050610e41565b507f646436560d9757cb3c0f01da0f62642c6040b00c9a80685f94ef1a7725cad5f181604051610eec919061438f565b60405180910390a150565b610eff612d3a565b33ff5b600081600180610f1183612ba3565b6003811115610f2257610f22613a52565b14610f2c82612c0e565b90610f4a5760405162461bcd60e51b81526004016102ed91906139ca565b50610f53612cf6565b6000858152600391820160205260409020015492505050919050565b60606000610f7c83612ba3565b6003811115610f8d57610f8d613a52565b03610fe05760405162461bcd60e51b815260206004820152602f6024820152600080516020614b7b83398151915260448201526e081b9bdd081e595d081c1bdcdd1959608a1b60648201526084016102ed565b6000610feb83612d99565b80549091506001600160a01b0316156110765780546040805163784a000160e11b815290516001600160a01b039092169163f0940002916004808201926000929091908290030181865afa158015611047573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261106f9190810190614417565b9150610dd2565b600281015415610dd25760028101546001820154604051630565c45f60e31b81526001600160a01b037f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc81692632b2e22f8926110dd92600401918252602082015260400190565b600060405180830381865afa1580156110fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111229190810190614417565b9392505050565b600060606000732163dbcbdbbec066ef8d8adab75af8b0b9a5cfaa63059c737f856040518263ffffffff1660e01b81526004016111669190614202565b600060405180830381865af4158015611183573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111ab919081019061445f565b8051602090910151909590945092505050565b60006111c8612cf6565b600101546001600160a01b031690508061120d575033806111e7612cf6565b60010180546001600160a01b0319166001600160a01b0392909216919091179055611267565b336001600160a01b038216146112675760405162461bcd60e51b815260206004820152602b6024820152600080516020614b7b83398151915260448201526a1037b7363c9037bbb732b960a91b60648201526084016102ed565b6000611271612cf6565b546001600160a01b031614611311577f000000000000000000000000ca9e7861643febcea7c657ea8f012645d6accec46001600160a01b03166112b2612cf6565b546001600160a01b0316036113115760405162461bcd60e51b81526020600482015260316024820152600080516020614b7b83398151915260448201527008185b1c9958591e481d5c19dc98591959607a1b60648201526084016102ed565b7f000000000000000000000000ca9e7861643febcea7c657ea8f012645d6accec461133a612cf6565b80546001600160a01b0319166001600160a01b039283161790557fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470907f000000000000000000000000ca9e7861643febcea7c657ea8f012645d6accec416337fe73e754121f0bad1327816970101955bfffdf53d270ac509d777c25be070d7f66113c26116b3565b6040516113cf91906139ca565b60405180910390a46113ee8280602001905181019061067891906144fe565b5050565b604080518082019091526000815260606020820152600061141283610d01565b9050600181600381111561142857611428613a52565b03611461576040805180820190915280600081526020016040518060600160405280602f8152602001614af4602f913990529392505050565b600081600381111561147557611475613a52565b036114ae576040805180820190915280600081526020016040518060600160405280602e8152602001614b23602e913990529392505050565b732163dbcbdbbec066ef8d8adab75af8b0b9a5cfaa637e1a92b76114d185612d1a565b6003016040518263ffffffff1660e01b81526004016114f09190614597565b600060405180830381865af492505050801561152e57506040513d6000823e601f3d908101601f1916820160405261152b919081019061445f565b60015b6111225761153a614622565b806308c379a003611596575061154e61463e565b806115595750611598565b6040805180820190915280600081526020018260405160200161157c91906146c7565b60408051601f198184030181529190529052949350505050565b505b3d8080156115c2576040519150601f19603f3d011682016040523d82523d6000602084013e6115c7565b606091505b50604080518082019091528060008152602001604051806060016040528060218152602001614a8b602191399052949350505050565b611605612d3a565b60005b81518110156116835760008282815181106116255761162561432c565b602002602001015190506001611646600080516020614b9b83398151915290565b6001600160a01b039290921660009081526020929092526040909120805460ff19169115159190911790558061167b81614376565b915050611608565b507f4d570ee36dec878006609360d34ac8d6a0b68d521871ae15a407b6340877ca0181604051610eec919061438f565b60606116de7f302e372e31342d39386133373737000000000000000000000000000000000000612db6565b905090565b336000908152600080516020614b9b833981519152602052604090205460ff1661171f5760405162461bcd60e51b81526004016102ed90614700565b8360018061172c83612ba3565b600381111561173d5761173d613a52565b1461174782612c0e565b906117655760405162461bcd60e51b81526004016102ed91906139ca565b5060008590036117875760405162461bcd60e51b81526004016102ed90614749565b60008390036117a85760405162461bcd60e51b81526004016102ed906147b1565b6117f3336117ee88428989898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612e6192505050565b612ee0565b604080518781523360208201527ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a1505050505050565b6000343a82611840826128e9565b9050808310156118625760405162461bcd60e51b81526004016102ed9061480e565b61186a612cf6565b6002016000815461187a90614376565b918290555093503361188a612cf6565b60008681526003919091016020526040812060090180546001600160a01b0319166001600160a01b0393909316929092179091556118c785612d99565b60028101889055600181018790556003810184905560048101859055604080518781523360208201529192507fcabaf9c102f83746b27ae932f638eebfaf5ea7d014edd20ab14dec3768a8f55c910160405180910390a15050505092915050565b8060018061193583612ba3565b600381111561194657611946613a52565b1461195082612c0e565b9061196e5760405162461bcd60e51b81526004016102ed91906139ca565b50600061197a84612d99565b9050600034826004015461198e919061484b565b60038301549091503a908111156119d55760006119aa826128e9565b9050808310156119cc5760405162461bcd60e51b81526004016102ed9061480e565b50600383018190555b50600490910155505050565b6000806119ec612cf6565b600101546001600160a01b031690507f000000000000000000000000000000000000000000000000000000000000000180156111225750826001600160a01b0316816001600160a01b0316149392505050565b6000610c8a82612ba3565b611a52612d3a565b611a5c6000612f1b565b565b604080516080810182526000808252602082018190529181019190915260608082015281600280611a8e83612ba3565b6003811115611a9f57611a9f613a52565b14611aa982612c0e565b90611ac75760405162461bcd60e51b81526004016102ed91906139ca565b50611ad184612d1a565b6040805160808101825282546001600160a01b0316815260018301546020820152600283015491810191909152600382018054919291606084019190611b1690614342565b80601f0160208091040260200160405190810160405280929190818152602001828054611b4290614342565b8015611b8f5780601f10611b6457610100808354040283529160200191611b8f565b820191906000526020600020905b815481529060010190602001808311611b7257829003601f168201915b50505050508152505092505050919050565b60015433906001600160a01b03168114611c0f5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b60648201526084016102ed565b611c1881612f1b565b50565b604080516080810182526000808252602082018190529181019190915260608082015281600280611c4b83612ba3565b6003811115611c5c57611c5c613a52565b14611c6682612c0e565b90611c845760405162461bcd60e51b81526004016102ed91906139ca565b506000611c8f612cf6565b60008681526003919091016020526040902060098101549091506001600160a01b03163314611d065760405162461bcd60e51b815260206004820152602f6024820152600080516020614b7b83398151915260448201526e1037b7363c903932b8bab2b9ba32b960891b60648201526084016102ed565b604080516080810182526005830180546001600160a01b0316825260068401546020830152600784015492820192909252600883018054919291606084019190611d4f90614342565b80601f0160208091040260200160405190810160405280929190818152602001828054611d7b90614342565b8015611dc85780601f10611d9d57610100808354040283529160200191611dc8565b820191906000526020600020905b815481529060010190602001808311611dab57829003601f168201915b5050505050815250509350611ddb612cf6565b600086815260039182016020526040812080546001600160a01b03199081168255600182018390556002820183905592810182905560048101829055600581018054909316835560068101829055600781018290559181611e3f600885018261382b565b50505060090180546001600160a01b0319169055604080518681523360208201527fdec847db058c9c012e0f3dbe2b99e05cfa4c693f61a7d8bc64652a68913cbfff910160405180910390a1505050919050565b6000610c8a82612f34565b336000908152600080516020614b9b833981519152602052604090205460ff16611eda5760405162461bcd60e51b81526004016102ed90614700565b8151600090815b81811015612179576000858281518110611efd57611efd61432c565b6020026020010151905060016003811115611f1a57611f1a613a52565b8151611f2590612ba3565b6003811115611f3657611f36613a52565b14611fa2578415611f9d5780516040805191825260208201819052602c90820152600080516020614b7b83398151915260608201526b08189859081c5d595c9e525960a21b6080820152600080516020614ad48339815191529060a0015b60405180910390a15b612166565b604081015160000361200c578415611f9d5780516040805191825260208201819052602d90820152600080516020614b7b83398151915260608201526c040c4c2c840c8e4a8f090c2e6d609b1b6080820152600080516020614ad48339815191529060a001611f94565b806060015151600003612078578415611f9d5780516040805191825260208201819052602e90820152600080516020614b7b83398151915260608201526d206261642063626f72427974657360901b6080820152600080516020614ad48339815191529060a001611f94565b6000816020015111801561208f5750428160200151115b156120f3578415611f9d5780516040805191825260208201819052602e90820152600080516020614b7b83398151915260608201526d0206261642074696d657374616d760941b6080820152600080516020614ad48339815191529060a001611f94565b8051602082015161211f91901561210e578260200151612110565b425b83604001518460600151612e61565b612129908561484b565b8151604080519182523360208301529195507ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a15b508061217181614376565b915050611ee1565b50811561218a5761218a3383612ee0565b50505050565b600061219a612cf6565b600101546001600160a01b0316919050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152816001806121e483612ba3565b60038111156121f5576121f5613a52565b146121ff82612c0e565b9061221d5760405162461bcd60e51b81526004016102ed91906139ca565b5061222784612d99565b6040805160a08101825282546001600160a01b0316815260018301546020820152600283015491810191909152600382015460608201526004909101546080820152949350505050565b60008160028061228083612ba3565b600381111561229157612291613a52565b1461229b82612c0e565b906122b95760405162461bcd60e51b81526004016102ed91906139ca565b506122c384612d1a565b546001600160a01b0316949350505050565b6000610c8a82612f69565b6000343a826122ee826128e9565b9050808310156123105760405162461bcd60e51b81526004016102ed9061480e565b6000801b856001600160a01b03166309bd5a606040518163ffffffff1660e01b8152600401602060405180830381865afa158015612352573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612376919061485e565b036123d75760405162461bcd60e51b81526020600482015260376024820152600080516020614b7b83398151915260448201527f206e6f20707265636f6d70696c6564207265717565737400000000000000000060648201526084016102ed565b6123df612cf6565b600201600081546123ef90614376565b91829055509350336123ff612cf6565b60008681526003919091016020526040812060090180546001600160a01b0319166001600160a01b03939093169290921790915561243c85612d99565b80546001600160a01b0319166001600160a01b0388161781556003810184905560048101859055604080518781523360208201529192507fcabaf9c102f83746b27ae932f638eebfaf5ea7d014edd20ab14dec3768a8f55c910160405180910390a150505050919050565b60408051638fadabeb60e01b8152823560048201526020830135602482015290820135604482015260608201356064820152608082013560848201526000906111229084906001600160a01b037f0000000000000000000000000000000e3a3d22d7510b36bdc88994dab11eadc81690638fadabeb9060a4016020604051808303816000875af115801561253f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078d919061485e565b6125cd6040805161010081019091526000606082018181526080830182905260a0830182905260c0830182905260e0830191909152819081526040805160808101825260008082526020828101829052928201526060808201529101908152600060209091015290565b6125d5612cf6565b60008381526003918201602090815260409182902082516101008101845281546001600160a01b0390811660608084019182526001850154608080860191909152600286015460a08601529785015460c0850152600485015460e0850152908352855196870186526005840180549092168752600684015487860152600784015495870195909552600883018054929693959487019491929184019161267a90614342565b80601f01602080910402602001604051908101604052809291908181526020018280546126a690614342565b80156126f35780601f106126c8576101008083540402835291602001916126f3565b820191906000526020600020905b8154815290600101906020018083116126d657829003601f168201915b505050919092525050508152600991909101546001600160a01b031660209091015292915050565b6000612725612cf6565b600201546116de90600161484b565b336000908152600080516020614b9b833981519152602052604090205460ff166127705760405162461bcd60e51b81526004016102ed90614700565b8460018061277d83612ba3565b600381111561278e5761278e613a52565b1461279882612c0e565b906127b65760405162461bcd60e51b81526004016102ed91906139ca565b50428611156128215760405162461bcd60e51b815260206004820152603160248201527f5769746e657452657175657374426f617264547275737461626c65446566617560448201527006c743a206261642074696d657374616d7607c1b60648201526084016102ed565b60008590036128425760405162461bcd60e51b81526004016102ed90614749565b60008390036128635760405162461bcd60e51b81526004016102ed906147b1565b6128a9336117ee89898989898080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612e6192505050565b604080518881523360208201527ee9413c6321ec446a267b7ebf5bb108663f2ef58b35c4f6e18905ac8f205cb2910160405180910390a150505050505050565b6000610c8a7f000000000000000000000000000000000000000000000000000000000001c13883614877565b61291d613865565b8160028061292a83612ba3565b600381111561293b5761293b613a52565b1461294582612c0e565b906129635760405162461bcd60e51b81526004016102ed91906139ca565b50600061296f85612d1a565b9050612a0681600301805461298390614342565b80601f01602080910402602001604051908101604052809291908181526020018280546129af90614342565b80156129fc5780601f106129d1576101008083540402835291602001916129fc565b820191906000526020600020905b8154815290600101906020018083116129df57829003601f168201915b5050505050612f9a565b95945050505050565b600081600280612a1e83612ba3565b6003811115612a2f57612a2f613a52565b14612a3982612c0e565b90612a575760405162461bcd60e51b81526004016102ed91906139ca565b50612a6184612d1a565b60020154949350505050565b612a75613865565b610c8a82612f9a565b612a86612d3a565b6000612a90612cf6565b600101546001600160a01b039081169150821681146113ee5781612ab2612cf6565b60010180546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006001600160e01b03198216631a12e29960e21b1480612b8457506001600160e01b0319821663d1ab0e8760e01b145b80610c8a57506301ffc9a760e01b6001600160e01b0319831614610c8a565b600080612bae612cf6565b600084815260039190910160205260409020600781015490915015612bd65750600292915050565b60098101546001600160a01b031615612bf25750600192915050565b612bfa612cf6565b60020154831115610dc95750600392915050565b60606001826003811115612c2457612c24613a52565b03612c4857604051806060016040528060288152602001614aac6028913992915050565b6002826003811115612c5c57612c5c613a52565b03612c80576040518060600160405280602a8152602001614b51602a913992915050565b6003826003811115612c9457612c94613a52565b03612cb857604051806060016040528060298152602001614a626029913992915050565b505060408051808201909152601c81527f5769746e657452657175657374426f6172643a20626164206d6f6f6400000000602082015290565b919050565b7ff595240b351bc8f951c2f53b26f4e78c32cb62122cf76c19b7fdda7d4968e18390565b6000612d24612cf6565b6000928352600301602052506040902060050190565b33612d43612190565b6001600160a01b031614611a5c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016102ed565b6000612da3612cf6565b6000928352600301602052506040902090565b60606000612dc383612fb8565b6001600160401b03811115612dda57612dda613a8b565b6040519080825280601f01601f191660200182016040528015612e04576020820181803683370190505b50905060005b8151811015612e5a57838160208110612e2557612e2561432c565b1a60f81b828281518110612e3b57612e3b61432c565b60200101906001600160f81b031916908160001a905350600101612e0a565b5092915050565b600080612e6d86612d99565b60068101869055600781018590556005810180546001600160a01b03191633178155909150819060088201612ea286826148dc565b505060049081015482546001600160a01b03191683556000600184018190556002840181905560038401819055929091019190915595945050505050565b6040516001600160a01b0383169082156108fc029083906000818181858888f19350505050158015612f16573d6000803e3d6000fd5b505050565b600180546001600160a01b0319169055611c1881612b03565b6000818060000151612f585760405162461bcd60e51b81526004016102ed9061499b565b611122612f6484612ff1565b613022565b6000818060000151612f8d5760405162461bcd60e51b81526004016102ed9061499b565b611122836020015161302f565b612fa2613865565b6000612fad83613092565b9050611122816130b7565b60005b6020811015612cf157818160208110612fd657612fd661432c565b1a60f81b6001600160f81b03191615612cf157600101612fbb565b60608180600001516130155760405162461bcd60e51b81526004016102ed9061499b565b61112283602001516130eb565b6000610c8a826020613235565b60008160008060ff16826040015160ff161461306f57604080830151905161800560e51b815260ff918216600482015290821660248201526044016102ed565b613081846000015185606001516132ad565b6001600160401b0316949350505050565b61309a613886565b604080518082019091528281526000602082015261112281613375565b6130bf613865565b5060a0810151604080518082019091526001600160401b03909116602714158152602081019190915290565b60608160028060ff16826040015160ff161461312b57604080830151905161800560e51b815260ff918216600482015290821660248201526044016102ed565b61313d846000015185606001516132ad565b6001600160401b03166080850181905263fffffffe190161321457600061316c85600001518660400151613495565b905063ffffffff808216101561320e5784516131919063ffffffff8084169061353b16565b6040516020016131a191906149ed565b60405160208183030381529060405293506131c485600001518660400151613495565b905063ffffffff808216101561320e57845184906131eb9063ffffffff8085169061353b16565b6040516020016131fc929190614a09565b60405160208183030381529060405293505b50610cfa565b6080840151845161322e9163ffffffff9081169061353b16565b9250610cfa565b600060208260ff16111561324b5761324b614a38565b60008260ff1684511161325f578351613264565b8260ff165b905060005b818110156132a557806008028582815181106132875761328761432c565b01602001516001600160f81b031916901c9290921791600101613269565b505092915050565b600060188260ff1610156132c5575060ff8116610c8a565b8160ff166018036132e3576132d9836135fb565b60ff169050610c8a565b8160ff16601903613302576132f78361365d565b61ffff169050610c8a565b8160ff16601a0361332357613316836136c9565b63ffffffff169050610c8a565b8160ff16601b0361333e5761333783613728565b9050610c8a565b8160ff16601f0361335757506001600160401b03610c8a565b604051636d785b1360e01b815260ff831660048201526024016102ed565b61337d613886565b81515182906000036133a2576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015613425576133c2896135fb565b9550816133ce81614376565b6007600589901c169650601f88169550925050600519850161341d5760208901516133f98a866132ad565b9350808a6020015161340b9190614a4e565b613415908461484b565b9250506133b3565b5060006133b3565b600760ff8616111561344f5760405163bd2ac87960e01b815260ff861660048201526024016102ed565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b6000806134a1846135fb565b90508060ff1660ff036134be576001600160401b03915050610c8a565b6134cb8482601f166132ad565b91506001600160401b038083161061350157604051636d785b1360e01b81526001600160401b03831660048201526024016102ed565b60ff83166007600583901c1614612e5a5760405161800560e51b81526007600583901c16600482015260ff841660248201526044016102ed565b606081836020015161354d919061484b565b8351518082111561357b576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b836001600160401b0381111561359357613593613a8b565b6040519080825280601f01601f1916602001820160405280156135bd576020820181803683370190505b50925083156132a55784516020808701519081830181019086016135e281838a613787565b6135ee898960016137cb565b5050505050505092915050565b6000816020015182600001515180821115613633576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b835160208501805180830160010151955090819061365082614376565b8152505050505050919050565b600081602001516002613670919061484b565b8251518082111561369e576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516002818401810151965090916136bc828461484b565b9052509395945050505050565b6000816020015160046136dc919061484b565b8251518082111561370a576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516004818401810151965090916136bc828461484b565b60008160200151600861373b919061484b565b82515180821115613769576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b83516020850180516008818401810151965090916136bc828461484b565b5b602081106137a7578151835260209283019290910190601f1901613788565b8015612f1657905182516020929092036101000a6000190180199091169116179052565b600082846000015151808211156137ff576040516363a056dd60e01b815260048101839052602481018290526044016102ed565b8315613817576020860151613814908661484b565b94505b602086018590528492505b50509392505050565b50805461383790614342565b6000825580601f10613847575050565b601f016020900490600052602060002090810190611c1891906138cd565b6040518060400160405280600015158152602001613881613886565b905290565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b5b808211156138e257600081556001016138ce565b5090565b60005b838110156139015781810151838201526020016138e9565b50506000910152565b600080516020614b7b833981519152815273040dcdee840d2dae0d8cadacadce8cac8744060f60631b60208201526000855161394d816034850160208a016138e6565b855190830190613964816034840160208a016138e6565b855191019061397a8160348401602089016138e6565b84519101906139908160348401602088016138e6565b016034019695505050505050565b600081518084526139b68160208601602086016138e6565b601f01601f19169290920160200192915050565b602081526000611122602083018461399e565b6000602082840312156139ef57600080fd5b81356001600160e01b03198116811461112257600080fd5b6001600160a01b0381168114611c1857600080fd5b600060208284031215613a2e57600080fd5b813561112281613a07565b600060208284031215613a4b57600080fd5b5035919050565b634e487b7160e01b600052602160045260246000fd5b60048110611c1857611c18613a52565b60208101613a8583613a68565b91905290565b634e487b7160e01b600052604160045260246000fd5b604081018181106001600160401b0382111715613ac057613ac0613a8b565b60405250565b60c081018181106001600160401b0382111715613ac057613ac0613a8b565b608081018181106001600160401b0382111715613ac057613ac0613a8b565b601f8201601f191681016001600160401b0381118282101715613b2957613b29613a8b565b6040525050565b60006001600160401b03821115613b4957613b49613a8b565b5060051b60200190565b60006020808385031215613b6657600080fd5b82356001600160401b03811115613b7c57600080fd5b8301601f81018513613b8d57600080fd5b8035613b9881613b30565b604051613ba58282613b04565b82815260059290921b8301840191848101915087831115613bc557600080fd5b928401925b82841015613bec578335613bdd81613a07565b82529284019290840190613bca565b979650505050505050565b80358015158114612cf157600080fd5b60006001600160401b03821115613c2057613c20613a8b565b50601f01601f191660200190565b600082601f830112613c3f57600080fd5b8135613c4a81613c07565b604051613c578282613b04565b828152856020848701011115613c6c57600080fd5b82602086016020830137600092810160200192909252509392505050565b803560ff81168114612cf157600080fd5b80356001600160401b0381168114612cf157600080fd5b60006020808385031215613cc557600080fd5b82356001600160401b0380821115613cdc57600080fd5b81850191506040808388031215613cf257600080fd5b8051613cfd81613aa1565b613d0684613bf7565b81528484013583811115613d1957600080fd5b939093019260c08489031215613d2e57600080fd5b8151613d3981613ac6565b843584811115613d4857600080fd5b8501808a03841315613d5957600080fd5b8351613d6481613aa1565b813586811115613d7357600080fd5b613d7f8c828501613c2e565b82525090870135878201528152613d97858701613c8a565b86820152613da6838601613c8a565b83820152613db660608601613c8a565b6060820152613dc760808601613c9b565b6080820152613dd860a08601613c9b565b60a082015294810194909452509195945050505050565b6101008110613e0057613e00613a52565b9052565b613e0e8184613def565b604060208201526000610d9f604083018461399e565b600060208284031215613e3657600080fd5b81356001600160401b03811115613e4c57600080fd5b610d9f84828501613c2e565b60208152613e6a602082018351613def565b60006020830151604080840152610d9f606084018261399e565b60008083601f840112613e9657600080fd5b5081356001600160401b03811115613ead57600080fd5b602083019150836020828501011115613ec557600080fd5b9250929050565b60008060008060608587031215613ee257600080fd5b843593506020850135925060408501356001600160401b03811115613f0657600080fd5b613f1287828801613e84565b95989497509550505050565b60008060408385031215613f3157600080fd5b50508035926020909101359150565b60018060a01b03815116825260208101516020830152604081015160408301526000606082015160806060850152610d9f608085018261399e565b6020815260006111226020830184613f40565b6000806040808486031215613fa257600080fd5b83356001600160401b0380821115613fb957600080fd5b818601915086601f830112613fcd57600080fd5b81356020613fda82613b30565b8551613fe68282613b04565b83815260059390931b850182019282810191508a84111561400657600080fd5b8286015b8481101561408e5780358681111561402157600080fd5b87016080818e03601f1901121561403757600080fd5b885161404281613ae5565b858201358152898201358682015260608201358a82015260808201358881111561406c5760008081fd5b61407a8f8883860101613c2e565b60608301525084525091830191830161400a565b50975061409e9050888201613bf7565b955050505050509250929050565b81516001600160a01b031681526020808301519082015260408083015190820152606080830151908201526080808301519082015260a08101610c8a565b60008082840360c08112156140fe57600080fd5b8335925060a0601f198201121561411457600080fd5b506020830190509250929050565b6020815261416560208201835180516001600160a01b03168252602080820151908301526040808201519083015260608082015190830152608090810151910152565b6000602083015160e060c0840152614181610100840182613f40565b604094909401516001600160a01b031660e093909301929092525090919050565b6000806000806000608086880312156141ba57600080fd5b85359450602086013593506040860135925060608601356001600160401b038111156141e557600080fd5b6141f188828901613e84565b969995985093965092949392505050565b6020815281511515602082015260006020830151604080840152805160c060608501528051604061012086015261423d61016086018261399e565b6020928301516101408701529183015160ff1660808601525060408201519061426b60a086018360ff169052565b606083015160ff1660c086015260808301516001600160401b0380821660e088015260a0909401519384166101008701529150612a06565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060ff8316806142e2576142e26142a3565b8060ff84160491505092915050565b60ff8181168382160190811115610c8a57610c8a6142b9565b600060ff83168061431d5761431d6142a3565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b600181811c9082168061435657607f821691505b602082108103610dd257634e487b7160e01b600052602260045260246000fd5b600060018201614388576143886142b9565b5060010190565b6020808252825182820181905260009190848201906040850190845b818110156143d05783516001600160a01b0316835292840192918401916001016143ab565b50909695505050505050565b60006143e783613c07565b6040516143f48282613b04565b80925084815285858501111561440957600080fd5b6138228560208301866138e6565b60006020828403121561442957600080fd5b81516001600160401b0381111561443f57600080fd5b8201601f8101841361445057600080fd5b610d9f848251602084016143dc565b60006020828403121561447157600080fd5b81516001600160401b038082111561448857600080fd5b908301906040828603121561449c57600080fd5b6040516144a881613aa1565b825161010081106144b857600080fd5b81526020830151828111156144cc57600080fd5b80840193505085601f8401126144e157600080fd5b6144f0868451602086016143dc565b602082015295945050505050565b6000602080838503121561451157600080fd5b82516001600160401b0381111561452757600080fd5b8301601f8101851361453857600080fd5b805161454381613b30565b6040516145508282613b04565b82815260059290921b830184019184810191508783111561457057600080fd5b928401925b82841015613bec57835161458881613a07565b82529284019290840190614575565b60006020808352600084546145ab81614342565b808487015260406001808416600081146145cc57600181146145e657614614565b60ff1985168984015283151560051b890183019550614614565b896000528660002060005b8581101561460c5781548b82018601529083019088016145f1565b8a0184019650505b509398975050505050505050565b600060033d111561463b5760046000803e5060005160e01c5b90565b600060443d101561464c5790565b6040516003193d81016004833e81513d6001600160401b03816024840111818411171561467b57505050505090565b82850191508151818111156146935750505050505090565b843d87010160208285010111156146ad5750505050505090565b6146bc60208286010187613b04565b509095945050505050565b7002bb4ba3732ba22b93937b939a634b11d1607d1b8152600082516146f38160118501602087016138e6565b9190910160110192915050565b60208082526029908201527f5769746e657452657175657374426f6172643a20756e617574686f72697a6564604082015268103932b837b93a32b960b91b606082015260800190565b60208082526042908201527f5769746e657452657175657374426f617264547275737461626c65446566617560408201527f6c743a205769746e65742064725478486173682063616e6e6f74206265207a65606082015261726f60f01b608082015260a00190565b6020808252603a908201527f5769746e657452657175657374426f617264547275737461626c65446566617560408201527f6c743a20726573756c742063616e6e6f7420626520656d707479000000000000606082015260800190565b6020808252602f90820152600080516020614b7b83398151915260408201526e2072657761726420746f6f206c6f7760881b606082015260800190565b80820180821115610c8a57610c8a6142b9565b60006020828403121561487057600080fd5b5051919050565b8082028115828204841417610c8a57610c8a6142b9565b601f821115612f1657600081815260208120601f850160051c810160208610156148b55750805b601f850160051c820191505b818110156148d4578281556001016148c1565b505050505050565b81516001600160401b038111156148f5576148f5613a8b565b614909816149038454614342565b8461488e565b602080601f83116001811461493e57600084156149265750858301515b600019600386901b1c1916600185901b1785556148d4565b600085815260208120601f198616915b8281101561496d5788860151825594840194600190910190840161494e565b508582101561498b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60208082526032908201527f5769746e65743a20747269656420746f206465636f64652076616c756520667260408201527137b69032b93937b932b2103932b9bab63a1760711b606082015260800190565b600082516149ff8184602087016138e6565b9190910192915050565b60008351614a1b8184602088016138e6565b835190830190614a2f8183602088016138e6565b01949350505050565b634e487b7160e01b600052600160045260246000fd5b81810381811115610c8a57610c8a6142b956fe5769746e657452657175657374426f6172643a206e6f7420696e2044656c65746564207374617475735769746e65744572726f72734c69623a20617373657274696f6e206661696c65645769746e657452657175657374426f6172643a206e6f7420696e20506f73746564207374617475734df64445edc775fba59db44b8001852fb1b777eea88fd54f04572dd114e3ff7f5769746e657452657175657374426f617264547275737461626c65426173653a206e6f742079657420736f6c7665645769746e657452657175657374426f617264547275737461626c65426173653a20756e6b6e6f776e2071756572795769746e657452657175657374426f6172643a206e6f7420696e205265706f72746564207374617475735769746e657452657175657374426f617264547275737461626c65426173653aa6db7263983f337bae2c9fb315730227961d1c1153ae1e10a56b5791465dd6fda26469706673582212205afe0f5db767084abd2c77df81db387107cb0230a3996be72f017f76595cff9864736f6c63430008110033

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

0000000000000000000000001111111fde7dc956e3d7922bc779d9e2349afb630000000000000000000000000000000000000000000000000000000000000001302e372e31342d39386133373737000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c138

-----Decoded View---------------
Arg [0] : _factory (address): 0x1111111FDE7dC956E3d7922Bc779D9E2349Afb63
Arg [1] : _upgradable (bool): True
Arg [2] : _versionTag (bytes32): 0x302e372e31342d39386133373737000000000000000000000000000000000000
Arg [3] : _reportResultGasLimit (uint256): 115000

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000001111111fde7dc956e3d7922bc779d9e2349afb63
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [2] : 302e372e31342d39386133373737000000000000000000000000000000000000
Arg [3] : 000000000000000000000000000000000000000000000000000000000001c138


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ 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.