События не отображаются на консоли? - PullRequest
0 голосов
/ 17 января 2020

Файл солидности Я буду вызывать update () из файла javascript, и я могу видеть запрос и обратный вызов через мост ethereum, но не могу понять, где функция не выполняется, поэтому я использую события, но они не работают

Функция обновления вызывается, но на консоли ничего не видно. В приложении. JS я пытаюсь следить за событиями, созданными

pragma solidity ^0.4.22;

import "installed_contracts/strings.sol";
import "installed_contracts/oraclize-api/contracts/usingOraclize.sol";

contract OraclizeTest is usingOraclize {

    using strings for *;        //strings import requirement
   // string public matchId; 
    uint public amount; 

//remove url traces
    address public homeBet;  
    address public awayBet;


    //string public ETHUSD;
    event LogFunctioning(string functioning);
    event LogInfo(string description);      //getting from update function
//event LogPriceUpdate(string price);     //waiting for price in callback 
    //then calling update function 
    //event LogUpdate(address indexed _owner, uint indexed _balance);     //getting from constructor 

    // Constructor
    constructor (uint _amount) public {      //adding args and not matchid
        amount = _amount;        

    //    emit LogUpdate(owner, address(this).balance); //owner was in original

        // Replace the next line with your version:
        OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);


        oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
        update();
    }
    //--------------------------------------------------------------------------------------
    function __callback(bytes32 id, string result, bytes proof) public {
   // emit LogInfo("REACHED CALLBACK");
    require(msg.sender == oraclize_cbAddress());        // just to be sure the calling address is the Oraclize authorized one
    //update();
    //string lib being used to compare
    makePayment(result);
    //ETHUSD = result;
    // emit LogPriceUpdate(ETHUSD);    //emit callback price console print 
    // update();
    }

    function makePayment(string result) public {
        if (result.toSlice().equals("home".toSlice()))
    {
        homeBet.transfer(address(this).balance);
    }
    else if(result.toSlice().equals("away".toSlice()))
    {
        awayBet.transfer(address(this).balance);
    }
    else if(result.toSlice().equals("draw".toSlice()))
    {
        homeBet.transfer(address(this).balance / 2);
        awayBet.transfer(address(this).balance / 2);
    }

    }

    function update()
    payable
    public {
        // Check if we have enough remaining funds
        if (oraclize_getPrice("URL") > address(this).balance) {
           emit LogInfo("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
        } else {
           emit LogInfo("Oraclize query was sent, standing by for the answer..");
           emit LogFunctioning("GAYI---------------------------------");
            // Using XPath to to fetch the right element in the JSON response
            oraclize_query("URL", "json(https://api.crowdscores.com/v1/matches/123945?api_key=93c4c515196741beaf5e4528b64ea511).outcome.winner");

        }
    }

}

Приложение. js

window.App = {

  // 'Constructor'
  start: function() {


    // Bootstrap the Contract abstraction for use with the current web3 instance
    OraclizeContract.setProvider(web3.currentProvider);

    // Get the initial account balance so it can be displayed.
    web3.eth.getAccounts(async function(err, accs) {

      if (err != null) {
        alert("There was an error fetching your accounts.");
        return;
      }

      if (accs.length == 0) {
        alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
        return;
      }

      accounts = accs;
      web3.eth.defaultAccount = accounts[0];
      account = accounts[0];


    });
  },

   addEventListeners: function(instance){
    var LogInfo = instance.LogInfo({},{fromBlock: 0, toBlock: 'latest'});
      var LogFunctioning = instance.LogFunctioning({},{fromBlock: 0, toBlock: 'latest'});

      LogFunctioning.watch(function(err, result){
      if(!err){
        console.info(result.args)
      }else{
        console.error(err)
      }
    })

    LogInfo.watch(function(err, results){
      if(!err){
        console.info(results.args)
      }else{
        console.error(err)
      }
    });

}
`````````````````````````````
OraclizeContract.deployed().then(function(instance) {

                          console.log("Initializing");
                          instance.update({from: fromAddress1, to: fromAddress2, gas: 3000000, value: web3.toWei(betAmount, 'ether')})
                               .then(function(v){
                                       console.log(v);
                                       console.log("Function Executed");
                                     //  return queryRecheck(instance);
                                 }).then(function(events) {
                                       console.log(events);
                                 });
                       }).then(function() {
                                              console.log("Testing");
                       }).catch(function(e) {
                                               console.log(e);
                       });
...