Browse Source
d5d2115 example contract using array, fixed #185 21ed235 removed connection keep-alive c44fe01 version 0.7.1 d9b785e fixed #248 490dde5 fixed encoding/decoding strings, #249 b3f5d09 fixed long bytes dynamic decoding/encoding, #249 d097821 small filter improvement d59b1cd removed xhr from browser 42b6e9d version 0.7.0 fe6defd gulp 44dcd24 set connection keepalive 2b17c0f gulpfile changes 4a46c73 Merge pull request #228 from ethereum/strings 93c8006 tests for encoding and decoding prematurely terminated strings and strings containing internal zeros 7dd44e7 Merge branch 'strings' of https://github.com/ethereum/ethereum.js into strings 390a9ff Merge branch 'develop' into strings bcd9cfb updated deps, removed unused karma ef15fc1 Merge pull request #244 from ethereum/allevents 6f74d57 Merge branch 'develop' into allevents 7aca17e Merge branch 'develop' into allevents c5ee34d fix for optional event parameters 8170a0a Merge pull request #245 from ethereum/filterInstantWatch 76a094c fixed all issues noted by marek d78b512 add possible callback to filters e1b17a9 re-build develop af9c027 all events filter b270616 version 0.6.1 c47d6a8 gulp 7cf7cf3 map file 6da1d3e gulp 450042e Update eth.js 3951286 Added sendRawTransaction 323b529 merged develop 16ffdf6 merged master ecf0a2c changed | to Math.floor d2b5ba2 Merge pull request #239 from ethereum/mistFixes 9e6bf9d removed browser XHR 9061116 fixed build issues in formatInputDynamicBytes 0e3b29c fixed coverage issue d51e9a2 merged latest develop f0247aa made meteor package available on the server side as well e97c5f5 fixed and tested meteor package init 3e49f56 add currentProvidor and mist fixes bd6d9ba merged develop 7b730b1 Merge branch 'strings' of github.com:ethereum/web3.js into strings cc533d9 fixed bytes wrong encoding 8c6f976 Merge branch 'develop' into strings 7c970e3 add bytes32 test with leading 0 9c7f7bb re-add .map files 189484f add extra int tests 73cc711 Merge branch 'develop' into strings fa3239f abi string type, fixes #216, #218, #219 git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: d5d2115bf9ad07a736a189e1022b7d3a549e4006cl-refactor
Marek Kotewicz
10 years ago
32 changed files with 1179 additions and 389 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,83 @@ |
|||
<!doctype> |
|||
<html> |
|||
|
|||
<head> |
|||
<script type="text/javascript" src="../dist/web3.js"></script> |
|||
<script type="text/javascript"> |
|||
|
|||
var web3 = require('web3'); |
|||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); |
|||
|
|||
// solidity code code |
|||
var source = "" + |
|||
"contract test {\n" + |
|||
" function take(uint[] a, uint b) constant returns(uint d) {\n" + |
|||
" return a[b];\n" + |
|||
" }\n" + |
|||
"}\n"; |
|||
|
|||
var compiled = web3.eth.compile.solidity(source); |
|||
var code = compiled.test.code; |
|||
// contract json abi, this is autogenerated using solc CLI |
|||
var abi = compiled.test.info.abiDefinition; |
|||
|
|||
var myContract; |
|||
|
|||
function createExampleContract() { |
|||
// hide create button |
|||
document.getElementById('create').style.visibility = 'hidden'; |
|||
document.getElementById('code').innerText = code; |
|||
|
|||
// let's assume that coinbase is our account |
|||
web3.eth.defaultAccount = web3.eth.coinbase; |
|||
|
|||
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'; |
|||
} |
|||
}); |
|||
|
|||
} |
|||
|
|||
function callExampleContract() { |
|||
// this should be generated by ethereum |
|||
var param = parseInt(document.getElementById('value').value); |
|||
|
|||
// call the contract |
|||
var res = myContract.take([0,6,5,2,1,5,6], param); |
|||
document.getElementById('result').innerText = res.toString(10); |
|||
} |
|||
|
|||
</script> |
|||
</head> |
|||
<body> |
|||
<h1>contract</h1> |
|||
<div id="code"></div> |
|||
<div id="status"></div> |
|||
<div id='create'> |
|||
<button type="button" onClick="createExampleContract();">create example contract</button> |
|||
</div> |
|||
<div id='call' style='visibility: hidden;'> |
|||
<div>var array = [0,6,5,2,1,5,6];</div> |
|||
<div>var x = array[ |
|||
<input type="number" id="value" onkeyup='callExampleContract()'></input> |
|||
]; |
|||
</div> |
|||
</div> |
|||
<div id="result"></div> |
|||
</body> |
|||
</html> |
|||
|
@ -1,95 +0,0 @@ |
|||
// Karma configuration
|
|||
// Generated on Thu Feb 19 2015 19:57:47 GMT+0100 (W. Europe Standard Time)
|
|||
|
|||
module.exports = function (config) { |
|||
config.set({ |
|||
|
|||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|||
basePath: '', |
|||
|
|||
// level of logging
|
|||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|||
|
|||
// Continuous Integration mode
|
|||
// if true, Karma captures browsers, runs the tests and exits
|
|||
singleRun: true, logLevel: config.LOG_INFO, |
|||
//singleRun: true, logLevel: config.LOG_DEBUG,
|
|||
|
|||
// frameworks to use
|
|||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|||
frameworks: ['browserify', 'mocha'], |
|||
|
|||
|
|||
// list of files / patterns to load in the browser
|
|||
files: [ |
|||
'test/*.js' |
|||
], |
|||
|
|||
|
|||
// list of files to exclude
|
|||
exclude: [ |
|||
], |
|||
|
|||
client: { |
|||
mocha: { |
|||
//ui: 'tdd'
|
|||
timeout: 5000 // especially for the post requests
|
|||
} |
|||
}, |
|||
browserify: { |
|||
bundleDelay: 750, |
|||
debug: true |
|||
// transform: [],
|
|||
// //extensions: ['.js']
|
|||
}, |
|||
|
|||
// preprocess matching files before serving them to the browser
|
|||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|||
preprocessors: { |
|||
'test/*.js': ['browserify'] |
|||
}, |
|||
|
|||
|
|||
// test results reporter to use
|
|||
// possible values: 'dots', 'progress'
|
|||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|||
reporters: ['dots'], |
|||
|
|||
|
|||
// web server port
|
|||
port: 9876, |
|||
|
|||
|
|||
// enable / disable colors in the output (reporters and logs)
|
|||
colors: true, |
|||
|
|||
|
|||
// enable / disable watching file and executing tests whenever any file changes
|
|||
autoWatch: true, |
|||
|
|||
|
|||
// start these browsers
|
|||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|||
// // Chrome
|
|||
// // PhantomJS
|
|||
browsers: ['Chrome', 'Safari', 'Firefox'], |
|||
browserNoActivityTimeout: 10000, |
|||
browserDisconnectTimeout: 5000, |
|||
|
|||
customLaunchers: { |
|||
chromeWithoutSecurity: { |
|||
base: 'Chrome', |
|||
flags: ['--disable-web-security'] |
|||
}, |
|||
|
|||
IE9: { |
|||
base: 'IE', |
|||
'x-ua-compatible': 'IE=EmulateIE9' |
|||
}, |
|||
IE8: { |
|||
base: 'IE', |
|||
'x-ua-compatible': 'IE=EmulateIE8' |
|||
} |
|||
} |
|||
}); |
|||
}; |
@ -1,3 +1,3 @@ |
|||
{ |
|||
"version": "0.6.0" |
|||
"version": "0.7.1" |
|||
} |
|||
|
@ -0,0 +1,81 @@ |
|||
/* |
|||
This file is part of ethereum.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** |
|||
* @file allevents.js |
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
var sha3 = require('../utils/sha3'); |
|||
var SolidityEvent = require('./event'); |
|||
var formatters = require('./formatters'); |
|||
var utils = require('../utils/utils'); |
|||
var Filter = require('./filter'); |
|||
var watches = require('./watches'); |
|||
|
|||
var AllSolidityEvents = function (json, address) { |
|||
this._json = json; |
|||
this._address = address; |
|||
}; |
|||
|
|||
AllSolidityEvents.prototype.encode = function (options) { |
|||
options = options || {}; |
|||
var result = {}; |
|||
|
|||
['fromBlock', 'toBlock'].filter(function (f) { |
|||
return options[f] !== undefined; |
|||
}).forEach(function (f) { |
|||
result[f] = formatters.inputBlockNumberFormatter(options[f]); |
|||
}); |
|||
|
|||
result.topics = [null, null, null, null, null]; // match all topics
|
|||
result.address = this._address; |
|||
|
|||
return result; |
|||
}; |
|||
|
|||
AllSolidityEvents.prototype.decode = function (data) { |
|||
data.data = data.data || ''; |
|||
data.topics = data.topics || []; |
|||
|
|||
var eventTopic = data.topics[0].slice(2); |
|||
var match = this._json.filter(function (j) { |
|||
return eventTopic === sha3(utils.transformToFullName(j)); |
|||
})[0]; |
|||
|
|||
if (!match) { // cannot find matching event?
|
|||
console.warn('cannot find event for log'); |
|||
return data; |
|||
} |
|||
|
|||
var event = new SolidityEvent(match, this._address); |
|||
return event.decode(data); |
|||
}; |
|||
|
|||
AllSolidityEvents.prototype.execute = function (options, callback) { |
|||
var o = this.encode(options); |
|||
var formatter = this.decode.bind(this); |
|||
return new Filter(o, watches.eth(), formatter, callback); |
|||
}; |
|||
|
|||
AllSolidityEvents.prototype.attachToContract = function (contract) { |
|||
var execute = this.execute.bind(this); |
|||
contract.allEvents = execute; |
|||
}; |
|||
|
|||
module.exports = AllSolidityEvents; |
|||
|
@ -1,8 +1,17 @@ |
|||
/* jshint ignore:start */ |
|||
|
|||
if(typeof web3 === 'undefined') { |
|||
web3 = require('web3'); |
|||
BigNumber = require('bignumber.js'); |
|||
|
|||
// Browser environment
|
|||
if(typeof window !== 'undefined') { |
|||
web3 = (typeof window.web3 !== 'undefined') ? window.web3 : require('web3'); |
|||
BigNumber = (typeof window.BigNumber !== 'undefined') ? window.BigNumber : require('bignumber.js'); |
|||
} |
|||
|
|||
|
|||
// Node environment
|
|||
if(typeof global !== 'undefined') { |
|||
web3 = (typeof global.web3 !== 'undefined') ? global.web3 : require('web3'); |
|||
BigNumber = (typeof global.BigNumber !== 'undefined') ? global.BigNumber : require('bignumber.js'); |
|||
} |
|||
|
|||
/* jshint ignore:end */ |
Loading…
Reference in new issue