This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
chore: high level api speccing #107
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33d57e9
begin
harrysolovay 9044cbd
modeling north star
harrysolovay 983799b
fix bad references to old location of branded types
harrysolovay 802486a
add block method to Chain
harrysolovay ce3c121
cleanup
harrysolovay 5da706d
continued
harrysolovay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
type Branded<T, Brand extends PropertyKey> = T & { [_ in Brand]: undefined }; | ||
|
||
export const HexStringBrand: unique symbol = Symbol(); | ||
export type HexString = Branded<string, typeof HexStringBrand>; | ||
|
||
export const HashHexStringBrand: unique symbol = Symbol(); | ||
export type HashHexString = Branded<HexString, typeof HashHexStringBrand>; | ||
|
||
export const AccountIdStringBrand: unique symbol = Symbol(); | ||
export type AccountIdString = Branded<string, typeof AccountIdStringBrand>; | ||
|
||
export const SubscriptionIdStringBrand: unique symbol = Symbol(); | ||
export type SubscriptionIdString = Branded<string, typeof SubscriptionIdStringBrand>; | ||
|
||
export const MultiAddressStringBrand: unique symbol = Symbol(); | ||
export type MultiAddressString = Branded<string, typeof MultiAddressStringBrand>; | ||
|
||
export const HexU64StringBrand: unique symbol = Symbol(); | ||
export type HexU64String = Branded<string, typeof HexU64StringBrand>; | ||
|
||
export const WsUrlStringBrand: unique symbol = Symbol(); | ||
export type WsUrlString = Branded<string, typeof HexStringBrand>; | ||
|
||
export const ChainSpecStringBrand: unique symbol = Symbol(); | ||
export type ChainSpecString = Branded<string, typeof ChainSpecStringBrand>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { HashHexString } from "../branded.ts"; | ||
import { Chain } from "./Chain.ts"; | ||
import { NodeBase, NodeKind } from "./Node.ts"; | ||
import { Read } from "./Read.ts"; | ||
|
||
export class Block extends NodeBase { | ||
readonly kind = NodeKind.Block; | ||
|
||
constructor( | ||
readonly chain: Chain, | ||
readonly hash?: HashHexString, | ||
) { | ||
super(); | ||
} | ||
|
||
read(): Read<this> { | ||
return new Read(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as B from "../branded.ts"; | ||
import { Block } from "./Block.ts"; | ||
import { Metadata } from "./Metadata.ts"; | ||
import { NodeBase, NodeKind } from "./Node.ts"; | ||
import { Pallet } from "./Pallet.ts"; | ||
|
||
export type Beacon = B.WsUrlString | B.ChainSpecString; | ||
|
||
export class Chain extends NodeBase { | ||
readonly kind = NodeKind.Chain; | ||
|
||
constructor(readonly beacon: Beacon) { | ||
super(); | ||
} | ||
|
||
metadata(block?: Block): Metadata { | ||
return new Metadata(this, block); | ||
} | ||
|
||
block(hash?: B.HashHexString): Block { | ||
return new Block(this, hash); | ||
} | ||
|
||
pallet(name: string): Pallet { | ||
return new Pallet(this, name); | ||
} | ||
} | ||
|
||
export function chain(beacon: Beacon): Chain { | ||
return new Chain(beacon); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MultiAddress } from "../primitives/MultiAddress.ts"; | ||
import { ExtrinsicFactory } from "./ExtrinsicFactory.ts"; | ||
import { NodeBase, NodeKind } from "./Node.ts"; | ||
import { SignedExtrinsic } from "./SignedExtrinsic.ts"; | ||
|
||
export class Extrinsic<CallData extends Record<string, unknown> = Record<string, any>> | ||
extends NodeBase | ||
{ | ||
readonly kind = NodeKind.Extrinsic; | ||
|
||
constructor( | ||
readonly factory: ExtrinsicFactory<CallData>, | ||
readonly caller: MultiAddress, | ||
readonly callData: CallData, | ||
) { | ||
super(); | ||
} | ||
|
||
sign(sign: (message: Uint8Array) => Uint8Array): SignedExtrinsic { | ||
return new SignedExtrinsic(this as Extrinsic, sign); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to also take
extra
andadditional