newFilter method

Future<int> newFilter ({MoacDefaultBlock fromBlock, MoacDefaultBlock toBlock, dynamic address, List<BigInt> 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 MoacUtilities class. See the Moac Wiki RPC page for examples. Returns a filter id.

Implementation

Future<int> newFilter(
    {MoacDefaultBlock fromBlock,
    MoacDefaultBlock toBlock,
    dynamic address,
    List<BigInt> topics}) async {
  final String fromBlockString = fromBlock.getSelection();
  final String toBlockString = toBlock.getSelection();
  final Map params = {"toBlock": toBlockString, "fromBlock": fromBlockString};
  if (address != null) {
    if (address is List) {
      final List<String> addresses =
          MoacUtilities.bigIntegerToHexList(address);
      params["address"] = addresses;
    } else {
      params["address"] = (MoacUtilities.bigIntegerToHex(address));
    }
  }
  if (topics != null) {
    params["topics"] = MoacUtilities.bigIntegerToHexList(topics);
  }
  final List paramBlock = [params];
  final String method = MoacRpcMethods.newFilter;
  final res = await rpcClient.request(method, paramBlock);
  if (res != null && res.containsKey(moacResultKey)) {
    return MoacUtilities.hexToInt(res[moacResultKey]);
  }
  _processError(method, res);
  return null;
}