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 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fcd111
commit ef22966
Showing
15 changed files
with
83 additions
and
38 deletions.
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
File renamed without changes.
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,16 @@ | ||
import * as C from "../../mod.ts"; | ||
import * as U from "../../util/mod.ts"; | ||
|
||
const root = C.watchBlocks(C.polkadot, (stop) => { | ||
let i = 0; | ||
|
||
return (event) => { | ||
console.log(event); | ||
if (i === 4) { | ||
stop(); | ||
} | ||
i++; | ||
}; | ||
}); | ||
|
||
console.log(U.throwIfError(await root.run())); |
Empty file.
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,34 @@ | ||
import { Extrinsic } from "../../frame_metadata/mod.ts"; | ||
import * as known from "../../known/mod.ts"; | ||
import * as U from "../../util/mod.ts"; | ||
import * as a from "../atoms/mod.ts"; | ||
import { readBlock } from "./readBlock.ts"; | ||
|
||
type Config = known.rpc.Config< | ||
string, | ||
"state_getMetadata" | "chain_getBlockHash" | "chain_getBlock" | "chain_unsubscribeNewHead", | ||
"chain_subscribeNewHeads" | ||
>; | ||
|
||
export function watchBlocks( | ||
config: Config, | ||
createWatchHandler: U.CreateWatchHandler<known.types.Block<Extrinsic>>, | ||
) { | ||
return a.rpcSubscription(config, "chain_subscribeNewHeads", [], (stop) => { | ||
const watchHandler = createWatchHandler(stop); | ||
return async (result) => { | ||
const blockNum = result.params.result.number; | ||
const blockHash = a | ||
.rpcCall(config, "chain_getBlockHash", [blockNum]) | ||
.select("result"); | ||
const block = await readBlock(config, blockHash as unknown as U.HashHexString).run(); // STOP THIS MADNESS | ||
if (block instanceof Error) { | ||
// TODO: subscription runtime error channel | ||
throw new Error(); | ||
} | ||
watchHandler(block.block); | ||
}; | ||
}, (ok) => { | ||
return a.rpcCall(config, "chain_unsubscribeNewHead", [ok.result]); | ||
}); | ||
} |
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