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

Commit

Permalink
feat: add smoldot known methods types
Browse files Browse the repository at this point in the history
  • Loading branch information
kratico committed Nov 15, 2022
1 parent 2692c9a commit c0fbd87
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions rpc/known/smoldot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { Hash, Hex, RpcResult, Subscription } from "./utils.ts"

export type NetworkConfig = {
totalAttempts: number
maxParallel: number
timeoutMs: number
}

export type MaybeRuntimeSpec = {
type: "valid"
spec: RuntimeSpec
} | {
type: "invalid"
error: string
}
export type RuntimeSpec = {
specName: string
implName: string
authoringVersion: number
specVersion: number
implVersion: number
transactionVersion?: number
apis: Record<Hex, number>
}

export type ChainHeadUnstableFollowEvent = {
event: "initialized"
finalizedBlockHash: Hash
finalizedBlockRuntime?: MaybeRuntimeSpec
} | {
event: "newBlock"
blockHash: Hash
parentBlockHash: Hash
newRuntime?: MaybeRuntimeSpec
} | {
event: "bestBlockChanged"
bestBlockHash: Hash
} | {
event: "finalized"
finalizedBlockHashes: Hash[]
prunedBlockHashes: Hash[]
} | {
event: "stop"
}

export type TransactionWatchEvent = {
event: "validated"
} | {
event: "broadcasted"
numPeers: number
} | {
event: "bestChainBlockIncluded"
block?: TransactionWatchEventBlock
} | {
event: "finalized"
block: TransactionWatchEventBlock
} | {
event: "error"
error: string
} | {
event: "invalid"
error: string
} | {
event: "dropped"
broadcasted: boolean
error: string
}

export type TransactionWatchEventBlock = {
hash: Hash
index: string
}

export type RpcMethods = {
methods: string[]
}

export type SmoldotRpc = {
// not found - state_getChildKeys
// already in childstate.ts - state_getChildReadProof
// not found - state_getChildStorage
// not found - state_getChildStorageHash
// not found - state_getChildStorageSize
sudo_unstable_p2pDiscover(multiaddr: string): RpcResult<void>
sudo_unstable_version(): RpcResult<string>
// not found - syncstate_genSyncSpec: TODO_NARROW_METHOD_TYPE;
transaction_unstable_unwatch(subscription: string): RpcResult<void>
chainHead_unstable_body(
followSubscription: string,
hash: Hash,
networkConfig?: NetworkConfig,
): RpcResult<string>
chainHead_unstable_call(
followSubscription: string,
hash: Hash,
fn: string,
callParameters: Hex,
networkConfig?: NetworkConfig,
): RpcResult<string>
chainHead_unstable_genesisHash(): RpcResult<Hash>
chainHead_unstable_header(followSubscription: string, hash: Hash): RpcResult<Hex>
chainHead_unstable_stopBody(subscription: string): RpcResult<void>
chainHead_unstable_stopCall(subscription: string): RpcResult<void>
chainHead_unstable_stopStorage(subscription: string): RpcResult<void>
chainHead_unstable_storage(
followSubscription: string,
hash: Hash,
key: Hex,
childKey?: Hex,
networkConfig?: NetworkConfig,
): RpcResult<string>
chainHead_unstable_unfollow(followSubscription: string): RpcResult<void>
chainHead_unstable_unpin(followSubscription: string, hash: Hash): RpcResult<void>
chainSpec_unstable_chainName(): RpcResult<string>
chainSpec_unstable_genesisHash(): RpcResult<Hash>
chainSpec_unstable_properties(): RpcResult<unknown>
// not found - chainSpec_getBlockStats(at: U.HexHash): T.BlockStats | null;
// not found - chainSpec_createBlock: TODO_NARROW_METHOD_TYPE;
// not found - chainSpec_finalizeBlock: TODO_NARROW_METHOD_TYPE;
rpc_methods(): RpcResult<RpcMethods>
// subscriptions
chainHead_unstable_follow(
runtimeUpdates: boolean,
): RpcResult<Subscription<"chainHead_unstable_follow", ChainHeadUnstableFollowEvent>>
transaction_unstable_submitAndWatch(
transaction: Hex,
): RpcResult<Subscription<"transaction_unstable_submitAndWatch", TransactionWatchEvent>>
}

export type ErrorResponse =
| ParseError
| InvalidRequest
| MethodNotFound
| InvalidParams
| InternalError
| ServerError
| MethodError

type ParseError = SerdeError<-32700>
type InvalidRequest = SerdeError<-32600>
type MethodNotFound = SerdeError<-32601>
type InvalidParams = SerdeError<-32602>
type InternalError = SerdeError<-32603>
type ServerError = SerdeError<number /*[-32099..=-32000]*/>
type MethodError = SerdeError<number /* [-32700..=-32000]*/>

type SerdeError<code = number> = {
code: code
message: string
data?: unknown
}

0 comments on commit c0fbd87

Please sign in to comment.