ethereum / aleth

Aleth – Ethereum C++ client, tools and libraries
GNU General Public License v3.0
3.96k stars 2.17k forks source link

events not working #929

Closed debris closed 9 years ago

debris commented 9 years ago

i'm having an issue with events. When I run following contract inside mix IDE everything is working, but when I run this example with ethereum headless client (eth -j -b), I do get only 1 callback in update function (just after starting watch).

code snippets:

contract Contract {
    event Incremented(bool indexed odd, uint x);
    function Contract() {
        x = 69;
    }
    function inc() {
        ++x;
        Incremented(x % 2 == 0, x);
    }
    uint x;
}
<html>
<head>
<script>
    var web3 = parent.web3;
    var contract = parent.contract;
    var interface = parent.contractInterface;
    console.log(JSON.stringify(interface));

    contract.Incremented({odd: true}).changed(function (res) {
        console.log(JSON.stringify(res));
    });

    var callContract = function() {
        contract.inc();
    };
</script>
</head>
<body>
    <div>
        <button type="button" onClick="callContract()">inc!</button>
    </div>
    <div id="x"></div>
</body>
</html>
chriseth commented 9 years ago

The Solidity implementation uses sha3("Incremented(bool,uint256)") as event signature. Might that be a misalignment? Also I see that "signatureFromAscii" removes the two first characters while "eventSignatureFromAscii" does not.

gavofyork commented 9 years ago

Works fine in AZ.

Please try following code:

<html>
<head>
<script>
    var Contract = web3.eth.contractFromAbi([{"constant":true,"inputs":[],"name":"x","outputs":[{"name":"x","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"inc","outputs":[],"type":"function"},{"inputs":[{"indexed":true,"name":"odd","type":"bool"},{"indexed":false,"name":"x","type":"uint256"}],"name":"Incremented","type":"event"}]);
    var contract = Contract("0x8a62a76a62d4da0cc242134e896f1086962bbe23");
</script>
</head>
<body>
    <div>
        <button type="button" onClick="contract.inc()">inc!</button>
    </div>
    <div id="x"></div>
    <script>
        contract.Incremented({odd: true}).changed(function (res) {
            console.log(JSON.stringify(res));
            document.getElementById('x').innerHTML = contract.x();
        });
    </script>
</body>
</html>

and

contract Contract {
    event Incremented(bool indexed odd, uint x);
    function Contract() {
        x = 69;
    }
    function inc() {
        ++x;
        Incremented(x % 2 == 0, x);
    }
    uint x;
}

but replace the HTML's 0x8a62...be23 with the address of the created contract.

gavofyork commented 9 years ago

@debris please check this is working and if so, close.

gavofyork commented 9 years ago

Works for me in AZ. @debris please check CLI and close if good.