Skip to content

Commit

Permalink
Accept address array in eth_newFilter params
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Aug 28, 2018
1 parent abd9663 commit 248468c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions subproviders/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ function LogFilter(opts) {
self.type = 'log'
self.fromBlock = (opts.fromBlock !== undefined) ? opts.fromBlock : 'latest'
self.toBlock = (opts.toBlock !== undefined) ? opts.toBlock : 'latest'
self.address = opts.address ? normalizeHex(opts.address) : opts.address
expectedAddress = opts.address && (Array.isArray(opts.address) ? opts.address : [opts.address]);
self.address = expectedAddress && expectedAddress.map(function(a) { return normalizeHex(a) });
self.topics = opts.topics || []
self.updates = []
self.allResults = []
Expand All @@ -362,7 +363,8 @@ LogFilter.prototype.validateLog = function(log){

// address is correct:
// console.log('LogFilter - validateLog - address', self.address)
if (self.address && self.address.toLowerCase() !== log.address.toLowerCase()) return false
if (self.address && !(self.address.map(
function(a) { return a.toLowerCase() }).includes(log.address.toLowerCase()))) return false

// topics match:
// topics are position-dependant
Expand Down
35 changes: 35 additions & 0 deletions test/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,41 @@ filterTest('log filter - mixed case', {
}
)

filterTest('log filter - address array', {
method: 'eth_newFilter',
params: [{
address: [
'0x00000000000000000000000000000000000000000000000000000000aAbBcCdD',
'0x00000000000000000000000000000000000000000000000000000000a1b2c3d4'],
topics: ['0x00000000000000000000000000000000000000000000000000DeadBeefCafe01']
}],
},
function afterInstall(t, testMeta, response, cb){
testMeta.tx = testMeta.blockProvider.addTx({
address: '0x00000000000000000000000000000000000000000000000000000000AABBCCDD',
topics: ['0x00000000000000000000000000000000000000000000000000DEADBEEFCAFE01']
})
testMeta.badTx = testMeta.blockProvider.addTx({
address: '0x00000000000000000000000000000000000000000000000000000000aAbBcCdD',
topics: ['0x00000000000000000000000000000000000000000000000000DeadBeefCafe02']
})
var block = testMeta.block = testMeta.blockProvider.nextBlock()
cb()
},
function filterChangesOne(t, testMeta, response, cb){
var results = response.result
var matchedTx = response.result[0]
t.equal(results.length, 1, 'correct number of results')
t.equal(matchedTx, testMeta.tx, 'correct result')
cb()
},
function filterChangesTwo(t, testMeta, response, cb){
var results = response.result
t.equal(results.length, 0, 'correct number of results')
cb()
}
)

filterTest('log filter - and logic', {
method: 'eth_newFilter',
params: [{
Expand Down

0 comments on commit 248468c

Please sign in to comment.