newFilter method
- required EthereumDefaultBlock fromBlock,
- required EthereumDefaultBlock toBlock,
- dynamic address,
- List<
EthereumData> ? topics,
New filter
Creates a filter object, based on filter options, to notify when
the state changes (logs).
To check if the state has changed, call getFilterChanges.
note on specifying topic filters:
Topics are order-dependent. A transaction with a log with topics A, B
will be matched by the following topic filters:
[] 'anything'
'A'
'A in first position (and anything after)'
null, B
'anything in first position AND B in second position
(and anything after)'
A, B
'A in first position AND B in second position (and anything after)'
[A, B
, A, B
] '(A OR B) in first position AND (A OR B)
in second position (and anything after)'
fromBlock: - (optional, default: 'latest')
Integer block number, or 'latest' for the last mined block or 'pending',
'earliest' for not yet mined transactions.
toBlock: - (optional, default: 'latest')
Integer block number, or 'latest' for the last mined block or
'pending', 'earliest' for not yet mined transactions.
address: - (optional) Contract address or a list of addresses
from which logs should originate.
topics: - (optional) topics. Topics are order-dependent.
Note: the user must build this structure using the utilities in the
EthereumUtilities class. See the Ethereum
Wiki RPC page for examples.
Returns a filter id.
Implementation
Future<int?> newFilter(
{required EthereumDefaultBlock fromBlock,
required EthereumDefaultBlock toBlock,
dynamic address,
List<EthereumData>? topics}) async {
final fromBlockString = fromBlock.getSelection();
final toBlockString = toBlock.getSelection();
final params = <String, dynamic>{
'toBlock': toBlockString,
'fromBlock': fromBlockString
};
if (address != null) {
if (address is List) {
final addresses =
EthereumAddress.toStringList(address as List<EthereumAddress>);
params['address'] = addresses;
} else {
params['address'] = <String?>[address.asString];
}
}
if (topics != null) {
params['topics'] = EthereumData.toStringList(topics);
}
final paramBlock = <dynamic>[params];
const method = EthereumRpcMethods.newFilter;
final dynamic res = await _client.rpcClient.request(method, paramBlock);
if (res != null && res.containsKey(EthereumConstants.ethResultKey)) {
return EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]);
}
_client.processError(method, res);
return null;
}