witnet / witnet-requests-js

Witnet Requests Javascript Library
MIT License
5 stars 11 forks source link

WitnetRequestInitializableBase.initialize(hex"undefined") when using rad2sol #83

Closed jiguantong closed 1 year ago

jiguantong commented 1 year ago

EthPrice.js

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 }

npx rad2sol --write-contracts EthPrice.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

// For the Witnet Request Board OVM-compatible (Optimism) "trustable" implementation (e.g. BOBA network),
// replace the next import line with:
// import "witnet-solidity-bridge/contracts/impls/trustable/WitnetRequestBoardTrustableBoba.sol";
import "witnet-solidity-bridge/contracts/impls/trustable/WitnetRequestBoardTrustableDefault.sol";
import "witnet-solidity-bridge/contracts/requests/WitnetRequestInitializableBase.sol";

// The bytecode of the EthPrice query that will be sent to Witnet
contract EthPriceRequest is WitnetRequestInitializableBase {
  function initialize() public {
    WitnetRequestInitializableBase.initialize(hex"undefined");
  }
}
aesedepece commented 1 year ago

Hi @jiguantong thanks for reporting! I'm trying to reproduce this error and will keep you posted of any findings. Stay tuned!

drcpu-github commented 1 year ago

This is a known bug and is because the tutorials contain an outdated command. See this Discord post and context around it. There are probably multiple workarounds, but the one I suggested where you run the other command and simply copy the bytecode into the contract worked for me.

aesedepece commented 1 year ago

This is a known bug and is because the tutorials contain an outdated command. See this Discord post and context around it. There are probably multiple workarounds, but the one I suggested where you run the other command and simply copy the bytecode into the contract worked for me.

I wasn't aware of this bug.

aesedepece commented 1 year ago

Solved in version 0.9.10 which will be live on npm in a few minutes. @jiguantong kindly confirm that it works on your side by upgrading the package version and retrying.

jiguantong commented 1 year ago

Solved in version 0.9.10 which will be live on npm in a few minutes. @jiguantong kindly confirm that it works on your side by upgrading the package version and retrying.

Thanks, I will try it tomorrow.