Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

chore: remove branded type fluff #537

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rpc/known/chain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HexEncoded } from "../../util/branded.ts"
import { Hash, Hex, ListOrValue, NumberOrHex, RpcResult, Subscription } from "./utils.ts"

// https://github.com/paritytech/substrate/blob/0ba251c/primitives/runtime/src/generic/digest.rs
Expand All @@ -14,7 +13,7 @@ export interface Header {
/** The parent hash. */
parentHash: Hash
/** The block number. */
number: HexEncoded<bigint>
number: Hex
/** The state trie merkle root */
stateRoot: Hash
/** The merkle root of the extrinsics. */
Expand Down
2 changes: 1 addition & 1 deletion rpc/known/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export type Hash = U.HexHash
export type SubId = string
export type AccountId = string
export type Subscription<T, U> = string & { _subscription: [T, U] }
export type NumberOrHex = U.HexEncoded<bigint> | number
export type NumberOrHex = U.Hex | number
export type ListOrValue<T> = T | T[]
export type RpcResult<T> = T
17 changes: 4 additions & 13 deletions util/branded.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { HasherKind } from "../frame_metadata/Metadata.ts"
export type Branded<T, Brand extends PropertyKey, V = undefined> = T & { [_ in Brand]: V }
export type Branded<T, Brand extends PropertyKey> = T & { [_ in Brand]: true }

declare const _hex: unique symbol
export type Hex<T extends Uint8Array = Uint8Array> = Branded<string, typeof _hex, T>

declare const _encoded: unique symbol
export type Encoded<T> = Branded<Uint8Array, typeof _encoded, T>
export type Hex = Branded<string, typeof _hex>

declare const _hash: unique symbol
export type Hash<T = unknown, K extends HasherKind = HasherKind> = Branded<
Uint8Array,
typeof _hash,
[T, K]
>
export type Hash = Branded<Uint8Array, typeof _hash>

export type HexEncoded<T> = Hex<Encoded<T>>
export type HexHash<T = unknown, K extends HasherKind = HasherKind> = Hex<Hash<T, K>>
export type HexHash = Hex & Hash