false
false

Contract Address Details

0x1ebD93231a7fE551E1d6405404Df34909eff4c2C

Contract Name
WitnetRandomness
Creator
0x102cb4–8586da at 0xa468d1–792fb6
Balance
0 KCS
Tokens
Fetching tokens...
Transactions
2 Transactions
Transfers
0 Transfers
Gas Used
498,258
Last Balance Update
36595719
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
WitnetRandomness




Optimization enabled
true
Compiler version
v0.8.11+commit.d7f03943




Optimization runs
200
EVM Version
default




Verified at
2022-01-04T15:46:30.975429Z

Constructor Arguments

5769746e6574526571756573744d616c6c6561626c65426173653a207769746e375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba7375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba8000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a

Arg [0] (address) : 0x744d616c6c6561626c65426173653a207769746e

              

Contract source code

// SPDX-License-Identifier: MIT


pragma solidity >=0.7.0 <0.9.0;

pragma experimental ABIEncoderV2;

// File: contracts\interfaces\IWitnetRequestBoardEvents.sol
/// @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: contracts\interfaces\IWitnetRequestBoardReporter.sol
/// @title The Witnet Request Board Reporter interface.
/// @author The Witnet Foundation.
interface 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 _result The result itself as bytes.
    function reportResult(uint256 _queryId, bytes32 _drTxHash, bytes calldata _result) external;

    /// 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 _result The result itself as bytes.
    function reportResult(uint256 _queryId, uint256 _timestamp, bytes32 _drTxHash, bytes calldata _result) external;
}
// File: contracts\interfaces\IWitnetRequest.sol
/// @title The Witnet Data Request basic interface.
/// @author The Witnet Foundation.
interface IWitnetRequest {
    /// A `IWitnetRequest` is constructed around a `bytes` value containing 
    /// a well-formed Witnet Data Request using Protocol Buffers.
    function bytecode() external view returns (bytes memory);

    /// Returns SHA256 hash of Witnet Data Request as CBOR-encoded bytes.
    function hash() external view returns (bytes32);
}
// File: contracts\libs\Witnet.sol
library Witnet {

    /// @notice Witnet function that computes the hash of a CBOR-encoded Data Request.
    /// @param _bytecode CBOR-encoded RADON.
    function hash(bytes memory _bytecode) internal pure returns (bytes32) {
        return sha256(_bytecode);
    }

    /// 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 {
        IWitnetRequest addr;    // The contract containing the Data Request which execution has been requested.
        address requester;      // Address from which the request was posted.
        bytes32 hash;           // Hash of the Data Request whose execution has been requested.
        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.
        CBOR value;             // Resulting value, in CBOR-serialized bytes.
    }

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

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

    /// Witnet error codes table.
    enum ErrorCodes {
        // 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 index 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,
        // This should not exist:
        /// 0xFF: Some tally error is not intercepted but should
        UnhandledIntercept
    }
}
// File: contracts\interfaces\IWitnetRequestBoardRequestor.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 {
    /// 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);

    /// 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 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 An unique query identifier.
    function postRequest(IWitnetRequest _addr) external payable returns (uint256 _queryId);

    /// 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: contracts\interfaces\IWitnetRequestBoardView.sol
/// @title Witnet Request Board info interface.
/// @author The Witnet Foundation.
interface 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) external view returns (uint256);

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

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

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

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

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

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

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

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

    /// Retrieves the hash of the Witnet transaction hash 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 returns (bytes32);    

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

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

    /// 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: contracts\interfaces\IWitnetRequestParser.sol
/// @title The Witnet interface for decoding Witnet-provided request to Data Requests.
/// This interface exposes functions to check for the success/failure of
/// a Witnet-provided result, as well as to parse and convert result into
/// Solidity types suitable to the application level. 
/// @author The Witnet Foundation.
interface IWitnetRequestParser {

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

    /// Decode a CBOR value into a Witnet.Result instance.
    /// @param _cborValue An instance of `Witnet.CBOR`.
    /// @return A `Witnet.Result` instance.
    function resultFromCborValue(Witnet.CBOR memory _cborValue) external pure returns (Witnet.Result memory);

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

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

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

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

    /// Decode an error code from a Witnet.Result as a member of `Witnet.ErrorCodes`.
    /// @param _result An instance of `Witnet.Result`.
    /// @return The `CBORValue.Error memory` decoded from the Witnet.Result.
    function asErrorCode(Witnet.Result memory _result) external pure returns (Witnet.ErrorCodes);


    /// Generate a suitable error message for a member of `Witnet.ErrorCodes` 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.ErrorCodes, string memory);

    /// Decode a raw error from a `Witnet.Result` as a `uint64[]`.
    /// @param _result An instance of `Witnet.Result`.
    /// @return The `uint64[]` raw error as decoded from the `Witnet.Result`.
    function asRawError(Witnet.Result memory _result) external pure returns(uint64[] memory);

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

    /// Decode a fixed16 (half-precision) numeric value from a Witnet.Result as an `int32` 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 _result An instance of Witnet.Result.
    /// @return The `int128` decoded from the Witnet.Result.
    function asFixed16(Witnet.Result memory _result) external pure returns (int32);

    /// Decode an array of fixed16 values from a Witnet.Result as an `int128[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128[]` decoded from the Witnet.Result.
    function asFixed16Array(Witnet.Result memory _result) external pure returns (int32[] memory);

    /// Decode a integer numeric value from a Witnet.Result as an `int128` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128` decoded from the Witnet.Result.
    function asInt128(Witnet.Result memory _result) external pure returns (int128);

    /// Decode an array of integer numeric values from a Witnet.Result as an `int128[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `int128[]` decoded from the Witnet.Result.
    function asInt128Array(Witnet.Result memory _result) external pure returns (int128[] memory);

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

    /// Decode an array of string values from a Witnet.Result as a `string[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `string[]` decoded from the Witnet.Result.
    function asStringArray(Witnet.Result memory _result) external pure returns (string[] memory);

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

    /// Decode an array of natural numeric values from a Witnet.Result as a `uint64[]` value.
    /// @param _result An instance of Witnet.Result.
    /// @return The `uint64[]` decoded from the Witnet.Result.
    function asUint64Array(Witnet.Result memory _result) external pure returns (uint64[] memory);

}
// File: contracts\WitnetRequestBoard.sol
/// @title Witnet Request Board functionality base contract.
/// @author The Witnet Foundation.
abstract contract WitnetRequestBoard is
    IWitnetRequestBoardEvents,
    IWitnetRequestBoardReporter,
    IWitnetRequestBoardRequestor,
    IWitnetRequestBoardView,
    IWitnetRequestParser
{
    receive() external payable {
        revert("WitnetRequestBoard: no transfers accepted");
    }
}
// File: contracts\UsingWitnet.sol
/// @title The UsingWitnet contract
/// @dev Witnet-aware contracts can inherit from this contract in order to interact with Witnet.
/// @author The Witnet Foundation.
abstract contract UsingWitnet {

    WitnetRequestBoard public immutable witnet;

    /// Include an address to specify the WitnetRequestBoard entry point address.
    /// @param _wrb The WitnetRequestBoard entry point address.
    constructor(WitnetRequestBoard _wrb)
    {
        require(address(_wrb) != address(0), "UsingWitnet: zero address");
        witnet = _wrb;
    }

    /// Provides a convenient way for client contracts extending this to block the execution of the main logic of the
    /// contract until a particular request has been successfully solved and reported by Witnet.
    modifier witnetRequestSolved(uint256 _id) {
        require(
                _witnetCheckResultAvailability(_id),
                "UsingWitnet: request not solved"
            );
        _;
    }

    /// Check if a data request has been solved and reported by Witnet.
    /// @dev Contracts depending on Witnet should not start their main business logic (e.g. receiving value from third.
    /// parties) before this method returns `true`.
    /// @param _id The unique identifier of a previously posted data request.
    /// @return A boolean telling if the request has been already resolved or not. Returns `false` also, if the result was deleted.
    function _witnetCheckResultAvailability(uint256 _id)
        internal view
        virtual
        returns (bool)
    {
        return witnet.getQueryStatus(_id) == Witnet.QueryStatus.Reported;
    }

    /// Estimate the reward amount.
    /// @param _gasPrice The gas price for which we want to retrieve the estimation.
    /// @return The reward to be included when either posting a new request, or upgrading the reward of a previously posted one.
    function _witnetEstimateReward(uint256 _gasPrice)
        internal view
        virtual
        returns (uint256)
    {
        return witnet.estimateReward(_gasPrice);
    }

    /// Estimates the reward amount, considering current transaction gas price.
    /// @return The reward to be included when either posting a new request, or upgrading the reward of a previously posted one.
    function _witnetEstimateReward()
        internal view
        virtual
        returns (uint256)
    {
        return witnet.estimateReward(tx.gasprice);
    }

    /// Send a new request to the Witnet network with transaction value as a reward.
    /// @param _request An instance of `IWitnetRequest` contract.
    /// @return _id Sequential identifier for the request included in the WitnetRequestBoard.
    /// @return _reward Current reward amount escrowed by the WRB until a result gets reported.
    function _witnetPostRequest(IWitnetRequest _request)
        internal
        virtual
        returns (uint256 _id, uint256 _reward)
    {
        _reward = _witnetEstimateReward();
        _id = witnet.postRequest{value: _reward}(_request);
    }

    /// Upgrade the reward for a previously posted request.
    /// @dev Call to `upgradeReward` function in the WitnetRequestBoard contract.
    /// @param _id The unique identifier of a request that has been previously sent to the WitnetRequestBoard.
    /// @return Amount in which the reward has been increased.
    function _witnetUpgradeReward(uint256 _id)
        internal
        virtual
        returns (uint256)
    {
        uint256 _currentReward = witnet.readRequestReward(_id);        
        uint256 _newReward = _witnetEstimateReward();
        uint256 _fundsToAdd = 0;
        if (_newReward > _currentReward) {
            _fundsToAdd = (_newReward - _currentReward);
        }
        witnet.upgradeReward{value: _fundsToAdd}(_id); // Let Request.gasPrice be updated
        return _fundsToAdd;
    }

    /// Read the Witnet-provided result to a previously posted request.
    /// @param _id The unique identifier of a request that was posted to Witnet.
    /// @return The result of the request as an instance of `Witnet.Result`.
    function _witnetReadResult(uint256 _id)
        internal view
        virtual
        returns (Witnet.Result memory)
    {
        return witnet.readResponseResult(_id);
    }

    /// Retrieves copy of all response data related to a previously posted request, removing the whole query from storage.
    /// @param _id The unique identifier of a previously posted request.
    /// @return The Witnet-provided result to the request.
    function _witnetDeleteQuery(uint256 _id)
        internal
        virtual
        returns (Witnet.Response memory)
    {
        return witnet.deleteQuery(_id);
    }

}
// File: contracts\interfaces\IWitnetRandomness.sol
/// @title The Witnet Randomness generator interface.
/// @author Witnet Foundation.
interface IWitnetRandomness {

    /// Thrown every time a new WitnetRandomnessRequest gets succesfully posted to the WitnetRequestBoard.
    /// @param from Address from which the randomize() function was called. 
    /// @param prevBlock Block number in which a randomness request got posted just before this one. 0 if none.
    /// @param witnetQueryId Unique query id assigned to this request by the WRB.
    /// @param witnetRequestHash SHA-256 hash of the WitnetRandomnessRequest actual bytecode just posted to the WRB.
    event Randomized(
        address indexed from,
        uint256 indexed prevBlock,
        uint256 witnetQueryId,
        bytes32 witnetRequestHash
    );

    /// Returns amount of wei required to be paid as a fee when requesting randomization with a 
    /// transaction gas price as the one given.
    function estimateRandomizeFee(uint256 _gasPrice) external view returns (uint256);

    /// Retrieves data of a randomization request that got successfully posted to the WRB within a given block.
    /// @dev Returns zero values if no randomness request was actually posted within a given block.
    /// @param _block Block number whose randomness request is being queried for.
    /// @return _from Address from which the latest randomness request was posted.
    /// @return _id Unique request identifier as provided by the WRB.
    /// @return _fee Request's total paid fee.
    /// @return _prevBlock Block number in which a randomness request got posted just before this one. 0 if none.
    /// @return _nextBlock Block number in which a randomness request got posted just after this one, 0 if none.
    function getRandomizeData(uint256 _block)
        external view returns (address _from, uint256 _id, uint256 _fee, uint256 _prevBlock, uint256 _nextBlock);

    /// Retrieves the randomness generated upon solving a request that was posted within a given block,
    /// if any, or to the _first_ request posted after that block, otherwise. Should the intended 
    /// request happen to be finalized with errors on the Witnet oracle network side, this function 
    /// will recursively try to return randomness from the next non-faulty randomization request found 
    /// in storage, if any. 
    /// @dev Fails if:
    /// @dev   i.   no `randomize()` was not called in either the given block, or afterwards.
    /// @dev   ii.  a request posted in/after given block does exist, but no result has been provided yet.
    /// @dev   iii. all requests in/after the given block were solved with errors.
    /// @param _block Block number from which the search will start.
    function getRandomnessAfter(uint256 _block) external view returns (bytes32); 

    /// Tells what is the number of the next block in which a randomization request was posted after the given one. 
    /// @param _block Block number from which the search will start.
    /// @return Number of the first block found after the given one, or `0` otherwise.
    function getRandomnessNextBlock(uint256 _block) external view returns (uint256); 

    /// Gets previous block in which a randomness request was posted before the given one.
    /// @param _block Block number from which the search will start.
    /// @return First block found before the given one, or `0` otherwise.
    function getRandomnessPrevBlock(uint256 _block) external view returns (uint256);

    /// Returns `true` only when the randomness request that got posted within given block was already
    /// reported back from the Witnet oracle, either successfully or with an error of any kind.
    function isRandomized(uint256 _block) external view returns (bool);

    /// Returns latest block in which a randomness request got sucessfully posted to the WRB.
    function latestRandomizeBlock() external view returns (uint256);

    /// Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using 
    /// the given `_nonce` value and the randomness returned by `getRandomnessAfter(_block)`. 
    /// @dev Fails under same conditions as `getRandomnessAfter(uint256)` may do.
    /// @param _range Range within which the uniformly-distributed random number will be generated.
    /// @param _nonce Nonce value enabling multiple random numbers from the same randomness value.
    /// @param _block Block number from which the search will start.
    function random(uint32 _range, uint256 _nonce, uint256 _block) external view returns (uint32);

    /// Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using 
    /// the given `_nonce` value and the given `_seed` as a source of entropy.
    /// @param _range Range within which the uniformly-distributed random number will be generated.
    /// @param _nonce Nonce value enabling multiple random numbers from the same randomness value.
    /// @param _seed Seed value used as entropy source.
    function random(uint32 _range, uint256 _nonce, bytes32 _seed) external pure returns (uint32);

    /// Requests the Witnet oracle to generate an EVM-agnostic and trustless source of randomness. 
    /// Only one randomness request per block will be actually posted to the WRB. Should there 
    /// already be a posted request within current block, it will try to upgrade Witnet fee of current's 
    /// block randomness request according to current gas price. In both cases, all unused funds shall 
    /// be transfered back to the tx sender.
    /// @return _usedFunds Amount of funds actually used from those provided by the tx sender.
    function randomize() external payable returns (uint256 _usedFunds);

    /// Increases Witnet fee related to a pending-to-be-solved randomness request, as much as it
    /// may be required in proportion to how much bigger the current tx gas price is with respect the 
    /// highest gas price that was paid in either previous fee upgrades, or when the given randomness 
    /// request was posted. All unused funds shall be transferred back to the tx sender.
    /// @return _usedFunds Amount of dunds actually used from those provided by the tx sender.
    function upgradeRandomizeFee(uint256 _block) external payable returns (uint256 _usedFunds);
}
// File: contracts\patterns\Initializable.sol
interface Initializable {
    /// @dev Initialize contract's storage context.
    function initialize(bytes calldata) external;
}
// File: contracts\patterns\Clonable.sol
abstract contract Clonable is Initializable {
    /// Immutable contract address that actually attends all calls to this contract.
    /// @dev Differs from `address(this)` when reached within a DELEGATECALL.
    address immutable public self = address(this);

    event Cloned(address indexed by, Clonable indexed self, Clonable indexed clone);

    /// Tells whether this contract is a clone of another (i.e. `self()`)
    function cloned()
        public view
        returns (bool)
    {
        return (
            address(this) != self
        );
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract
    /// behaviour while using its own EVM storage.
    /// @dev This function should always provide a new address, no matter how many times 
    /// @dev is actually called from the same `msg.sender`.
    /// @dev See https://eips.ethereum.org/EIPS/eip-1167.
    /// @dev See https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/.
    function clone()
        public virtual
        returns (Clonable _instance)
    {
        address _self = self;
        assembly {
            // ptr to free mem:
            let ptr := mload(0x40)
            // begin minimal proxy construction bytecode:
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            // make minimal proxy delegate all calls to `self()`:
            mstore(add(ptr, 0x14), shl(0x60, _self))
            // end minimal proxy construction bytecode:
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            // CREATE new instance:
            _instance := create(0, ptr, 0x37)
        }        
        require(address(_instance) != address(0), "Clonable: CREATE failed");
        emit Cloned(msg.sender, Clonable(self), _instance);
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract 
    /// behaviour while using its own EVM storage.
    /// @dev This function uses the CREATE2 opcode and a `_salt` to deterministically deploy
    /// @dev the clone. Using the same `_salt` multiple times will revert, since
    /// @dev no contract can be deployed more than once at the same address.
    /// @dev See https://eips.ethereum.org/EIPS/eip-1167.
    /// @dev See https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/.
    function cloneDeterministic(bytes32 _salt)
        public virtual
        returns (Clonable _instance)
    {
        address _self = self;
        assembly {
            // ptr to free mem:
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            // make minimal proxy delegate all calls to `self()`:
            mstore(add(ptr, 0x14), shl(0x60, _self))
            // end minimal proxy construction bytecode:
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            // CREATE2 new instance:
            _instance := create2(0, ptr, 0x37, _salt)
        }
        require(address(_instance) != address(0), "Clonable: CREATE2 failed");
        emit Cloned(msg.sender, Clonable(self), _instance);
    }
}
// File: contracts\patterns\Context.sol
/// @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).
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    function _msgValue() internal view virtual returns (uint256) {
        return msg.value;
    }
}
// File: contracts\patterns\Ownable.sol
// OpenZeppelin Contracts v4.3.2 (access/Ownable.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 Returns the address of the current owner.
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /// @dev Throws if called by any account other than the owner.
    modifier onlyOwner() {
        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: contracts\patterns\Proxiable.sol
interface Proxiable {
    /// @dev Complying with EIP-1822: Universal Upgradable Proxy Standard (UUPS)
    /// @dev See https://eips.ethereum.org/EIPS/eip-1822.
    function proxiableUUID() external pure returns (bytes32);
}
// File: contracts\requests\WitnetRequestMalleableBase.sol
abstract contract WitnetRequestMalleableBase
    is
        IWitnetRequest,
        Clonable,
        Ownable,
        Proxiable
{   
    using Witnet for *;

    event WitnessingParamsChanged(
        address indexed by,
        uint8 numWitnesses,
        uint8 minWitnessingConsensus,
        uint64 witnssingCollateral,
        uint64 witnessingReward,
        uint64 witnessingUnitaryFee
    );

    struct WitnetRequestMalleableBaseContext {
        /// Contract owner address.
        address owner;
        /// Immutable bytecode template.
        bytes template;
        /// Current request bytecode.
        bytes bytecode;
        /// Current request hash.
        bytes32 hash;
        /// Current request witnessing params.
        WitnetRequestWitnessingParams params;
    }

    struct WitnetRequestWitnessingParams {
        /// Number of witnesses required to be involved for solving this Witnet Data Request.
        uint8 numWitnesses;

        /// Threshold percentage for aborting resolution of a request if the witnessing nodes did not arrive to a broad consensus.
        uint8 minWitnessingConsensus;

        /// Amount of nanowits that a witness solving the request will be required to collateralize in the commitment transaction.
        uint64 witnessingCollateral;

        /// Amount of nanowits that every request-solving witness will be rewarded with.
        uint64 witnessingReward;

        /// Amount of nanowits that will be earned by Witnet miners for each each valid commit/reveal transaction they include in a block.
        uint64 witnessingUnitaryFee;
    }

    /// Returns current Witnet Data Request bytecode, encoded using Protocol Buffers.
    function bytecode() external view override returns (bytes memory) {
        return _request().bytecode;
    }

    /// Returns SHA256 hash of current Witnet Data Request bytecode.
    function hash() external view override returns (bytes32) {
        return _request().hash;
    }

    /// Sets amount of nanowits that a witness solving the request will be required to collateralize in the commitment transaction.
    function setWitnessingCollateral(uint64 _witnessingCollateral)
        public
        virtual
        onlyOwner
    {
        WitnetRequestWitnessingParams storage _params = _request().params;
        _params.witnessingCollateral = _witnessingCollateral;
        _malleateBytecode(
            _params.numWitnesses,
            _params.minWitnessingConsensus,
            _witnessingCollateral,
            _params.witnessingReward,
            _params.witnessingUnitaryFee
        );
    }

    /// Specifies how much you want to pay for rewarding each of the Witnet nodes.
    /// @param _witnessingReward Amount of nanowits that every request-solving witness will be rewarded with.
    /// @param _witnessingUnitaryFee Amount of nanowits that will be earned by Witnet miners for each each valid 
    /// commit/reveal transaction they include in a block.
    function setWitnessingFees(uint64 _witnessingReward, uint64 _witnessingUnitaryFee)
        public
        virtual
        onlyOwner
    {
        WitnetRequestWitnessingParams storage _params = _request().params;
        _params.witnessingReward = _witnessingReward;
        _params.witnessingUnitaryFee = _witnessingUnitaryFee;
        _malleateBytecode(
            _params.numWitnesses,
            _params.minWitnessingConsensus,
            _params.witnessingCollateral,
            _witnessingReward,
            _witnessingUnitaryFee
        );
    }

    /// Sets how many Witnet nodes will be "hired" for resolving the request.
    /// @param _numWitnesses Number of witnesses required to be involved for solving this Witnet Data Request.
    /// @param _minWitnessingConsensus Threshold percentage for aborting resolution of a request if the witnessing 
    /// nodes did not arrive to a broad consensus.
    function setWitnessingQuorum(uint8 _numWitnesses, uint8 _minWitnessingConsensus)
        public
        virtual
        onlyOwner
    {
        WitnetRequestWitnessingParams storage _params = _request().params;
        _params.numWitnesses = _numWitnesses;
        _params.minWitnessingConsensus = _minWitnessingConsensus;
        _malleateBytecode(
            _numWitnesses,
            _minWitnessingConsensus,
            _params.witnessingCollateral,
            _params.witnessingReward,
            _params.witnessingUnitaryFee
        );
    }

    /// Returns immutable template bytecode: actual CBOR-encoded data request at the Witnet protocol
    /// level, including no witnessing parameters at all.
    function template()
        external view
        returns (bytes memory)
    {
        return _request().template;
    }

    /// Returns total amount of nanowits that witnessing nodes will need to collateralize all together.
    function totalWitnessingCollateral()
        external view
        returns (uint128)
    {
        WitnetRequestWitnessingParams storage _params = _request().params;
        return _params.numWitnesses * _params.witnessingCollateral;
    }

    /// Returns total amount of nanowits that will have to be paid in total for this request to be solved.
    function totalWitnessingFee()
        external view
        returns (uint128)
    {
        WitnetRequestWitnessingParams storage _params = _request().params;
        return _params.numWitnesses * (2 * _params.witnessingUnitaryFee + _params.witnessingReward);
    }

    /// Returns witnessing parameters of current Witnet Data Request.
    function witnessingParams()
        external view
        returns (WitnetRequestWitnessingParams memory)
    {
        return _request().params;
    }


    // ================================================================================================================
    // --- 'Clonable' overriden functions -----------------------------------------------------------------------------

    /// Deploys and returns the address of a minimal proxy clone that replicates contract
    /// behaviour while using its own EVM storage.
    /// @dev This function should always provide a new address, no matter how many times 
    /// @dev is actually called from the same `msg.sender`.
    function clone()
        public
        virtual override
        returns (Clonable _instance)
    {
        _instance = super.clone();
        _instance.initialize(_request().template);
        Ownable(address(_instance)).transferOwnership(msg.sender);
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract 
    /// behaviour while using its own EVM storage.
    /// @dev This function uses the CREATE2 opcode and a `_salt` to deterministically deploy
    /// @dev the clone. Using the same `_salt` multiple time will revert, since
    /// @dev no contract can be deployed more than once at the same address.
    function cloneDeterministic(bytes32 _salt)
        public
        virtual override
        returns (Clonable _instance)
    {
        _instance = super.cloneDeterministic(_salt);
        _instance.initialize(_request().template);
        Ownable(address(_instance)).transferOwnership(msg.sender);
    }


    // ================================================================================================================
    // --- 'Initializable' overriden functions ------------------------------------------------------------------------

    /// @dev Initializes contract's storage context.
    function initialize(bytes memory _template)
        public
        virtual override
    {
        require(_request().template.length == 0, "WitnetRequestMalleableBase: already initialized");
        _initialize(_template);
        _transferOwnership(_msgSender());
    }

    // ================================================================================================================
    // --- 'Ownable' overriden functions ------------------------------------------------------------------------------

    /// Returns the address of the current owner.
    function owner()
        public view
        virtual override
        returns (address)
    {
        return _request().owner;
    }

    /// @dev Transfers ownership of the contract to a new account (`newOwner`).
    function _transferOwnership(address newOwner)
        internal
        virtual override
    {
        address oldOwner = _request().owner;
        _request().owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    // ================================================================================================================
    // --- 'Proxiable 'overriden functions ----------------------------------------------------------------------------

    /// @dev Complying with EIP-1822: Universal Upgradable Proxy Standard (UUPS)
    /// @dev See https://eips.ethereum.org/EIPS/eip-1822.
    function proxiableUUID()
        external pure
        virtual override
        returns (bytes32)
    {
        return (
            /* keccak256("io.witnet.requests.malleable") */
            0x851d0a92a3ad30295bef33afc69d6874779826b7789386b336e22621365ed2c2
        );
    }


    // ================================================================================================================
    // --- INTERNAL FUNCTIONS -----------------------------------------------------------------------------------------    

    /// @dev Initializes witnessing params and template bytecode.
    function _initialize(bytes memory _template)
        internal
    {
        assert(_template.length > 0);
        _request().template = _template;

        WitnetRequestWitnessingParams storage _params = _request().params;
        _params.numWitnesses = 2;
        _params.minWitnessingConsensus = 51;
        _params.witnessingCollateral = 10 ** 9;      // 1 WIT
        _params.witnessingReward = 5 * 10 ** 5;      // 0.5 milliWITs
        _params.witnessingUnitaryFee = 25 * 10 ** 4; // 0.25 milliWITs
        
        _malleateBytecode(
            _params.numWitnesses,
            _params.minWitnessingConsensus,
            _params.witnessingCollateral,
            _params.witnessingReward,
            _params.witnessingUnitaryFee
        );
    }

    /// @dev Serializes new `bytecode` by combining immutable template with given parameters.
    function _malleateBytecode(
            uint8 _numWitnesses,
            uint8 _minWitnessingConsensus,
            uint64 _witnessingCollateral,
            uint64 _witnessingReward,
            uint64 _witnessingUnitaryFee
        )
        internal
        virtual
    {
        require(
            _witnessingReward > 0,
            "WitnetRequestMalleableBase: no reward"
        );
        require(
            _numWitnesses >= 1 && _numWitnesses <= 127,
            "WitnetRequestMalleableBase: number of witnesses out of range"
        );
        require(
            _minWitnessingConsensus >= 51 && _minWitnessingConsensus <= 99,
            "WitnetRequestMalleableBase: witnessing consensus out of range"
        );
        require(
            _witnessingCollateral >= 10 ** 9,
            "WitnetRequestMalleableBase: witnessing collateral below 1 WIT"
        );

        _request().bytecode = abi.encodePacked(
            _request().template,
            _uint64varint(bytes1(0x10), _witnessingReward),
            _uint8varint(bytes1(0x18), _numWitnesses),
            _uint64varint(0x20, _witnessingUnitaryFee),
            _uint8varint(0x28, _minWitnessingConsensus),
            _uint64varint(0x30, _witnessingCollateral)
        );
        _request().hash = _request().bytecode.hash();
        emit WitnessingParamsChanged(
            msg.sender,
            _numWitnesses,
            _minWitnessingConsensus,
            _witnessingCollateral,
            _witnessingReward,
            _witnessingUnitaryFee
        );
    }

    /// @dev Returns pointer to storage slot where State struct is located.
    function _request()
        internal pure
        virtual
        returns (WitnetRequestMalleableBaseContext storage _ptr)
    {
        assembly {
            _ptr.slot :=
                /* keccak256("io.witnet.requests.malleable.context") */
                0x375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba7
        }
    }

    /// @dev Encode uint64 into tagged varint.
    /// @dev See https://developers.google.com/protocol-buffers/docs/encoding#varints.
    /// @param t Tag
    /// @param n Number
    /// @return Marshaled bytes
    function _uint64varint(bytes1 t, uint64 n)
        internal pure
        returns (bytes memory)
    {
        // Count the number of groups of 7 bits
        // We need this pre-processing step since Solidity doesn't allow dynamic memory resizing
        uint64 tmp = n;
        uint64 numBytes = 2;
        while (tmp > 0x7F) {
            tmp = tmp >> 7;
            numBytes += 1;
        }
        bytes memory buf = new bytes(numBytes);
        tmp = n;
        buf[0] = t;
        for (uint64 i = 1; i < numBytes; i++) {
            // Set the first bit in the byte for each group of 7 bits
            buf[i] = bytes1(0x80 | uint8(tmp & 0x7F));
            tmp = tmp >> 7;
        }
        // Unset the first bit of the last byte
        buf[numBytes - 1] &= 0x7F;
        return buf;
    }

    /// @dev Encode uint8 into tagged varint.
    /// @param t Tag
    /// @param n Number
    /// @return Marshaled bytes
    function _uint8varint(bytes1 t, uint8 n)
        internal pure
        returns (bytes memory)
    {
        return _uint64varint(t, uint64(n));
    }
}
// File: contracts\requests\WitnetRequestRandomness.sol
contract WitnetRequestRandomness is WitnetRequestMalleableBase {
    bytes internal constant _WITNET_RANDOMNESS_BYTECODE_TEMPLATE = hex"0a0f120508021a01801a0210022202100b";

    constructor() {
        initialize(bytes(""));
    }

    function initialize(bytes memory)
        public
        virtual override
    {
        super.initialize(_WITNET_RANDOMNESS_BYTECODE_TEMPLATE);
    }
}
// File: contracts\examples\WitnetRandomness.sol
/// @title WitnetRandomness: A trustless randomness generator and registry, based on the Witnet oracle. 
/// @author Witnet Foundation.
contract WitnetRandomness
    is
        IWitnetRandomness,
        UsingWitnet,
        Clonable
{
    WitnetRequestRandomness public witnetRandomnessRequest;
    uint256 public override latestRandomizeBlock;

    mapping (uint256 => RandomizeData) internal __randomize_;
    struct RandomizeData {
        address from;
        uint256 prevBlock;
        uint256 nextBlock;
        uint256 witnetQueryId;
    }

    /// Include an address to specify the immutable WitnetRequestBoard entrypoint address.
    /// @param _wrb The WitnetRequestBoard immutable entrypoint address.
    constructor(WitnetRequestBoard _wrb)
        UsingWitnet(_wrb)
    {
        witnetRandomnessRequest = new WitnetRequestRandomness();
        witnetRandomnessRequest.transferOwnership(msg.sender);
    }

    /// Returns amount of wei required to be paid as a fee when requesting randomization with a 
    /// transaction gas price as the one given.
    function estimateRandomizeFee(uint256 _gasPrice)
        public view
        virtual override
        returns (uint256)
    {
        return _witnetEstimateReward(_gasPrice);
    }

    /// Retrieves data of a randomization request that got successfully posted to the WRB within a given block.
    /// @dev Returns zero values if no randomness request was actually posted within a given block.
    /// @param _block Block number whose randomness request is being queried for.
    /// @return _from Address from which the latest randomness request was posted.
    /// @return _id Unique request identifier as provided by the WRB.
    /// @return _fee Request's total paid fee.
    /// @return _prevBlock Block number in which a randomness request got posted just before this one. 0 if none.
    /// @return _nextBlock Block number in which a randomness request got posted just after this one, 0 if none.
    function getRandomizeData(uint256 _block)
        external view
        override
        returns (
            address _from,
            uint256 _id,
            uint256 _fee,
            uint256 _prevBlock,
            uint256 _nextBlock
        )
    {
        RandomizeData storage _data = __randomize_[_block];
        _id = _data.witnetQueryId;
        _fee = witnet.readRequestReward(_id);
        _from = _data.from;
        _prevBlock = _data.prevBlock;
        _nextBlock = _data.nextBlock;
    }

    /// Retrieves the randomness generated upon solving a request that was posted within a given block,
    /// if any, or to the _first_ request posted after that block, otherwise. Should the intended 
    /// request happen to be finalized with errors on the Witnet oracle network side, this function 
    /// will recursively try to return randomness from the next non-faulty randomization request found 
    /// in storage, if any. 
    /// @dev Fails if:
    /// @dev   i.   no `randomize()` was not called in either the given block, or afterwards.
    /// @dev   ii.  a request posted in/after given block does exist, but no result has been provided yet.
    /// @dev   iii. all requests in/after the given block were solved with errors.
    /// @param _block Block number from which the search will start.
    function getRandomnessAfter(uint256 _block)
        public view
        virtual override
        returns (bytes32)
    {
        if (__randomize_[_block].from == address(0)) {
            _block = getRandomnessNextBlock(_block);
        }
        uint256 _queryId = __randomize_[_block].witnetQueryId;
        require(_queryId != 0, "WitnetRandomness: not randomized");
        require(_witnetCheckResultAvailability(_queryId), "WitnetRandomness: pending randomize");
        Witnet.Result memory _witnetResult = _witnetReadResult(_queryId);
        if (witnet.isOk(_witnetResult)) {
            return witnet.asBytes32(_witnetResult);
        } else {
            uint256 _nextRandomizeBlock = __randomize_[_block].nextBlock;
            require(_nextRandomizeBlock != 0, "WitnetRandomness: faulty randomize");
            return getRandomnessAfter(_nextRandomizeBlock);
        }
    }

    /// Tells what is the number of the next block in which a randomization request was posted after the given one. 
    /// @param _block Block number from which the search will start.
    /// @return Number of the first block found after the given one, or `0` otherwise.
    function getRandomnessNextBlock(uint256 _block)
        public view
        virtual override
        returns (uint256)
    {
        return ((__randomize_[_block].from != address(0))
            ? __randomize_[_block].nextBlock
            // start search from the latest block
            : _searchNextBlock(_block, latestRandomizeBlock)
        );
    }

    /// Gets previous block in which a randomness request was posted before the given one.
    /// @param _block Block number from which the search will start. Cannot be zero.
    /// @return First block found before the given one, or `0` otherwise.
    function getRandomnessPrevBlock(uint256 _block)
        public view
        virtual override
        returns (uint256)
    {
        assert(_block > 0);
        uint256 _latest = latestRandomizeBlock;
        return ((_block > _latest)
            ? _latest
            // start search from the latest block
            : _searchPrevBlock(_block, __randomize_[_latest].prevBlock)
        );
    }

    /// Returns `true` only when the randomness request that got posted within given block was already
    /// reported back from the Witnet oracle, either successfully or with an error of any kind.
    function isRandomized(uint256 _block)
        public view
        virtual override
        returns (bool)
    {
        RandomizeData storage _data = __randomize_[_block];
        return (
            _data.witnetQueryId != 0 
                && _witnetCheckResultAvailability(_data.witnetQueryId)
        );
    }

    /// Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using 
    /// the given `_nonce` value and the randomness returned by `getRandomnessAfter(_block)`. 
    /// @dev Fails under same conditions as `getRandomnessAfter(uint256)` may do.
    /// @param _range Range within which the uniformly-distributed random number will be generated.
    /// @param _nonce Nonce value enabling multiple random numbers from the same randomness value.
    /// @param _block Block number from which the search will start.
    function random(uint32 _range, uint256 _nonce, uint256 _block)
        external view
        virtual override
        returns (uint32)
    {
        return random(
            _range,
            _nonce,
            keccak256(
                abi.encode(
                    msg.sender,
                    getRandomnessAfter(_block)
                )
            )
        );
    }

    /// Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using 
    /// the given `_nonce` value and the given `_seed` as a source of entropy.
    /// @param _range Range within which the uniformly-distributed random number will be generated.
    /// @param _nonce Nonce value enabling multiple random numbers from the same randomness value.
    /// @param _seed Seed value used as entropy source.
    function random(uint32 _range, uint256 _nonce, bytes32 _seed)
        public pure
        virtual override
        returns (uint32)
    {
        uint8 _flagBits = uint8(255 - _msbDeBruijn32(_range));
        uint256 _number = uint256(
                keccak256(
                    abi.encode(_seed, _nonce)
                )
            ) & uint256(2 ** _flagBits - 1);
        return uint32((_number * _range) >> _flagBits);
    }

    /// Requests the Witnet oracle to generate an EVM-agnostic and trustless source of randomness. 
    /// Only one randomness request per block will be actually posted to the WRB. Should there 
    /// already be a posted request within current block, it will try to upgrade Witnet fee of current's 
    /// block randomness request according to current gas price. In both cases, all unused funds shall 
    /// be transfered back to the tx sender.
    /// @return _usedFunds Amount of funds actually used from those provided by the tx sender.
    function randomize()
        external payable
        virtual override
        returns (uint256 _usedFunds)
    {
        if (latestRandomizeBlock < block.number) {
            // Post the Witnet Randomness request:
            uint _queryId;
            (_queryId, _usedFunds) = _witnetPostRequest(witnetRandomnessRequest);
            // Keep Randomize data in storage:
            RandomizeData storage _data = __randomize_[block.number];
            _data.witnetQueryId = _queryId;
            _data.from = msg.sender;
            // Update block links:
            uint256 _prevBlock = latestRandomizeBlock;
            _data.prevBlock = _prevBlock;
            __randomize_[_prevBlock].nextBlock = block.number;
            latestRandomizeBlock = block.number;
            // Throw event:
            emit Randomized(
                msg.sender,
                _prevBlock,
                _queryId,
                witnetRandomnessRequest.hash()
            );
            // Transfer back unused tx value:
            if (_usedFunds < msg.value) {
                payable(msg.sender).transfer(msg.value - _usedFunds);
            }
        } else {
            return upgradeRandomizeFee(block.number);
        }
    }

    /// Increases Witnet fee related to a pending-to-be-solved randomness request, as much as it
    /// may be required in proportion to how much bigger the current tx gas price is with respect the 
    /// highest gas price that was paid in either previous fee upgrades, or when the given randomness 
    /// request was posted. All unused funds shall be transferred back to the tx sender.
    /// @return _usedFunds Amount of dunds actually used from those provided by the tx sender.
    function upgradeRandomizeFee(uint256 _block)
        public payable
        virtual override
        returns (uint256 _usedFunds)
    {
        RandomizeData storage _data = __randomize_[_block];
        if (_data.witnetQueryId != 0) {
            _usedFunds = _witnetUpgradeReward(_data.witnetQueryId);
            if (_usedFunds > 0) {
                payable(msg.sender).transfer(msg.value - _usedFunds);
            }
        }
    }


    // ================================================================================================================
    // --- 'Clonable' overriden functions -----------------------------------------------------------------------------

    /// Deploys and returns the address of a minimal proxy clone that replicates contract
    /// behaviour while using its own EVM storage.
    /// @dev This function should always provide a new address, no matter how many times 
    /// @dev is actually called from the same `msg.sender`.
    function clone()
        public
        virtual override
        returns (Clonable _newInstance)
    {
        _newInstance = super.clone();
        _clone(_newInstance);
    }

    /// Deploys and returns the address of a minimal proxy clone that replicates contract 
    /// behaviour while using its own EVM storage.
    /// @dev This function uses the CREATE2 opcode and a `_salt` to deterministically deploy
    /// @dev the clone. Using the same `_salt` multiple time will revert, since
    /// @dev no contract can be deployed more than once at the same address.
    function cloneDeterministic(bytes32 _salt)
        public
        virtual override
        returns (Clonable _newInstance)
    {
        _newInstance = super.cloneDeterministic(_salt);
        _clone(_newInstance);
    }


    // ================================================================================================================
    // --- 'Initializable' overriden functions ------------------------------------------------------------------------

    /// @dev Initializes contract's storage context.
    function initialize(bytes memory _initData)
        public
        virtual override
    {
        require(address(witnetRandomnessRequest) == address(0), "WitnetRandomness: already initialized");
        witnetRandomnessRequest = WitnetRequestRandomness(
            abi.decode(
                _initData,
                (address)
            )
        );
    }


    // ================================================================================================================
    // --- INTERNAL FUNCTIONS -----------------------------------------------------------------------------------------

    /// @dev Common steps for both deterministic and non-deterministic cloning.
    function _clone(Clonable _instance) internal {
        address _request = address(witnetRandomnessRequest.clone());
        Ownable(_request).transferOwnership(msg.sender);
        _instance.initialize(abi.encode(_request));
    }

    /// @dev Returns index of the Most Significant Bit of the given number, applying De Bruijn O(1) algorithm.
    function _msbDeBruijn32(uint32 _v)
        internal pure
        returns (uint8)
    {
        uint8[32] memory _bitPosition = [
                0, 9, 1, 10, 13, 21, 2, 29,
                11, 14, 16, 18, 22, 25, 3, 30,
                8, 12, 20, 28, 15, 17, 24, 7,
                19, 27, 23, 6, 26, 5, 4, 31
            ];
        _v |= _v >> 1;
        _v |= _v >> 2;
        _v |= _v >> 4;
        _v |= _v >> 8;
        _v |= _v >> 16;
        return _bitPosition[
            uint32(_v * uint256(0x07c4acdd)) >> 27
        ];
    }

    /// @dev Recursively searches for the number of the first block after the given one in which a Witnet randomization request was posted.
    /// @dev Returns 0 if none found.
    function _searchNextBlock(uint256 _target, uint256 _latest) internal view returns (uint256) {
        return ((_target >= _latest) 
            ? __randomize_[_latest].nextBlock
            : _searchNextBlock(_target, __randomize_[_latest].prevBlock)
        );
    }

    /// @dev Recursively searches for the number of the first block before the given one in which a Witnet randomization request was posted.
    /// @dev Returns 0 if none found.

    function _searchPrevBlock(uint256 _target, uint256 _latest) internal view returns (uint256) {
        return ((_target > _latest)
            ? _latest
            : _searchPrevBlock(_target, __randomize_[_latest].prevBlock)
        );
    }
}
        

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_wrb","internalType":"contract WitnetRequestBoard"}]},{"type":"event","name":"Cloned","inputs":[{"type":"address","name":"by","internalType":"address","indexed":true},{"type":"address","name":"self","internalType":"contract Clonable","indexed":true},{"type":"address","name":"clone","internalType":"contract Clonable","indexed":true}],"anonymous":false},{"type":"event","name":"Randomized","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"uint256","name":"prevBlock","internalType":"uint256","indexed":true},{"type":"uint256","name":"witnetQueryId","internalType":"uint256","indexed":false},{"type":"bytes32","name":"witnetRequestHash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"_newInstance","internalType":"contract Clonable"}],"name":"clone","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"_newInstance","internalType":"contract Clonable"}],"name":"cloneDeterministic","inputs":[{"type":"bytes32","name":"_salt","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"cloned","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimateRandomizeFee","inputs":[{"type":"uint256","name":"_gasPrice","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"_from","internalType":"address"},{"type":"uint256","name":"_id","internalType":"uint256"},{"type":"uint256","name":"_fee","internalType":"uint256"},{"type":"uint256","name":"_prevBlock","internalType":"uint256"},{"type":"uint256","name":"_nextBlock","internalType":"uint256"}],"name":"getRandomizeData","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRandomnessAfter","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRandomnessNextBlock","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRandomnessPrevBlock","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"bytes","name":"_initData","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRandomized","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"latestRandomizeBlock","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint32","name":"","internalType":"uint32"}],"name":"random","inputs":[{"type":"uint32","name":"_range","internalType":"uint32"},{"type":"uint256","name":"_nonce","internalType":"uint256"},{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint32","name":"","internalType":"uint32"}],"name":"random","inputs":[{"type":"uint32","name":"_range","internalType":"uint32"},{"type":"uint256","name":"_nonce","internalType":"uint256"},{"type":"bytes32","name":"_seed","internalType":"bytes32"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"_usedFunds","internalType":"uint256"}],"name":"randomize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"self","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"_usedFunds","internalType":"uint256"}],"name":"upgradeRandomizeFee","inputs":[{"type":"uint256","name":"_block","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetRequestBoard"}],"name":"witnet","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract WitnetRequestRandomness"}],"name":"witnetRandomnessRequest","inputs":[]}]
              

Contract Creation Code

0x60c06040523060a0523480156200001557600080fd5b506040516200439438038062004394833981016040819052620000389162000150565b806001600160a01b038116620000945760405162461bcd60e51b815260206004820152601960248201527f5573696e675769746e65743a207a65726f206164647265737300000000000000604482015260640160405180910390fd5b6001600160a01b0316608052604051620000ae9062000142565b604051809103906000f080158015620000cb573d6000803e3d6000fd5b50600080546001600160a01b0319166001600160a01b0392909216918217905560405163f2fde38b60e01b815233600482015263f2fde38b90602401600060405180830381600087803b1580156200012257600080fd5b505af115801562000137573d6000803e3d6000fd5b505050505062000182565b61250f8062001e8583390190565b6000602082840312156200016357600080fd5b81516001600160a01b03811681146200017b57600080fd5b9392505050565b60805160a051611c746200021160003960008181610253015281816102ca01528181610b9801528181610c4601528181611058015261110701526000818161021701528181610739015281816109f401528181610a8601528181610e9001528181610f2201528181610fc60152818161118e015281816112340152818161149e015261152d0152611c746000f3fe6080604052600436106101095760003560e01c80639938fd0c11610095578063a60ee26811610064578063a60ee2681461034c578063daaa360c1461036c578063e35329f81461038c578063e7d4a0161461039f578063fb476cad146103bf57600080fd5b80639938fd0c146102755780639bc86fec1461028b578063a04daef0146102bb578063a3252f68146102fa57600080fd5b806340b41daa116100dc57806340b41daa146101c3578063439fab91146101e357806346d1d21a14610205578063699b328a146102395780637104ddb21461024157600080fd5b806309ed46071461010e57806324cbbfc11461014057806336b651bb146101755780633b13e76e146101a3575b600080fd5b34801561011a57600080fd5b506101236103df565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561014c57600080fd5b5061016061015b3660046115b5565b6103f7565b60405163ffffffff9091168152602001610137565b34801561018157600080fd5b506101956101903660046115ea565b610445565b604051908152602001610137565b3480156101af57600080fd5b50600054610123906001600160a01b031681565b3480156101cf57600080fd5b506101956101de3660046115ea565b61048b565b3480156101ef57600080fd5b506102036101fe3660046116be565b6104d2565b005b34801561021157600080fd5b506101237f000000000000000000000000000000000000000000000000000000000000000081565b610195610575565b34801561024d57600080fd5b506101237f000000000000000000000000000000000000000000000000000000000000000081565b34801561028157600080fd5b5061019560015481565b34801561029757600080fd5b506102ab6102a63660046115ea565b6106e0565b6040519015158152602001610137565b3480156102c757600080fd5b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163014156102ab565b34801561030657600080fd5b5061031a6103153660046115ea565b610709565b604080516001600160a01b0390961686526020860194909452928401919091526060830152608082015260a001610137565b34801561035857600080fd5b506101956103673660046115ea565b6107d5565b34801561037857600080fd5b506101236103873660046115ea565b6107e0565b61019561039a3660046115ea565b6107fb565b3480156103ab57600080fd5b506101606103ba3660046115b5565b610866565b3480156103cb57600080fd5b506101956103da3660046115ea565b6108e7565b60006103e9610b79565b90506103f481610ca8565b90565b600061043d848433610408866108e7565b604080516001600160a01b03909316602084015282015260600160405160208183030381529060405280519060200120610866565b949350505050565b60008082116104565761045661173e565b6001548083116104825760008181526002602052604090206001015461047d908490610dfd565b610484565b805b9392505050565b6000818152600260205260408120546001600160a01b03166104b8576104b382600154610e23565b6104cc565b600082815260026020819052604090912001545b92915050565b6000546001600160a01b03161561053e5760405162461bcd60e51b815260206004820152602560248201527f5769746e657452616e646f6d6e6573733a20616c726561647920696e697469616044820152641b1a5e995960da1b60648201526084015b60405180910390fd5b808060200190518101906105529190611769565b600080546001600160a01b0319166001600160a01b039290921691909117905550565b60004360015410156106d25760008054610597906001600160a01b0316610e63565b4360008181526002602081815260408084206003810188905580546001600160a01b031916339081178255600180548184018190558088528488209096018890559690965593548151624dead360e51b81529151969950969750929591948594937faf291bb4e1767569c77502edb6ad1009e856f57c09f214886c6becc9836c20c09389936001600160a01b0391909116926309bd5a609260048082019392918290030181865afa158015610650573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106749190611786565b6040805192835260208301919091520160405180910390a3348410156106cc57336108fc6106a286346117b5565b6040518115909202916000818181858888f193505050501580156106ca573d6000803e3d6000fd5b505b50505090565b6106db436107fb565b905090565b600081815260026020526040812060038101541580159061048457506104848160030154610f08565b60008181526002602052604080822060038101549151631dd27daf60e01b815260048101839052839182918291907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690631dd27daf90602401602060405180830381865afa158015610788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ac9190611786565b815460018301546002909301546001600160a01b03909116999698509096509094909350915050565b60006104cc82610fad565b60006107eb82611039565b90506107f681610ca8565b919050565b600081815260026020526040812060038101541561086057610820816003015461116b565b9150811561086057336108fc61083684346117b5565b6040518115909202916000818181858888f1935050505015801561085e573d6000803e3d6000fd5b505b50919050565b600080610872856112a3565b61087d9060ff6117cc565b90506000600161088e8360026118d3565b61089891906117b5565b604080516020810187905290810187905260600160408051601f19818403018152919052805160209091012016905060ff82166108db63ffffffff8816836118e2565b901c9695505050505050565b6000818152600260205260408120546001600160a01b031661090f5761090c8261048b565b91505b6000828152600260205260409020600301548061096e5760405162461bcd60e51b815260206004820181905260248201527f5769746e657452616e646f6d6e6573733a206e6f742072616e646f6d697a65646044820152606401610535565b61097781610f08565b6109cf5760405162461bcd60e51b815260206004820152602360248201527f5769746e657452616e646f6d6e6573733a2070656e64696e672072616e646f6d604482015262697a6560e81b6064820152608401610535565b60006109da82611432565b604051635430260d60e11b81529091506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a8604c1a90610a2990849060040161195d565b602060405180830381865afa158015610a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6a9190611a1f565b15610afc5760405163cf62d11560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063cf62d11590610abb90849060040161195d565b602060405180830381865afa158015610ad8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043d9190611786565b6000848152600260208190526040909120015480610b675760405162461bcd60e51b815260206004820152602260248201527f5769746e657452616e646f6d6e6573733a206661756c74792072616e646f6d696044820152617a6560f01b6064820152608401610535565b610b70816108e7565b95945050505050565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000000000000000000000000000000000000000000000606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b602883015260009160378184f09250506001600160a01b038216610c3a5760405162461bcd60e51b815260206004820152601760248201527f436c6f6e61626c653a20435245415445206661696c65640000000000000000006044820152606401610535565b816001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a45090565b60008060009054906101000a90046001600160a01b03166001600160a01b03166309ed46076040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610cfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d229190611769565b60405163f2fde38b60e01b81523360048201529091506001600160a01b0382169063f2fde38b90602401600060405180830381600087803b158015610d6657600080fd5b505af1158015610d7a573d6000803e3d6000fd5b5050604080516001600160a01b0385811660208301528616935063439fab919250016040516020818303038152906040526040518263ffffffff1660e01b8152600401610dc79190611a3a565b600060405180830381600087803b158015610de157600080fd5b505af1158015610df5573d6000803e3d6000fd5b505050505050565b60008183116108605760008281526002602052604090206001015461047d908490610dfd565b600081831015610e4a5760008281526002602052604090206001015461047d908490610e23565b5060009081526002602081905260409091200154919050565b600080610e6e611515565b60405163b281a7bd60e01b81526001600160a01b0385811660048301529192507f00000000000000000000000000000000000000000000000000000000000000009091169063b281a7bd90839060240160206040518083038185885af1158015610edc573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f019190611786565b9150915091565b60006002604051631bc1eaf360e21b8152600481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636f07abcc90602401602060405180830381865afa158015610f71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f959190611a63565b6003811115610fa657610fa6611a4d565b1492915050565b60405163d2e8756160e01b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d2e8756190602401602060405180830381865afa158015611015573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104cc9190611786565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000000000000000000000000000000000000000000000606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b60288301526000918360378285f59250506001600160a01b0382166110fb5760405162461bcd60e51b815260206004820152601860248201527f436c6f6e61626c653a2043524541544532206661696c656400000000000000006044820152606401610535565b816001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a450919050565b604051631dd27daf60e01b81526004810182905260009081906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631dd27daf90602401602060405180830381865afa1580156111d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111f99190611786565b90506000611205611515565b905060008282111561121e5761121b83836117b5565b90505b6040516366bfdc7560e01b8152600481018690527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906366bfdc759083906024016000604051808303818588803b15801561128157600080fd5b505af1158015611295573d6000803e3d6000fd5b509398975050505050505050565b60408051610400810182526000808252600960208301526001928201839052600a6060830152600d6080830152601560a0830152600260c08301819052601d60e0840152600b610100840152600e610120840152601061014084018190526012610160850152601661018085015260196101a085015260036101c0850152601e6101e085015260086102008501819052600c6102208601526014610240860152601c610260860152600f61028086015260116102a086015260186102c086015260076102e08601526013610300860152601b610320860181905260176103408701526006610360870152601a61038087015260056103a087015260046103c08701819052601f6103e08801529688901c637fffffff1680891763ffffffff998a1690911790941c939093179586901c630fffffff1680871796881617901c949094179384901c61ffff168085179592948493611408926307c4acdd92909116176118e2565b63ffffffff16901c63ffffffff166020811061142657611426611a84565b60200201519392505050565b6114886040805180820182526000808252825161010081018452606060c0820181815260e083018490528252602082810184905294820183905281018290526080810182905260a0810191909152909182015290565b6040516335369a6b60e21b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d4da69ac90602401600060405180830381865afa1580156114ed573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526104cc9190810190611ac3565b60405163d2e8756160e01b81523a60048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d2e8756190602401602060405180830381865afa15801561157c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106db9190611786565b63ffffffff811681146115b257600080fd5b50565b6000806000606084860312156115ca57600080fd5b83356115d5816115a0565b95602085013595506040909401359392505050565b6000602082840312156115fc57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b6040805190810167ffffffffffffffff8111828210171561163c5761163c611603565b60405290565b60405160c0810167ffffffffffffffff8111828210171561163c5761163c611603565b604051601f8201601f1916810167ffffffffffffffff8111828210171561168e5761168e611603565b604052919050565b600067ffffffffffffffff8211156116b0576116b0611603565b50601f01601f191660200190565b6000602082840312156116d057600080fd5b813567ffffffffffffffff8111156116e757600080fd5b8201601f810184136116f857600080fd5b803561170b61170682611696565b611665565b81815285602083850101111561172057600080fd5b81602084016020830137600091810160200191909152949350505050565b634e487b7160e01b600052600160045260246000fd5b6001600160a01b03811681146115b257600080fd5b60006020828403121561177b57600080fd5b815161048481611754565b60006020828403121561179857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000828210156117c7576117c761179f565b500390565b600060ff821660ff8416808210156117e6576117e661179f565b90039392505050565b600181815b8085111561182a5781600019048211156118105761181061179f565b8085161561181d57918102915b93841c93908002906117f4565b509250929050565b600082611841575060016104cc565b8161184e575060006104cc565b8160018114611864576002811461186e5761188a565b60019150506104cc565b60ff84111561187f5761187f61179f565b50506001821b6104cc565b5060208310610133831016604e8410600b84101617156118ad575081810a6104cc565b6118b783836117ef565b80600019048211156118cb576118cb61179f565b029392505050565b600061048460ff841683611832565b60008160001904831182151516156118fc576118fc61179f565b500290565b60005b8381101561191c578181015183820152602001611904565b8381111561192b576000848401525b50505050565b60008151808452611949816020860160208601611901565b601f01601f19169290920160200192915050565b6020815281511515602082015260006020830151604080840152805160c0606085015280516040610120860152611998610160860182611931565b60209283015163ffffffff166101408701529183015160ff81166080870152919050604083015160ff811660a08701529150606083015160ff811660c08701529150608083015167ffffffffffffffff811660e0870152915060a08301519250610b7061010086018467ffffffffffffffff169052565b805180151581146107f657600080fd5b600060208284031215611a3157600080fd5b61048482611a0f565b6020815260006104846020830184611931565b634e487b7160e01b600052602160045260246000fd5b600060208284031215611a7557600080fd5b81516004811061048457600080fd5b634e487b7160e01b600052603260045260246000fd5b805160ff811681146107f657600080fd5b805167ffffffffffffffff811681146107f657600080fd5b60006020808385031215611ad657600080fd5b825167ffffffffffffffff80821115611aee57600080fd5b9084019060408287031215611b0257600080fd5b611b0a611619565b611b1383611a0f565b81528383015182811115611b2657600080fd5b929092019160c08388031215611b3b57600080fd5b611b43611642565b835183811115611b5257600080fd5b84016040818a031215611b6457600080fd5b611b6c611619565b815185811115611b7b57600080fd5b82019450601f85018a13611b8e57600080fd5b8451611b9c61170682611696565b8181528b89838901011115611bb057600080fd5b611bbf828a83018b8a01611901565b825250818701519450611bd1856115a0565b808701859052825250611be5848601611a9a565b85820152611bf560408501611a9a565b6040820152611c0660608501611a9a565b6060820152611c1760808501611aab565b6080820152611c2860a08501611aab565b60a082015293810193909352509094935050505056fea2646970667358221220b57b35529e19ee0bd2543d9f0a3dae4abb235544e26ae12075f03afb397ed50e64736f6c634300080b003360a0604052306080523480156200001557600080fd5b50620000213362000041565b6040805160208101909152600081526200003b90620000a1565b62000b4d565b600080516020620024cf83398151915280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b620000e0604051806040016040528060118152602001700a0f120508021a01801a0210022202100b60781b815250620000e360201b6200099b1760201c565b50565b600080516020620024ef83398151915280546200010090620008ee565b1590506200016d5760405162461bcd60e51b815260206004820152602f60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a20616c726560448201526e18591e481a5b9a5d1a585b1a5e9959608a1b60648201526084015b60405180910390fd5b620001788162000183565b620000e03362000041565b60008151116200019757620001976200092b565b8051620001ba90600080516020620024ef83398151915290602084019062000848565b507f375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfbab80546001600160d01b0319167403d090000000000007a120000000003b9aca00330217808255620002449060029060ff610100820416906001600160401b036201000082048116916a01000000000000000000008104821691600160901b9091041662000248565b5050565b6000826001600160401b031611620002b15760405162461bcd60e51b815260206004820152602560248201527f5769746e6574526571756573744d616c6c6561626c65426173653a206e6f2072604482015264195dd85c9960da1b606482015260840162000164565b60018560ff1610158015620002ca5750607f8560ff1611155b6200033e5760405162461bcd60e51b815260206004820152603c60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a206e756d6260448201527f6572206f66207769746e6573736573206f7574206f662072616e676500000000606482015260840162000164565b60338460ff161015801562000357575060638460ff1611155b620003ba5760405162461bcd60e51b815260206004820152603d6024820152600080516020620024af83398151915260448201527f657373696e6720636f6e73656e737573206f7574206f662072616e6765000000606482015260840162000164565b633b9aca00836001600160401b031610156200042e5760405162461bcd60e51b815260206004820152603d6024820152600080516020620024af83398151915260448201527f657373696e6720636f6c6c61746572616c2062656c6f77203120574954000000606482015260840162000164565b600080516020620024ef8339815191526200044e600160fc1b846200061e565b6200045e600360fb1b88620007d3565b6200046e600160fd1b856200061e565b6200047e600560fb1b89620007d3565b6200048e600360fc1b896200061e565b604051602001620004a5969594939291906200097f565b60408051601f198184030181529190528051620004ea917f375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba99160209091019062000848565b50620005a4600080516020620024cf83398151915260020180546200050f90620008ee565b80601f01602080910402602001604051908101604052809291908181526020018280546200053d90620008ee565b80156200058e5780601f1062000562576101008083540402835291602001916200058e565b820191906000526020600020905b8154815290600101906020018083116200057057829003601f168201915b5050505050620007eb60201b62000a2a1760201c565b600080516020620024cf833981519152600301556040805160ff8781168252861660208201526001600160401b0385811682840152848116606083015283166080820152905133917f897a395aeb2699d9730b6377870654a5c371d6bb6dc4486cfc5c80eeafd095b0919081900360a00190a25050505050565b60608160025b607f826001600160401b031611156200065e576007826001600160401b0316901c915060018162000656919062000a76565b905062000624565b6000816001600160401b03166001600160401b0381111562000684576200068462000aa4565b6040519080825280601f01601f191660200182016040528015620006af576020820181803683370190505b5090508492508581600081518110620006cc57620006cc62000aba565b60200101906001600160f81b031916908160001a90535060015b826001600160401b0316816001600160401b03161015620007665783607f1660801760f81b82826001600160401b03168151811062000729576200072962000aba565b60200101906001600160f81b031916908160001a9053506007846001600160401b0316901c935080806200075d9062000ad0565b915050620006e6565b50607f60f81b816200077a60018562000afa565b6001600160401b03168151811062000796576200079662000aba565b0160200180519091167fff000000000000000000000000000000000000000000000000000000000000001690600082901a90535095945050505050565b6060620007e48360ff84166200061e565b9392505050565b6000600282604051620007ff919062000b25565b602060405180830381855afa1580156200081d573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019062000842919062000b33565b92915050565b8280546200085690620008ee565b90600052602060002090601f0160209004810192826200087a5760008555620008c5565b82601f106200089557805160ff1916838001178555620008c5565b82800160010185558215620008c5579182015b82811115620008c5578251825591602001919060010190620008a8565b50620008d3929150620008d7565b5090565b5b80821115620008d35760008155600101620008d8565b600181811c908216806200090357607f821691505b602082108114156200092557634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052600160045260246000fd5b6000815160005b8181101562000964576020818501810151868301520162000948565b8181111562000974576000828601525b509290920192915050565b600080885481600182811c9150808316806200099c57607f831692505b6020808410821415620009bd57634e487b7160e01b86526022600452602486fd5b818015620009d45760018114620009e65762000a15565b60ff1986168952848901965062000a15565b60008f81526020902060005b8681101562000a0d5781548b820152908501908301620009f2565b505084890196505b50505050505062000a5362000a4c62000a4562000a3e62000a37858d62000941565b8b62000941565b8962000941565b8762000941565b8562000941565b9998505050505050505050565b634e487b7160e01b600052601160045260246000fd5b60006001600160401b0382811684821680830382111562000a9b5762000a9b62000a60565b01949350505050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60006001600160401b038281168082141562000af05762000af062000a60565b6001019392505050565b60006001600160401b038381169083168181101562000b1d5762000b1d62000a60565b039392505050565b6000620007e4828462000941565b60006020828403121562000b4657600080fd5b5051919050565b60805161192362000b8c6000396000818161020c0152818161027501528181610ac501528181610b730152818161100101526110b001526119236000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c80638da5cb5b116100a2578063daaa360c11610071578063daaa360c146102c7578063ef53d97a146102da578063f0940002146102e2578063f2fde38b146102ea578063ff21c3ba146102fd57600080fd5b80638da5cb5b1461025f578063a04daef014610267578063d196c2e3146102a1578063d9b9a961146102b457600080fd5b806352d1902d116100e957806352d1902d146101cc5780636f2ddd93146101f25780637104ddb214610207578063715018a61461022e5780638a481dad1461023657600080fd5b806309bd5a601461011b57806309ed460714610136578063439fab911461015657806348f9b8311461016b575b600080fd5b610123610310565b6040519081526020015b60405180910390f35b61013e610323565b6040516001600160a01b03909116815260200161012d565b6101696101643660046113ff565b6103f3565b005b610173610428565b60405161012d9190600060a08201905060ff835116825260ff602084015116602083015260408301516001600160401b038082166040850152806060860151166060850152806080860151166080850152505092915050565b7f851d0a92a3ad30295bef33afc69d6874779826b7789386b336e22621365ed2c2610123565b6101fa6104b5565b60405161012d91906114df565b61013e7f000000000000000000000000000000000000000000000000000000000000000081565b610169610550565b61023e610594565b6040516fffffffffffffffffffffffffffffffff909116815260200161012d565b61013e6105f5565b604051306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161415815260200161012d565b6101696102af366004611528565b61060e565b6101696102c2366004611572565b61069d565b61013e6102d536600461158d565b610739565b61023e61080c565b6101fa61083b565b6101696102f83660046115a6565b610853565b61016961030b3660046115cf565b6108f0565b600061031a610a82565b60030154905090565b600061032d610aa6565b9050806001600160a01b031663439fab91610346610a82565b6001016040518263ffffffff1660e01b81526004016103659190611634565b600060405180830381600087803b15801561037f57600080fd5b505af1158015610393573d6000803e3d6000fd5b505060405163f2fde38b60e01b81523360048201526001600160a01b038416925063f2fde38b9150602401600060405180830381600087803b1580156103d857600080fd5b505af11580156103ec573d6000803e3d6000fd5b5050505090565b610425604051806040016040528060118152602001700a0f120508021a01801a0210022202100b60781b81525061099b565b50565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915261045b610a82565b6040805160a0810182526004929092015460ff808216845261010082041660208401526001600160401b03620100008204811692840192909252600160501b810482166060840152600160901b9004166080820152919050565b60606104bf610a82565b60010180546104cd906115f9565b80601f01602080910402602001604051908101604052809291908181526020018280546104f9906115f9565b80156105465780601f1061051b57610100808354040283529160200191610546565b820191906000526020600020905b81548152906001019060200180831161052957829003601f168201915b5050505050905090565b336105596105f5565b6001600160a01b0316146105885760405162461bcd60e51b815260040161057f906116b9565b60405180910390fd5b6105926000610bd5565b565b60008061059f610a82565b60040180549091506001600160401b03600160501b82048116916105cd91600160901b909104166002611704565b6105d79190611733565b81546105e6919060ff16611704565b6001600160401b031691505090565b60006105ff610a82565b546001600160a01b0316919050565b336106176105f5565b6001600160a01b03161461063d5760405162461bcd60e51b815260040161057f906116b9565b6000610647610a82565b600401805460ff8481166101000261ffff19909216908616171780825590915061069890849084906001600160401b03620100008204811691600160501b8104821691600160901b90910416610c42565b505050565b336106a66105f5565b6001600160a01b0316146106cc5760405162461bcd60e51b815260040161057f906116b9565b60006106d6610a82565b60040180546001600160401b03808516620100000269ffffffffffffffff000019831681178085559394506107359360ff91821693821693909317926101008104909116918691600160501b8104821691600160901b90910416610c42565b5050565b600061074482610fe2565b9050806001600160a01b031663439fab9161075d610a82565b6001016040518263ffffffff1660e01b815260040161077c9190611634565b600060405180830381600087803b15801561079657600080fd5b505af11580156107aa573d6000803e3d6000fd5b505060405163f2fde38b60e01b81523360048201526001600160a01b038416925063f2fde38b9150602401600060405180830381600087803b1580156107ef57600080fd5b505af1158015610803573d6000803e3d6000fd5b50505050919050565b600080610817610a82565b60040180549091506105e6906001600160401b03620100008204169060ff16611704565b6060610845610a82565b60020180546104cd906115f9565b3361085c6105f5565b6001600160a01b0316146108825760405162461bcd60e51b815260040161057f906116b9565b6001600160a01b0381166108e75760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161057f565b61042581610bd5565b336108f96105f5565b6001600160a01b03161461091f5760405162461bcd60e51b815260040161057f906116b9565b6000610929610a82565b60040180546fffffffffffffffffffffffffffffffff60501b1916600160501b6001600160401b038681169190910267ffffffffffffffff60901b191691909117600160901b85831602178083559192506106989160ff80821692610100830490911691620100009004168686610c42565b6109a3610a82565b60010180546109b1906115f9565b159050610a185760405162461bcd60e51b815260206004820152602f60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a20616c726560448201526e18591e481a5b9a5d1a585b1a5e9959608a1b606482015260840161057f565b610a2181611114565b61042533610bd5565b6000600282604051610a3c919061177a565b602060405180830381855afa158015610a59573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610a7c9190611796565b92915050565b7f375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba790565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000000000000000000000000000000000000000000000606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b602883015260009160378184f09250506001600160a01b038216610b675760405162461bcd60e51b815260206004820152601760248201527f436c6f6e61626c653a20435245415445206661696c6564000000000000000000604482015260640161057f565b816001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a45090565b6000610bdf610a82565b546001600160a01b0316905081610bf4610a82565b80546001600160a01b0319166001600160a01b03928316179055604051838216918316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000826001600160401b031611610ca95760405162461bcd60e51b815260206004820152602560248201527f5769746e6574526571756573744d616c6c6561626c65426173653a206e6f2072604482015264195dd85c9960da1b606482015260840161057f565b60018560ff1610158015610cc15750607f8560ff1611155b610d335760405162461bcd60e51b815260206004820152603c60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a206e756d6260448201527f6572206f66207769746e6573736573206f7574206f662072616e676500000000606482015260840161057f565b60338460ff1610158015610d4b575060638460ff1611155b610dbd5760405162461bcd60e51b815260206004820152603d60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a207769746e60448201527f657373696e6720636f6e73656e737573206f7574206f662072616e6765000000606482015260840161057f565b633b9aca00836001600160401b03161015610e405760405162461bcd60e51b815260206004820152603d60248201527f5769746e6574526571756573744d616c6c6561626c65426173653a207769746e60448201527f657373696e6720636f6c6c61746572616c2062656c6f77203120574954000000606482015260840161057f565b610e48610a82565b600101610e59600160fc1b846111b4565b610e67600360fb1b8861133a565b610e75600160fd1b856111b4565b610e83600560fb1b8961133a565b610e91600360fc1b896111b4565b604051602001610ea6969594939291906117af565b604051602081830303815290604052610ebd610a82565b6002019080519060200190610ed3929190611350565b50610f70610edf610a82565b6002018054610eed906115f9565b80601f0160208091040260200160405190810160405280929190818152602001828054610f19906115f9565b8015610f665780601f10610f3b57610100808354040283529160200191610f66565b820191906000526020600020905b815481529060010190602001808311610f4957829003601f168201915b5050505050610a2a565b610f78610a82565b600301556040805160ff8781168252861660208201526001600160401b0385811682840152848116606083015283166080820152905133917f897a395aeb2699d9730b6377870654a5c371d6bb6dc4486cfc5c80eeafd095b0919081900360a00190a25050505050565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000000000000000000000000000000000000000000000606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b60288301526000918360378285f59250506001600160a01b0382166110a45760405162461bcd60e51b815260206004820152601860248201527f436c6f6e61626c653a2043524541544532206661696c65640000000000000000604482015260640161057f565b816001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a450919050565b600081511161112557611125611872565b8061112e610a82565b6001019080519060200190611144929190611350565b50600061114f610a82565b60040180546001600160d01b0319167403d090000000000007a120000000003b9aca003302178082559091506107359060029060ff610100820416906001600160401b03620100008204811691600160501b8104821691600160901b90910416610c42565b60608160025b607f826001600160401b031611156111f0576007826001600160401b0316901c91506001816111e99190611733565b90506111ba565b6000816001600160401b03166001600160401b03811115611213576112136113e9565b6040519080825280601f01601f19166020018201604052801561123d576020820181803683370190505b509050849250858160008151811061125757611257611888565b60200101906001600160f81b031916908160001a90535060015b826001600160401b0316816001600160401b031610156112ea5783607f1660801760f81b82826001600160401b0316815181106112b0576112b0611888565b60200101906001600160f81b031916908160001a9053506007846001600160401b0316901c935080806112e29061189e565b915050611271565b50607f60f81b816112fc6001856118c5565b6001600160401b03168151811061131557611315611888565b0160200180519091166001600160f81b03191690600082901a90535095945050505050565b6060611349838360ff166111b4565b9392505050565b82805461135c906115f9565b90600052602060002090601f01602090048101928261137e57600085556113c4565b82601f1061139757805160ff19168380011785556113c4565b828001600101855582156113c4579182015b828111156113c45782518255916020019190600101906113a9565b506113d09291506113d4565b5090565b5b808211156113d057600081556001016113d5565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561141157600080fd5b81356001600160401b038082111561142857600080fd5b818401915084601f83011261143c57600080fd5b81358181111561144e5761144e6113e9565b604051601f8201601f19908116603f01168101908382118183101715611476576114766113e9565b8160405282815287602084870101111561148f57600080fd5b826020860160208301376000928101602001929092525095945050505050565b60005b838110156114ca5781810151838201526020016114b2565b838111156114d9576000848401525b50505050565b60208152600082518060208401526114fe8160408501602087016114af565b601f01601f19169190910160400192915050565b803560ff8116811461152357600080fd5b919050565b6000806040838503121561153b57600080fd5b61154483611512565b915061155260208401611512565b90509250929050565b80356001600160401b038116811461152357600080fd5b60006020828403121561158457600080fd5b6113498261155b565b60006020828403121561159f57600080fd5b5035919050565b6000602082840312156115b857600080fd5b81356001600160a01b038116811461134957600080fd5b600080604083850312156115e257600080fd5b6115eb8361155b565b91506115526020840161155b565b600181811c9082168061160d57607f821691505b6020821081141561162e57634e487b7160e01b600052602260045260246000fd5b50919050565b6000602080835260008454611648816115f9565b80848701526040600180841660008114611669576001811461167d576116ab565b60ff198516898401526060890195506116ab565b896000528660002060005b858110156116a35781548b8201860152908301908801611688565b8a0184019650505b509398975050505050505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b60006001600160401b038083168185168183048111821515161561172a5761172a6116ee565b02949350505050565b60006001600160401b03808316818516808303821115611755576117556116ee565b01949350505050565b600081516117708185602086016114af565b9290920192915050565b6000825161178c8184602087016114af565b9190910192915050565b6000602082840312156117a857600080fd5b5051919050565b60008088546117bd816115f9565b600182811680156117d557600181146117e657611815565b60ff19841687528287019450611815565b8c60005260208060002060005b8581101561180c5781548a8201529084019082016117f3565b50505082870194505b505050508751611829818360208c016114af565b875191019061183c818360208b016114af565b865191019061184f818360208a016114af565b61186461185e8284018861175e565b8661175e565b9a9950505050505050505050565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b60006001600160401b03808316818114156118bb576118bb6116ee565b6001019392505050565b60006001600160401b03838116908316818110156118e5576118e56116ee565b03939250505056fea26469706673582212205e7c6eb623f943a47c0a36f84a3518c2134b2551ebb99e2d97ffe94a9c6cb5a264736f6c634300080b00335769746e6574526571756573744d616c6c6561626c65426173653a207769746e375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba7375930152e1d0d102998be6e496b0cee86c9ecd0efef01014ecff169b17dfba8000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a

Deployed ByteCode

0x6080604052600436106101095760003560e01c80639938fd0c11610095578063a60ee26811610064578063a60ee2681461034c578063daaa360c1461036c578063e35329f81461038c578063e7d4a0161461039f578063fb476cad146103bf57600080fd5b80639938fd0c146102755780639bc86fec1461028b578063a04daef0146102bb578063a3252f68146102fa57600080fd5b806340b41daa116100dc57806340b41daa146101c3578063439fab91146101e357806346d1d21a14610205578063699b328a146102395780637104ddb21461024157600080fd5b806309ed46071461010e57806324cbbfc11461014057806336b651bb146101755780633b13e76e146101a3575b600080fd5b34801561011a57600080fd5b506101236103df565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561014c57600080fd5b5061016061015b3660046115b5565b6103f7565b60405163ffffffff9091168152602001610137565b34801561018157600080fd5b506101956101903660046115ea565b610445565b604051908152602001610137565b3480156101af57600080fd5b50600054610123906001600160a01b031681565b3480156101cf57600080fd5b506101956101de3660046115ea565b61048b565b3480156101ef57600080fd5b506102036101fe3660046116be565b6104d2565b005b34801561021157600080fd5b506101237f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a81565b610195610575565b34801561024d57600080fd5b506101237f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c81565b34801561028157600080fd5b5061019560015481565b34801561029757600080fd5b506102ab6102a63660046115ea565b6106e0565b6040519015158152602001610137565b3480156102c757600080fd5b507f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c6001600160a01b03163014156102ab565b34801561030657600080fd5b5061031a6103153660046115ea565b610709565b604080516001600160a01b0390961686526020860194909452928401919091526060830152608082015260a001610137565b34801561035857600080fd5b506101956103673660046115ea565b6107d5565b34801561037857600080fd5b506101236103873660046115ea565b6107e0565b61019561039a3660046115ea565b6107fb565b3480156103ab57600080fd5b506101606103ba3660046115b5565b610866565b3480156103cb57600080fd5b506101956103da3660046115ea565b6108e7565b60006103e9610b79565b90506103f481610ca8565b90565b600061043d848433610408866108e7565b604080516001600160a01b03909316602084015282015260600160405160208183030381529060405280519060200120610866565b949350505050565b60008082116104565761045661173e565b6001548083116104825760008181526002602052604090206001015461047d908490610dfd565b610484565b805b9392505050565b6000818152600260205260408120546001600160a01b03166104b8576104b382600154610e23565b6104cc565b600082815260026020819052604090912001545b92915050565b6000546001600160a01b03161561053e5760405162461bcd60e51b815260206004820152602560248201527f5769746e657452616e646f6d6e6573733a20616c726561647920696e697469616044820152641b1a5e995960da1b60648201526084015b60405180910390fd5b808060200190518101906105529190611769565b600080546001600160a01b0319166001600160a01b039290921691909117905550565b60004360015410156106d25760008054610597906001600160a01b0316610e63565b4360008181526002602081815260408084206003810188905580546001600160a01b031916339081178255600180548184018190558088528488209096018890559690965593548151624dead360e51b81529151969950969750929591948594937faf291bb4e1767569c77502edb6ad1009e856f57c09f214886c6becc9836c20c09389936001600160a01b0391909116926309bd5a609260048082019392918290030181865afa158015610650573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106749190611786565b6040805192835260208301919091520160405180910390a3348410156106cc57336108fc6106a286346117b5565b6040518115909202916000818181858888f193505050501580156106ca573d6000803e3d6000fd5b505b50505090565b6106db436107fb565b905090565b600081815260026020526040812060038101541580159061048457506104848160030154610f08565b60008181526002602052604080822060038101549151631dd27daf60e01b815260048101839052839182918291907f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b031690631dd27daf90602401602060405180830381865afa158015610788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ac9190611786565b815460018301546002909301546001600160a01b03909116999698509096509094909350915050565b60006104cc82610fad565b60006107eb82611039565b90506107f681610ca8565b919050565b600081815260026020526040812060038101541561086057610820816003015461116b565b9150811561086057336108fc61083684346117b5565b6040518115909202916000818181858888f1935050505015801561085e573d6000803e3d6000fd5b505b50919050565b600080610872856112a3565b61087d9060ff6117cc565b90506000600161088e8360026118d3565b61089891906117b5565b604080516020810187905290810187905260600160408051601f19818403018152919052805160209091012016905060ff82166108db63ffffffff8816836118e2565b901c9695505050505050565b6000818152600260205260408120546001600160a01b031661090f5761090c8261048b565b91505b6000828152600260205260409020600301548061096e5760405162461bcd60e51b815260206004820181905260248201527f5769746e657452616e646f6d6e6573733a206e6f742072616e646f6d697a65646044820152606401610535565b61097781610f08565b6109cf5760405162461bcd60e51b815260206004820152602360248201527f5769746e657452616e646f6d6e6573733a2070656e64696e672072616e646f6d604482015262697a6560e81b6064820152608401610535565b60006109da82611432565b604051635430260d60e11b81529091506001600160a01b037f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a169063a8604c1a90610a2990849060040161195d565b602060405180830381865afa158015610a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6a9190611a1f565b15610afc5760405163cf62d11560e01b81526001600160a01b037f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a169063cf62d11590610abb90849060040161195d565b602060405180830381865afa158015610ad8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043d9190611786565b6000848152600260208190526040909120015480610b675760405162461bcd60e51b815260206004820152602260248201527f5769746e657452616e646f6d6e6573733a206661756c74792072616e646f6d696044820152617a6560f01b6064820152608401610535565b610b70816108e7565b95945050505050565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b602883015260009160378184f09250506001600160a01b038216610c3a5760405162461bcd60e51b815260206004820152601760248201527f436c6f6e61626c653a20435245415445206661696c65640000000000000000006044820152606401610535565b816001600160a01b03167f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c6001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a45090565b60008060009054906101000a90046001600160a01b03166001600160a01b03166309ed46076040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610cfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d229190611769565b60405163f2fde38b60e01b81523360048201529091506001600160a01b0382169063f2fde38b90602401600060405180830381600087803b158015610d6657600080fd5b505af1158015610d7a573d6000803e3d6000fd5b5050604080516001600160a01b0385811660208301528616935063439fab919250016040516020818303038152906040526040518263ffffffff1660e01b8152600401610dc79190611a3a565b600060405180830381600087803b158015610de157600080fd5b505af1158015610df5573d6000803e3d6000fd5b505050505050565b60008183116108605760008281526002602052604090206001015461047d908490610dfd565b600081831015610e4a5760008281526002602052604090206001015461047d908490610e23565b5060009081526002602081905260409091200154919050565b600080610e6e611515565b60405163b281a7bd60e01b81526001600160a01b0385811660048301529192507f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a9091169063b281a7bd90839060240160206040518083038185885af1158015610edc573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f019190611786565b9150915091565b60006002604051631bc1eaf360e21b8152600481018490527f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b031690636f07abcc90602401602060405180830381865afa158015610f71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f959190611a63565b6003811115610fa657610fa6611a4d565b1492915050565b60405163d2e8756160e01b8152600481018290526000907f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b03169063d2e8756190602401602060405180830381865afa158015611015573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104cc9190611786565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81527f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c606081901b60148301526e5af43d82803e903d91602b57fd5bf360881b60288301526000918360378285f59250506001600160a01b0382166110fb5760405162461bcd60e51b815260206004820152601860248201527f436c6f6e61626c653a2043524541544532206661696c656400000000000000006044820152606401610535565b816001600160a01b03167f0000000000000000000000001ebd93231a7fe551e1d6405404df34909eff4c2c6001600160a01b0316336001600160a01b03167ff376596be5039d6b2fb36fead4c8a370eae426e790a869be8db074ab608cc24860405160405180910390a450919050565b604051631dd27daf60e01b81526004810182905260009081906001600160a01b037f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a1690631dd27daf90602401602060405180830381865afa1580156111d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111f99190611786565b90506000611205611515565b905060008282111561121e5761121b83836117b5565b90505b6040516366bfdc7560e01b8152600481018690527f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b0316906366bfdc759083906024016000604051808303818588803b15801561128157600080fd5b505af1158015611295573d6000803e3d6000fd5b509398975050505050505050565b60408051610400810182526000808252600960208301526001928201839052600a6060830152600d6080830152601560a0830152600260c08301819052601d60e0840152600b610100840152600e610120840152601061014084018190526012610160850152601661018085015260196101a085015260036101c0850152601e6101e085015260086102008501819052600c6102208601526014610240860152601c610260860152600f61028086015260116102a086015260186102c086015260076102e08601526013610300860152601b610320860181905260176103408701526006610360870152601a61038087015260056103a087015260046103c08701819052601f6103e08801529688901c637fffffff1680891763ffffffff998a1690911790941c939093179586901c630fffffff1680871796881617901c949094179384901c61ffff168085179592948493611408926307c4acdd92909116176118e2565b63ffffffff16901c63ffffffff166020811061142657611426611a84565b60200201519392505050565b6114886040805180820182526000808252825161010081018452606060c0820181815260e083018490528252602082810184905294820183905281018290526080810182905260a0810191909152909182015290565b6040516335369a6b60e21b8152600481018390527f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b03169063d4da69ac90602401600060405180830381865afa1580156114ed573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526104cc9190810190611ac3565b60405163d2e8756160e01b81523a60048201526000907f000000000000000000000000d653fbd7c736838289262f0f41a458f35393c88a6001600160a01b03169063d2e8756190602401602060405180830381865afa15801561157c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106db9190611786565b63ffffffff811681146115b257600080fd5b50565b6000806000606084860312156115ca57600080fd5b83356115d5816115a0565b95602085013595506040909401359392505050565b6000602082840312156115fc57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b6040805190810167ffffffffffffffff8111828210171561163c5761163c611603565b60405290565b60405160c0810167ffffffffffffffff8111828210171561163c5761163c611603565b604051601f8201601f1916810167ffffffffffffffff8111828210171561168e5761168e611603565b604052919050565b600067ffffffffffffffff8211156116b0576116b0611603565b50601f01601f191660200190565b6000602082840312156116d057600080fd5b813567ffffffffffffffff8111156116e757600080fd5b8201601f810184136116f857600080fd5b803561170b61170682611696565b611665565b81815285602083850101111561172057600080fd5b81602084016020830137600091810160200191909152949350505050565b634e487b7160e01b600052600160045260246000fd5b6001600160a01b03811681146115b257600080fd5b60006020828403121561177b57600080fd5b815161048481611754565b60006020828403121561179857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000828210156117c7576117c761179f565b500390565b600060ff821660ff8416808210156117e6576117e661179f565b90039392505050565b600181815b8085111561182a5781600019048211156118105761181061179f565b8085161561181d57918102915b93841c93908002906117f4565b509250929050565b600082611841575060016104cc565b8161184e575060006104cc565b8160018114611864576002811461186e5761188a565b60019150506104cc565b60ff84111561187f5761187f61179f565b50506001821b6104cc565b5060208310610133831016604e8410600b84101617156118ad575081810a6104cc565b6118b783836117ef565b80600019048211156118cb576118cb61179f565b029392505050565b600061048460ff841683611832565b60008160001904831182151516156118fc576118fc61179f565b500290565b60005b8381101561191c578181015183820152602001611904565b8381111561192b576000848401525b50505050565b60008151808452611949816020860160208601611901565b601f01601f19169290920160200192915050565b6020815281511515602082015260006020830151604080840152805160c0606085015280516040610120860152611998610160860182611931565b60209283015163ffffffff166101408701529183015160ff81166080870152919050604083015160ff811660a08701529150606083015160ff811660c08701529150608083015167ffffffffffffffff811660e0870152915060a08301519250610b7061010086018467ffffffffffffffff169052565b805180151581146107f657600080fd5b600060208284031215611a3157600080fd5b61048482611a0f565b6020815260006104846020830184611931565b634e487b7160e01b600052602160045260246000fd5b600060208284031215611a7557600080fd5b81516004811061048457600080fd5b634e487b7160e01b600052603260045260246000fd5b805160ff811681146107f657600080fd5b805167ffffffffffffffff811681146107f657600080fd5b60006020808385031215611ad657600080fd5b825167ffffffffffffffff80821115611aee57600080fd5b9084019060408287031215611b0257600080fd5b611b0a611619565b611b1383611a0f565b81528383015182811115611b2657600080fd5b929092019160c08388031215611b3b57600080fd5b611b43611642565b835183811115611b5257600080fd5b84016040818a031215611b6457600080fd5b611b6c611619565b815185811115611b7b57600080fd5b82019450601f85018a13611b8e57600080fd5b8451611b9c61170682611696565b8181528b89838901011115611bb057600080fd5b611bbf828a83018b8a01611901565b825250818701519450611bd1856115a0565b808701859052825250611be5848601611a9a565b85820152611bf560408501611a9a565b6040820152611c0660608501611a9a565b6060820152611c1760808501611aab565b6080820152611c2860a08501611aab565b60a082015293810193909352509094935050505056fea2646970667358221220b57b35529e19ee0bd2543d9f0a3dae4abb235544e26ae12075f03afb397ed50e64736f6c634300080b0033