Skip to content

Commit

Permalink
substrate: add .at() method to generated classes (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Jul 29, 2024
1 parent 938b773 commit 7ee0a60
Show file tree
Hide file tree
Showing 18 changed files with 908 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/scale-type-system",
"comment": "export more utility types",
"type": "minor"
}
],
"packageName": "@subsquid/scale-type-system"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/substrate-runtime",
"comment": "add `.hasStorage()` method",
"type": "minor"
}
],
"packageName": "@subsquid/substrate-runtime"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"changes": [
{
"packageName": "@subsquid/substrate-typegen",
"comment": "add `.at()` method on generated classes",
"type": "minor"
},
{
"packageName": "@subsquid/substrate-typegen",
"comment": "add `index.ts` to pallet modules",
"type": "minor"
},
],
"packageName": "@subsquid/substrate-typegen"
}
4 changes: 2 additions & 2 deletions substrate/scale-type-system/src/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
UnknownType
} from './types/primitives'
import {GetStructType, StructType} from './types/struct'
import {TupleType} from './types/tuple'
import {TupleType, GetTupleType} from './types/tuple'
import {UnionType} from './types/union'


export {GetType, ExternalEnum, ValueCase}
export {GetType, ExternalEnum, ValueCase, GetEnumType, GetTupleType, GetStructType}


const numberType = new NumberType()
Expand Down
4 changes: 1 addition & 3 deletions substrate/scale-type-system/src/types/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {BaseType, ScaleType, Type, TypeChecker} from '../type-checker'
import {GetType} from '../type-util'


export type GetTupleType<T> = {
[I in keyof T]: GetType<T[I]>
}
export type GetTupleType<T> = T extends readonly [infer A, ...infer R] ? [GetType<A>, ...GetTupleType<R>] : []


export class TupleType<T extends readonly Type[]> extends BaseType<GetTupleType<T>> {
Expand Down
5 changes: 5 additions & 0 deletions substrate/substrate-runtime/src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ export class Runtime {
return this.checkType(def.type, ty)
}

hasStorage(name: QualifiedName): boolean {
let qn = parseQualifiedName(name)
return !!this.description.storage[qn[0]]?.items[qn[1]]
}

checkStorageType(
name: QualifiedName,
modifier: StorageItem['modifier'] | StorageItem['modifier'][],
Expand Down
Loading

0 comments on commit 7ee0a60

Please sign in to comment.