6

I'm using oraclize to get the price feed using this code:

import "oraclizeAPI.sol";

contract PriceFeed is usingOraclize{
  uint public BTCUSD;

  function PriceFeed(){
    oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
    update(0); // first check at contract creation
  }

  function __callback(bytes32 myid, string result, bytes proof) {
    if (msg.sender != oraclize_cbAddress()) throw;
    BTCUSD = parseInt(result, 2); // save it as $ cents
    // The following line is what I do which ends up with the error message
   //MyContract.BTCUSD = BTCUSD;

    update(360); // schedule another check in 60 seconds
  }

  function update(uint delay){
    oraclize_query(delay, "URL",
      "json(https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD).USD");
  }
}

Now I have the second contract in the same file that has a variable called BTCUSD. I need to update that variable when I get callback from oraclize. I've tried multiple methods, writing a setter/getter method on both contracts, using MyContract.BTCUSD = BTCUSD style assignments but I get errors.

contract MyContract {
  uint public BTCUSD;
}

I'm using linter on atom and these are the errors I get depending on how I try to assign the value:

Member "BTCUSD" not found or not visible after argument-dependent lookup in type(contract MyContract)

eth
  • 85,679
  • 53
  • 285
  • 406
Shayan
  • 895
  • 2
  • 8
  • 24
  • It seems like using the following would resolve linter errors but still fails to compile

    contract PriceFeed is usingOraclize, Options {

    – Shayan Jun 29 '16 at 22:20
  • 2
    Your "MyContract" could use Oraclize straight away, what is the need to have two contracts? Btw calling an external contract method, to set a value for example, works in a different way: MyContractInterface(mycontract_address).setterMethodforBTCUSD(BTCUSD). My suggestion is still to use Oraclize straight away from MyContract, unless you really need to keep the two contracts separated. – Thomas Bertani Jun 30 '16 at 00:01

1 Answers1

5

As @Thomas Bertani mentions in the comment, Oraclize can be used directly in MyContract. If you need to use 2 contracts, expanding on his comment, then you need to create a setter, and invoke the setter on a specific instance of MyContract. Example:

contract MyContract {
  uint public BTCUSD;

  function set(uint val) {
      BTCUSD = val;
  }
}

contract PriceFeed {
    function setVal(address addr) {
        MyContract(addr).set(2);
    }
}
eth
  • 85,679
  • 53
  • 285
  • 406