# SyncStatus

What a node reports about its sync: the literal `false` once it is in sync, or its progress as
three block numbers while it is syncing.

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const remaining = Effect.gen(function* () {
  const status = yield* Eth.syncing();
  if (status === false) return 0n;
  // status: SyncStatus.Progress
  return status.highestBlock - status.currentBlock;
});
```

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `SyncStatus.schema` | `SyncStatus.SyncStatus` | `false`, or a `SyncStatus.Progress` | [`Eth.syncing`](https://ethect.dev/rpc/eth/syncing/), and as one of the forms [`Eth.subscribe.syncing`](https://ethect.dev/rpc/eth/subscribe/syncing/) pushes |
| `SyncStatus.progressSchema` | `SyncStatus.Progress` | how far a syncing node has come | as the other member of `SyncStatus.SyncStatus` |

Import a type to name it in your own signatures.

```ts
import type { SyncStatus } from "@ethect/core/rpc";

/** How much of the way from where it started the node has come. */
const percent = ({ startingBlock = 0n, ...sync }: SyncStatus.Progress) =>
  sync.highestBlock === startingBlock
    ? 100
    : Number(
        ((sync.currentBlock - startingBlock) * 100n) /
          (sync.highestBlock - startingBlock),
      );
```

## Fields

`SyncStatus.Progress`.

| Field | Type | Notes |
| --- | --- | --- |
| `startingBlock` | `bigint` (optional) | the block the sync started from. Not sent by every client. |
| `currentBlock` | `bigint` | the block the node has reached |
| `highestBlock` | `bigint` | the block the node is syncing towards |

## Behavior

- **`false`, never `true`.** A node in sync answers `false`. A node that is syncing answers the
  progress object, not `true`: compare with `=== false` to narrow the type.
- **`startingBlock` can be absent.** A client that does not say where it started gives a
  progress without the key. Test it with `progress.startingBlock !== undefined`.
- **Other fields are dropped.** A node that reports more than these three still decodes. The
  extra fields are not in the result.
- **Numbers.** The three fields are block numbers, so they are `bigint`. See
  [values on the wire](https://ethect.dev/rpc/guides/values/).
