Skip to content

Latest commit

 

History

History
111 lines (64 loc) · 14.1 KB

witnetrequesttemplate.md

File metadata and controls

111 lines (64 loc) · 14.1 KB
layout
title description tableOfContents outline pagination
visible
true
visible
visible
true
visible
true
visible
true

📃 WitnetRequestTemplate

Built from the WitnetRequestFactory, contracts of this kind contain references to one or more parameterized data sources (i.e. Radon Retrievals). Concrete parameters can be provided on-the-fly from a smart contract, producing WitnetRequest instances.

{% hint style="success" %} Did you know?

WitnetRequestTemplate addresses are counter-factual to the data sources (i.e. Radon Retrievals) they rely on.

Meaning that if you try to build a WitnetRequestTemplate with exactly the same sources as someone else did in the past, you will get exactly the same address. The underlying minimal-proxy contract would get constructed only once, of course. Building an already built request template works, and it requires less gas than building it for the first time. {% endhint %}

Interfaces

{% hint style="info" %} ^ Pure methods that neither write nor read from storage.

= View methods that read from immutable code storage.

:: View methods that read from storage.

+ Methods that may potentially alter storage.

$ Payable methods that may potentially alter storage.

[]! Methods that may revert under certain conditions. {% endhint %}

IWitnetRequestFactoryAppliance

MethodsDescription
= class(): stringReturns the name of the contract that's actually implementing the ABI's specs() logic.
= factory(): WitnetRequestFactoryAddress of the WitnetRequestFactory contract from which this template was created.
= specs(): bytes4Returns the immutable ERC-165 id of the expected functionality as for the WitnetRequestTemplate ABI.
= witnet(): WitnetOracleAddress of the WitnetOracle contract that WitnetRequest instances created by this template will be compliant with.

IWitnetRequestTemplate

MethodsDescription
:: getArgsCount():uint256[]Returns an array of integers telling the number of parameters required by every single data source (i.e. Radon Retrievals) that compose this WitnetRequestTemplate. The length of the returned array tells the number of data sources that compose this instance.
:: getResultDataType():RadonDataTypesReturns the expected data type produced by successful resolutions of any WitnetRequest that gets built out of this WitnetRequestTemplate.
:: getAggregateReducer():RadonReducerReturns the filters and reducing function to be applied by witnessing nodes on the Witnet blockchain when aggregating data extracted from the public data sources (i.e. Radon Retrievals) of the data requests that get eventually built out of this WitnetRequestTemplate.
:! getRetrievalByIndex(uint256):RRet.Returns metadata concerning the data source specified by the given index.
:: getRetrievals():RadonRetrievals[]Returns the array of one or more parameterized data sources that compose this WitnetRequestTemplate.
:: getTallyReducer():RadonReducerReturns the slashing filters and reducing function to be applied to the values revealed by the witnessing nodes on the Witnet blockchain that contribute to solve data requests built out of this WitnetRequestTemplate.
+! buildWitnetRequest(string[][]):addr

Build a WitnetRequest instance that will provide the bytecode and RAD hash of some Witnet-compliant Radon Request, provably made out of the data sources, aggregate and tally Radon Reducers that compose this WitnetRequestTemplate.

Produced addresses are counter-factual to the given values.

Reverts if the ranks of passed array don't match either the number of this template's data sources, or the number of required parameters by each one of those.

+! verifyRadonRequest(string[][]):b32

Verifies into the WitnetRadonRegistry bound to the witnet() contract the actual bytecode and RAD hash of the Witnet-compliant Radon Request that gets provably made out of the data sources, aggregate and tally Radon Reducers that compose this WitnetRequestTemplate.

While no WitnetRequest instance is actually constructed, the returned bytes32 value will be accepted as a valid RAD hash on the witnet() contract from now on.

Reverts if the ranks of passed array don't match either the number of this template's data sources, or the number of required parameters by each one of those.

This method requires less gas than buildWitnetRequest(string[][]), and it's usually preferred when parameterized data requests made out of this template are intended to be used just once in lifetime.

:: version()If built out of an upgradable factory, returns the SemVer tag of the factory implementation at the time when this WitnetRequestTemplate got built.

Events

IWitnetRadonRegistryEvents

EventsArgumentsDescription
NewRadonRequestbytes32 radHashEmitted every time a new Witnet.RadonRequest gets successfully verified and stored into the WitnetRadonRegistry.

IWitnetRequestFactoryEvents

EventsArgumentsDescription
WitnetRequestBuiltaddress requestEmitted every time a new counter-factual WitnetRequest gets verified or built out of this template.

Structs

Witnet.RadonFilter

Struct defining the data filtering to be applied at either the Aggregate or Tally stages within the resolution of a data request within the Witnet blockchain.

FieldTypeDescription
opcodeWitnet.RadonFilterOpcodesFiltering function.
cborArgsbytesCBOR-encoded array of filter parameters. Empty if no parameters are to be specified.

Witnet.RadonReducer

Struct defining the array of filters, if any, and reduce function to be applied at either the Aggregate or Tally stages within the resolution of a data request within the Witnet blockchain.

FieldTypeDescription
opcodeWitnet.RadonReducerOpcodesReducing function.
filtersWitnet.RadonFilter[]Zero, one or more filters to be orderly applied to input dataset before actually executing the reduce function.

Witnet.RadonRequest

Struct containing the Retrieve-Attestation-Delivery parts of a Witnet-compliant Data Request Object.

FieldTypeDescription
retrieveWitnet.RadonRetrieval[]One or more public data sources (i.e. Radon Retrievals) out from where data will be retrieved by all witnessing nodes in the Witnet-blockchain attending the resolution of this data request.
aggregateWitnet.RadonReducerFiltering and reduce operations that will executed by every single witnessing node as to aggregate the data extracted from the request's data sources.
tallyWitnet.RadonReducerFiltering and reduce operations that will be applied to the aggregated data revealed by each witnessing node. Witnessing nodes revealing data that gets ultimately filtered out, will get slashed.

Witnet.RadonRetrieval

Struct containing all parameters that fully describe the Radon Retrievals that can form part of Witnet-compliant Data Request Objects.

FieldTypeDescription
argsCountuint8Number of indexed parameters to be provided whenever this Radon Retrieval is to be included into a Radon Request.
methodWitnet.RadonRetrievalMethodsImmutable method to be used for retrieving data.
dataTypeWitnet.RadonDataTypesDeterministic data type that successful executions will return.
urlstringRequest URL. Mandatory on HttpGet, HttpPost and HttpHead retrieving methods.
bodystringRequest body. Optional on HttpGet and HttpPost retrieving methods.
headersstring[2][]Request key/value headers. Optional on HttpGet and HttpPost retrieving methods.
radonScriptbytesOptional CBOR-encoded Radon Script that will transform whatever value is returned from the source. Not supported on RNG retrievals.

Enums

Witnet.RadonDataTypes

Primitive data types that can be contained in successful results to Witnet data requests.

HexCaptionDescription
0x00AnyCBOR-encoded value of undetermined type.
0x01ArrayAn array of CBOR values.
0x02BoolA CBOR-encoded boolean value.
0x03BytesA CBOR-encoded bytes buffer.
0x04IntegerA CBOR-encoded integer value.
0x05FloatA CBOR-encoded float value.
0x06MapA key/value map of CBOR values.
0x07StringA CBOR-encoded string value.

Witnet.RadonFilterOpcodes

Dataset filtering methods currently supported on the Witnet blockchain.

HexCaptionDescription
0x05StandardDeviationFilters out all input items that deviates from the average more than a threshold. Requires a CBOR-encoded float as single but mandatory filter parameter. Works only with arrays of numbers (integers or floats) as input datasets.
0x08ModeFilters out all input items that diverge from the mode.

Witnet.RadonReducerOpcodes

Reducing functions currently supported on the Witnet blockchain.

HexCaptionDescription
0x02ModeReturns the mode value from the input dataset.
0x03AverageMeanReturns the average mean from the input dataset. Works only with arrays of numbers as input datasets.
0x05AverageMedianReturns the median from the input dataset. Works only with arrays of numbers as input datasets.
0x07StandardDeviationReturns the standard deviation calculated out from the input dataset. Works only with arrays of numbers as input datasets.
0x0BConcatenateAndHashReturns the SHA-256 hash of the concatenation of the input buffers. Works only with arrays of buffers as input datasets. Used mainly on RNG requests for mixing randomness produced by independent and randomly selected witnessing nodes.

Witnet.RadonRetrievalMethods

Possible data request methods that can be specified on a Radon Retrieval.

HexCaptionDescription
0x01HttpGetData shall be retrieved from HTTP-GET requests.
0x02RNGRandom seeds shall be independently produced by the witnessing nodes themselves, out of their respective VRF-eligibility proofs.
0x03HttpPostData shall be retrieved from HTTP-POST requests.
0x04HttpHeadData shall be retrieved from HTTP-HEAD requests.