This commit is contained in:
Marek Kotewicz 2015-01-29 12:35:21 +01:00
parent 61e8ae2f7b
commit 842b8cf323
10 changed files with 106 additions and 10 deletions

18
dist/ethereum.js vendored
View File

@ -451,7 +451,7 @@ module.exports = {
* @date 2014
*/
var web3 = require('./web3'); // jshint ignore:line
var web3 = require('./web3');
var abi = require('./abi');
/**
@ -493,7 +493,17 @@ var contract = function (address, desc) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
var result = {};
var result = {
address: address,
};
Object.defineProperty(result, 'topics', {
get: function() {
return abi.filterEvents(desc).map(function (event) {
return abi.methodSignature(event.name);
});
}
});
result.call = function (options) {
result._isTransact = false;
@ -579,11 +589,13 @@ var contract = function (address, desc) {
var displayName = abi.methodDisplayName(event.name);
var typeName = abi.methodTypeName(event.name);
var impl = function (options) {
var signature = abi.methodSignature(event.name);
var o = options || {};
o.address = o.address || address;
o.topics = o.topics || [];
o.topics.push(abi.methodSignature(event.name));
o.topics.push(signature);
return web3.eth.watch(o);
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@
// contract description, this will be autogenerated somehow
var desc = [{
"name": "multiply(uint256)",
"type": "function",
"inputs": [
{
"name": "a",

View File

@ -21,6 +21,7 @@
// contract description, this will be autogenerated somehow
var desc = [{
"name": "multiply(uint256)",
"type": "function",
"inputs": [
{
"name": "a",

View File

@ -20,7 +20,7 @@
* @date 2014
*/
var web3 = require('./web3'); // jshint ignore:line
var web3 = require('./web3');
var abi = require('./abi');
/**
@ -62,7 +62,17 @@ var contract = function (address, desc) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
var result = {};
var result = {
address: address,
};
Object.defineProperty(result, 'topics', {
get: function() {
return abi.filterEvents(desc).map(function (event) {
return abi.methodSignature(event.name);
});
}
});
result.call = function (options) {
result._isTransact = false;
@ -148,11 +158,13 @@ var contract = function (address, desc) {
var displayName = abi.methodDisplayName(event.name);
var typeName = abi.methodTypeName(event.name);
var impl = function (options) {
var signature = abi.methodSignature(event.name);
var o = options || {};
o.address = o.address || address;
o.topics = o.topics || [];
o.topics.push(abi.methodSignature(event.name));
o.topics.push(signature);
return web3.eth.watch(o);
};

16
lib/event.js Normal file
View File

@ -0,0 +1,16 @@
var abi = require('./abi');
var implementationOfEvent = function (event, address, signature) {
return function (options) {
var o = options || {};
o.address = o.address || address;
o.topics = o.topics || [];
o.topics.push(signature);
return o;
};
};
module.exports = implementationOfEvent;

View File

@ -146,7 +146,6 @@ describe('contract', function() {
// given
var description = [{
"name": "test(uint256)",
"type": "event",
"inputs": [{
"name": "a",
"type": "uint256"
@ -168,5 +167,35 @@ describe('contract', function() {
assert.equal('undefined', typeof con.test);
});
it('should create contract with one event', function () {
// given
var description = [{
"name": "test",
"type": "event",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
// when
var con = contract(null, description);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
});
});

View File

25
test/event.js Normal file
View File

@ -0,0 +1,25 @@
var assert = require('assert');
var event = require('../lib/event.js');
describe('event', function () {
it('should create filter input object from given', function () {
// given
var address = '0x012345';
var signature = '0x987654';
var e = {
name: 'test',
type: 'event',
};
// when
var impl = event(e, address, signature);
var result = impl();
// then
assert.equal(result.address, address);
assert.equal(result.topics.length, 1);
assert.equal(result.topics[0], signature);
});
});