Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation errors rad2sol #90

Open
YokiToki opened this issue Aug 9, 2024 · 0 comments
Open

Compilation errors rad2sol #90

YokiToki opened this issue Aug 9, 2024 · 0 comments

Comments

@YokiToki
Copy link

YokiToki commented Aug 9, 2024

I got errors when trying to compile the query script

witnet/EthPrice.js content:

import * as Witnet from "witnet-requests"

const binance = new Witnet.Source("https://api.binance.US/api/v3/trades?symbol=ETHUSD")
  .parseJSONMap()
  .getFloat("price")
  .multiply(10 ** 6)
  .round()

const coinbase = new Witnet.Source("https://api.coinbase.com/v2/exchange-rates?currency=ETH")
  .parseJSONMap()
  .getMap("data")
  .getMap("rates")
  .getFloat("USD")
  .multiply(10 ** 6)
  .round()

const kraken = new Witnet.Source("https://api.kraken.com/0/public/Ticker?pair=ETHUSD")
  .parseJSONMap()
  .getMap("result")
  .getMap("XETHZUSD")
  .getArray("a")
  .getFloat(0)
  .multiply(10 ** 6)
  .round()

const aggregator = Witnet.Aggregator.deviationAndMean(1.5)
const tally = Witnet.Tally.deviationAndMean(2.5)

const query = new Witnet.Query()
  .addSource(binance)
  .addSource(coinbase)
  .addSource(kraken)
  .setAggregator(aggregator) // Set the aggregator function
  .setTally(tally) // Set the tally function
  .setQuorum(10, 51) // Set witness count and minimum consensus percentage
  .setFees(5 * 10 ** 9, 10 ** 9) // Witnessing nodes will be rewarded 5 $WIT each
  .setCollateral(50 * 10 ** 9) // Require each witness node to stake 50 $WIT

// Do not forget to export the query object
export { query as default }

Here is output

/Users/user/.nvm/versions/node/v18.20.0/bin/yarn run witnet:compile
yarn run v1.22.22
$ rad2sol --verbose --write-contracts

Compiling your Witnet queries...
=================================
> Compiling /Users/user/IdeaProjects/DWFG/contract/witnet/EthPrice.js

! WITNET REQUESTS COMPILATION ERRORS:
- Cannot read properties of undefined (reading 'dataPointType')
/Users/user/IdeaProjects/DWFG/contract/node_modules/witnet-requests/dist/lib/rad2sol/steps.js:127
    console.log("  - The result type of the query is \x1B[36m".concat(Witnet.Types.typeFormat(query.dataPointType), "\x1B[0m"));
                                                                                                    ^

TypeError: Cannot read properties of undefined (reading 'dataPointType')
    at execute (/Users/user/IdeaProjects/DWFG/contract/node_modules/witnet-requests/dist/lib/rad2sol/steps.js:127:101)
    at /Users/user/IdeaProjects/DWFG/contract/node_modules/witnet-requests/dist/lib/rad2sol/scripts.js:30:31
    at /Users/user/IdeaProjects/DWFG/contract/node_modules/witnet-requests/dist/bin/rad2sol.js:60:14
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)

Node.js v18.20.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 1

I try to debug and see vm.runInContext(code, context, __dirname) returns undefined in steps.js:126
https://github.com/witnet/witnet-requests-js/blob/0.9.12/src/lib/rad2sol/steps.js#L107-L108

    var query = vm.runInContext(code, context, __dirname);
    console.log("  - The result type of the query is \x1B[36m".concat(Witnet.Types.typeFormat(query.dataPointType), "\x1B[0m"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant