get method

FutureOr<BlockhashWithExpiryBlockHeight> get(
  1. HttpConnection connection, {
  2. required bool disabled,
})

Returns the latest blockhash.

The cached value is returned when disabled is false and its timeout duration has not elapsed. Otherwise, a request is made over the provided connection to fetch and store the latest blockhash.

If a request to fetch the latest blockhash is in progress, the method waits for it to complete before returning a value, even if disabled is false and there's a valid cache value.

Implementation

FutureOr<BlockhashWithExpiryBlockHeight> get(
  final HttpConnection connection, {
  required final bool disabled,
}) async {
  /// Make a request to fetch the latest blockhash if the cache is [disabled].
  if (disabled) {
    return _fetch(connection);
  }

  /// Return the cached value or make a request to fetch the latest blockhash.
  return value ?? _syncFetch(connection);
}