Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
80c97ca2
Commit
80c97ca2
authored
Jan 31, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
events
parent
2491c99b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
22 deletions
+120
-22
ethereum.js
dist/ethereum.js
+20
-8
ethereum.js.map
dist/ethereum.js.map
+2
-2
ethereum.min.js
dist/ethereum.min.js
+1
-1
event.js
lib/event.js
+20
-8
event.js
test/event.js
+77
-3
No files found.
dist/ethereum.js
View file @
80c97ca2
...
...
@@ -502,27 +502,36 @@ var utils = require('./utils');
var
inputWithName
=
function
(
inputs
,
name
)
{
var
index
=
utils
.
findIndex
(
inputs
,
function
(
input
)
{
return
input
.
name
===
name
;
return
input
.
name
===
name
;
});
if
(
index
===
-
1
)
{
console
.
error
(
'indexed param '
+
name
+
' not found in the abi
'
);
return
undefined
;
console
.
error
(
'indexed paray with name '
+
name
+
' not found
'
);
return
undefined
;
}
return
inputs
[
index
];
};
var
indexedParamsToTopics
=
function
(
inputs
,
indexed
)
{
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
var
inp
=
inputWithName
(
key
);
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
// sort keys?
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
// TODO: simplify this!
var
parser
=
abi
.
inputParser
([{
name
:
'test'
,
inputs
:
[
inputWithName
(
event
.
inputs
,
key
)]
}]);
var
value
=
indexed
[
key
];
if
(
value
instanceof
Array
)
{
return
value
.
map
(
function
(
v
)
{
return
parser
.
test
(
v
);
});
}
return
parser
.
test
(
value
);
});
};
var
implementationOfEvent
=
function
(
address
,
signature
,
event
)
{
// valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
return
function
(
indexed
,
options
)
{
...
...
@@ -530,6 +539,9 @@ var implementationOfEvent = function (address, signature, event) {
o
.
address
=
address
;
o
.
topic
=
[];
o
.
topic
.
push
(
signature
);
if
(
indexed
)
{
o
.
topic
=
o
.
topic
.
concat
(
indexedParamsToTopics
(
event
,
indexed
));
}
return
o
;
};
};
...
...
dist/ethereum.js.map
View file @
80c97ca2
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
80c97ca2
This diff is collapsed.
Click to expand it.
lib/event.js
View file @
80c97ca2
...
...
@@ -25,27 +25,36 @@ var utils = require('./utils');
var
inputWithName
=
function
(
inputs
,
name
)
{
var
index
=
utils
.
findIndex
(
inputs
,
function
(
input
)
{
return
input
.
name
===
name
;
return
input
.
name
===
name
;
});
if
(
index
===
-
1
)
{
console
.
error
(
'indexed param '
+
name
+
' not found in the abi
'
);
return
undefined
;
console
.
error
(
'indexed paray with name '
+
name
+
' not found
'
);
return
undefined
;
}
return
inputs
[
index
];
};
var
indexedParamsToTopics
=
function
(
inputs
,
indexed
)
{
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
var
inp
=
inputWithName
(
key
);
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
// sort keys?
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
// TODO: simplify this!
var
parser
=
abi
.
inputParser
([{
name
:
'test'
,
inputs
:
[
inputWithName
(
event
.
inputs
,
key
)]
}]);
var
value
=
indexed
[
key
];
if
(
value
instanceof
Array
)
{
return
value
.
map
(
function
(
v
)
{
return
parser
.
test
(
v
);
});
}
return
parser
.
test
(
value
);
});
};
var
implementationOfEvent
=
function
(
address
,
signature
,
event
)
{
// valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
return
function
(
indexed
,
options
)
{
...
...
@@ -53,6 +62,9 @@ var implementationOfEvent = function (address, signature, event) {
o
.
address
=
address
;
o
.
topic
=
[];
o
.
topic
.
push
(
signature
);
if
(
indexed
)
{
o
.
topic
=
o
.
topic
.
concat
(
indexedParamsToTopics
(
event
,
indexed
));
}
return
o
;
};
};
...
...
test/event.js
View file @
80c97ca2
var
assert
=
require
(
'assert'
);
var
event
=
require
(
'../lib/event.js'
);
var
f
=
require
(
'../lib/formatters.js'
);
describe
(
'event'
,
function
()
{
it
(
'should create basic filter input object'
,
function
()
{
...
...
@@ -7,9 +8,13 @@ describe('event', function () {
// given
var
address
=
'0x012345'
;
var
signature
=
'0x987654'
;
var
e
=
{
name
:
'Event'
,
inputs
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
,
"indexed"
:
true
},{
"name"
:
"b"
,
"type"
:
"hash256"
,
"indexed"
:
false
}]
};
// when
var
impl
=
event
(
address
,
signature
);
var
impl
=
event
(
address
,
signature
,
e
);
var
result
=
impl
();
// then
...
...
@@ -19,7 +24,7 @@ describe('event', function () {
});
it
(
'should create
basic filter input object
'
,
function
()
{
it
(
'should create
filter input object with options
'
,
function
()
{
// given
var
address
=
'0x012345'
;
...
...
@@ -30,9 +35,13 @@ describe('event', function () {
offset
:
3
,
max
:
4
};
var
e
=
{
name
:
'Event'
,
inputs
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
,
"indexed"
:
true
},{
"name"
:
"b"
,
"type"
:
"hash256"
,
"indexed"
:
false
}]
};
// when
var
impl
=
event
(
address
,
signature
);
var
impl
=
event
(
address
,
signature
,
e
);
var
result
=
impl
({},
options
);
// then
...
...
@@ -46,5 +55,70 @@ describe('event', function () {
});
it
(
'should create filter input object with indexed params'
,
function
()
{
// given
var
address
=
'0x012345'
;
var
signature
=
'0x987654'
;
var
options
=
{
earliest
:
1
,
latest
:
2
,
offset
:
3
,
max
:
4
};
var
e
=
{
name
:
'Event'
,
inputs
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
,
"indexed"
:
true
},{
"name"
:
"b"
,
"type"
:
"hash256"
,
"indexed"
:
false
}]
};
// when
var
impl
=
event
(
address
,
signature
,
e
);
var
result
=
impl
({
a
:
4
},
options
);
// then
assert
.
equal
(
result
.
address
,
address
);
assert
.
equal
(
result
.
topic
.
length
,
2
);
assert
.
equal
(
result
.
topic
[
0
],
signature
);
assert
.
equal
(
result
.
topic
[
1
],
f
.
formatInputInt
(
4
));
assert
.
equal
(
result
.
earliest
,
options
.
earliest
);
assert
.
equal
(
result
.
latest
,
options
.
latest
);
assert
.
equal
(
result
.
offset
,
options
.
offset
);
assert
.
equal
(
result
.
max
,
options
.
max
);
});
it
(
'should create filter input object with an array of indexed params'
,
function
()
{
// given
var
address
=
'0x012345'
;
var
signature
=
'0x987654'
;
var
options
=
{
earliest
:
1
,
latest
:
2
,
offset
:
3
,
max
:
4
};
var
e
=
{
name
:
'Event'
,
inputs
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
,
"indexed"
:
true
},{
"name"
:
"b"
,
"type"
:
"hash256"
,
"indexed"
:
false
}]
};
// when
var
impl
=
event
(
address
,
signature
,
e
);
var
result
=
impl
({
a
:
[
4
,
69
]},
options
);
// then
assert
.
equal
(
result
.
address
,
address
);
assert
.
equal
(
result
.
topic
.
length
,
2
);
assert
.
equal
(
result
.
topic
[
0
],
signature
);
assert
.
equal
(
result
.
topic
[
1
][
0
],
f
.
formatInputInt
(
4
));
assert
.
equal
(
result
.
topic
[
1
][
1
],
f
.
formatInputInt
(
69
));
assert
.
equal
(
result
.
earliest
,
options
.
earliest
);
assert
.
equal
(
result
.
latest
,
options
.
latest
);
assert
.
equal
(
result
.
offset
,
options
.
offset
);
assert
.
equal
(
result
.
max
,
options
.
max
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment