pull/296/head
Marek Kotewicz 10 years ago
parent 61e8ae2f7b
commit 842b8cf323
  1. 18
      dist/ethereum.js
  2. 4
      dist/ethereum.js.map
  3. 2
      dist/ethereum.min.js
  4. 1
      example/contract.html
  5. 1
      example/natspec_contract.html
  6. 18
      lib/contract.js
  7. 16
      lib/event.js
  8. 31
      test/eth.contract.js
  9. 0
      test/eth.event.js
  10. 25
      test/event.js

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);
};

File diff suppressed because one or more lines are too long

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);
};

@ -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']);
});
});

@ -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…
Cancel
Save