-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (71 loc) · 4.63 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!doctype>
<html>
<head>
<script type="text/javascript" src="../node_modules/bignumber.js/bignumber.min.js"></script>
<script type="text/javascript" src="../dist/web3-light.js"></script>
<script type="text/javascript">
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider());
function watchBalance() {
var coinbase = web3.eth.coinbase;
var originalBalance = web3.eth.getBalance(coinbase).toNumber();
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';
web3.eth.filter('latest').watch(function() {
var currentBalance = web3.eth.getBalance(coinbase).toNumber();
document.getElementById("current").innerText = 'current: ' + currentBalance;
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
});
}
function mineAudit() {
// TODO migrate to chess repo
document.getElementById('log').innerText = 'log - mine audit started';
//I branch - for some reason abi is not showed. The compilator is there as - when a code with errors is submitted a compilation error is shown in the mist log.
//also the same code works in mist console. Actually, the abi in the second branch is from there.
//address = 0xDaCE34b2B90675cc49be43cAD6aa465f2e98B150
//block #0x034cf42de9b5a0768e0174cea5befd8a3cc1706d45019c1742113db085c1fd64
//tx 0x32a8b75162fb210f88a437df1e8842dd3608392138dbf8c513eb915a546ef8d7
//var source = "pragma solidity ^0.4.2; contract FireEvent { event AddMsg(address indexed sender, bytes32 msg); function makeEvent() { AddMsg(msg.sender, \"Short message\");} }"
//var compiled = web3.eth.compile.solidity(source);
//var abi = compiled.FireEvent.info.abiDefinition;
//var str = JSON.stringify(abi, null, 2);
//document.getElementById('log').innerText = 'log: ' + str;
//II branch working version - works with 221175 where is the actual transaction is in 221174. with 'latest' doesnt work, probably testnet latency problem
//Also the same code executed in console find 2 events. The second one is in block 209902. No explanation for that so far ...
var address = "0xdace34b2b90675cc49be43cad6aa465f2e98b150";
var abi_string = "[{ \"constant\": false, \"inputs\": [], \"name\": \"makeEvent\", \"outputs\": [], \"payable\": false, \"type\": \"function\" }, { \"anonymous\": false, \"inputs\": [ { \"indexed\": true, \"name\": \"sender\", \"type\": \"address\" }, { \"indexed\": false, \"name\": \"msg\", \"type\": \"bytes32\" } ], \"name\": \"AddMsg\", \"type\": \"event\" }]";
var abi = JSON.parse(abi_string);
var MyContract = web3.eth.contract(abi);
var contractInstance = MyContract.at(address);
var event = contractInstance.AddMsg( {}, {fromBlock: 0, toBlock: 221175},
function(error, result) {
if (!error) {
document.getElementById('log_events').innerText = 'log_events: saw event' + JSON.stringify(result); //parse later the content of result
}
} );
//for console-
//event = contractInstance.AddMsg( {},{fromBlock: 0, toBlock: 'latest'}, function(error, result) {if (!error) { console.log('log_events: saw event');}} );
//branch III - why to use event instead of filter ? to investigate. Probably one is faster then another.
//if toBlock is put to "latest" also doesnt work.
//filter = web3.eth.filter({fromBlock: 0, toBlock: 221175, address: '0xdace34b2b90675cc49be43cad6aa465f2e98b150', topics:['0x'+web3.sha3('AddMsg(address,bytes32)')]});
//filter.watch(function(error, result) {if(!error) console.log("saw event");})
//here I used get. TODO difference between get and watch
//filter.get(function(error, result) { if(!error) console.log(JSON.stringify(result));})
}
</script>
</head>
<body>
<h1>mine audit event29</h1>
<button type="button" onClick="mineAudit();">mine audit</button>
<div id="log"></div>
<div id="log_events"></div>
<h1>coinbase balance</h1>
<button type="button" onClick="watchBalance();">watch balance</button>
<div></div>
<div id="coinbase"></div>
<div id="original"></div>
<div id="current"></div>
<div id="diff"></div>
</body>
</html>