Source Code
Overview
CELO Balance
CELO Value
$0.00Multichain Info
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
WitnetEncodingLib
Compiler Version
v0.8.17+commit.8df45f5f
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "./WitnetV2.sol";
/// @title A library for encoding Witnet Data Requests.
/// @author The Witnet Foundation.
library WitnetEncodingLib {
using WitnetBuffer for WitnetBuffer.Buffer;
using WitnetCBOR for WitnetCBOR.CBOR;
using WitnetCBOR for WitnetCBOR.CBOR[];
bytes internal constant WITNET_RADON_OPCODES_RESULT_TYPES =
hex"10ffffffffffffffffffffffffffffff0401ff010203050406071311ff01ffff07ff02ffffffffffffffffffffffffff0703ffffffffffffffffffffffffffff0405070202ff04040404ffffffffffff05070402040205050505ff04ff04ffffff010203050406070101ffffffffffff02ff050404000106060707ffffffffff";
// 10ffffffffffffffffffffffffffffff
// 0401ff000203050406070100ff01ffff
// 07ff02ffffffffffffffffffffffffff
// 0703ffffffffffffffffffffffffffff
// 0405070202ff04040404ffffffffffff
// 05070402040205050505ff04ff04ffff
// ff010203050406070101ffffffffffff
// 02ff050404000106060707ffffffffff
/// ===============================================================================================================
/// --- WitnetLib internal methods --------------------------------------------------------------------------------
function size(WitnetV2.RadonDataTypes _type) internal pure returns (uint16) {
if (_type == WitnetV2.RadonDataTypes.Integer
|| _type == WitnetV2.RadonDataTypes.Float
) {
return 9;
} else if (_type == WitnetV2.RadonDataTypes.Bool) {
return 1;
} else {
// undetermined
return 0;
}
}
/// ===============================================================================================================
/// --- WitnetLib public methods (if used library will have to linked to calling contracts) -----------------------
/// @notice Encode bytes array into given major type (UTF-8 not yet supported)
/// @param buf Bytes array
/// @return Marshaled bytes
function encode(bytes memory buf, uint majorType)
public pure
returns (bytes memory)
{
uint len = buf.length;
if (len < 23) {
return abi.encodePacked(
uint8((majorType << 5) | uint8(len)),
buf
);
} else {
uint8 buf0 = uint8((majorType << 5));
bytes memory buf1;
if (len <= 0xff) {
buf0 |= 24;
buf1 = abi.encodePacked(uint8(len));
} else if (len <= 0xffff) {
buf0 |= 25;
buf1 = abi.encodePacked(uint16(len));
} else if (len <= 0xffffffff) {
buf0 |= 26;
buf1 = abi.encodePacked(uint32(len));
} else {
buf0 |= 27;
buf1 = abi.encodePacked(uint64(len));
}
return abi.encodePacked(
buf0,
buf1,
buf
);
}
}
/// @notice Encode bytes array.
/// @param buf Bytes array
/// @return Mashaled bytes
function encode(bytes memory buf)
public pure
returns (bytes memory)
{
return encode(buf, WitnetCBOR.MAJOR_TYPE_BYTES);
}
/// @notice Encode string array (UTF-8 not yet supported).
/// @param str String bytes.
/// @return Mashaled bytes
function encode(string memory str)
public pure
returns (bytes memory)
{
return encode(bytes(str), WitnetCBOR.MAJOR_TYPE_STRING);
}
/// @dev Encode uint64 into tagged varint.
/// @dev See https://developers.google.com/protocol-buffers/docs/encoding#varints.
/// @param n Number
/// @param t Tag
/// @return buf Marshaled bytes
function encode(uint64 n, bytes1 t)
public pure
returns (bytes memory buf)
{
unchecked {
// 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;
}
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;
}
}
function encode(WitnetV2.RadonRetrieval memory source)
public pure
returns (bytes memory)
{
bytes memory _encodedMethod = encode(uint64(source.method), bytes1(0x08));
bytes memory _encodedUrl;
if (bytes(source.url).length > 0) {
_encodedUrl = abi.encodePacked(
encode(uint64(bytes(source.url).length), bytes1(0x12)),
bytes(source.url)
);
}
bytes memory _encodedScript;
if (source.script.length > 0) {
_encodedScript = abi.encodePacked(
encode(uint64(source.script.length), bytes1(0x1a)),
source.script
);
}
bytes memory _encodedBody;
if (bytes(source.body).length > 0) {
_encodedBody = abi.encodePacked(
encode(uint64(bytes(source.body).length), bytes1(0x22)),
bytes(source.body)
);
}
bytes memory _encodedHeaders;
if (source.headers.length > 0) {
for (uint _ix = 0; _ix < source.headers.length; _ix ++) {
bytes memory _headers = abi.encodePacked(
encode(uint64(bytes(source.headers[_ix][0]).length), bytes1(0x0a)),
bytes(source.headers[_ix][0]),
encode(uint64(bytes(source.headers[_ix][1]).length), bytes1(0x12)),
bytes(source.headers[_ix][1])
);
_encodedHeaders = abi.encodePacked(
_encodedHeaders,
encode(uint64(_headers.length), bytes1(0x2a)),
_headers
);
}
}
uint _innerSize = (
_encodedMethod.length
+ _encodedUrl.length
+ _encodedScript.length
+ _encodedBody.length
+ _encodedHeaders.length
);
return abi.encodePacked(
encode(uint64(_innerSize), bytes1(0x12)),
_encodedMethod,
_encodedUrl,
_encodedScript,
_encodedBody,
_encodedHeaders
);
}
function encode(
WitnetV2.RadonRetrieval[] memory sources,
string[][] memory args,
bytes memory aggregatorInnerBytecode,
bytes memory tallyInnerBytecode,
uint16 resultMaxSize
)
public pure
returns (bytes memory)
{
bytes[] memory encodedSources = new bytes[](sources.length);
for (uint ix = 0; ix < sources.length; ix ++) {
replaceWildcards(sources[ix], args[ix]);
encodedSources[ix] = encode(sources[ix]);
}
return abi.encodePacked(
(resultMaxSize > 0
? encode(uint64(resultMaxSize), 0x08)
: bytes("")
),
WitnetBuffer.concat(encodedSources),
encode(uint64(aggregatorInnerBytecode.length), bytes1(0x1a)),
aggregatorInnerBytecode,
encode(uint64(tallyInnerBytecode.length), bytes1(0x22)),
tallyInnerBytecode
);
}
function encode(WitnetV2.RadonReducer memory reducer)
public pure
returns (bytes memory bytecode)
{
if (reducer.script.length == 0) {
for (uint ix = 0; ix < reducer.filters.length; ix ++) {
bytecode = abi.encodePacked(
bytecode,
encode(reducer.filters[ix])
);
}
bytecode = abi.encodePacked(
bytecode,
encode(reducer.opcode)
);
} else {
return abi.encodePacked(
encode(uint64(reducer.script.length), bytes1(0x18)),
reducer.script
);
}
}
function encode(WitnetV2.RadonFilter memory filter)
public pure
returns (bytes memory bytecode)
{
bytecode = abi.encodePacked(
encode(uint64(filter.opcode), bytes1(0x08)),
filter.args.length > 0
? abi.encodePacked(
encode(uint64(filter.args.length), bytes1(0x12)),
filter.args
) : bytes("")
);
return abi.encodePacked(
encode(uint64(bytecode.length), bytes1(0x0a)),
bytecode
);
}
function encode(WitnetV2.RadonReducerOpcodes opcode)
public pure
returns (bytes memory)
{
return encode(uint64(opcode), bytes1(0x10));
}
function encode(WitnetV2.RadonSLA memory sla)
public pure
returns (bytes memory)
{
return abi.encodePacked(
encode(uint64(sla.witnessReward), bytes1(0x10)),
encode(uint64(sla.numWitnesses), bytes1(0x18)),
encode(uint64(sla.minerCommitRevealFee), bytes1(0x20)),
encode(uint64(sla.minConsensusPercentage), bytes1(0x28)),
encode(uint64(sla.witnessCollateral), bytes1(0x30))
);
}
function replaceCborStringsFromBytes(
bytes memory data,
string[] memory args
)
public pure
returns (bytes memory)
{
WitnetCBOR.CBOR memory cbor = WitnetCBOR.fromBytes(data);
while (!cbor.eof()) {
if (cbor.majorType == WitnetCBOR.MAJOR_TYPE_STRING) {
_replaceCborWildcards(cbor, args);
cbor = cbor.settle();
} else {
cbor = cbor.skip().settle();
}
}
return cbor.buffer.data;
}
function replaceWildcards(WitnetV2.RadonRetrieval memory self, string[] memory args)
public pure
{
self.url = WitnetBuffer.replace(self.url, args);
self.body = WitnetBuffer.replace(self.body, args);
self.script = replaceCborStringsFromBytes(self.script, args);
}
function validate(
WitnetV2.DataRequestMethods method,
string memory url,
string memory body,
string[2][] memory headers,
bytes memory script
)
public pure
returns (bytes32)
{
if (!(
bytes(url).length > 0
&& (method == WitnetV2.DataRequestMethods.HttpGet || method == WitnetV2.DataRequestMethods.HttpPost)
|| method == WitnetV2.DataRequestMethods.Rng
&& bytes(url).length == 0
&& headers.length == 0
&& script.length >= 1
)) {
revert WitnetV2.UnsupportedDataRequestMethod(
uint8(method),
url,
body,
headers
);
}
return keccak256(abi.encode(method, url, body, headers, script));
}
function validate(
WitnetV2.DataRequestMethods method,
string memory schema,
string memory authority,
string memory path,
string memory query,
string memory body,
string[2][] memory headers,
bytes memory script
)
public pure
returns (bytes32)
{
if (!(
(method == WitnetV2.DataRequestMethods.HttpGet || method == WitnetV2.DataRequestMethods.HttpPost)
&& bytes(authority).length > 0
&& (
bytes(schema).length == 0
|| keccak256(bytes(schema)) == keccak256(bytes("https://"))
|| keccak256(bytes(schema)) == keccak256(bytes("http://"))
)
|| method == WitnetV2.DataRequestMethods.Rng
&& bytes(schema).length == 0
&& bytes(authority).length == 0
&& bytes(path).length == 0
&& bytes(query).length == 0
&& bytes(body).length == 0
&& headers.length == 0
&& script.length >= 1
)) {
revert WitnetV2.UnsupportedDataRequestMethod(
uint8(method),
schema,
body,
headers
);
}
return keccak256(abi.encode(
method,
schema,
authority,
path,
query,
body,
headers,
script
));
}
function validate(
WitnetV2.RadonDataTypes dataType,
uint16 maxDataSize
)
public pure
returns (uint16)
{
if (
dataType == WitnetV2.RadonDataTypes.Any
|| dataType == WitnetV2.RadonDataTypes.String
|| dataType == WitnetV2.RadonDataTypes.Bytes
|| dataType == WitnetV2.RadonDataTypes.Array
|| dataType == WitnetV2.RadonDataTypes.Map
) {
if (/*maxDataSize == 0 ||*/maxDataSize > 2048) {
revert WitnetV2.UnsupportedRadonDataType(
uint8(dataType),
maxDataSize
);
}
return maxDataSize;
} else if (
dataType == WitnetV2.RadonDataTypes.Integer
|| dataType == WitnetV2.RadonDataTypes.Float
|| dataType == WitnetV2.RadonDataTypes.Bool
) {
return 0; // TBD: size(dataType);
} else {
revert WitnetV2.UnsupportedRadonDataType(
uint8(dataType),
size(dataType)
);
}
}
function validate(WitnetV2.RadonFilter memory filter)
public pure
{
if (
filter.opcode == WitnetV2.RadonFilterOpcodes.StandardDeviation
) {
// check filters that require arguments
if (filter.args.length == 0) {
revert WitnetV2.RadonFilterMissingArgs(uint8(filter.opcode));
}
} else if (
filter.opcode == WitnetV2.RadonFilterOpcodes.Mode
) {
// check filters that don't require any arguments
if (filter.args.length > 0) {
revert WitnetV2.UnsupportedRadonFilterArgs(uint8(filter.opcode), filter.args);
}
} else {
// reject unsupported opcodes
revert WitnetV2.UnsupportedRadonFilterOpcode(uint8(filter.opcode));
}
}
function validate(WitnetV2.RadonReducer memory reducer)
public pure
{
if (reducer.script.length == 0) {
if (!(
reducer.opcode == WitnetV2.RadonReducerOpcodes.AverageMean
|| reducer.opcode == WitnetV2.RadonReducerOpcodes.StandardDeviation
|| reducer.opcode == WitnetV2.RadonReducerOpcodes.Mode
|| reducer.opcode == WitnetV2.RadonReducerOpcodes.ConcatenateAndHash
|| reducer.opcode == WitnetV2.RadonReducerOpcodes.AverageMedian
)) {
revert WitnetV2.UnsupportedRadonReducerOpcode(uint8(reducer.opcode));
}
for (uint ix = 0; ix < reducer.filters.length; ix ++) {
validate(reducer.filters[ix]);
}
} else {
if (uint8(reducer.opcode) != 0xff || reducer.filters.length > 0) {
revert WitnetV2.UnsupportedRadonReducerScript(
uint8(reducer.opcode),
reducer.script,
0
);
}
}
}
function validate(WitnetV2.RadonSLA memory sla)
public pure
{
if (sla.witnessReward == 0) {
revert WitnetV2.RadonSlaNoReward();
}
if (sla.numWitnesses == 0) {
revert WitnetV2.RadonSlaNoWitnesses();
} else if (sla.numWitnesses > 127) {
revert WitnetV2.RadonSlaTooManyWitnesses(sla.numWitnesses);
}
if (
sla.minConsensusPercentage < 51
|| sla.minConsensusPercentage > 99
) {
revert WitnetV2.RadonSlaConsensusOutOfRange(sla.minConsensusPercentage);
}
if (sla.witnessCollateral < 10 ** 9) {
revert WitnetV2.RadonSlaLowCollateral(sla.witnessCollateral);
}
}
function verifyRadonScriptResultDataType(bytes memory script)
public pure
returns (WitnetV2.RadonDataTypes)
{
return _verifyRadonScriptResultDataType(
WitnetCBOR.fromBytes(script),
false
);
}
/// ===============================================================================================================
/// --- WitnetLib private methods ---------------------------------------------------------------------------------
function _replaceCborWildcards(
WitnetCBOR.CBOR memory self,
string[] memory args
) private pure
{
uint _rewind = self.len;
uint _start = self.buffer.cursor;
bytes memory _peeks = bytes(self.readString());
(bytes memory _pokes, uint _replacements) = WitnetBuffer.replace(_peeks, args);
if (_replacements > 0) {
bytes memory _encodedPokes = encode(string(_pokes));
self.buffer.cursor = _start - _rewind;
self.buffer.mutate(
_peeks.length + _rewind,
_encodedPokes
);
self.buffer.cursor += _encodedPokes.length;
}
}
function _verifyRadonScriptResultDataType(WitnetCBOR.CBOR memory self, bool flip)
private pure
returns (WitnetV2.RadonDataTypes)
{
if (self.majorType == WitnetCBOR.MAJOR_TYPE_ARRAY) {
WitnetCBOR.CBOR[] memory items = self.readArray();
if (items.length > 1) {
return flip
? _verifyRadonScriptResultDataType(items[0], false)
: _verifyRadonScriptResultDataType(items[items.length - 2], true)
;
} else {
return WitnetV2.RadonDataTypes.Any;
}
} else if (self.majorType == WitnetCBOR.MAJOR_TYPE_INT) {
uint cursor = self.buffer.cursor;
uint opcode = self.readUint();
uint8 dataType = (opcode > WITNET_RADON_OPCODES_RESULT_TYPES.length
? 0xff
: uint8(WITNET_RADON_OPCODES_RESULT_TYPES[opcode])
);
if (dataType > uint8(type(WitnetV2.RadonDataTypes).max)) {
revert WitnetV2.UnsupportedRadonScriptOpcode(
self.buffer.data,
cursor,
uint8(opcode)
);
}
return WitnetV2.RadonDataTypes(dataType);
} else {
revert WitnetCBOR.UnexpectedMajorType(
WitnetCBOR.MAJOR_TYPE_INT,
self.majorType
);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
/// @title The Witnet Data Request basic interface.
/// @author The Witnet Foundation.
interface IWitnetRequest {
/// @notice A `IWitnetRequest` is constructed around a `bytes` value containing
/// @notice a well-formed Witnet Data Request using Protocol Buffers.
function bytecode() external view returns (bytes memory);
/// @notice Returns SHA256 hash of Witnet Data Request as CBOR-encoded bytes.
function hash() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../interfaces/IWitnetRequest.sol";
import "./WitnetCBOR.sol";
library Witnet {
using WitnetBuffer for WitnetBuffer.Buffer;
using WitnetCBOR for WitnetCBOR.CBOR;
using WitnetCBOR for WitnetCBOR.CBOR[];
/// Struct containing both request and response data related to every query posted to the Witnet Request Board
struct Query {
Request request;
Response response;
address from; // Address from which the request was posted.
}
/// Possible status of a Witnet query.
enum QueryStatus {
Unknown,
Posted,
Reported,
Deleted
}
/// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
struct Request {
address addr; // Address of the IWitnetRequest contract containing Witnet data request raw bytecode.
bytes32 slaHash; // Radon SLA hash of the Witnet data request.
bytes32 radHash; // Radon radHash of the Witnet data request.
uint256 gasprice; // Minimum gas price the DR resolver should pay on the solving tx.
uint256 reward; // Escrowed reward to be paid to the DR resolver.
}
/// Data kept in EVM-storage containing Witnet-provided response metadata and result.
struct Response {
address reporter; // Address from which the result was reported.
uint256 timestamp; // Timestamp of the Witnet-provided result.
bytes32 drTxHash; // Hash of the Witnet transaction that solved the queried Data Request.
bytes cborBytes; // Witnet-provided result CBOR-bytes to the queried Data Request.
}
/// Data struct containing the Witnet-provided result to a Data Request.
struct Result {
bool success; // Flag stating whether the request could get solved successfully, or not.
WitnetCBOR.CBOR value; // Resulting value, in CBOR-serialized bytes.
}
/// Final query's result status from a requester's point of view.
enum ResultStatus {
Void,
Awaiting,
Ready,
Error
}
/// Data struct describing an error when trying to fetch a Witnet-provided result to a Data Request.
struct ResultError {
ResultErrorCodes code;
string reason;
}
enum ResultErrorCodes {
/// 0x00: Unknown error. Something went really bad!
Unknown,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Script format errors =============================================================================================
/// 0x01: At least one of the source scripts is not a valid CBOR-encoded value.
SourceScriptNotCBOR,
/// 0x02: The CBOR value decoded from a source script is not an Array.
SourceScriptNotArray,
/// 0x03: The Array value decoded form a source script is not a valid Data Request.
SourceScriptNotRADON,
/// Unallocated
ScriptFormat0x04, ScriptFormat0x05, ScriptFormat0x06, ScriptFormat0x07, ScriptFormat0x08, ScriptFormat0x09,
ScriptFormat0x0A, ScriptFormat0x0B, ScriptFormat0x0C, ScriptFormat0x0D, ScriptFormat0x0E, ScriptFormat0x0F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Complexity errors ================================================================================================
/// 0x10: The request contains too many sources.
RequestTooManySources,
/// 0x11: The script contains too many calls.
ScriptTooManyCalls,
/// Unallocated
Complexity0x12, Complexity0x13, Complexity0x14, Complexity0x15, Complexity0x16, Complexity0x17, Complexity0x18,
Complexity0x19, Complexity0x1A, Complexity0x1B, Complexity0x1C, Complexity0x1D, Complexity0x1E, Complexity0x1F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Operator errors ===================================================================================================
/// 0x20: The operator does not exist.
UnsupportedOperator,
/// Unallocated
Operator0x21, Operator0x22, Operator0x23, Operator0x24, Operator0x25, Operator0x26, Operator0x27, Operator0x28,
Operator0x29, Operator0x2A, Operator0x2B, Operator0x2C, Operator0x2D, Operator0x2E, Operator0x2F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Retrieval-specific errors =========================================================================================
/// 0x30: At least one of the sources could not be retrieved, but returned HTTP error.
HTTP,
/// 0x31: Retrieval of at least one of the sources timed out.
RetrievalTimeout,
/// Unallocated
Retrieval0x32, Retrieval0x33, Retrieval0x34, Retrieval0x35, Retrieval0x36, Retrieval0x37, Retrieval0x38,
Retrieval0x39, Retrieval0x3A, Retrieval0x3B, Retrieval0x3C, Retrieval0x3D, Retrieval0x3E, Retrieval0x3F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Math errors =======================================================================================================
/// 0x40: Math operator caused an underflow.
Underflow,
/// 0x41: Math operator caused an overflow.
Overflow,
/// 0x42: Tried to divide by zero.
DivisionByZero,
/// Unallocated
Math0x43, Math0x44, Math0x45, Math0x46, Math0x47, Math0x48, Math0x49,
Math0x4A, Math0x4B, Math0x4C, Math0x4D, Math0x4E, Math0x4F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Other errors ======================================================================================================
/// 0x50: Received zero reveals
NoReveals,
/// 0x51: Insufficient consensus in tally precondition clause
InsufficientConsensus,
/// 0x52: Received zero commits
InsufficientCommits,
/// 0x53: Generic error during tally execution
TallyExecution,
/// Unallocated
OtherError0x54, OtherError0x55, OtherError0x56, OtherError0x57, OtherError0x58, OtherError0x59,
OtherError0x5A, OtherError0x5B, OtherError0x5C, OtherError0x5D, OtherError0x5E, OtherError0x5F,
/// 0x60: Invalid reveal serialization (malformed reveals are converted to this value)
MalformedReveal,
/// Unallocated
OtherError0x61, OtherError0x62, OtherError0x63, OtherError0x64, OtherError0x65, OtherError0x66,
OtherError0x67, OtherError0x68, OtherError0x69, OtherError0x6A, OtherError0x6B, OtherError0x6C,
OtherError0x6D, OtherError0x6E,OtherError0x6F,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Access errors =====================================================================================================
/// 0x70: Tried to access a value from an array using an index that is out of bounds
ArrayIndexOutOfBounds,
/// 0x71: Tried to access a value from a map using a key that does not exist
MapKeyNotFound,
/// Unallocated
OtherError0x72, OtherError0x73, OtherError0x74, OtherError0x75, OtherError0x76, OtherError0x77, OtherError0x78,
OtherError0x79, OtherError0x7A, OtherError0x7B, OtherError0x7C, OtherError0x7D, OtherError0x7E, OtherError0x7F,
OtherError0x80, OtherError0x81, OtherError0x82, OtherError0x83, OtherError0x84, OtherError0x85, OtherError0x86,
OtherError0x87, OtherError0x88, OtherError0x89, OtherError0x8A, OtherError0x8B, OtherError0x8C, OtherError0x8D,
OtherError0x8E, OtherError0x8F, OtherError0x90, OtherError0x91, OtherError0x92, OtherError0x93, OtherError0x94,
OtherError0x95, OtherError0x96, OtherError0x97, OtherError0x98, OtherError0x99, OtherError0x9A, OtherError0x9B,
OtherError0x9C, OtherError0x9D, OtherError0x9E, OtherError0x9F, OtherError0xA0, OtherError0xA1, OtherError0xA2,
OtherError0xA3, OtherError0xA4, OtherError0xA5, OtherError0xA6, OtherError0xA7, OtherError0xA8, OtherError0xA9,
OtherError0xAA, OtherError0xAB, OtherError0xAC, OtherError0xAD, OtherError0xAE, OtherError0xAF, OtherError0xB0,
OtherError0xB1, OtherError0xB2, OtherError0xB3, OtherError0xB4, OtherError0xB5, OtherError0xB6, OtherError0xB7,
OtherError0xB8, OtherError0xB9, OtherError0xBA, OtherError0xBB, OtherError0xBC, OtherError0xBD, OtherError0xBE,
OtherError0xBF, OtherError0xC0, OtherError0xC1, OtherError0xC2, OtherError0xC3, OtherError0xC4, OtherError0xC5,
OtherError0xC6, OtherError0xC7, OtherError0xC8, OtherError0xC9, OtherError0xCA, OtherError0xCB, OtherError0xCC,
OtherError0xCD, OtherError0xCE, OtherError0xCF, OtherError0xD0, OtherError0xD1, OtherError0xD2, OtherError0xD3,
OtherError0xD4, OtherError0xD5, OtherError0xD6, OtherError0xD7, OtherError0xD8, OtherError0xD9, OtherError0xDA,
OtherError0xDB, OtherError0xDC, OtherError0xDD, OtherError0xDE, OtherError0xDF,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Bridge errors: errors that only belong in inter-client communication ==============================================
/// 0xE0: Requests that cannot be parsed must always get this error as their result.
/// However, this is not a valid result in a Tally transaction, because invalid requests
/// are never included into blocks and therefore never get a Tally in response.
BridgeMalformedRequest,
/// 0xE1: Witnesses exceeds 100
BridgePoorIncentives,
/// 0xE2: The request is rejected on the grounds that it may cause the submitter to spend or stake an
/// amount of value that is unjustifiably high when compared with the reward they will be getting
BridgeOversizedResult,
/// Unallocated
OtherError0xE3, OtherError0xE4, OtherError0xE5, OtherError0xE6, OtherError0xE7, OtherError0xE8, OtherError0xE9,
OtherError0xEA, OtherError0xEB, OtherError0xEC, OtherError0xED, OtherError0xEE, OtherError0xEF, OtherError0xF0,
OtherError0xF1, OtherError0xF2, OtherError0xF3, OtherError0xF4, OtherError0xF5, OtherError0xF6, OtherError0xF7,
OtherError0xF8, OtherError0xF9, OtherError0xFA, OtherError0xFB, OtherError0xFC, OtherError0xFD, OtherError0xFE,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 0xFF: Some tally error is not intercepted but should
UnhandledIntercept
}
/// ===============================================================================================================
/// --- 'Witnet.Result' helper methods ----------------------------------------------------------------------------
modifier _isError(Result memory result) {
require(!result.success, "Witnet: no actual errors");
_;
}
modifier _isReady(Result memory result) {
require(result.success, "Witnet: tried to decode value from errored result.");
_;
}
/// @dev Decode an address from the Witnet.Result's CBOR value.
function asAddress(Witnet.Result memory result)
internal pure
_isReady(result)
returns (address)
{
if (result.value.majorType == uint8(WitnetCBOR.MAJOR_TYPE_BYTES)) {
return toAddress(result.value.readBytes());
} else {
// TODO
revert("WitnetLib: reading address from string not yet supported.");
}
}
/// @dev Decode a `bool` value from the Witnet.Result's CBOR value.
function asBool(Witnet.Result memory result)
internal pure
_isReady(result)
returns (bool)
{
return result.value.readBool();
}
/// @dev Decode a `bytes` value from the Witnet.Result's CBOR value.
function asBytes(Witnet.Result memory result)
internal pure
_isReady(result)
returns(bytes memory)
{
return result.value.readBytes();
}
/// @dev Decode a `bytes4` value from the Witnet.Result's CBOR value.
function asBytes4(Witnet.Result memory result)
internal pure
_isReady(result)
returns (bytes4)
{
return toBytes4(asBytes(result));
}
/// @dev Decode a `bytes32` value from the Witnet.Result's CBOR value.
function asBytes32(Witnet.Result memory result)
internal pure
_isReady(result)
returns (bytes32)
{
return toBytes32(asBytes(result));
}
/// @notice Returns the Witnet.Result's unread CBOR value.
function asCborValue(Witnet.Result memory result)
internal pure
_isReady(result)
returns (WitnetCBOR.CBOR memory)
{
return result.value;
}
/// @notice Decode array of CBOR values from the Witnet.Result's CBOR value.
function asCborArray(Witnet.Result memory result)
internal pure
_isReady(result)
returns (WitnetCBOR.CBOR[] memory)
{
return result.value.readArray();
}
/// @dev Decode a fixed16 (half-precision) numeric value from the Witnet.Result's CBOR value.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values.
/// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`.
/// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
function asFixed16(Witnet.Result memory result)
internal pure
_isReady(result)
returns (int32)
{
return result.value.readFloat16();
}
/// @dev Decode an array of fixed16 values from the Witnet.Result's CBOR value.
function asFixed16Array(Witnet.Result memory result)
internal pure
_isReady(result)
returns (int32[] memory)
{
return result.value.readFloat16Array();
}
/// @dev Decode an `int64` value from the Witnet.Result's CBOR value.
function asInt(Witnet.Result memory result)
internal pure
_isReady(result)
returns (int)
{
return result.value.readInt();
}
/// @dev Decode an array of integer numeric values from a Witnet.Result as an `int[]` array.
/// @param result An instance of Witnet.Result.
/// @return The `int[]` decoded from the Witnet.Result.
function asIntArray(Witnet.Result memory result)
internal pure
_isReady(result)
returns (int[] memory)
{
return result.value.readIntArray();
}
/// @dev Decode a `string` value from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `string` decoded from the Witnet.Result.
function asText(Witnet.Result memory result)
internal pure
_isReady(result)
returns(string memory)
{
return result.value.readString();
}
/// @dev Decode an array of strings from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `string[]` decoded from the Witnet.Result.
function asTextArray(Witnet.Result memory result)
internal pure
_isReady(result)
returns (string[] memory)
{
return result.value.readStringArray();
}
/// @dev Decode a `uint64` value from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `uint` decoded from the Witnet.Result.
function asUint(Witnet.Result memory result)
internal pure
_isReady(result)
returns (uint)
{
return result.value.readUint();
}
/// @dev Decode an array of `uint64` values from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `uint[]` decoded from the Witnet.Result.
function asUintArray(Witnet.Result memory result)
internal pure
returns (uint[] memory)
{
return result.value.readUintArray();
}
/// ===============================================================================================================
/// --- 'bytes' helper methods ------------------------------------------------------------------------------------
/// @dev Transform given bytes into a Witnet.Result instance.
/// @param bytecode Raw bytes representing a CBOR-encoded value.
/// @return A `Witnet.Result` instance.
function resultFromCborBytes(bytes memory bytecode)
internal pure
returns (Witnet.Result memory)
{
WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(bytecode);
return _resultFromCborValue(cborValue);
}
function toAddress(bytes memory _value) internal pure returns (address) {
return address(toBytes20(_value));
}
function toBytes4(bytes memory _value) internal pure returns (bytes4) {
return bytes4(toFixedBytes(_value, 4));
}
function toBytes20(bytes memory _value) internal pure returns (bytes20) {
return bytes20(toFixedBytes(_value, 20));
}
function toBytes32(bytes memory _value) internal pure returns (bytes32) {
return toFixedBytes(_value, 32);
}
function toFixedBytes(bytes memory _value, uint8 _numBytes)
internal pure
returns (bytes32 _bytes32)
{
assert(_numBytes <= 32);
unchecked {
uint _len = _value.length > _numBytes ? _numBytes : _value.length;
for (uint _i = 0; _i < _len; _i ++) {
_bytes32 |= bytes32(_value[_i] & 0xff) >> (_i * 8);
}
}
}
/// ===============================================================================================================
/// --- 'string' helper methods -----------------------------------------------------------------------------------
function toLowerCase(string memory str)
internal pure
returns (string memory)
{
bytes memory lowered = new bytes(bytes(str).length);
unchecked {
for (uint i = 0; i < lowered.length; i ++) {
uint8 char = uint8(bytes(str)[i]);
if (char >= 65 && char <= 90) {
lowered[i] = bytes1(char + 32);
} else {
lowered[i] = bytes1(char);
}
}
}
return string(lowered);
}
/// @notice Converts bytes32 into string.
function toString(bytes32 _bytes32)
internal pure
returns (string memory)
{
bytes memory _bytes = new bytes(_toStringLength(_bytes32));
for (uint _i = 0; _i < _bytes.length;) {
_bytes[_i] = _bytes32[_i];
unchecked {
_i ++;
}
}
return string(_bytes);
}
function tryUint(string memory str)
internal pure
returns (uint res, bool)
{
unchecked {
for (uint256 i = 0; i < bytes(str).length; i++) {
if (
(uint8(bytes(str)[i]) - 48) < 0
|| (uint8(bytes(str)[i]) - 48) > 9
) {
return (0, false);
}
res += (uint8(bytes(str)[i]) - 48) * 10 ** (bytes(str).length - i - 1);
}
return (res, true);
}
}
/// ===============================================================================================================
/// --- 'uint8' helper methods ------------------------------------------------------------------------------------
/// @notice Convert a `uint8` into a 2 characters long `string` representing its two less significant hexadecimal values.
function toHexString(uint8 _u)
internal pure
returns (string memory)
{
bytes memory b2 = new bytes(2);
uint8 d0 = uint8(_u / 16) + 48;
uint8 d1 = uint8(_u % 16) + 48;
if (d0 > 57)
d0 += 7;
if (d1 > 57)
d1 += 7;
b2[0] = bytes1(d0);
b2[1] = bytes1(d1);
return string(b2);
}
/// @notice Convert a `uint8` into a 1, 2 or 3 characters long `string` representing its.
/// three less significant decimal values.
function toString(uint8 _u)
internal pure
returns (string memory)
{
if (_u < 10) {
bytes memory b1 = new bytes(1);
b1[0] = bytes1(uint8(_u) + 48);
return string(b1);
} else if (_u < 100) {
bytes memory b2 = new bytes(2);
b2[0] = bytes1(uint8(_u / 10) + 48);
b2[1] = bytes1(uint8(_u % 10) + 48);
return string(b2);
} else {
bytes memory b3 = new bytes(3);
b3[0] = bytes1(uint8(_u / 100) + 48);
b3[1] = bytes1(uint8(_u % 100 / 10) + 48);
b3[2] = bytes1(uint8(_u % 10) + 48);
return string(b3);
}
}
/// @notice Convert a `uint` into a string` representing its value.
function toString(uint v)
internal pure
returns (string memory)
{
uint maxlength = 100;
bytes memory reversed = new bytes(maxlength);
uint i = 0;
do {
uint8 remainder = uint8(v % 10);
v = v / 10;
reversed[i ++] = bytes1(48 + remainder);
} while (v != 0);
bytes memory buf = new bytes(i);
for (uint j = 1; j <= i; j ++) {
buf[j - 1] = reversed[i - j];
}
return string(buf);
}
/// ===============================================================================================================
/// --- Witnet library private methods ----------------------------------------------------------------------------
/// @dev Decode a CBOR value into a Witnet.Result instance.
function _resultFromCborValue(WitnetCBOR.CBOR memory cbor)
private pure
returns (Witnet.Result memory)
{
// Witnet uses CBOR tag 39 to represent RADON error code identifiers.
// [CBOR tag 39] Identifiers for CBOR: https://github.com/lucas-clemente/cbor-specs/blob/master/id.md
bool success = cbor.tag != 39;
return Witnet.Result(success, cbor);
}
/// @dev Calculate length of string-equivalent to given bytes32.
function _toStringLength(bytes32 _bytes32)
private pure
returns (uint _length)
{
for (; _length < 32; ) {
if (_bytes32[_length] == 0) {
break;
}
unchecked {
_length ++;
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
/// @title A convenient wrapper around the `bytes memory` type that exposes a buffer-like interface
/// @notice The buffer has an inner cursor that tracks the final offset of every read, i.e. any subsequent read will
/// start with the byte that goes right after the last one in the previous read.
/// @dev `uint32` is used here for `cursor` because `uint16` would only enable seeking up to 8KB, which could in some
/// theoretical use cases be exceeded. Conversely, `uint32` supports up to 512MB, which cannot credibly be exceeded.
/// @author The Witnet Foundation.
library WitnetBuffer {
error EmptyBuffer();
error IndexOutOfBounds(uint index, uint range);
error MissingArgs(uint expected, uint given);
/// Iterable bytes buffer.
struct Buffer {
bytes data;
uint cursor;
}
// Ensures we access an existing index in an array
modifier withinRange(uint index, uint _range) {
if (index > _range) {
revert IndexOutOfBounds(index, _range);
}
_;
}
/// @notice Concatenate undefinite number of bytes chunks.
/// @dev Faster than looping on `abi.encodePacked(output, _buffs[ix])`.
function concat(bytes[] memory _buffs)
internal pure
returns (bytes memory output)
{
unchecked {
uint destinationPointer;
uint destinationLength;
assembly {
// get safe scratch location
output := mload(0x40)
// set starting destination pointer
destinationPointer := add(output, 32)
}
for (uint ix = 1; ix <= _buffs.length; ix ++) {
uint source;
uint sourceLength;
uint sourcePointer;
assembly {
// load source length pointer
source := mload(add(_buffs, mul(ix, 32)))
// load source length
sourceLength := mload(source)
// sets source memory pointer
sourcePointer := add(source, 32)
}
memcpy(
destinationPointer,
sourcePointer,
sourceLength
);
assembly {
// increase total destination length
destinationLength := add(destinationLength, sourceLength)
// sets destination memory pointer
destinationPointer := add(destinationPointer, sourceLength)
}
}
assembly {
// protect output bytes
mstore(output, destinationLength)
// set final output length
mstore(0x40, add(mload(0x40), add(destinationLength, 32)))
}
}
}
function fork(WitnetBuffer.Buffer memory buffer)
internal pure
returns (WitnetBuffer.Buffer memory)
{
return Buffer(
buffer.data,
buffer.cursor
);
}
function mutate(
WitnetBuffer.Buffer memory buffer,
uint length,
bytes memory pokes
)
internal pure
withinRange(length, buffer.data.length - buffer.cursor + 1)
{
bytes[] memory parts = new bytes[](3);
parts[0] = peek(
buffer,
0,
buffer.cursor
);
parts[1] = pokes;
parts[2] = peek(
buffer,
buffer.cursor + length,
buffer.data.length - buffer.cursor - length
);
buffer.data = concat(parts);
}
/// @notice Read and consume the next byte from the buffer.
/// @param buffer An instance of `Buffer`.
/// @return The next byte in the buffer counting from the cursor position.
function next(Buffer memory buffer)
internal pure
withinRange(buffer.cursor, buffer.data.length)
returns (bytes1)
{
// Return the byte at the position marked by the cursor and advance the cursor all at once
return buffer.data[buffer.cursor ++];
}
function peek(
WitnetBuffer.Buffer memory buffer,
uint offset,
uint length
)
internal pure
withinRange(offset + length, buffer.data.length)
returns (bytes memory)
{
bytes memory data = buffer.data;
bytes memory peeks = new bytes(length);
uint destinationPointer;
uint sourcePointer;
assembly {
destinationPointer := add(peeks, 32)
sourcePointer := add(add(data, 32), offset)
}
memcpy(
destinationPointer,
sourcePointer,
length
);
return peeks;
}
// @notice Extract bytes array from buffer starting from current cursor.
/// @param buffer An instance of `Buffer`.
/// @param length How many bytes to peek from the Buffer.
// solium-disable-next-line security/no-assign-params
function peek(
WitnetBuffer.Buffer memory buffer,
uint length
)
internal pure
withinRange(length, buffer.data.length - buffer.cursor)
returns (bytes memory)
{
return peek(
buffer,
buffer.cursor,
length
);
}
/// @notice Read and consume a certain amount of bytes from the buffer.
/// @param buffer An instance of `Buffer`.
/// @param length How many bytes to read and consume from the buffer.
/// @return output A `bytes memory` containing the first `length` bytes from the buffer, counting from the cursor position.
function read(Buffer memory buffer, uint length)
internal pure
withinRange(buffer.cursor + length, buffer.data.length)
returns (bytes memory output)
{
// Create a new `bytes memory destination` value
output = new bytes(length);
// Early return in case that bytes length is 0
if (length > 0) {
bytes memory input = buffer.data;
uint offset = buffer.cursor;
// Get raw pointers for source and destination
uint sourcePointer;
uint destinationPointer;
assembly {
sourcePointer := add(add(input, 32), offset)
destinationPointer := add(output, 32)
}
// Copy `length` bytes from source to destination
memcpy(
destinationPointer,
sourcePointer,
length
);
// Move the cursor forward by `length` bytes
seek(
buffer,
length,
true
);
}
}
/// @notice Read and consume the next 2 bytes from the buffer as an IEEE 754-2008 floating point number enclosed in an
/// `int32`.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `float16`
/// use cases. In other words, the integer output of this method is 10,000 times the actual value. The input bytes are
/// expected to follow the 16-bit base-2 format (a.k.a. `binary16`) in the IEEE 754-2008 standard.
/// @param buffer An instance of `Buffer`.
/// @return result The `int32` value of the next 4 bytes in the buffer counting from the cursor position.
function readFloat16(Buffer memory buffer)
internal pure
returns (int32 result)
{
uint32 value = readUint16(buffer);
// Get bit at position 0
uint32 sign = value & 0x8000;
// Get bits 1 to 5, then normalize to the [-15, 16] range so as to counterweight the IEEE 754 exponent bias
int32 exponent = (int32(value & 0x7c00) >> 10) - 15;
// Get bits 6 to 15
int32 fraction = int32(value & 0x03ff);
// Add 2^10 to the fraction if exponent is not -15
if (exponent != -15) {
fraction |= 0x400;
} else if (exponent == 16) {
revert(
string(abi.encodePacked(
"WitnetBuffer.readFloat16: ",
sign != 0 ? "negative" : hex"",
" infinity"
))
);
}
// Compute `2 ^ exponent · (1 + fraction / 1024)`
if (exponent >= 0) {
result = int32(int(
int(1 << uint256(int256(exponent)))
* 10000
* fraction
) >> 10);
} else {
result = int32(int(
int(fraction)
* 10000
/ int(1 << uint(int(- exponent)))
) >> 10);
}
// Make the result negative if the sign bit is not 0
if (sign != 0) {
result *= -1;
}
}
/// @notice Consume the next 4 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `float32`
/// use cases. In other words, the integer output of this method is 10^9 times the actual value. The input bytes are
/// expected to follow the 64-bit base-2 format (a.k.a. `binary32`) in the IEEE 754-2008 standard.
/// @param buffer An instance of `Buffer`.
/// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
function readFloat32(Buffer memory buffer)
internal pure
returns (int result)
{
uint value = readUint32(buffer);
// Get bit at position 0
uint sign = value & 0x80000000;
// Get bits 1 to 8, then normalize to the [-127, 128] range so as to counterweight the IEEE 754 exponent bias
int exponent = (int(value & 0x7f800000) >> 23) - 127;
// Get bits 9 to 31
int fraction = int(value & 0x007fffff);
// Add 2^23 to the fraction if exponent is not -127
if (exponent != -127) {
fraction |= 0x800000;
} else if (exponent == 128) {
revert(
string(abi.encodePacked(
"WitnetBuffer.readFloat32: ",
sign != 0 ? "negative" : hex"",
" infinity"
))
);
}
// Compute `2 ^ exponent · (1 + fraction / 2^23)`
if (exponent >= 0) {
result = (
int(1 << uint(exponent))
* (10 ** 9)
* fraction
) >> 23;
} else {
result = (
fraction
* (10 ** 9)
/ int(1 << uint(-exponent))
) >> 23;
}
// Make the result negative if the sign bit is not 0
if (sign != 0) {
result *= -1;
}
}
/// @notice Consume the next 8 bytes from the buffer as an IEEE 754-2008 floating point number enclosed into an `int`.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `float64`
/// use cases. In other words, the integer output of this method is 10^15 times the actual value. The input bytes are
/// expected to follow the 64-bit base-2 format (a.k.a. `binary64`) in the IEEE 754-2008 standard.
/// @param buffer An instance of `Buffer`.
/// @return result The `int` value of the next 8 bytes in the buffer counting from the cursor position.
function readFloat64(Buffer memory buffer)
internal pure
returns (int result)
{
uint value = readUint64(buffer);
// Get bit at position 0
uint sign = value & 0x8000000000000000;
// Get bits 1 to 12, then normalize to the [-1023, 1024] range so as to counterweight the IEEE 754 exponent bias
int exponent = (int(value & 0x7ff0000000000000) >> 52) - 1023;
// Get bits 6 to 15
int fraction = int(value & 0x000fffffffffffff);
// Add 2^52 to the fraction if exponent is not -1023
if (exponent != -1023) {
fraction |= 0x10000000000000;
} else if (exponent == 1024) {
revert(
string(abi.encodePacked(
"WitnetBuffer.readFloat64: ",
sign != 0 ? "negative" : hex"",
" infinity"
))
);
}
// Compute `2 ^ exponent · (1 + fraction / 1024)`
if (exponent >= 0) {
result = (
int(1 << uint(exponent))
* (10 ** 15)
* fraction
) >> 52;
} else {
result = (
fraction
* (10 ** 15)
/ int(1 << uint(-exponent))
) >> 52;
}
// Make the result negative if the sign bit is not 0
if (sign != 0) {
result *= -1;
}
}
// Read a text string of a given length from a buffer. Returns a `bytes memory` value for the sake of genericness,
/// but it can be easily casted into a string with `string(result)`.
// solium-disable-next-line security/no-assign-params
function readText(
WitnetBuffer.Buffer memory buffer,
uint64 length
)
internal pure
returns (bytes memory text)
{
text = new bytes(length);
unchecked {
for (uint64 index = 0; index < length; index ++) {
uint8 char = readUint8(buffer);
if (char & 0x80 != 0) {
if (char < 0xe0) {
char = (char & 0x1f) << 6
| (readUint8(buffer) & 0x3f);
length -= 1;
} else if (char < 0xf0) {
char = (char & 0x0f) << 12
| (readUint8(buffer) & 0x3f) << 6
| (readUint8(buffer) & 0x3f);
length -= 2;
} else {
char = (char & 0x0f) << 18
| (readUint8(buffer) & 0x3f) << 12
| (readUint8(buffer) & 0x3f) << 6
| (readUint8(buffer) & 0x3f);
length -= 3;
}
}
text[index] = bytes1(char);
}
// Adjust text to actual length:
assembly {
mstore(text, length)
}
}
}
/// @notice Read and consume the next byte from the buffer as an `uint8`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint8` value of the next byte in the buffer counting from the cursor position.
function readUint8(Buffer memory buffer)
internal pure
withinRange(buffer.cursor, buffer.data.length)
returns (uint8 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 1), offset))
}
buffer.cursor ++;
}
/// @notice Read and consume the next 2 bytes from the buffer as an `uint16`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint16` value of the next 2 bytes in the buffer counting from the cursor position.
function readUint16(Buffer memory buffer)
internal pure
withinRange(buffer.cursor + 2, buffer.data.length)
returns (uint16 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 2), offset))
}
buffer.cursor += 2;
}
/// @notice Read and consume the next 4 bytes from the buffer as an `uint32`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint32` value of the next 4 bytes in the buffer counting from the cursor position.
function readUint32(Buffer memory buffer)
internal pure
withinRange(buffer.cursor + 4, buffer.data.length)
returns (uint32 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 4), offset))
}
buffer.cursor += 4;
}
/// @notice Read and consume the next 8 bytes from the buffer as an `uint64`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint64` value of the next 8 bytes in the buffer counting from the cursor position.
function readUint64(Buffer memory buffer)
internal pure
withinRange(buffer.cursor + 8, buffer.data.length)
returns (uint64 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 8), offset))
}
buffer.cursor += 8;
}
/// @notice Read and consume the next 16 bytes from the buffer as an `uint128`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint128` value of the next 16 bytes in the buffer counting from the cursor position.
function readUint128(Buffer memory buffer)
internal pure
withinRange(buffer.cursor + 16, buffer.data.length)
returns (uint128 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 16), offset))
}
buffer.cursor += 16;
}
/// @notice Read and consume the next 32 bytes from the buffer as an `uint256`.
/// @param buffer An instance of `Buffer`.
/// @return value The `uint256` value of the next 32 bytes in the buffer counting from the cursor position.
function readUint256(Buffer memory buffer)
internal pure
withinRange(buffer.cursor + 32, buffer.data.length)
returns (uint256 value)
{
bytes memory data = buffer.data;
uint offset = buffer.cursor;
assembly {
value := mload(add(add(data, 32), offset))
}
buffer.cursor += 32;
}
/// @notice Count number of required parameters for given bytes arrays
/// @dev Wildcard format: "\#\", with # in ["0".."9"].
/// @param input Bytes array containing strings.
/// @param count Highest wildcard index found, plus 1.
function argsCountOf(bytes memory input)
internal pure
returns (uint8 count)
{
if (input.length < 3) {
return 0;
}
unchecked {
uint ix = 0;
uint length = input.length - 2;
for (; ix < length; ) {
if (
input[ix] == bytes1("\\")
&& input[ix + 2] == bytes1("\\")
&& input[ix + 1] >= bytes1("0")
&& input[ix + 1] <= bytes1("9")
) {
uint8 ax = uint8(uint8(input[ix + 1]) - uint8(bytes1("0")) + 1);
if (ax > count) {
count = ax;
}
ix += 3;
} else {
ix ++;
}
}
}
}
/// @notice Replace bytecode indexed wildcards by correspondent substrings.
/// @dev Wildcard format: "\#\", with # in ["0".."9"].
/// @param input Bytes array containing strings.
/// @param args Array of substring values for replacing indexed wildcards.
/// @return output Resulting bytes array after replacing all wildcards.
/// @return hits Total number of replaced wildcards.
function replace(bytes memory input, string[] memory args)
internal pure
returns (bytes memory output, uint hits)
{
uint ix = 0; uint lix = 0;
uint inputLength;
uint inputPointer;
uint outputLength;
uint outputPointer;
uint source;
uint sourceLength;
uint sourcePointer;
if (input.length < 3) {
return (input, 0);
}
assembly {
// set starting input pointer
inputPointer := add(input, 32)
// get safe output location
output := mload(0x40)
// set starting output pointer
outputPointer := add(output, 32)
}
unchecked {
uint length = input.length - 2;
for (; ix < length; ) {
if (
input[ix] == bytes1("\\")
&& input[ix + 2] == bytes1("\\")
&& input[ix + 1] >= bytes1("0")
&& input[ix + 1] <= bytes1("9")
) {
inputLength = (ix - lix);
if (ix > lix) {
memcpy(
outputPointer,
inputPointer,
inputLength
);
inputPointer += inputLength + 3;
outputPointer += inputLength;
} else {
inputPointer += 3;
}
uint ax = uint(uint8(input[ix + 1]) - uint8(bytes1("0")));
if (ax >= args.length) {
revert MissingArgs(ax + 1, args.length);
}
assembly {
source := mload(add(args, mul(32, add(ax, 1))))
sourceLength := mload(source)
sourcePointer := add(source, 32)
}
memcpy(
outputPointer,
sourcePointer,
sourceLength
);
outputLength += inputLength + sourceLength;
outputPointer += sourceLength;
ix += 3;
lix = ix;
hits ++;
} else {
ix ++;
}
}
ix = input.length;
}
if (outputLength > 0) {
if (ix > lix ) {
memcpy(
outputPointer,
inputPointer,
ix - lix
);
outputLength += (ix - lix);
}
assembly {
// set final output length
mstore(output, outputLength)
// protect output bytes
mstore(0x40, add(mload(0x40), add(outputLength, 32)))
}
}
else {
return (input, 0);
}
}
/// @notice Replace string indexed wildcards by correspondent substrings.
/// @dev Wildcard format: "\#\", with # in ["0".."9"].
/// @param input String potentially containing wildcards.
/// @param args Array of substring values for replacing indexed wildcards.
/// @return output Resulting string after replacing all wildcards.
function replace(string memory input, string[] memory args)
internal pure
returns (string memory)
{
(bytes memory _outputBytes, ) = replace(bytes(input), args);
return string(_outputBytes);
}
/// @notice Move the inner cursor of the buffer to a relative or absolute position.
/// @param buffer An instance of `Buffer`.
/// @param offset How many bytes to move the cursor forward.
/// @param relative Whether to count `offset` from the last position of the cursor (`true`) or the beginning of the
/// buffer (`true`).
/// @return The final position of the cursor (will equal `offset` if `relative` is `false`).
// solium-disable-next-line security/no-assign-params
function seek(
Buffer memory buffer,
uint offset,
bool relative
)
internal pure
withinRange(offset, buffer.data.length)
returns (uint)
{
// Deal with relative offsets
if (relative) {
offset += buffer.cursor;
}
buffer.cursor = offset;
return offset;
}
/// @notice Move the inner cursor a number of bytes forward.
/// @dev This is a simple wrapper around the relative offset case of `seek()`.
/// @param buffer An instance of `Buffer`.
/// @param relativeOffset How many bytes to move the cursor forward.
/// @return The final position of the cursor.
function seek(
Buffer memory buffer,
uint relativeOffset
)
internal pure
returns (uint)
{
return seek(
buffer,
relativeOffset,
true
);
}
/// @notice Copy bytes from one memory address into another.
/// @dev This function was borrowed from Nick Johnson's `solidity-stringutils` lib, and reproduced here under the terms
/// of [Apache License 2.0](https://github.com/Arachnid/solidity-stringutils/blob/master/LICENSE).
/// @param dest Address of the destination memory.
/// @param src Address to the source memory.
/// @param len How many bytes to copy.
// solium-disable-next-line security/no-assign-params
function memcpy(
uint dest,
uint src,
uint len
)
private pure
{
unchecked {
// Copy word-length chunks while possible
for (; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
dest += 32;
src += 32;
}
if (len > 0) {
// Copy remaining bytes
uint _mask = 256 ** (32 - len) - 1;
assembly {
let srcpart := and(mload(src), not(_mask))
let destpart := and(mload(dest), _mask)
mstore(dest, or(destpart, srcpart))
}
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "./WitnetBuffer.sol";
/// @title A minimalistic implementation of “RFC 7049 Concise Binary Object Representation”
/// @notice This library leverages a buffer-like structure for step-by-step decoding of bytes so as to minimize
/// the gas cost of decoding them into a useful native type.
/// @dev Most of the logic has been borrowed from Patrick Gansterer’s cbor.js library: https://github.com/paroga/cbor-js
/// @author The Witnet Foundation.
library WitnetCBOR {
using WitnetBuffer for WitnetBuffer.Buffer;
using WitnetCBOR for WitnetCBOR.CBOR;
/// Data struct following the RFC-7049 standard: Concise Binary Object Representation.
struct CBOR {
WitnetBuffer.Buffer buffer;
uint8 initialByte;
uint8 majorType;
uint8 additionalInformation;
uint64 len;
uint64 tag;
}
uint8 internal constant MAJOR_TYPE_INT = 0;
uint8 internal constant MAJOR_TYPE_NEGATIVE_INT = 1;
uint8 internal constant MAJOR_TYPE_BYTES = 2;
uint8 internal constant MAJOR_TYPE_STRING = 3;
uint8 internal constant MAJOR_TYPE_ARRAY = 4;
uint8 internal constant MAJOR_TYPE_MAP = 5;
uint8 internal constant MAJOR_TYPE_TAG = 6;
uint8 internal constant MAJOR_TYPE_CONTENT_FREE = 7;
uint32 internal constant UINT32_MAX = type(uint32).max;
uint64 internal constant UINT64_MAX = type(uint64).max;
error EmptyArray();
error InvalidLengthEncoding(uint length);
error UnexpectedMajorType(uint read, uint expected);
error UnsupportedPrimitive(uint primitive);
error UnsupportedMajorType(uint unexpected);
modifier isMajorType(
WitnetCBOR.CBOR memory cbor,
uint8 expected
) {
if (cbor.majorType != expected) {
revert UnexpectedMajorType(cbor.majorType, expected);
}
_;
}
modifier notEmpty(WitnetBuffer.Buffer memory buffer) {
if (buffer.data.length == 0) {
revert WitnetBuffer.EmptyBuffer();
}
_;
}
function eof(CBOR memory cbor)
internal pure
returns (bool)
{
return cbor.buffer.cursor >= cbor.buffer.data.length;
}
/// @notice Decode a CBOR structure from raw bytes.
/// @dev This is the main factory for CBOR instances, which can be later decoded into native EVM types.
/// @param bytecode Raw bytes representing a CBOR-encoded value.
/// @return A `CBOR` instance containing a partially decoded value.
function fromBytes(bytes memory bytecode)
internal pure
returns (CBOR memory)
{
WitnetBuffer.Buffer memory buffer = WitnetBuffer.Buffer(bytecode, 0);
return fromBuffer(buffer);
}
/// @notice Decode a CBOR structure from raw bytes.
/// @dev This is an alternate factory for CBOR instances, which can be later decoded into native EVM types.
/// @param buffer A Buffer structure representing a CBOR-encoded value.
/// @return A `CBOR` instance containing a partially decoded value.
function fromBuffer(WitnetBuffer.Buffer memory buffer)
internal pure
notEmpty(buffer)
returns (CBOR memory)
{
uint8 initialByte;
uint8 majorType = 255;
uint8 additionalInformation;
uint64 tag = UINT64_MAX;
uint256 len;
bool isTagged = true;
while (isTagged) {
// Extract basic CBOR properties from input bytes
initialByte = buffer.readUint8();
len ++;
majorType = initialByte >> 5;
additionalInformation = initialByte & 0x1f;
// Early CBOR tag parsing.
if (majorType == MAJOR_TYPE_TAG) {
uint _cursor = buffer.cursor;
tag = readLength(buffer, additionalInformation);
len += buffer.cursor - _cursor;
} else {
isTagged = false;
}
}
if (majorType > MAJOR_TYPE_CONTENT_FREE) {
revert UnsupportedMajorType(majorType);
}
return CBOR(
buffer,
initialByte,
majorType,
additionalInformation,
uint64(len),
tag
);
}
function fork(WitnetCBOR.CBOR memory self)
internal pure
returns (WitnetCBOR.CBOR memory)
{
return CBOR({
buffer: self.buffer.fork(),
initialByte: self.initialByte,
majorType: self.majorType,
additionalInformation: self.additionalInformation,
len: self.len,
tag: self.tag
});
}
function settle(CBOR memory self)
internal pure
returns (WitnetCBOR.CBOR memory)
{
if (!self.eof()) {
return fromBuffer(self.buffer);
} else {
return self;
}
}
function skip(CBOR memory self)
internal pure
returns (WitnetCBOR.CBOR memory)
{
if (
self.majorType == MAJOR_TYPE_INT
|| self.majorType == MAJOR_TYPE_NEGATIVE_INT
|| (
self.majorType == MAJOR_TYPE_CONTENT_FREE
&& self.additionalInformation >= 25
&& self.additionalInformation <= 27
)
) {
self.buffer.cursor += self.peekLength();
} else if (
self.majorType == MAJOR_TYPE_STRING
|| self.majorType == MAJOR_TYPE_BYTES
) {
uint64 len = readLength(self.buffer, self.additionalInformation);
self.buffer.cursor += len;
} else if (
self.majorType == MAJOR_TYPE_ARRAY
|| self.majorType == MAJOR_TYPE_MAP
) {
self.len = readLength(self.buffer, self.additionalInformation);
} else if (
self.majorType != MAJOR_TYPE_CONTENT_FREE
|| (
self.additionalInformation != 20
&& self.additionalInformation != 21
)
) {
revert("WitnetCBOR.skip: unsupported major type");
}
return self;
}
function peekLength(CBOR memory self)
internal pure
returns (uint64)
{
if (self.additionalInformation < 24) {
return 0;
} else if (self.additionalInformation < 28) {
return uint64(1 << (self.additionalInformation - 24));
} else {
revert InvalidLengthEncoding(self.additionalInformation);
}
}
function readArray(CBOR memory self)
internal pure
isMajorType(self, MAJOR_TYPE_ARRAY)
returns (CBOR[] memory items)
{
// read array's length and move self cursor forward to the first array element:
uint64 len = readLength(self.buffer, self.additionalInformation);
items = new CBOR[](len + 1);
for (uint ix = 0; ix < len; ix ++) {
// settle next element in the array:
self = self.settle();
// fork it and added to the list of items to be returned:
items[ix] = self.fork();
if (self.majorType == MAJOR_TYPE_ARRAY) {
CBOR[] memory _subitems = self.readArray();
// move forward to the first element after inner array:
self = _subitems[_subitems.length - 1];
} else if (self.majorType == MAJOR_TYPE_MAP) {
CBOR[] memory _subitems = self.readMap();
// move forward to the first element after inner map:
self = _subitems[_subitems.length - 1];
} else {
// move forward to the next element:
self.skip();
}
}
// return self cursor as extra item at the end of the list,
// as to optimize recursion when jumping over nested arrays:
items[len] = self;
}
function readMap(CBOR memory self)
internal pure
isMajorType(self, MAJOR_TYPE_MAP)
returns (CBOR[] memory items)
{
// read number of items within the map and move self cursor forward to the first inner element:
uint64 len = readLength(self.buffer, self.additionalInformation) * 2;
items = new CBOR[](len + 1);
for (uint ix = 0; ix < len; ix ++) {
// settle next element in the array:
self = self.settle();
// fork it and added to the list of items to be returned:
items[ix] = self.fork();
if (ix % 2 == 0 && self.majorType != MAJOR_TYPE_STRING) {
revert UnexpectedMajorType(self.majorType, MAJOR_TYPE_STRING);
} else if (self.majorType == MAJOR_TYPE_ARRAY || self.majorType == MAJOR_TYPE_MAP) {
CBOR[] memory _subitems = (self.majorType == MAJOR_TYPE_ARRAY
? self.readArray()
: self.readMap()
);
// move forward to the first element after inner array or map:
self = _subitems[_subitems.length - 1];
} else {
// move forward to the next element:
self.skip();
}
}
// return self cursor as extra item at the end of the list,
// as to optimize recursion when jumping over nested arrays:
items[len] = self;
}
/// Reads the length of the settle CBOR item from a buffer, consuming a different number of bytes depending on the
/// value of the `additionalInformation` argument.
function readLength(
WitnetBuffer.Buffer memory buffer,
uint8 additionalInformation
)
internal pure
returns (uint64)
{
if (additionalInformation < 24) {
return additionalInformation;
}
if (additionalInformation == 24) {
return buffer.readUint8();
}
if (additionalInformation == 25) {
return buffer.readUint16();
}
if (additionalInformation == 26) {
return buffer.readUint32();
}
if (additionalInformation == 27) {
return buffer.readUint64();
}
if (additionalInformation == 31) {
return UINT64_MAX;
}
revert InvalidLengthEncoding(additionalInformation);
}
/// @notice Read a `CBOR` structure into a native `bool` value.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as a `bool` value.
function readBool(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
returns (bool)
{
if (cbor.additionalInformation == 20) {
return false;
} else if (cbor.additionalInformation == 21) {
return true;
} else {
revert UnsupportedPrimitive(cbor.additionalInformation);
}
}
/// @notice Decode a `CBOR` structure into a native `bytes` value.
/// @param cbor An instance of `CBOR`.
/// @return output The value represented by the input, as a `bytes` value.
function readBytes(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_BYTES)
returns (bytes memory output)
{
cbor.len = readLength(
cbor.buffer,
cbor.additionalInformation
);
if (cbor.len == UINT32_MAX) {
// These checks look repetitive but the equivalent loop would be more expensive.
uint32 length = uint32(_readIndefiniteStringLength(
cbor.buffer,
cbor.majorType
));
if (length < UINT32_MAX) {
output = abi.encodePacked(cbor.buffer.read(length));
length = uint32(_readIndefiniteStringLength(
cbor.buffer,
cbor.majorType
));
if (length < UINT32_MAX) {
output = abi.encodePacked(
output,
cbor.buffer.read(length)
);
}
}
} else {
return cbor.buffer.read(uint32(cbor.len));
}
}
/// @notice Decode a `CBOR` structure into a `fixed16` value.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`
/// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as an `int128` value.
function readFloat16(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
returns (int32)
{
if (cbor.additionalInformation == 25) {
return cbor.buffer.readFloat16();
} else {
revert UnsupportedPrimitive(cbor.additionalInformation);
}
}
/// @notice Decode a `CBOR` structure into a `fixed32` value.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 9 decimal orders so as to get a fixed precision of 9 decimal positions, which should be OK for most `fixed64`
/// use cases. In other words, the output of this method is 10^9 times the actual value, encoded into an `int`.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as an `int` value.
function readFloat32(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
returns (int)
{
if (cbor.additionalInformation == 26) {
return cbor.buffer.readFloat32();
} else {
revert UnsupportedPrimitive(cbor.additionalInformation);
}
}
/// @notice Decode a `CBOR` structure into a `fixed64` value.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values
/// by 15 decimal orders so as to get a fixed precision of 15 decimal positions, which should be OK for most `fixed64`
/// use cases. In other words, the output of this method is 10^15 times the actual value, encoded into an `int`.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as an `int` value.
function readFloat64(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_CONTENT_FREE)
returns (int)
{
if (cbor.additionalInformation == 27) {
return cbor.buffer.readFloat64();
} else {
revert UnsupportedPrimitive(cbor.additionalInformation);
}
}
/// @notice Decode a `CBOR` structure into a native `int128[]` value whose inner values follow the same convention
/// @notice as explained in `decodeFixed16`.
/// @param cbor An instance of `CBOR`.
function readFloat16Array(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_ARRAY)
returns (int32[] memory values)
{
uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
if (length < UINT64_MAX) {
values = new int32[](length);
for (uint64 i = 0; i < length; ) {
CBOR memory item = fromBuffer(cbor.buffer);
values[i] = readFloat16(item);
unchecked {
i ++;
}
}
} else {
revert InvalidLengthEncoding(length);
}
}
/// @notice Decode a `CBOR` structure into a native `int128` value.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as an `int128` value.
function readInt(CBOR memory cbor)
internal pure
returns (int)
{
if (cbor.majorType == 1) {
uint64 _value = readLength(
cbor.buffer,
cbor.additionalInformation
);
return int(-1) - int(uint(_value));
} else if (cbor.majorType == 0) {
// Any `uint64` can be safely casted to `int128`, so this method supports majorType 1 as well so as to have offer
// a uniform API for positive and negative numbers
return int(readUint(cbor));
}
else {
revert UnexpectedMajorType(cbor.majorType, 1);
}
}
/// @notice Decode a `CBOR` structure into a native `int[]` value.
/// @param cbor instance of `CBOR`.
/// @return array The value represented by the input, as an `int[]` value.
function readIntArray(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_ARRAY)
returns (int[] memory array)
{
uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
if (length < UINT64_MAX) {
array = new int[](length);
for (uint i = 0; i < length; ) {
CBOR memory item = fromBuffer(cbor.buffer);
array[i] = readInt(item);
unchecked {
i ++;
}
}
} else {
revert InvalidLengthEncoding(length);
}
}
/// @notice Decode a `CBOR` structure into a native `string` value.
/// @param cbor An instance of `CBOR`.
/// @return text The value represented by the input, as a `string` value.
function readString(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_STRING)
returns (string memory text)
{
cbor.len = readLength(cbor.buffer, cbor.additionalInformation);
if (cbor.len == UINT64_MAX) {
bool _done;
while (!_done) {
uint64 length = _readIndefiniteStringLength(
cbor.buffer,
cbor.majorType
);
if (length < UINT64_MAX) {
text = string(abi.encodePacked(
text,
cbor.buffer.readText(length / 4)
));
} else {
_done = true;
}
}
} else {
return string(cbor.buffer.readText(cbor.len));
}
}
/// @notice Decode a `CBOR` structure into a native `string[]` value.
/// @param cbor An instance of `CBOR`.
/// @return strings The value represented by the input, as an `string[]` value.
function readStringArray(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_ARRAY)
returns (string[] memory strings)
{
uint length = readLength(cbor.buffer, cbor.additionalInformation);
if (length < UINT64_MAX) {
strings = new string[](length);
for (uint i = 0; i < length; ) {
CBOR memory item = fromBuffer(cbor.buffer);
strings[i] = readString(item);
unchecked {
i ++;
}
}
} else {
revert InvalidLengthEncoding(length);
}
}
/// @notice Decode a `CBOR` structure into a native `uint64` value.
/// @param cbor An instance of `CBOR`.
/// @return The value represented by the input, as an `uint64` value.
function readUint(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_INT)
returns (uint)
{
return readLength(
cbor.buffer,
cbor.additionalInformation
);
}
/// @notice Decode a `CBOR` structure into a native `uint64[]` value.
/// @param cbor An instance of `CBOR`.
/// @return values The value represented by the input, as an `uint64[]` value.
function readUintArray(CBOR memory cbor)
internal pure
isMajorType(cbor, MAJOR_TYPE_ARRAY)
returns (uint[] memory values)
{
uint64 length = readLength(cbor.buffer, cbor.additionalInformation);
if (length < UINT64_MAX) {
values = new uint[](length);
for (uint ix = 0; ix < length; ) {
CBOR memory item = fromBuffer(cbor.buffer);
values[ix] = readUint(item);
unchecked {
ix ++;
}
}
} else {
revert InvalidLengthEncoding(length);
}
}
/// Read the length of a CBOR indifinite-length item (arrays, maps, byte strings and text) from a buffer, consuming
/// as many bytes as specified by the first byte.
function _readIndefiniteStringLength(
WitnetBuffer.Buffer memory buffer,
uint8 majorType
)
private pure
returns (uint64 len)
{
uint8 initialByte = buffer.readUint8();
if (initialByte == 0xff) {
return UINT64_MAX;
}
len = readLength(
buffer,
initialByte & 0x1f
);
if (len >= UINT64_MAX) {
revert InvalidLengthEncoding(len);
} else if (majorType != (initialByte >> 5)) {
revert UnexpectedMajorType((initialByte >> 5), majorType);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "./Witnet.sol";
library WitnetV2 {
error IndexOutOfBounds(uint256 index, uint256 range);
error InsufficientBalance(uint256 weiBalance, uint256 weiExpected);
error InsufficientFee(uint256 weiProvided, uint256 weiExpected);
error Unauthorized(address violator);
error RadonFilterMissingArgs(uint8 opcode);
error RadonRequestNoSources();
error RadonRequestSourcesArgsMismatch(uint expected, uint actual);
error RadonRequestMissingArgs(uint index, uint expected, uint actual);
error RadonRequestResultsMismatch(uint index, uint8 read, uint8 expected);
error RadonRequestTooHeavy(bytes bytecode, uint weight);
error RadonSlaNoReward();
error RadonSlaNoWitnesses();
error RadonSlaTooManyWitnesses(uint256 numWitnesses);
error RadonSlaConsensusOutOfRange(uint256 percentage);
error RadonSlaLowCollateral(uint256 witnessCollateral);
error UnsupportedDataRequestMethod(uint8 method, string schema, string body, string[2][] headers);
error UnsupportedRadonDataType(uint8 datatype, uint256 maxlength);
error UnsupportedRadonFilterOpcode(uint8 opcode);
error UnsupportedRadonFilterArgs(uint8 opcode, bytes args);
error UnsupportedRadonReducerOpcode(uint8 opcode);
error UnsupportedRadonReducerScript(uint8 opcode, bytes script, uint256 offset);
error UnsupportedRadonScript(bytes script, uint256 offset);
error UnsupportedRadonScriptOpcode(bytes script, uint256 cursor, uint8 opcode);
error UnsupportedRadonTallyScript(bytes32 hash);
function toEpoch(uint _timestamp) internal pure returns (uint) {
return 1 + (_timestamp - 11111) / 15;
}
function toTimestamp(uint _epoch) internal pure returns (uint) {
return 111111+ _epoch * 15;
}
struct Beacon {
uint256 escrow;
uint256 evmBlock;
uint256 gasprice;
address relayer;
address slasher;
uint256 superblockIndex;
uint256 superblockRoot;
}
enum BeaconStatus {
Idle
}
struct Block {
bytes32 blockHash;
bytes32 drTxsRoot;
bytes32 drTallyTxsRoot;
}
enum BlockStatus {
Idle
}
struct DrPost {
uint256 block;
DrPostStatus status;
DrPostRequest request;
DrPostResponse response;
}
/// Data kept in EVM-storage for every Request posted to the Witnet Request Board.
struct DrPostRequest {
uint256 epoch;
address requester;
address reporter;
bytes32 radHash;
bytes32 slaHash;
uint256 weiReward;
}
/// Data kept in EVM-storage containing Witnet-provided response metadata and result.
struct DrPostResponse {
address disputer;
address reporter;
uint256 escrowed;
uint256 drCommitTxEpoch;
uint256 drTallyTxEpoch;
bytes32 drTallyTxHash;
bytes drTallyResultCborBytes;
}
enum DrPostStatus {
Void,
Deleted,
Expired,
Posted,
Disputed,
Reported,
Finalized,
Accepted,
Rejected
}
struct DataProvider {
string authority;
uint256 totalEndpoints;
mapping (uint256 => bytes32) endpoints;
}
enum DataRequestMethods {
/* 0 */ Unknown,
/* 1 */ HttpGet,
/* 2 */ Rng,
/* 3 */ HttpPost
}
enum RadonDataTypes {
/* 0x00 */ Any,
/* 0x01 */ Array,
/* 0x02 */ Bool,
/* 0x03 */ Bytes,
/* 0x04 */ Integer,
/* 0x05 */ Float,
/* 0x06 */ Map,
/* 0x07 */ String,
Unused0x08, Unused0x09, Unused0x0A, Unused0x0B,
Unused0x0C, Unused0x0D, Unused0x0E, Unused0x0F,
/* 0x10 */ Same,
/* 0x11 */ Inner,
/* 0x12 */ Match,
/* 0x13 */ Subscript
}
struct RadonFilter {
RadonFilterOpcodes opcode;
bytes args;
}
enum RadonFilterOpcodes {
/* 0x00 */ GreaterThan,
/* 0x01 */ LessThan,
/* 0x02 */ Equals,
/* 0x03 */ AbsoluteDeviation,
/* 0x04 */ RelativeDeviation,
/* 0x05 */ StandardDeviation,
/* 0x06 */ Top,
/* 0x07 */ Bottom,
/* 0x08 */ Mode,
/* 0x09 */ LessOrEqualThan
}
struct RadonReducer {
RadonReducerOpcodes opcode;
RadonFilter[] filters;
bytes script;
}
enum RadonReducerOpcodes {
/* 0x00 */ Minimum,
/* 0x01 */ Maximum,
/* 0x02 */ Mode,
/* 0x03 */ AverageMean,
/* 0x04 */ AverageMeanWeighted,
/* 0x05 */ AverageMedian,
/* 0x06 */ AverageMedianWeighted,
/* 0x07 */ StandardDeviation,
/* 0x08 */ AverageDeviation,
/* 0x09 */ MedianDeviation,
/* 0x0A */ MaximumDeviation,
/* 0x0B */ ConcatenateAndHash
}
struct RadonRetrieval {
uint8 argsCount;
DataRequestMethods method;
RadonDataTypes resultDataType;
string url;
string body;
string[2][] headers;
bytes script;
}
struct RadonSLA {
uint numWitnesses;
uint minConsensusPercentage;
uint witnessReward;
uint witnessCollateral;
uint minerCommitRevealFee;
}
/// @notice Returns `true` if all witnessing parameters in `b` have same
/// @notice value or greater than the ones in `a`.
function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b)
internal pure
returns (bool)
{
return (
a.numWitnesses >= b.numWitnesses
&& a.minConsensusPercentage >= b.minConsensusPercentage
&& a.witnessReward >= b.witnessReward
&& a.witnessCollateral >= b.witnessCollateral
&& a.minerCommitRevealFee >= b.minerCommitRevealFee
);
}
}{
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"EmptyBuffer","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"range","type":"uint256"}],"name":"IndexOutOfBounds","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"InvalidLengthEncoding","type":"error"},{"inputs":[{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"given","type":"uint256"}],"name":"MissingArgs","type":"error"},{"inputs":[{"internalType":"uint8","name":"opcode","type":"uint8"}],"name":"RadonFilterMissingArgs","type":"error"},{"inputs":[{"internalType":"uint256","name":"percentage","type":"uint256"}],"name":"RadonSlaConsensusOutOfRange","type":"error"},{"inputs":[{"internalType":"uint256","name":"witnessCollateral","type":"uint256"}],"name":"RadonSlaLowCollateral","type":"error"},{"inputs":[],"name":"RadonSlaNoReward","type":"error"},{"inputs":[],"name":"RadonSlaNoWitnesses","type":"error"},{"inputs":[{"internalType":"uint256","name":"numWitnesses","type":"uint256"}],"name":"RadonSlaTooManyWitnesses","type":"error"},{"inputs":[{"internalType":"uint256","name":"read","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"UnexpectedMajorType","type":"error"},{"inputs":[{"internalType":"uint8","name":"method","type":"uint8"},{"internalType":"string","name":"schema","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"}],"name":"UnsupportedDataRequestMethod","type":"error"},{"inputs":[{"internalType":"uint256","name":"unexpected","type":"uint256"}],"name":"UnsupportedMajorType","type":"error"},{"inputs":[{"internalType":"uint8","name":"datatype","type":"uint8"},{"internalType":"uint256","name":"maxlength","type":"uint256"}],"name":"UnsupportedRadonDataType","type":"error"},{"inputs":[{"internalType":"uint8","name":"opcode","type":"uint8"},{"internalType":"bytes","name":"args","type":"bytes"}],"name":"UnsupportedRadonFilterArgs","type":"error"},{"inputs":[{"internalType":"uint8","name":"opcode","type":"uint8"}],"name":"UnsupportedRadonFilterOpcode","type":"error"},{"inputs":[{"internalType":"uint8","name":"opcode","type":"uint8"}],"name":"UnsupportedRadonReducerOpcode","type":"error"},{"inputs":[{"internalType":"uint8","name":"opcode","type":"uint8"},{"internalType":"bytes","name":"script","type":"bytes"},{"internalType":"uint256","name":"offset","type":"uint256"}],"name":"UnsupportedRadonReducerScript","type":"error"},{"inputs":[{"internalType":"bytes","name":"script","type":"bytes"},{"internalType":"uint256","name":"cursor","type":"uint256"},{"internalType":"uint8","name":"opcode","type":"uint8"}],"name":"UnsupportedRadonScriptOpcode","type":"error"},{"inputs":[{"internalType":"bytes","name":"buf","type":"bytes"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"enum WitnetV2.RadonReducerOpcodes","name":"opcode","type":"WitnetV2.RadonReducerOpcodes"},{"components":[{"internalType":"enum WitnetV2.RadonFilterOpcodes","name":"opcode","type":"WitnetV2.RadonFilterOpcodes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct WitnetV2.RadonFilter[]","name":"filters","type":"tuple[]"},{"internalType":"bytes","name":"script","type":"bytes"}],"internalType":"struct WitnetV2.RadonReducer","name":"reducer","type":"tuple"}],"name":"encode","outputs":[{"internalType":"bytes","name":"bytecode","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"argsCount","type":"uint8"},{"internalType":"enum WitnetV2.DataRequestMethods","name":"method","type":"WitnetV2.DataRequestMethods"},{"internalType":"enum WitnetV2.RadonDataTypes","name":"resultDataType","type":"WitnetV2.RadonDataTypes"},{"internalType":"string","name":"url","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"},{"internalType":"bytes","name":"script","type":"bytes"}],"internalType":"struct WitnetV2.RadonRetrieval[]","name":"sources","type":"tuple[]"},{"internalType":"string[][]","name":"args","type":"string[][]"},{"internalType":"bytes","name":"aggregatorInnerBytecode","type":"bytes"},{"internalType":"bytes","name":"tallyInnerBytecode","type":"bytes"},{"internalType":"uint16","name":"resultMaxSize","type":"uint16"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"numWitnesses","type":"uint256"},{"internalType":"uint256","name":"minConsensusPercentage","type":"uint256"},{"internalType":"uint256","name":"witnessReward","type":"uint256"},{"internalType":"uint256","name":"witnessCollateral","type":"uint256"},{"internalType":"uint256","name":"minerCommitRevealFee","type":"uint256"}],"internalType":"struct WitnetV2.RadonSLA","name":"sla","type":"tuple"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"argsCount","type":"uint8"},{"internalType":"enum WitnetV2.DataRequestMethods","name":"method","type":"WitnetV2.DataRequestMethods"},{"internalType":"enum WitnetV2.RadonDataTypes","name":"resultDataType","type":"WitnetV2.RadonDataTypes"},{"internalType":"string","name":"url","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"},{"internalType":"bytes","name":"script","type":"bytes"}],"internalType":"struct WitnetV2.RadonRetrieval","name":"source","type":"tuple"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"enum WitnetV2.RadonReducerOpcodes","name":"opcode","type":"WitnetV2.RadonReducerOpcodes"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"buf","type":"bytes"},{"internalType":"uint256","name":"majorType","type":"uint256"}],"name":"encode","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint64","name":"n","type":"uint64"},{"internalType":"bytes1","name":"t","type":"bytes1"}],"name":"encode","outputs":[{"internalType":"bytes","name":"buf","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"enum WitnetV2.RadonFilterOpcodes","name":"opcode","type":"WitnetV2.RadonFilterOpcodes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct WitnetV2.RadonFilter","name":"filter","type":"tuple"}],"name":"encode","outputs":[{"internalType":"bytes","name":"bytecode","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"string[]","name":"args","type":"string[]"}],"name":"replaceCborStringsFromBytes","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"argsCount","type":"uint8"},{"internalType":"enum WitnetV2.DataRequestMethods","name":"method","type":"WitnetV2.DataRequestMethods"},{"internalType":"enum WitnetV2.RadonDataTypes","name":"resultDataType","type":"WitnetV2.RadonDataTypes"},{"internalType":"string","name":"url","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"},{"internalType":"bytes","name":"script","type":"bytes"}],"internalType":"struct WitnetV2.RadonRetrieval","name":"self","type":"tuple"},{"internalType":"string[]","name":"args","type":"string[]"}],"name":"replaceWildcards","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"enum WitnetV2.DataRequestMethods","name":"method","type":"WitnetV2.DataRequestMethods"},{"internalType":"string","name":"url","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"},{"internalType":"bytes","name":"script","type":"bytes"}],"name":"validate","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"enum WitnetV2.RadonDataTypes","name":"dataType","type":"WitnetV2.RadonDataTypes"},{"internalType":"uint16","name":"maxDataSize","type":"uint16"}],"name":"validate","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"enum WitnetV2.DataRequestMethods","name":"method","type":"WitnetV2.DataRequestMethods"},{"internalType":"string","name":"schema","type":"string"},{"internalType":"string","name":"authority","type":"string"},{"internalType":"string","name":"path","type":"string"},{"internalType":"string","name":"query","type":"string"},{"internalType":"string","name":"body","type":"string"},{"internalType":"string[2][]","name":"headers","type":"string[2][]"},{"internalType":"bytes","name":"script","type":"bytes"}],"name":"validate","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"enum WitnetV2.RadonFilterOpcodes","name":"opcode","type":"WitnetV2.RadonFilterOpcodes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct WitnetV2.RadonFilter","name":"filter","type":"tuple"}],"name":"validate","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"enum WitnetV2.RadonReducerOpcodes","name":"opcode","type":"WitnetV2.RadonReducerOpcodes"},{"components":[{"internalType":"enum WitnetV2.RadonFilterOpcodes","name":"opcode","type":"WitnetV2.RadonFilterOpcodes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct WitnetV2.RadonFilter[]","name":"filters","type":"tuple[]"},{"internalType":"bytes","name":"script","type":"bytes"}],"internalType":"struct WitnetV2.RadonReducer","name":"reducer","type":"tuple"}],"name":"validate","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"numWitnesses","type":"uint256"},{"internalType":"uint256","name":"minConsensusPercentage","type":"uint256"},{"internalType":"uint256","name":"witnessReward","type":"uint256"},{"internalType":"uint256","name":"witnessCollateral","type":"uint256"},{"internalType":"uint256","name":"minerCommitRevealFee","type":"uint256"}],"internalType":"struct WitnetV2.RadonSLA","name":"sla","type":"tuple"}],"name":"validate","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"script","type":"bytes"}],"name":"verifyRadonScriptResultDataType","outputs":[{"internalType":"enum WitnetV2.RadonDataTypes","name":"","type":"WitnetV2.RadonDataTypes"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
613ced61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061012b5760003560e01c80638da685f1116100b7578063bdc7ba6c1161007b578063bdc7ba6c1461026f578063dfaecd1114610282578063e4ec8d4214610295578063f04e6e29146102a8578063f3106f78146102bb57600080fd5b80638da685f11461020e578063962bd70e14610223578063a8c06a1314610236578063acbade1f14610249578063bb635d3e1461025c57600080fd5b80635a7ebb07116100fe5780635a7ebb07146101af5780635c38f1eb146101c25780635ddcdf25146101d55780636a11b2a8146101e857806387fffb1c146101fb57600080fd5b8063027fe7821461013057806312496a1b14610156578063195476cb146101765780632fcc361214610189575b600080fd5b61014361013e366004612c9e565b6102db565b6040519081526020015b60405180910390f35b610169610164366004612d5b565b6103d1565b60405161014d9190612de7565b610169610184366004612e86565b6103e4565b61019c610197366004612fb8565b6104c4565b60405161ffff909116815260200161014d565b6101696101bd3660046131e5565b61063c565b6101696101d0366004613312565b6107b7565b6101436101e3366004613381565b610828565b6101696101f6366004612d5b565b6109f3565b6101696102093660046134ac565b610a00565b61022161021c3660046134e0565b610d01565b005b610169610231366004613514565b610de7565b61016961024436600461352f565b610e08565b610169610257366004613573565b610f58565b61016961026a3660046134e0565b6110c1565b61022161027d3660046135c5565b611179565b610169610290366004613628565b6111bb565b6102216102a3366004612e86565b611222565b6102216102b6366004613312565b6113a0565b6102ce6102c9366004612d5b565b61147e565b60405161014d9190613674565b6000808551118015610319575060018660038111156102fc576102fc61365e565b1480610319575060038660038111156103175761031761365e565b145b80610358575060028660038111156103335761033361365e565b14801561033f57508451155b801561034a57508251155b801561035857506001825110155b6103975785600381111561036e5761036e61365e565b858585604051633a3cb62160e01b815260040161038e949392919061370e565b60405180910390fd5b85858585856040516020016103b095949392919061376f565b60405160208183030381529060405280519060200120905095945050505050565b60606103de826002610e08565b92915050565b60608160400151516000036104955760005b82602001515181101561045f578161042a8460200151838151811061041d5761041d6137d5565b60200260200101516110c1565b60405160200161043b9291906137eb565b6040516020818303038152906040529150808061045790613830565b9150506103f6565b508061046e8360000151610de7565b60405160200161047f9291906137eb565b6040516020818303038152906040529050919050565b6040820151516104a990600360fb1b610f58565b826040015160405160200161047f9291906137eb565b919050565b6000808360138111156104d9576104d961365e565b14806104f6575060078360138111156104f4576104f461365e565b145b80610512575060038360138111156105105761051061365e565b145b8061052e5750600183601381111561052c5761052c61365e565b145b8061054a575060068360138111156105485761054861365e565b145b1561059f576108008261ffff1611156105985782601381111561056f5761056f61365e565b604051637aba172760e01b815260ff909116600482015261ffff8316602482015260440161038e565b50806103de565b60048360138111156105b3576105b361365e565b14806105d0575060058360138111156105ce576105ce61365e565b145b806105ec575060028360138111156105ea576105ea61365e565b145b156105f9575060006103de565b82601381111561060b5761060b61365e565b61061484611493565b604051637aba172760e01b815260ff909216600483015261ffff16602482015260440161038e565b6060600086516001600160401b0381111561065957610659612a6c565b60405190808252806020026020018201604052801561068c57816020015b60608152602001906001900390816106775790505b50905060005b8751811015610729576106d78882815181106106b0576106b06137d5565b60200260200101518883815181106106ca576106ca6137d5565b6020026020010151611179565b6106f98882815181106106ec576106ec6137d5565b6020026020010151610a00565b82828151811061070b5761070b6137d5565b6020026020010181905250808061072190613830565b915050610692565b5060008361ffff161161074b576040518060200160405280600081525061075d565b61075d61ffff8416600160fb1b610f58565b610766826114fc565b865161077690600d60f91b610f58565b876107868851602260f81b610f58565b8860405160200161079c96959493929190613849565b60405160208183030381529060405291505095945050505050565b60606107cb8260400151601060f81b610f58565b82516107db90600360fb1b610f58565b60808401516107ee90600160fd1b610f58565b602085015161080190600560fb1b610f58565b606086015161081490600360fc1b610f58565b60405160200161047f9594939291906138c8565b6000600189600381111561083e5761083e61365e565b148061085b575060038960038111156108595761085961365e565b145b8015610868575060008751115b801561090f5750875115806108c1575060408051808201909152600881526768747470733a2f2f60c01b6020918201528851908901207f22a0bccaefa7e44032d5e21026b45254e49ef9bce8763cb450aaa27db3ce52a1145b8061090f5750604080518082019091526007815266687474703a2f2f60c81b6020918201528851908901207f12b2bb7976d0b719e943d3571505f9bf0e02bddb064dee61c48b0c3312656fb7145b8061097a575060028960038111156109295761092961365e565b14801561093557508751155b801561094057508651155b801561094b57508551155b801561095657508451155b801561096157508351155b801561096c57508251155b801561097a57506001825110155b6109b0578860038111156109905761099061365e565b888585604051633a3cb62160e01b815260040161038e949392919061370e565b88888888888888886040516020016109cf989796959493929190613933565b60405160208183030381529060405280519060200120905098975050505050505050565b60606103de826003610e08565b60606000610a2783602001516003811115610a1d57610a1d61365e565b600160fb1b610f58565b9050606060008460600151511115610a7557606084015151610a4d90600960f91b610f58565b8460600151604051602001610a639291906137eb565b60405160208183030381529060405290505b60c08401515160609015610abf5760c085015151610a9790600d60f91b610f58565b8560c00151604051602001610aad9291906137eb565b60405160208183030381529060405290505b60808501515160609015610b0957608086015151610ae190601160f91b610f58565b8660800151604051602001610af79291906137eb565b60405160208183030381529060405290505b60a08601515160609015610c875760005b8760a0015151811015610c85576000610b6c8960a001518381518110610b4257610b426137d5565b6020026020010151600060028110610b5c57610b5c6137d5565b602002015151600560f91b610f58565b8960a001518381518110610b8257610b826137d5565b6020026020010151600060028110610b9c57610b9c6137d5565b6020020151610be48b60a001518581518110610bba57610bba6137d5565b6020026020010151600160028110610bd457610bd46137d5565b602002015151600960f91b610f58565b8b60a001518581518110610bfa57610bfa6137d5565b6020026020010151600160028110610c1457610c146137d5565b6020020151604051602001610c2c94939291906139db565b604051602081830303815290604052905082610c4d8251602a60f81b610f58565b82604051602001610c6093929190613a32565b6040516020818303038152906040529250508080610c7d90613830565b915050610b1a565b505b600081518351855187518951610c9d9190613a75565b610ca79190613a75565b610cb19190613a75565b610cbb9190613a75565b9050610ccb81600960f91b610f58565b8686868686604051602001610ce596959493929190613849565b6040516020818303038152906040529650505050505050919050565b600581516009811115610d1657610d1661365e565b03610d5d57806020015151600003610d5a5780516009811115610d3b57610d3b61365e565b604051636799dcab60e01b815260ff909116600482015260240161038e565b50565b600881516009811115610d7257610d7261365e565b03610db55760208101515115610d5a5780516009811115610d9557610d9561365e565b81602001516040516319037b1360e31b815260040161038e929190613a88565b80516009811115610dc857610dc861365e565b60405163ddb08eaf60e01b815260ff909116600482015260240161038e565b60606103de82600b811115610dfe57610dfe61365e565b600160fc1b610f58565b81516060906017811015610e49578060ff16600584901b1784604051602001610e32929190613aa4565b6040516020818303038152906040529150506103de565b600583901b606060ff8311610e90576040516001600160f81b031960f885901b166020820152601892909217916021015b6040516020818303038152906040529050610f23565b61ffff8311610ebf576040516001600160f01b031960f085901b16602082015260199290921791602201610e7a565b63ffffffff8311610ef0576040516001600160e01b031960e085901b166020820152601a9290921791602401610e7a565b6040516001600160c01b031960c085901b166020820152601b929092179160280160405160208183030381529060405290505b818187604051602001610f3893929190613ad3565b60405160208183030381529060405293505050506103de565b5092915050565b60608260025b607f826001600160401b03161115610f8b576007826001600160401b0316901c9150600181019050610f5e565b806001600160401b03166001600160401b03811115610fac57610fac612a6c565b6040519080825280601f01601f191660200182016040528015610fd6576020820181803683370190505b5092508491508383600081518110610ff057610ff06137d5565b60200101906001600160f81b031916908160001a90535060015b816001600160401b0316816001600160401b031610156110795782607f1660801760f81b84826001600160401b031681518110611049576110496137d5565b60200101906001600160f81b031916908160001a90535060079290921c6701ffffffffffffff169160010161100a565b50607f60f81b83600183036001600160401b03168151811061109d5761109d6137d5565b0160200180519091166001600160f81b03191690600082901a905350505092915050565b60606110dc82600001516009811115610a1d57610a1d61365e565b6000836020015151116110fe5760405180602001604052806000815250611136565b60208301515161111290600960f91b610f58565b6020808501516040516111269392016137eb565b6040516020818303038152906040525b6040516020016111479291906137eb565b60405160208183030381529060405290506111678151600a60f81b610f58565b8160405160200161047f9291906137eb565b611187826060015182611552565b6060830152608082015161119b9082611552565b608083015260c08201516111af90826111bb565b8260c001819052505050565b606060006111c884611569565b90505b8051805151602090910151101561121957600360ff16816040015160ff1603611208576111f88184611595565b6112018161162a565b90506111cb565b61120161121482611652565b61162a565b51519392505050565b80604001515160000361133b5760038151600b8111156112445761124461365e565b1480611262575060078151600b8111156112605761126061365e565b145b8061127f575060028151600b81111561127d5761127d61365e565b145b8061129c5750600b8151600b81111561129a5761129a61365e565b145b806112b9575060058151600b8111156112b7576112b761365e565b145b6112ef578051600b8111156112d0576112d061365e565b60405163a1165d6360e01b815260ff909116600482015260240161038e565b60005b8160200151518110156113375761132582602001518281518110611318576113186137d5565b6020026020010151610d01565b8061132f81613830565b9150506112f2565b5050565b8051600b81111561134e5761134e61365e565b60ff1660ff14158061136557506000816020015151115b15610d5a578051600b81111561137d5761137d61365e565b8160400151600060405163037eac0960e21b815260040161038e93929190613b18565b80604001516000036113c557604051630e4cd9b760e31b815260040160405180910390fd5b80516000036113e75760405163a81d950760e01b815260040160405180910390fd5b8051607f101561141057805160405163df9adc2960e01b8152600481019190915260240161038e565b603381602001511080611427575060638160200151115b1561144d578060200151604051638fb8882560e01b815260040161038e91815260200190565b633b9aca0081606001511015610d5a578060600151604051637cedfd2360e01b815260040161038e91815260200190565b60006103de61148c83611569565b6000611817565b600060048260138111156114a9576114a961365e565b14806114c6575060058260138111156114c4576114c461365e565b145b156114d357506009919050565b60028260138111156114e7576114e761365e565b036114f457506001919050565b506000919050565b60405160208101600060015b8451811161153c5760208181028601518051909182016115298682846119a6565b5093840193929092019150600101611508565b5080835260208101604051016040525050919050565b6060600061156084846119ed565b50949350505050565b611571612a16565b604080518082019091528281526000602082015261158e81611c84565b9392505050565b60808201518251602001516001600160401b039091169060006115b785611da4565b90506000806115c683876119ed565b909250905080156116215760006115dc836109f3565b90506115e88686613b44565b8851602001528351611608906115ff908890613a75565b89519083611ead565b80518851602001805161161c908390613a75565b905250505b50505050505050565b611632612a16565b8151805151602090910151101561164e5781516103de90611c84565b5090565b61165a612a16565b604082015160ff1615806116755750604082015160ff166001145b806116ae5750604082015160ff16600714801561169a57506019826060015160ff1610155b80156116ae5750601b826060015160ff1611155b156116e1576116bc82611fd9565b6001600160401b031682600001516020018181516116da9190613a75565b9052505090565b604082015160ff16600314806116fe5750604082015160ff166002145b1561174257600061171783600001518460600151612046565b9050806001600160401b031683600001516020018181516117389190613a75565b90525061164e9050565b604082015160ff166004148061175f5750604082015160ff166005145b156117885761177682600001518360600151612046565b6001600160401b031660808301525090565b604082015160ff1660071415806117ba5750816060015160ff166014141580156117ba5750816060015160ff16601514155b1561164e5760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b606482015260840161038e565b6000600460ff16836040015160ff16036118b45760006118368461210e565b90506001815111156118aa578261187d5761187881600283516118599190613b44565b81518110611869576118696137d5565b60200260200101516001611817565b6118a2565b6118a281600081518110611893576118936137d5565b60200260200101516000611817565b9150506103de565b60009150506103de565b604083015160ff1661197d5782516020015160006118d1856122c8565b905060006040518060a0016040528060808152602001613c386080913951821161192c576040518060a0016040528060808152602001613c3860809139828151811061191f5761191f6137d5565b016020015160f81c61192f565b60ff5b9050601360ff8216111561195e57855151604051631aef51bd60e31b815261038e919085908590600401613b57565b8060ff1660138111156119735761197361365e565b93505050506103de565b604080840151905161800560e51b81526000600482015260ff909116602482015260440161038e565b5b602081106119c6578151835260209283019290910190601f19016119a7565b80156119e8578151835160208390036101000a60001901801990921691161783525b505050565b60606000806000905060008080600080600080600060038d511015611a21578c60009a509a50505050505050505050611c7d565b6040518d51909b5060208e810197508c019450600119015b808a1015611c0d57601760fa1b6001600160f81b0319168e8b81518110611a6257611a626137d5565b01602001516001600160f81b031916148015611aae5750601760fa1b6001600160f81b0319168e8b60020181518110611a9d57611a9d6137d5565b01602001516001600160f81b031916145b8015611aeb5750600360fc1b6001600160f81b0319168e8b60010181518110611ad957611ad96137d5565b01602001516001600160f81b03191610155b8015611b285750603960f81b6001600160f81b0319168e8b60010181518110611b1657611b166137d5565b01602001516001600160f81b03191611155b15611c0257888a039750888a1115611b5557611b4585888a6119a6565b9587016003019593870193611b5c565b6003870196505b6000600360fc1b60f81c8f8c60010181518110611b7b57611b7b6137d5565b602001015160f81c60f81b60f81c0360ff1690508d518110611bbf578d516040516306786e0760e21b8152600183016004820152602481019190915260440161038e565b600181016020028e0151945084519350602085019250611be08684866119a6565b506001909a019960039990990198899850878301959095019493820193611a39565b600190990198611a39565b508c5198508415611c5e5787891115611c4b57611c348487611c2f8b8d613b44565b6119a6565b611c3e888a613b44565b611c489086613a75565b94505b848b526020850160405101604052611c73565b8c60009a509a50505050505050505050611c7d565b5050505050505050505b9250929050565b611c8c612a16565b8151518290600003611cb1576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611d3457611cd18961232b565b955081611cdd81613830565b6007600589901c169650601f881695509250506005198501611d2c576020890151611d088a86612046565b9350808a60200151611d1a9190613b44565b611d249084613a75565b925050611cc2565b506000611cc2565b600760ff86161115611d5e5760405163bd2ac87960e01b815260ff8616600482015260240161038e565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b60608160038060ff16826040015160ff1614611de457604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b611df684600001518560600151612046565b6001600160401b03166080850181905267fffffffffffffffe1901611e935760005b80611e8d576000611e318660000151876040015161238d565b90506001600160401b038082161015611e825784611e5b611e53600484613b99565b885190612433565b604051602001611e6c9291906137eb565b6040516020818303038152906040529450611e87565b600191505b50611e18565b50611ea6565b60808401518451611ea391612433565b92505b5050919050565b60208301518351518391611ec091613b44565b611ecb906001613a75565b80821115611ef6576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b60408051600380825260808201909252600091816020015b6060815260200190600190039081611f0e579050509050611f3586600088602001516125ba565b81600081518110611f4857611f486137d5565b60200260200101819052508381600181518110611f6757611f676137d5565b6020026020010181905250611fa886868860200151611f869190613a75565b60208901518951518991611f9991613b44565b611fa39190613b44565b6125ba565b81600281518110611fbb57611fbb6137d5565b6020026020010181905250611fcf816114fc565b9095525050505050565b60006018826060015160ff161015611ff357506000919050565b601c826060015160ff16101561202257601882606001516120149190613bbf565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff909116600482015260240161038e565b600060188260ff16101561205e575060ff81166103de565b8160ff1660180361207c576120728361232b565b60ff1690506103de565b8160ff1660190361209b5761209083612660565b61ffff1690506103de565b8160ff16601a036120bc576120af836126cc565b63ffffffff1690506103de565b8160ff16601b036120d7576120d08361272b565b90506103de565b8160ff16601f036120f057506001600160401b036103de565b604051636d785b1360e01b815260ff8316600482015260240161038e565b60608160048060ff16826040015160ff161461214e57604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b600061216285600001518660600151612046565b905061216f816001613bd8565b6001600160401b03166001600160401b0381111561218f5761218f612a6c565b6040519080825280602002602001820160405280156121c857816020015b6121b5612a16565b8152602001906001900390816121ad5790505b50935060005b816001600160401b0316811015612298576121e88661162a565b95506121f38661278a565b858281518110612205576122056137d5565b6020026020010181905250600460ff16866040015160ff160361225e57600061222d8761210e565b9050806001825161223e9190613b44565b8151811061224e5761224e6137d5565b6020026020010151965050612286565b600560ff16866040015160ff160361227b57600061222d87612822565b61228486611652565b505b8061229081613830565b9150506121ce565b508484826001600160401b0316815181106122b5576122b56137d5565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff161461230857604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b61231a84600001518560600151612046565b6001600160401b0316949350505050565b6000816020015182600001515180821115612363576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b835160208501805180830160010151955090819061238082613830565b8152505050505050919050565b6000806123998461232b565b90508060ff1660ff036123b6576001600160401b039150506103de565b6123c38482601f16612046565b91506001600160401b03808316106123f957604051636d785b1360e01b81526001600160401b038316600482015260240161038e565b60ff83166007600583901c1614610f515760405161800560e51b81526007600583901c16600482015260ff8416602482015260440161038e565b6060816001600160401b03166001600160401b0381111561245657612456612a6c565b6040519080825280601f01601f191660200182016040528015612480576020820181803683370190505b50905060005b826001600160401b0316816001600160401b031610156125b15760006124ab8561232b565b905060808116156125725760e08160ff1610156124e7576124cb8561232b565b603f16600682601f1660ff16901b179050600184039350612572565b60f08160ff16101561252c576124fc8561232b565b603f16600661250a8761232b565b603f1660ff16901b600c83600f1660ff16901b17179050600284039350612572565b6125358561232b565b603f1660066125438761232b565b603f16901b600c6125538861232b565b603f1660ff16901b601284600f1660ff16901b17171790506003840393505b8060f81b83836001600160401b031681518110612591576125916137d5565b60200101906001600160f81b031916908160001a90535050600101612486565b50908152919050565b60606125c68284613a75565b845151808211156125f4576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b85516000856001600160401b0381111561261057612610612a6c565b6040519080825280601f01601f19166020018201604052801561263a576020820181803683370190505b5090506020808201908389010161265282828a6119a6565b509098975050505050505050565b6000816020015160026126739190613a75565b825151808211156126a1576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516002818401810151965090916126bf8284613a75565b9052509395945050505050565b6000816020015160046126df9190613a75565b8251518082111561270d576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516004818401810151965090916126bf8284613a75565b60008160200151600861273e9190613a75565b8251518082111561276c576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516008818401810151965090916126bf8284613a75565b612792612a16565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff161461286257604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b600061287685600001518660600151612046565b612881906002613bf8565b905061288e816001613bd8565b6001600160401b03166001600160401b038111156128ae576128ae612a6c565b6040519080825280602002602001820160405280156128e757816020015b6128d4612a16565b8152602001906001900390816128cc5790505b50935060005b816001600160401b0316811015612298576129078661162a565b95506129128661278a565b858281518110612924576129246137d5565b602090810291909101015261293a600282613c23565b15801561294f5750604086015160ff16600314155b1561297d57604080870151905161800560e51b815260ff90911660048201526003602482015260440161038e565b604086015160ff166004148061299a5750604086015160ff166005145b156129f957604086015160009060ff166004146129bf576129ba87612822565b6129c8565b6129c88761210e565b905080600182516129d99190613b44565b815181106129e9576129e96137d5565b6020026020010151965050612a04565b612a0286611652565b505b80612a0e81613830565b9150506128ed565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b8035600481106104bf57600080fd5b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715612aa457612aa4612a6c565b60405290565b604051606081016001600160401b0381118282101715612aa457612aa4612a6c565b60405160e081016001600160401b0381118282101715612aa457612aa4612a6c565b604051601f8201601f191681016001600160401b0381118282101715612b1657612b16612a6c565b604052919050565b600082601f830112612b2f57600080fd5b81356001600160401b03811115612b4857612b48612a6c565b612b5b601f8201601f1916602001612aee565b818152846020838601011115612b7057600080fd5b816020850160208301376000918101602001919091529392505050565b60006001600160401b03821115612ba657612ba6612a6c565b5060051b60200190565b600082601f830112612bc157600080fd5b81356020612bd6612bd183612b8d565b612aee565b82815260059290921b84018101918181019086841115612bf557600080fd5b8286015b84811015612c935780356001600160401b0380821115612c195760008081fd5b818901915089603f830112612c2e5760008081fd5b612c36612a82565b80606084018c811115612c495760008081fd5b8885015b81811015612c8157803585811115612c655760008081fd5b612c738f8c838a0101612b1e565b855250928901928901612c4d565b50508652505050918301918301612bf9565b509695505050505050565b600080600080600060a08688031215612cb657600080fd5b612cbf86612a5d565b945060208601356001600160401b0380821115612cdb57600080fd5b612ce789838a01612b1e565b95506040880135915080821115612cfd57600080fd5b612d0989838a01612b1e565b94506060880135915080821115612d1f57600080fd5b612d2b89838a01612bb0565b93506080880135915080821115612d4157600080fd5b50612d4e88828901612b1e565b9150509295509295909350565b600060208284031215612d6d57600080fd5b81356001600160401b03811115612d8357600080fd5b612d8f84828501612b1e565b949350505050565b60005b83811015612db2578181015183820152602001612d9a565b50506000910152565b60008151808452612dd3816020860160208601612d97565b601f01601f19169290920160200192915050565b60208152600061158e6020830184612dbb565b8035600c81106104bf57600080fd5b600060408284031215612e1b57600080fd5b604051604081016001600160401b038282108183111715612e3e57612e3e612a6c565b8160405282935084359150600a8210612e5657600080fd5b90825260208401359080821115612e6c57600080fd5b50612e7985828601612b1e565b6020830152505092915050565b60006020808385031215612e9957600080fd5b82356001600160401b0380821115612eb057600080fd5b9084019060608287031215612ec457600080fd5b612ecc612aaa565b612ed583612dfa565b81528383013582811115612ee857600080fd5b8301601f81018813612ef957600080fd5b8035612f07612bd182612b8d565b81815260059190911b8201860190868101908a831115612f2657600080fd5b8784015b83811015612f5e57803587811115612f425760008081fd5b612f508d8b83890101612e09565b845250918801918801612f2a565b508088860152505050506040830135935081841115612f7c57600080fd5b612f8887858501612b1e565b60408201529695505050505050565b8035601481106104bf57600080fd5b803561ffff811681146104bf57600080fd5b60008060408385031215612fcb57600080fd5b612fd483612f97565b9150612fe260208401612fa6565b90509250929050565b803560ff811681146104bf57600080fd5b600060e0828403121561300e57600080fd5b613016612acc565b905061302182612feb565b815261302f60208301612a5d565b602082015261304060408301612f97565b604082015260608201356001600160401b038082111561305f57600080fd5b61306b85838601612b1e565b6060840152608084013591508082111561308457600080fd5b61309085838601612b1e565b608084015260a08401359150808211156130a957600080fd5b6130b585838601612bb0565b60a084015260c08401359150808211156130ce57600080fd5b506130db84828501612b1e565b60c08301525092915050565b600082601f8301126130f857600080fd5b81356020613108612bd183612b8d565b82815260059290921b8401810191818101908684111561312757600080fd5b8286015b84811015612c935780356001600160401b0381111561314a5760008081fd5b6131588986838b0101612b1e565b84525091830191830161312b565b600082601f83011261317757600080fd5b81356020613187612bd183612b8d565b82815260059290921b840181019181810190868411156131a657600080fd5b8286015b84811015612c935780356001600160401b038111156131c95760008081fd5b6131d78986838b01016130e7565b8452509183019183016131aa565b600080600080600060a086880312156131fd57600080fd5b85356001600160401b038082111561321457600080fd5b818801915088601f83011261322857600080fd5b81356020613238612bd183612b8d565b82815260059290921b8401810191818101908c84111561325757600080fd5b8286015b8481101561328f578035868111156132735760008081fd5b6132818f86838b0101612ffc565b84525091830191830161325b565b50995050890135925050808211156132a657600080fd5b6132b289838a01613166565b955060408801359150808211156132c857600080fd5b6132d489838a01612b1e565b945060608801359150808211156132ea57600080fd5b506132f788828901612b1e565b92505061330660808701612fa6565b90509295509295909350565b600060a0828403121561332457600080fd5b60405160a081018181106001600160401b038211171561334657613346612a6c565b806040525082358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b600080600080600080600080610100898b03121561339e57600080fd5b6133a789612a5d565b975060208901356001600160401b03808211156133c357600080fd5b6133cf8c838d01612b1e565b985060408b01359150808211156133e557600080fd5b6133f18c838d01612b1e565b975060608b013591508082111561340757600080fd5b6134138c838d01612b1e565b965060808b013591508082111561342957600080fd5b6134358c838d01612b1e565b955060a08b013591508082111561344b57600080fd5b6134578c838d01612b1e565b945060c08b013591508082111561346d57600080fd5b6134798c838d01612bb0565b935060e08b013591508082111561348f57600080fd5b5061349c8b828c01612b1e565b9150509295985092959890939650565b6000602082840312156134be57600080fd5b81356001600160401b038111156134d457600080fd5b612d8f84828501612ffc565b6000602082840312156134f257600080fd5b81356001600160401b0381111561350857600080fd5b612d8f84828501612e09565b60006020828403121561352657600080fd5b61158e82612dfa565b6000806040838503121561354257600080fd5b82356001600160401b0381111561355857600080fd5b61356485828601612b1e565b95602094909401359450505050565b6000806040838503121561358657600080fd5b82356001600160401b038116811461359d57600080fd5b915060208301356001600160f81b0319811681146135ba57600080fd5b809150509250929050565b600080604083850312156135d857600080fd5b82356001600160401b03808211156135ef57600080fd5b6135fb86838701612ffc565b9350602085013591508082111561361157600080fd5b5061361e858286016130e7565b9150509250929050565b6000806040838503121561363b57600080fd5b82356001600160401b038082111561365257600080fd5b6135fb86838701612b1e565b634e487b7160e01b600052602160045260246000fd5b60208101601483106136885761368861365e565b91905290565b6000815180845260208085019450848260051b86018286016000805b86811015613700578484038a5282518460408101845b60028110156136eb5787820383526136d9828551612dbb565b938a0193928a019291506001016136c0565b509b88019b95505050918501916001016136aa565b509198975050505050505050565b60ff8516815260806020820152600061372a6080830186612dbb565b828103604084015261373c8186612dbb565b90508281036060840152613750818561368e565b979650505050505050565b6004811061376b5761376b61365e565b9052565b613779818761375b565b60a06020820152600061378f60a0830187612dbb565b82810360408401526137a18187612dbb565b905082810360608401526137b5818661368e565b905082810360808401526137c98185612dbb565b98975050505050505050565b634e487b7160e01b600052603260045260246000fd5b600083516137fd818460208801612d97565b835190830190613811818360208801612d97565b01949350505050565b634e487b7160e01b600052601160045260246000fd5b6000600182016138425761384261381a565b5060010190565b60008751602061385c8285838d01612d97565b88519184019161386f8184848d01612d97565b88519201916138818184848c01612d97565b87519201916138938184848b01612d97565b86519201916138a58184848a01612d97565b85519201916138b78184848901612d97565b919091019998505050505050505050565b600086516138da818460208b01612d97565b8651908301906138ee818360208b01612d97565b8651910190613901818360208a01612d97565b8551910190613914818360208901612d97565b8451910190613927818360208801612d97565b01979650505050505050565b6000610100613942838c61375b565b8060208401526139548184018b612dbb565b90508281036040840152613968818a612dbb565b9050828103606084015261397c8189612dbb565b905082810360808401526139908188612dbb565b905082810360a08401526139a48187612dbb565b905082810360c08401526139b8818661368e565b905082810360e08401526139cc8185612dbb565b9b9a5050505050505050505050565b600085516139ed818460208a01612d97565b855190830190613a01818360208a01612d97565b8551910190613a14818360208901612d97565b8451910190613a27818360208801612d97565b019695505050505050565b60008451613a44818460208901612d97565b845190830190613a58818360208901612d97565b8451910190613a6b818360208801612d97565b0195945050505050565b808201808211156103de576103de61381a565b60ff83168152604060208201526000612d8f6040830184612dbb565b60ff60f81b8360f81b16815260008251613ac5816001850160208701612d97565b919091016001019392505050565b60ff60f81b8460f81b16815260008351613af4816001850160208801612d97565b835190830190613b0b816001840160208801612d97565b0160010195945050505050565b60ff84168152606060208201526000613b346060830185612dbb565b9050826040830152949350505050565b818103818111156103de576103de61381a565b606081526000613b6a6060830186612dbb565b905083602083015260ff83166040830152949350505050565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b0380841680613bb357613bb3613b83565b92169190910492915050565b60ff82811682821603908111156103de576103de61381a565b6001600160401b03818116838216019080821115610f5157610f5161381a565b6001600160401b03818116838216028082169190828114613c1b57613c1b61381a565b505092915050565b600082613c3257613c32613b83565b50069056fe10ffffffffffffffffffffffffffffff0401ff010203050406071311ff01ffff07ff02ffffffffffffffffffffffffff0703ffffffffffffffffffffffffffff0405070202ff04040404ffffffffffff05070402040205050505ff04ff04ffffff010203050406070101ffffffffffff02ff050404000106060707ffffffffffa264697066735822122076594b7ea4a1b7caced4acbf626f0d779c13535d30293d52712a5bf458b1fcf964736f6c63430008110033
Deployed Bytecode
0x738ae7693f8a560369bcd06c75772974eee9b293ba301460806040526004361061012b5760003560e01c80638da685f1116100b7578063bdc7ba6c1161007b578063bdc7ba6c1461026f578063dfaecd1114610282578063e4ec8d4214610295578063f04e6e29146102a8578063f3106f78146102bb57600080fd5b80638da685f11461020e578063962bd70e14610223578063a8c06a1314610236578063acbade1f14610249578063bb635d3e1461025c57600080fd5b80635a7ebb07116100fe5780635a7ebb07146101af5780635c38f1eb146101c25780635ddcdf25146101d55780636a11b2a8146101e857806387fffb1c146101fb57600080fd5b8063027fe7821461013057806312496a1b14610156578063195476cb146101765780632fcc361214610189575b600080fd5b61014361013e366004612c9e565b6102db565b6040519081526020015b60405180910390f35b610169610164366004612d5b565b6103d1565b60405161014d9190612de7565b610169610184366004612e86565b6103e4565b61019c610197366004612fb8565b6104c4565b60405161ffff909116815260200161014d565b6101696101bd3660046131e5565b61063c565b6101696101d0366004613312565b6107b7565b6101436101e3366004613381565b610828565b6101696101f6366004612d5b565b6109f3565b6101696102093660046134ac565b610a00565b61022161021c3660046134e0565b610d01565b005b610169610231366004613514565b610de7565b61016961024436600461352f565b610e08565b610169610257366004613573565b610f58565b61016961026a3660046134e0565b6110c1565b61022161027d3660046135c5565b611179565b610169610290366004613628565b6111bb565b6102216102a3366004612e86565b611222565b6102216102b6366004613312565b6113a0565b6102ce6102c9366004612d5b565b61147e565b60405161014d9190613674565b6000808551118015610319575060018660038111156102fc576102fc61365e565b1480610319575060038660038111156103175761031761365e565b145b80610358575060028660038111156103335761033361365e565b14801561033f57508451155b801561034a57508251155b801561035857506001825110155b6103975785600381111561036e5761036e61365e565b858585604051633a3cb62160e01b815260040161038e949392919061370e565b60405180910390fd5b85858585856040516020016103b095949392919061376f565b60405160208183030381529060405280519060200120905095945050505050565b60606103de826002610e08565b92915050565b60608160400151516000036104955760005b82602001515181101561045f578161042a8460200151838151811061041d5761041d6137d5565b60200260200101516110c1565b60405160200161043b9291906137eb565b6040516020818303038152906040529150808061045790613830565b9150506103f6565b508061046e8360000151610de7565b60405160200161047f9291906137eb565b6040516020818303038152906040529050919050565b6040820151516104a990600360fb1b610f58565b826040015160405160200161047f9291906137eb565b919050565b6000808360138111156104d9576104d961365e565b14806104f6575060078360138111156104f4576104f461365e565b145b80610512575060038360138111156105105761051061365e565b145b8061052e5750600183601381111561052c5761052c61365e565b145b8061054a575060068360138111156105485761054861365e565b145b1561059f576108008261ffff1611156105985782601381111561056f5761056f61365e565b604051637aba172760e01b815260ff909116600482015261ffff8316602482015260440161038e565b50806103de565b60048360138111156105b3576105b361365e565b14806105d0575060058360138111156105ce576105ce61365e565b145b806105ec575060028360138111156105ea576105ea61365e565b145b156105f9575060006103de565b82601381111561060b5761060b61365e565b61061484611493565b604051637aba172760e01b815260ff909216600483015261ffff16602482015260440161038e565b6060600086516001600160401b0381111561065957610659612a6c565b60405190808252806020026020018201604052801561068c57816020015b60608152602001906001900390816106775790505b50905060005b8751811015610729576106d78882815181106106b0576106b06137d5565b60200260200101518883815181106106ca576106ca6137d5565b6020026020010151611179565b6106f98882815181106106ec576106ec6137d5565b6020026020010151610a00565b82828151811061070b5761070b6137d5565b6020026020010181905250808061072190613830565b915050610692565b5060008361ffff161161074b576040518060200160405280600081525061075d565b61075d61ffff8416600160fb1b610f58565b610766826114fc565b865161077690600d60f91b610f58565b876107868851602260f81b610f58565b8860405160200161079c96959493929190613849565b60405160208183030381529060405291505095945050505050565b60606107cb8260400151601060f81b610f58565b82516107db90600360fb1b610f58565b60808401516107ee90600160fd1b610f58565b602085015161080190600560fb1b610f58565b606086015161081490600360fc1b610f58565b60405160200161047f9594939291906138c8565b6000600189600381111561083e5761083e61365e565b148061085b575060038960038111156108595761085961365e565b145b8015610868575060008751115b801561090f5750875115806108c1575060408051808201909152600881526768747470733a2f2f60c01b6020918201528851908901207f22a0bccaefa7e44032d5e21026b45254e49ef9bce8763cb450aaa27db3ce52a1145b8061090f5750604080518082019091526007815266687474703a2f2f60c81b6020918201528851908901207f12b2bb7976d0b719e943d3571505f9bf0e02bddb064dee61c48b0c3312656fb7145b8061097a575060028960038111156109295761092961365e565b14801561093557508751155b801561094057508651155b801561094b57508551155b801561095657508451155b801561096157508351155b801561096c57508251155b801561097a57506001825110155b6109b0578860038111156109905761099061365e565b888585604051633a3cb62160e01b815260040161038e949392919061370e565b88888888888888886040516020016109cf989796959493929190613933565b60405160208183030381529060405280519060200120905098975050505050505050565b60606103de826003610e08565b60606000610a2783602001516003811115610a1d57610a1d61365e565b600160fb1b610f58565b9050606060008460600151511115610a7557606084015151610a4d90600960f91b610f58565b8460600151604051602001610a639291906137eb565b60405160208183030381529060405290505b60c08401515160609015610abf5760c085015151610a9790600d60f91b610f58565b8560c00151604051602001610aad9291906137eb565b60405160208183030381529060405290505b60808501515160609015610b0957608086015151610ae190601160f91b610f58565b8660800151604051602001610af79291906137eb565b60405160208183030381529060405290505b60a08601515160609015610c875760005b8760a0015151811015610c85576000610b6c8960a001518381518110610b4257610b426137d5565b6020026020010151600060028110610b5c57610b5c6137d5565b602002015151600560f91b610f58565b8960a001518381518110610b8257610b826137d5565b6020026020010151600060028110610b9c57610b9c6137d5565b6020020151610be48b60a001518581518110610bba57610bba6137d5565b6020026020010151600160028110610bd457610bd46137d5565b602002015151600960f91b610f58565b8b60a001518581518110610bfa57610bfa6137d5565b6020026020010151600160028110610c1457610c146137d5565b6020020151604051602001610c2c94939291906139db565b604051602081830303815290604052905082610c4d8251602a60f81b610f58565b82604051602001610c6093929190613a32565b6040516020818303038152906040529250508080610c7d90613830565b915050610b1a565b505b600081518351855187518951610c9d9190613a75565b610ca79190613a75565b610cb19190613a75565b610cbb9190613a75565b9050610ccb81600960f91b610f58565b8686868686604051602001610ce596959493929190613849565b6040516020818303038152906040529650505050505050919050565b600581516009811115610d1657610d1661365e565b03610d5d57806020015151600003610d5a5780516009811115610d3b57610d3b61365e565b604051636799dcab60e01b815260ff909116600482015260240161038e565b50565b600881516009811115610d7257610d7261365e565b03610db55760208101515115610d5a5780516009811115610d9557610d9561365e565b81602001516040516319037b1360e31b815260040161038e929190613a88565b80516009811115610dc857610dc861365e565b60405163ddb08eaf60e01b815260ff909116600482015260240161038e565b60606103de82600b811115610dfe57610dfe61365e565b600160fc1b610f58565b81516060906017811015610e49578060ff16600584901b1784604051602001610e32929190613aa4565b6040516020818303038152906040529150506103de565b600583901b606060ff8311610e90576040516001600160f81b031960f885901b166020820152601892909217916021015b6040516020818303038152906040529050610f23565b61ffff8311610ebf576040516001600160f01b031960f085901b16602082015260199290921791602201610e7a565b63ffffffff8311610ef0576040516001600160e01b031960e085901b166020820152601a9290921791602401610e7a565b6040516001600160c01b031960c085901b166020820152601b929092179160280160405160208183030381529060405290505b818187604051602001610f3893929190613ad3565b60405160208183030381529060405293505050506103de565b5092915050565b60608260025b607f826001600160401b03161115610f8b576007826001600160401b0316901c9150600181019050610f5e565b806001600160401b03166001600160401b03811115610fac57610fac612a6c565b6040519080825280601f01601f191660200182016040528015610fd6576020820181803683370190505b5092508491508383600081518110610ff057610ff06137d5565b60200101906001600160f81b031916908160001a90535060015b816001600160401b0316816001600160401b031610156110795782607f1660801760f81b84826001600160401b031681518110611049576110496137d5565b60200101906001600160f81b031916908160001a90535060079290921c6701ffffffffffffff169160010161100a565b50607f60f81b83600183036001600160401b03168151811061109d5761109d6137d5565b0160200180519091166001600160f81b03191690600082901a905350505092915050565b60606110dc82600001516009811115610a1d57610a1d61365e565b6000836020015151116110fe5760405180602001604052806000815250611136565b60208301515161111290600960f91b610f58565b6020808501516040516111269392016137eb565b6040516020818303038152906040525b6040516020016111479291906137eb565b60405160208183030381529060405290506111678151600a60f81b610f58565b8160405160200161047f9291906137eb565b611187826060015182611552565b6060830152608082015161119b9082611552565b608083015260c08201516111af90826111bb565b8260c001819052505050565b606060006111c884611569565b90505b8051805151602090910151101561121957600360ff16816040015160ff1603611208576111f88184611595565b6112018161162a565b90506111cb565b61120161121482611652565b61162a565b51519392505050565b80604001515160000361133b5760038151600b8111156112445761124461365e565b1480611262575060078151600b8111156112605761126061365e565b145b8061127f575060028151600b81111561127d5761127d61365e565b145b8061129c5750600b8151600b81111561129a5761129a61365e565b145b806112b9575060058151600b8111156112b7576112b761365e565b145b6112ef578051600b8111156112d0576112d061365e565b60405163a1165d6360e01b815260ff909116600482015260240161038e565b60005b8160200151518110156113375761132582602001518281518110611318576113186137d5565b6020026020010151610d01565b8061132f81613830565b9150506112f2565b5050565b8051600b81111561134e5761134e61365e565b60ff1660ff14158061136557506000816020015151115b15610d5a578051600b81111561137d5761137d61365e565b8160400151600060405163037eac0960e21b815260040161038e93929190613b18565b80604001516000036113c557604051630e4cd9b760e31b815260040160405180910390fd5b80516000036113e75760405163a81d950760e01b815260040160405180910390fd5b8051607f101561141057805160405163df9adc2960e01b8152600481019190915260240161038e565b603381602001511080611427575060638160200151115b1561144d578060200151604051638fb8882560e01b815260040161038e91815260200190565b633b9aca0081606001511015610d5a578060600151604051637cedfd2360e01b815260040161038e91815260200190565b60006103de61148c83611569565b6000611817565b600060048260138111156114a9576114a961365e565b14806114c6575060058260138111156114c4576114c461365e565b145b156114d357506009919050565b60028260138111156114e7576114e761365e565b036114f457506001919050565b506000919050565b60405160208101600060015b8451811161153c5760208181028601518051909182016115298682846119a6565b5093840193929092019150600101611508565b5080835260208101604051016040525050919050565b6060600061156084846119ed565b50949350505050565b611571612a16565b604080518082019091528281526000602082015261158e81611c84565b9392505050565b60808201518251602001516001600160401b039091169060006115b785611da4565b90506000806115c683876119ed565b909250905080156116215760006115dc836109f3565b90506115e88686613b44565b8851602001528351611608906115ff908890613a75565b89519083611ead565b80518851602001805161161c908390613a75565b905250505b50505050505050565b611632612a16565b8151805151602090910151101561164e5781516103de90611c84565b5090565b61165a612a16565b604082015160ff1615806116755750604082015160ff166001145b806116ae5750604082015160ff16600714801561169a57506019826060015160ff1610155b80156116ae5750601b826060015160ff1611155b156116e1576116bc82611fd9565b6001600160401b031682600001516020018181516116da9190613a75565b9052505090565b604082015160ff16600314806116fe5750604082015160ff166002145b1561174257600061171783600001518460600151612046565b9050806001600160401b031683600001516020018181516117389190613a75565b90525061164e9050565b604082015160ff166004148061175f5750604082015160ff166005145b156117885761177682600001518360600151612046565b6001600160401b031660808301525090565b604082015160ff1660071415806117ba5750816060015160ff166014141580156117ba5750816060015160ff16601514155b1561164e5760405162461bcd60e51b815260206004820152602760248201527f5769746e657443424f522e736b69703a20756e737570706f72746564206d616a6044820152666f72207479706560c81b606482015260840161038e565b6000600460ff16836040015160ff16036118b45760006118368461210e565b90506001815111156118aa578261187d5761187881600283516118599190613b44565b81518110611869576118696137d5565b60200260200101516001611817565b6118a2565b6118a281600081518110611893576118936137d5565b60200260200101516000611817565b9150506103de565b60009150506103de565b604083015160ff1661197d5782516020015160006118d1856122c8565b905060006040518060a0016040528060808152602001613c386080913951821161192c576040518060a0016040528060808152602001613c3860809139828151811061191f5761191f6137d5565b016020015160f81c61192f565b60ff5b9050601360ff8216111561195e57855151604051631aef51bd60e31b815261038e919085908590600401613b57565b8060ff1660138111156119735761197361365e565b93505050506103de565b604080840151905161800560e51b81526000600482015260ff909116602482015260440161038e565b5b602081106119c6578151835260209283019290910190601f19016119a7565b80156119e8578151835160208390036101000a60001901801990921691161783525b505050565b60606000806000905060008080600080600080600060038d511015611a21578c60009a509a50505050505050505050611c7d565b6040518d51909b5060208e810197508c019450600119015b808a1015611c0d57601760fa1b6001600160f81b0319168e8b81518110611a6257611a626137d5565b01602001516001600160f81b031916148015611aae5750601760fa1b6001600160f81b0319168e8b60020181518110611a9d57611a9d6137d5565b01602001516001600160f81b031916145b8015611aeb5750600360fc1b6001600160f81b0319168e8b60010181518110611ad957611ad96137d5565b01602001516001600160f81b03191610155b8015611b285750603960f81b6001600160f81b0319168e8b60010181518110611b1657611b166137d5565b01602001516001600160f81b03191611155b15611c0257888a039750888a1115611b5557611b4585888a6119a6565b9587016003019593870193611b5c565b6003870196505b6000600360fc1b60f81c8f8c60010181518110611b7b57611b7b6137d5565b602001015160f81c60f81b60f81c0360ff1690508d518110611bbf578d516040516306786e0760e21b8152600183016004820152602481019190915260440161038e565b600181016020028e0151945084519350602085019250611be08684866119a6565b506001909a019960039990990198899850878301959095019493820193611a39565b600190990198611a39565b508c5198508415611c5e5787891115611c4b57611c348487611c2f8b8d613b44565b6119a6565b611c3e888a613b44565b611c489086613a75565b94505b848b526020850160405101604052611c73565b8c60009a509a50505050505050505050611c7d565b5050505050505050505b9250929050565b611c8c612a16565b8151518290600003611cb1576040516309036d4760e21b815260040160405180910390fd5b600060ff816001600160401b038160015b8015611d3457611cd18961232b565b955081611cdd81613830565b6007600589901c169650601f881695509250506005198501611d2c576020890151611d088a86612046565b9350808a60200151611d1a9190613b44565b611d249084613a75565b925050611cc2565b506000611cc2565b600760ff86161115611d5e5760405163bd2ac87960e01b815260ff8616600482015260240161038e565b506040805160c08101825298895260ff95861660208a015293851693880193909352921660608601526001600160401b0390811660808601521660a08401525090919050565b60608160038060ff16826040015160ff1614611de457604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b611df684600001518560600151612046565b6001600160401b03166080850181905267fffffffffffffffe1901611e935760005b80611e8d576000611e318660000151876040015161238d565b90506001600160401b038082161015611e825784611e5b611e53600484613b99565b885190612433565b604051602001611e6c9291906137eb565b6040516020818303038152906040529450611e87565b600191505b50611e18565b50611ea6565b60808401518451611ea391612433565b92505b5050919050565b60208301518351518391611ec091613b44565b611ecb906001613a75565b80821115611ef6576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b60408051600380825260808201909252600091816020015b6060815260200190600190039081611f0e579050509050611f3586600088602001516125ba565b81600081518110611f4857611f486137d5565b60200260200101819052508381600181518110611f6757611f676137d5565b6020026020010181905250611fa886868860200151611f869190613a75565b60208901518951518991611f9991613b44565b611fa39190613b44565b6125ba565b81600281518110611fbb57611fbb6137d5565b6020026020010181905250611fcf816114fc565b9095525050505050565b60006018826060015160ff161015611ff357506000919050565b601c826060015160ff16101561202257601882606001516120149190613bbf565b60ff166001901b9050919050565b6060820151604051636d785b1360e01b815260ff909116600482015260240161038e565b600060188260ff16101561205e575060ff81166103de565b8160ff1660180361207c576120728361232b565b60ff1690506103de565b8160ff1660190361209b5761209083612660565b61ffff1690506103de565b8160ff16601a036120bc576120af836126cc565b63ffffffff1690506103de565b8160ff16601b036120d7576120d08361272b565b90506103de565b8160ff16601f036120f057506001600160401b036103de565b604051636d785b1360e01b815260ff8316600482015260240161038e565b60608160048060ff16826040015160ff161461214e57604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b600061216285600001518660600151612046565b905061216f816001613bd8565b6001600160401b03166001600160401b0381111561218f5761218f612a6c565b6040519080825280602002602001820160405280156121c857816020015b6121b5612a16565b8152602001906001900390816121ad5790505b50935060005b816001600160401b0316811015612298576121e88661162a565b95506121f38661278a565b858281518110612205576122056137d5565b6020026020010181905250600460ff16866040015160ff160361225e57600061222d8761210e565b9050806001825161223e9190613b44565b8151811061224e5761224e6137d5565b6020026020010151965050612286565b600560ff16866040015160ff160361227b57600061222d87612822565b61228486611652565b505b8061229081613830565b9150506121ce565b508484826001600160401b0316815181106122b5576122b56137d5565b6020026020010181905250505050919050565b60008160008060ff16826040015160ff161461230857604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b61231a84600001518560600151612046565b6001600160401b0316949350505050565b6000816020015182600001515180821115612363576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b835160208501805180830160010151955090819061238082613830565b8152505050505050919050565b6000806123998461232b565b90508060ff1660ff036123b6576001600160401b039150506103de565b6123c38482601f16612046565b91506001600160401b03808316106123f957604051636d785b1360e01b81526001600160401b038316600482015260240161038e565b60ff83166007600583901c1614610f515760405161800560e51b81526007600583901c16600482015260ff8416602482015260440161038e565b6060816001600160401b03166001600160401b0381111561245657612456612a6c565b6040519080825280601f01601f191660200182016040528015612480576020820181803683370190505b50905060005b826001600160401b0316816001600160401b031610156125b15760006124ab8561232b565b905060808116156125725760e08160ff1610156124e7576124cb8561232b565b603f16600682601f1660ff16901b179050600184039350612572565b60f08160ff16101561252c576124fc8561232b565b603f16600661250a8761232b565b603f1660ff16901b600c83600f1660ff16901b17179050600284039350612572565b6125358561232b565b603f1660066125438761232b565b603f16901b600c6125538861232b565b603f1660ff16901b601284600f1660ff16901b17171790506003840393505b8060f81b83836001600160401b031681518110612591576125916137d5565b60200101906001600160f81b031916908160001a90535050600101612486565b50908152919050565b60606125c68284613a75565b845151808211156125f4576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b85516000856001600160401b0381111561261057612610612a6c565b6040519080825280601f01601f19166020018201604052801561263a576020820181803683370190505b5090506020808201908389010161265282828a6119a6565b509098975050505050505050565b6000816020015160026126739190613a75565b825151808211156126a1576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516002818401810151965090916126bf8284613a75565b9052509395945050505050565b6000816020015160046126df9190613a75565b8251518082111561270d576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516004818401810151965090916126bf8284613a75565b60008160200151600861273e9190613a75565b8251518082111561276c576040516363a056dd60e01b8152600481018390526024810182905260440161038e565b83516020850180516008818401810151965090916126bf8284613a75565b612792612a16565b6040805160c081018083528451610100830184526060909152600060e0830152825180840190935280518352602090810151908301529081908152602001836020015160ff168152602001836040015160ff168152602001836060015160ff16815260200183608001516001600160401b031681526020018360a001516001600160401b03168152509050919050565b60608160058060ff16826040015160ff161461286257604080830151905161800560e51b815260ff9182166004820152908216602482015260440161038e565b600061287685600001518660600151612046565b612881906002613bf8565b905061288e816001613bd8565b6001600160401b03166001600160401b038111156128ae576128ae612a6c565b6040519080825280602002602001820160405280156128e757816020015b6128d4612a16565b8152602001906001900390816128cc5790505b50935060005b816001600160401b0316811015612298576129078661162a565b95506129128661278a565b858281518110612924576129246137d5565b602090810291909101015261293a600282613c23565b15801561294f5750604086015160ff16600314155b1561297d57604080870151905161800560e51b815260ff90911660048201526003602482015260440161038e565b604086015160ff166004148061299a5750604086015160ff166005145b156129f957604086015160009060ff166004146129bf576129ba87612822565b6129c8565b6129c88761210e565b905080600182516129d99190613b44565b815181106129e9576129e96137d5565b6020026020010151965050612a04565b612a0286611652565b505b80612a0e81613830565b9150506128ed565b604080516101008101909152606060c08201908152600060e08301528190815260006020820181905260408201819052606082018190526080820181905260a09091015290565b8035600481106104bf57600080fd5b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715612aa457612aa4612a6c565b60405290565b604051606081016001600160401b0381118282101715612aa457612aa4612a6c565b60405160e081016001600160401b0381118282101715612aa457612aa4612a6c565b604051601f8201601f191681016001600160401b0381118282101715612b1657612b16612a6c565b604052919050565b600082601f830112612b2f57600080fd5b81356001600160401b03811115612b4857612b48612a6c565b612b5b601f8201601f1916602001612aee565b818152846020838601011115612b7057600080fd5b816020850160208301376000918101602001919091529392505050565b60006001600160401b03821115612ba657612ba6612a6c565b5060051b60200190565b600082601f830112612bc157600080fd5b81356020612bd6612bd183612b8d565b612aee565b82815260059290921b84018101918181019086841115612bf557600080fd5b8286015b84811015612c935780356001600160401b0380821115612c195760008081fd5b818901915089603f830112612c2e5760008081fd5b612c36612a82565b80606084018c811115612c495760008081fd5b8885015b81811015612c8157803585811115612c655760008081fd5b612c738f8c838a0101612b1e565b855250928901928901612c4d565b50508652505050918301918301612bf9565b509695505050505050565b600080600080600060a08688031215612cb657600080fd5b612cbf86612a5d565b945060208601356001600160401b0380821115612cdb57600080fd5b612ce789838a01612b1e565b95506040880135915080821115612cfd57600080fd5b612d0989838a01612b1e565b94506060880135915080821115612d1f57600080fd5b612d2b89838a01612bb0565b93506080880135915080821115612d4157600080fd5b50612d4e88828901612b1e565b9150509295509295909350565b600060208284031215612d6d57600080fd5b81356001600160401b03811115612d8357600080fd5b612d8f84828501612b1e565b949350505050565b60005b83811015612db2578181015183820152602001612d9a565b50506000910152565b60008151808452612dd3816020860160208601612d97565b601f01601f19169290920160200192915050565b60208152600061158e6020830184612dbb565b8035600c81106104bf57600080fd5b600060408284031215612e1b57600080fd5b604051604081016001600160401b038282108183111715612e3e57612e3e612a6c565b8160405282935084359150600a8210612e5657600080fd5b90825260208401359080821115612e6c57600080fd5b50612e7985828601612b1e565b6020830152505092915050565b60006020808385031215612e9957600080fd5b82356001600160401b0380821115612eb057600080fd5b9084019060608287031215612ec457600080fd5b612ecc612aaa565b612ed583612dfa565b81528383013582811115612ee857600080fd5b8301601f81018813612ef957600080fd5b8035612f07612bd182612b8d565b81815260059190911b8201860190868101908a831115612f2657600080fd5b8784015b83811015612f5e57803587811115612f425760008081fd5b612f508d8b83890101612e09565b845250918801918801612f2a565b508088860152505050506040830135935081841115612f7c57600080fd5b612f8887858501612b1e565b60408201529695505050505050565b8035601481106104bf57600080fd5b803561ffff811681146104bf57600080fd5b60008060408385031215612fcb57600080fd5b612fd483612f97565b9150612fe260208401612fa6565b90509250929050565b803560ff811681146104bf57600080fd5b600060e0828403121561300e57600080fd5b613016612acc565b905061302182612feb565b815261302f60208301612a5d565b602082015261304060408301612f97565b604082015260608201356001600160401b038082111561305f57600080fd5b61306b85838601612b1e565b6060840152608084013591508082111561308457600080fd5b61309085838601612b1e565b608084015260a08401359150808211156130a957600080fd5b6130b585838601612bb0565b60a084015260c08401359150808211156130ce57600080fd5b506130db84828501612b1e565b60c08301525092915050565b600082601f8301126130f857600080fd5b81356020613108612bd183612b8d565b82815260059290921b8401810191818101908684111561312757600080fd5b8286015b84811015612c935780356001600160401b0381111561314a5760008081fd5b6131588986838b0101612b1e565b84525091830191830161312b565b600082601f83011261317757600080fd5b81356020613187612bd183612b8d565b82815260059290921b840181019181810190868411156131a657600080fd5b8286015b84811015612c935780356001600160401b038111156131c95760008081fd5b6131d78986838b01016130e7565b8452509183019183016131aa565b600080600080600060a086880312156131fd57600080fd5b85356001600160401b038082111561321457600080fd5b818801915088601f83011261322857600080fd5b81356020613238612bd183612b8d565b82815260059290921b8401810191818101908c84111561325757600080fd5b8286015b8481101561328f578035868111156132735760008081fd5b6132818f86838b0101612ffc565b84525091830191830161325b565b50995050890135925050808211156132a657600080fd5b6132b289838a01613166565b955060408801359150808211156132c857600080fd5b6132d489838a01612b1e565b945060608801359150808211156132ea57600080fd5b506132f788828901612b1e565b92505061330660808701612fa6565b90509295509295909350565b600060a0828403121561332457600080fd5b60405160a081018181106001600160401b038211171561334657613346612a6c565b806040525082358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b600080600080600080600080610100898b03121561339e57600080fd5b6133a789612a5d565b975060208901356001600160401b03808211156133c357600080fd5b6133cf8c838d01612b1e565b985060408b01359150808211156133e557600080fd5b6133f18c838d01612b1e565b975060608b013591508082111561340757600080fd5b6134138c838d01612b1e565b965060808b013591508082111561342957600080fd5b6134358c838d01612b1e565b955060a08b013591508082111561344b57600080fd5b6134578c838d01612b1e565b945060c08b013591508082111561346d57600080fd5b6134798c838d01612bb0565b935060e08b013591508082111561348f57600080fd5b5061349c8b828c01612b1e565b9150509295985092959890939650565b6000602082840312156134be57600080fd5b81356001600160401b038111156134d457600080fd5b612d8f84828501612ffc565b6000602082840312156134f257600080fd5b81356001600160401b0381111561350857600080fd5b612d8f84828501612e09565b60006020828403121561352657600080fd5b61158e82612dfa565b6000806040838503121561354257600080fd5b82356001600160401b0381111561355857600080fd5b61356485828601612b1e565b95602094909401359450505050565b6000806040838503121561358657600080fd5b82356001600160401b038116811461359d57600080fd5b915060208301356001600160f81b0319811681146135ba57600080fd5b809150509250929050565b600080604083850312156135d857600080fd5b82356001600160401b03808211156135ef57600080fd5b6135fb86838701612ffc565b9350602085013591508082111561361157600080fd5b5061361e858286016130e7565b9150509250929050565b6000806040838503121561363b57600080fd5b82356001600160401b038082111561365257600080fd5b6135fb86838701612b1e565b634e487b7160e01b600052602160045260246000fd5b60208101601483106136885761368861365e565b91905290565b6000815180845260208085019450848260051b86018286016000805b86811015613700578484038a5282518460408101845b60028110156136eb5787820383526136d9828551612dbb565b938a0193928a019291506001016136c0565b509b88019b95505050918501916001016136aa565b509198975050505050505050565b60ff8516815260806020820152600061372a6080830186612dbb565b828103604084015261373c8186612dbb565b90508281036060840152613750818561368e565b979650505050505050565b6004811061376b5761376b61365e565b9052565b613779818761375b565b60a06020820152600061378f60a0830187612dbb565b82810360408401526137a18187612dbb565b905082810360608401526137b5818661368e565b905082810360808401526137c98185612dbb565b98975050505050505050565b634e487b7160e01b600052603260045260246000fd5b600083516137fd818460208801612d97565b835190830190613811818360208801612d97565b01949350505050565b634e487b7160e01b600052601160045260246000fd5b6000600182016138425761384261381a565b5060010190565b60008751602061385c8285838d01612d97565b88519184019161386f8184848d01612d97565b88519201916138818184848c01612d97565b87519201916138938184848b01612d97565b86519201916138a58184848a01612d97565b85519201916138b78184848901612d97565b919091019998505050505050505050565b600086516138da818460208b01612d97565b8651908301906138ee818360208b01612d97565b8651910190613901818360208a01612d97565b8551910190613914818360208901612d97565b8451910190613927818360208801612d97565b01979650505050505050565b6000610100613942838c61375b565b8060208401526139548184018b612dbb565b90508281036040840152613968818a612dbb565b9050828103606084015261397c8189612dbb565b905082810360808401526139908188612dbb565b905082810360a08401526139a48187612dbb565b905082810360c08401526139b8818661368e565b905082810360e08401526139cc8185612dbb565b9b9a5050505050505050505050565b600085516139ed818460208a01612d97565b855190830190613a01818360208a01612d97565b8551910190613a14818360208901612d97565b8451910190613a27818360208801612d97565b019695505050505050565b60008451613a44818460208901612d97565b845190830190613a58818360208901612d97565b8451910190613a6b818360208801612d97565b0195945050505050565b808201808211156103de576103de61381a565b60ff83168152604060208201526000612d8f6040830184612dbb565b60ff60f81b8360f81b16815260008251613ac5816001850160208701612d97565b919091016001019392505050565b60ff60f81b8460f81b16815260008351613af4816001850160208801612d97565b835190830190613b0b816001840160208801612d97565b0160010195945050505050565b60ff84168152606060208201526000613b346060830185612dbb565b9050826040830152949350505050565b818103818111156103de576103de61381a565b606081526000613b6a6060830186612dbb565b905083602083015260ff83166040830152949350505050565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b0380841680613bb357613bb3613b83565b92169190910492915050565b60ff82811682821603908111156103de576103de61381a565b6001600160401b03818116838216019080821115610f5157610f5161381a565b6001600160401b03818116838216028082169190828114613c1b57613c1b61381a565b505092915050565b600082613c3257613c32613b83565b50069056fe10ffffffffffffffffffffffffffffff0401ff010203050406071311ff01ffff07ff02ffffffffffffffffffffffffff0703ffffffffffffffffffffffffffff0405070202ff04040404ffffffffffff05070402040205050505ff04ff04ffffff010203050406070101ffffffffffff02ff050404000106060707ffffffffffa264697066735822122076594b7ea4a1b7caced4acbf626f0d779c13535d30293d52712a5bf458b1fcf964736f6c63430008110033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.