forked from cerc-io/plugeth
event.js
This commit is contained in:
parent
61e8ae2f7b
commit
842b8cf323
18
dist/ethereum.js
vendored
18
dist/ethereum.js
vendored
@ -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);
|
||||
};
|
||||
|
4
dist/ethereum.js.map
vendored
4
dist/ethereum.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethereum.min.js
vendored
2
dist/ethereum.min.js
vendored
File diff suppressed because one or more lines are too long
@ -20,6 +20,7 @@
|
||||
// contract description, this will be autogenerated somehow
|
||||
var desc = [{
|
||||
"name": "multiply(uint256)",
|
||||
"type": "function",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
|
@ -21,6 +21,7 @@
|
||||
// contract description, this will be autogenerated somehow
|
||||
var desc = [{
|
||||
"name": "multiply(uint256)",
|
||||
"type": "function",
|
||||
"inputs": [
|
||||
{
|
||||
"name": "a",
|
||||
|
@ -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
16
lib/event.js
Normal 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;
|
||||
|
@ -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']);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
25
test/event.js
Normal file
25
test/event.js
Normal 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);
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user