arkpar
10 years ago
34 changed files with 1181 additions and 391 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