Declaring contract for remote call giving error of definition of function

Hello Everyone

I am trying to call a contract remotely and for that I am trying o declare that contract methods like:

contract OracleConnector =
    payable entrypoint query: (string) => bytes(32)

But I am receiving this error on compilation:

  response: {
    ok: false,
    url: 'https://latest.compiler.aepps.com/compile',
    status: 400,
    statusText: 'Bad Request',
    headers: {
      connection: 'close',
      'content-length': '107',
      'content-type': 'application/json',
      date: [Array],
      server: 'Cowboy'
    },
    text: `[{"message":"Missing definition of function 'getAnswer'.\\n","pos":{"col":16,"line":4},"type":"code_error"}]`,
    data: `[{"message":"Missing definition of function 'getAnswer'.\\n","pos":{"col":16,"line":4},"type":"code_error"}]`,
    body: [ [Object] ],
    obj: [ [Object] ]
  }
2 Likes

can you share the whole example?

Sure

include "String.aes"

contract OracleConnector =
    entrypoint getAnswer : (bytes(32)) => option(string)
    payable entrypoint query : (string) => bytes(32)
    entrypoint canCallBack: () => bool
    entrypoint getBaseFee: () => int

contract OraclesManager =
    entrypoint getAddress : (string) => address
    entrypoint setContractOracle : (string) => bool
    entrypoint getContractOracle : (address) => string
    entrypoint getListOfOracles : () => list(string)

namespace Say =

    record setup = {
        oracle_address: OraclesManager,
        oracle_connector: OracleConnector
      }
    // Must run this to select oracle at init
    public function setOracle(oracle_id: string) : bool =
        let _oracle_address : OraclesManager = ct_fy4zj9srmKorX8F1jeWRog9KVx41ycciWToqn42J5r5Qs4d9K
        _oracle_address.setContractOracle(oracle_id)
    
    public function getOracleId() : string =
        let _oracle_address : OraclesManager = ct_fy4zj9srmKorX8F1jeWRog9KVx41ycciWToqn42J5r5Qs4d9K
        _oracle_address.getContractOracle(Call.caller)

    public function set() : setup =
        let _oracle_address : OraclesManager = ct_fy4zj9srmKorX8F1jeWRog9KVx41ycciWToqn42J5r5Qs4d9K
        let _oracle_connector : OracleConnector = Address.to_contract(_oracle_address.getAddress(getOracleId()))
        
        {oracle_address = _oracle_address, oracle_connector = _oracle_connector}
    
    public function getOracleAddress() : address =
        set().oracle_address.getAddress(getOracleId())

    public function canCallBack() : bool =
        set().oracle_connector.canCallBack()
    
    public function getBaseFee() : int =
        set().oracle_connector.getBaseFee()

    public function getAnswer(query_id: bytes(32)) : option(string) =
        set().oracle_connector.getAnswer(query_id)

    stateful function query(args: string, value_received: int) : bytes(32) =
        set().oracle_connector.query(args, value = value_received)

    public function availableOracles() : list(string) =
        set().oracle_address.getListOfOracles()


main contract MyContract =
    record state = {
      query_id : bytes(32),
      answer: option(string)
     }

    stateful entrypoint init() = 
     Say.setOracle("oracle_plain")
     {query_id = #000000000000000000000000000000000000000000000000000000000000000,
      answer = None}
    public entrypoint plus() : address =
      Say.getOracleAddress()

    payable stateful entrypoint query(args: string) : bytes(32) =
      require(Say.getBaseFee() =< Call.value, "Insufficient fee")
      let _id : bytes(32) = Say.query(args, Call.value)
      put(state{query_id=_id})
      _id
    
    stateful entrypoint getAnswer() : option(string) =
      Say.getAnswer(state.query_id)

    stateful entrypoint useAnswer() : option(string) =
      put(state{answer = Say.getAnswer(state.query_id)})
      state.answer





interface contract?

1 Like

Thanks @hanssv.chain you always know where the problem is :slight_smile:

3 Likes