-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
236 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as Witnet from 'witnet-requests' | ||
|
||
// Retrieves USD price of a bitcoin from the BitStamp API | ||
const bitstamp = new Witnet.Source('https://www.bitstamp.net/api/ticker/') | ||
.parseJSONMap() // Parse a `Map` from the retrieved `String` | ||
.getFloat('last') // Get the `Float` value associated to the `last` key | ||
.multiply(1000) | ||
.round() | ||
|
||
// Retrieves USD price of a bitcoin from CoinDesk's "bitcoin price index" API | ||
// The JSON here is a bit more complex, thus more operators are needed | ||
const coindesk = new Witnet.Source( | ||
'https://api.coindesk.com/v1/bpi/currentprice.json', | ||
) | ||
.parseJSONMap() // Parse a `Map` from the retrieved `String` | ||
.getMap('bpi') // Get the `Map` value associated to the `bpi` key | ||
.getMap('USD') // Get the `Map` value associated to the `USD` key | ||
.getFloat('rate_float') // Get the `Float` value associated to the `rate_float` key | ||
.multiply(1000) | ||
.round() | ||
|
||
// Filters out any value that is more than 1.5 times the standard | ||
// deviationaway from the average, then computes the average mean of the | ||
// values that pass the filter. | ||
const aggregator = new Witnet.Aggregator({ | ||
filters: [[Witnet.Types.FILTERS.deviationStandard, 1.5]], | ||
reducer: Witnet.Types.REDUCERS.averageMean, | ||
}) | ||
|
||
// Filters out any value that is more than 1.5 times the standard | ||
// deviationaway from the average, then computes the average mean of the | ||
// values that pass the filter. | ||
const tally = new Witnet.Tally({ | ||
filters: [[Witnet.Types.FILTERS.deviationStandard, 1.5]], | ||
reducer: Witnet.Types.REDUCERS.averageMean, | ||
}) | ||
|
||
// This is the Witnet.Request object that needs to be exported | ||
const request = new Witnet.Request() | ||
.addSource(bitstamp) // Use source 1 | ||
.addSource(coindesk) // Use source 2 | ||
.setAggregator(aggregator) // Set the aggregator function | ||
.setTally(tally) // Set the tally function | ||
.setQuorum(100, 70) // Set witness count | ||
.setFees(10, 1) // Set economic incentives | ||
.schedule(0) // Make this request immediately solvable | ||
|
||
// Do not forget to export the request object | ||
export { request as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as Witnet from 'witnet-requests' | ||
|
||
// Retrieves USD price of eth from the BitStamp API | ||
const bitstamp = new Witnet.Source( | ||
'https://www.bitstamp.net/api/v2/ticker/ethusd/', | ||
) | ||
.parseJSONMap() // Parse a `Map` from the retrieved `String` | ||
.getFloat('last') // Get the `Float` value associated to the `last` key | ||
.multiply(1000) | ||
.round() | ||
|
||
// Retrieves USD price of eth from the coincap API | ||
const coincap = new Witnet.Source('https://api.coincap.io/v2/assets') | ||
.parseJSONMap() | ||
.getArray('data') | ||
.getMap(1) | ||
.getFloat('priceUsd') | ||
.multiply(1000) | ||
.round() | ||
|
||
// Retrieves USD price of eth from the coinpaprika API | ||
const coinpaprika = new Witnet.Source( | ||
'https://api.coinpaprika.com/v1/tickers/eth-ethereum', | ||
) | ||
.parseJSONMap() | ||
.getMap('quotes') | ||
.getMap('USD') | ||
.getFloat('price') | ||
.multiply(1000) | ||
.round() | ||
|
||
// Filters out any value that is more than 1.5 times the standard | ||
// deviationaway from the average, then computes the average mean of the | ||
// values that pass the filter. | ||
const aggregator = new Witnet.Aggregator({ | ||
filters: [[Witnet.Types.FILTERS.deviationStandard, 1.5]], | ||
reducer: Witnet.Types.REDUCERS.averageMean, | ||
}) | ||
|
||
// Filters out any value that is more than 1.0 times the standard | ||
// deviationaway from the average, then computes the average mean of the | ||
// values that pass the filter. | ||
const tally = new Witnet.Tally({ | ||
filters: [[Witnet.Types.FILTERS.deviationStandard, 1.5]], | ||
reducer: Witnet.Types.REDUCERS.averageMean, | ||
}) | ||
|
||
// This is the Witnet.Request object that needs to be exported | ||
const request = new Witnet.Request() | ||
.addSource(bitstamp) // Use source 1 | ||
.addSource(coincap) // Use source 2 | ||
.addSource(coinpaprika) // Use source 3 | ||
.setAggregator(aggregator) // Set the aggregator function | ||
.setTally(tally) // Set the tally function | ||
.setQuorum(100, 70) // Set witness count | ||
.setFees(10, 1) // Set economic incentives | ||
.schedule(0) // Make this request immediately solvable | ||
|
||
// Do not forget to export the request object | ||
export { request as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3109,6 +3109,11 @@ bignumber.js@^9.0.0: | |
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.0.tgz#805880f84a329b5eac6e7cb6f8274b6d82bdf075" | ||
integrity sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A== | ||
|
||
bignumber.js@^9.0.1: | ||
version "9.0.1" | ||
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5" | ||
integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== | ||
|
||
binary-extensions@^1.0.0: | ||
version "1.13.1" | ||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65" | ||
|
@@ -3733,6 +3738,14 @@ cbor@^4.1.5: | |
json-text-sequence "^0.1" | ||
nofilter "^1.0.3" | ||
|
||
cbor@^5.0.1: | ||
version "5.2.0" | ||
resolved "https://registry.yarnpkg.com/cbor/-/cbor-5.2.0.tgz#4cca67783ccd6de7b50ab4ed62636712f287a67c" | ||
integrity sha512-5IMhi9e1QU76ppa5/ajP1BmMWZ2FHkhAhjeVKQ/EFCgYSEaeVaoGtL7cxJskf9oCCk+XjzaIdc3IuU/dbA/o2A== | ||
dependencies: | ||
bignumber.js "^9.0.1" | ||
nofilter "^1.0.4" | ||
|
||
ccount@^1.0.0: | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/ccount/-/ccount-1.0.5.tgz#ac82a944905a65ce204eb03023157edf29425c17" | ||
|
@@ -6674,6 +6687,20 @@ functional-red-black-tree@^1.0.1: | |
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" | ||
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= | ||
|
||
generate-function@^2.0.0: | ||
version "2.3.1" | ||
resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.3.1.tgz#f069617690c10c868e73b8465746764f97c3479f" | ||
integrity sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ== | ||
dependencies: | ||
is-property "^1.0.2" | ||
|
||
generate-object-property@^1.2.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/generate-object-property/-/generate-object-property-1.2.0.tgz#9c0e1c40308ce804f4783618b937fa88f99d50d0" | ||
integrity sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA= | ||
dependencies: | ||
is-property "^1.0.0" | ||
|
||
generic-names@^2.0.1: | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/generic-names/-/generic-names-2.0.1.tgz#f8a378ead2ccaa7a34f0317b05554832ae41b872" | ||
|
@@ -8063,6 +8090,11 @@ is-promise@^2.0.0: | |
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.2.2.tgz#39ab959ccbf9a774cf079f7b40c7a26f763135f1" | ||
integrity sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ== | ||
|
||
is-property@^1.0.0, is-property@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84" | ||
integrity sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ= | ||
|
||
is-regex@^1.0.3, is-regex@^1.0.4, is-regex@^1.1.0: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.1.tgz#c6f98aacc546f6cec5468a07b7b153ab564a57b9" | ||
|
@@ -10119,7 +10151,7 @@ node-releases@^1.1.29, node-releases@^1.1.3, node-releases@^1.1.60: | |
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.61.tgz#707b0fca9ce4e11783612ba4a2fcba09047af16e" | ||
integrity sha512-DD5vebQLg8jLCOzwupn954fbIiZht05DAZs0k2u8NStSe6h9XdsuIQL8hSRKYiU8WUQRznmSDrKGbv3ObOmC7g== | ||
|
||
nofilter@^1.0.3: | ||
nofilter@^1.0.3, nofilter@^1.0.4: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/nofilter/-/nofilter-1.0.4.tgz#78d6f4b6a613e7ced8b015cec534625f7667006e" | ||
integrity sha512-N8lidFp+fCz+TD51+haYdbDGrcBWwuHX40F5+z0qkUjMJ5Tp+rdSuAkMJ9N9eoolDlEVTf6u5icM+cNKkKW2mA== | ||
|
@@ -11596,6 +11628,31 @@ proto-list@~1.2.1: | |
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" | ||
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= | ||
|
||
protocol-buffers-encodings@^1.1.0: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/protocol-buffers-encodings/-/protocol-buffers-encodings-1.1.1.tgz#f1e4a386711823137330171d2c82b49d062e75d3" | ||
integrity sha512-5aFshI9SbhtcMiDiZZu3g2tMlZeS5lhni//AGJ7V34PQLU5JA91Cva7TIs6inZhYikS3OpnUzAUuL6YtS0CyDA== | ||
dependencies: | ||
signed-varint "^2.0.1" | ||
varint "5.0.0" | ||
|
||
protocol-buffers-schema@^3.1.1: | ||
version "3.5.1" | ||
resolved "https://registry.yarnpkg.com/protocol-buffers-schema/-/protocol-buffers-schema-3.5.1.tgz#8388e768d383ac8cbea23e1280dfadb79f4122ad" | ||
integrity sha512-YVCvdhxWNDP8/nJDyXLuM+UFsuPk4+1PB7WGPVDzm3HTHbzFLxQYeW2iZpS4mmnXrQJGBzt230t/BbEb7PrQaw== | ||
|
||
protocol-buffers@^4.1.0: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/protocol-buffers/-/protocol-buffers-4.2.0.tgz#e25c64c36bf9b0c77b5546f147344d900c495001" | ||
integrity sha512-hNp56d5uuREVde7UqP+dmBkwzxrhJwYU5nL/mdivyFfkRZdgAgojkyBeU3jKo7ZHrjdSx6Q1CwUmYJI6INt20g== | ||
dependencies: | ||
generate-function "^2.0.0" | ||
generate-object-property "^1.2.0" | ||
protocol-buffers-encodings "^1.1.0" | ||
protocol-buffers-schema "^3.1.1" | ||
signed-varint "^2.0.0" | ||
varint "^5.0.0" | ||
|
||
proxy-addr@~2.0.5: | ||
version "2.0.6" | ||
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf" | ||
|
@@ -13125,6 +13182,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: | |
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" | ||
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== | ||
|
||
signed-varint@^2.0.0, signed-varint@^2.0.1: | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/signed-varint/-/signed-varint-2.0.1.tgz#50a9989da7c98c2c61dad119bc97470ef8528129" | ||
integrity sha1-UKmYnafJjCxh2tEZvJdHDvhSgSk= | ||
dependencies: | ||
varint "~5.0.0" | ||
|
||
simple-swizzle@^0.2.2: | ||
version "0.2.2" | ||
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a" | ||
|
@@ -14855,6 +14919,16 @@ validate-npm-package-license@^3.0.1: | |
spdx-correct "^3.0.0" | ||
spdx-expression-parse "^3.0.0" | ||
|
||
[email protected]: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/varint/-/varint-5.0.0.tgz#d826b89f7490732fabc0c0ed693ed475dcb29ebf" | ||
integrity sha1-2Ca4n3SQcy+rwMDtaT7Uddyynr8= | ||
|
||
varint@^5.0.0, varint@~5.0.0: | ||
version "5.0.2" | ||
resolved "https://registry.yarnpkg.com/varint/-/varint-5.0.2.tgz#5b47f8a947eb668b848e034dcfa87d0ff8a7f7a4" | ||
integrity sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow== | ||
|
||
vary@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" | ||
|
@@ -15494,6 +15568,13 @@ [email protected]: | |
prettier "^2.0.5" | ||
rosetta "^1.1.0" | ||
|
||
"witnet-requests@git+https://github.com/witnet/witnet-requests-js": | ||
version "0.3.0" | ||
resolved "git+https://github.com/witnet/witnet-requests-js#4ed30f2e3c8551b1a8a61265df7ed03e08e38e6f" | ||
dependencies: | ||
cbor "^5.0.1" | ||
protocol-buffers "^4.1.0" | ||
|
||
word-wrap@~1.2.3: | ||
version "1.2.3" | ||
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" | ||
|