Skip to content

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Jul 7, 2015
1 parent 368b1b5 commit 84a3d93
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion example/balance.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';

web3.eth.filter('pending').watch(function() {
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);
Expand Down
33 changes: 19 additions & 14 deletions example/contract.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@
var watch = web3.eth.filter('latest');

// create contract
myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);

if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error('contract creation failed!');
return;
}
});
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);

if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
});
}

function callExampleContract() {
Expand Down
33 changes: 19 additions & 14 deletions example/contract_array.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@
var watch = web3.eth.filter('latest');

// create contract
myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);

if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error('contract creation failed!');
return;
}
});
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);

if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
});
}

function callExampleContract() {
Expand Down
29 changes: 13 additions & 16 deletions example/event_inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,24 @@

var watch = web3.eth.filter('latest');

contract = web3.eth.contract(abi).new({data: code});

console.log('address: ' + contract.address);

document.getElementById('create').style.visibility = 'hidden';
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);

if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
web3.eth.contract(abi).new({data: code}, function (err, c) {
if (err) {
console.error('contract creation failed!');
return;
}
});

inc = contract.Incremented({odd: true});
inc.watch(update);
contract = c;

console.log('address: ' + contract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';

inc = contract.Incremented({odd: true});
inc.watch(update);
});
};

var counter = 0;
Expand Down

0 comments on commit 84a3d93

Please sign in to comment.