forked from ton-core/ton
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Showing
3 changed files
with
40 additions
and
13 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
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 |
---|---|---|
@@ -1,16 +1,42 @@ | ||
import { z } from 'zod'; | ||
import type { TvmTuple, TvmList } from './tvmValues'; | ||
|
||
type SerializedCell = { bytes: string }; | ||
const serializedCellSchema = z.object({ | ||
bytes: z.string(), | ||
}); | ||
type SerializedCell = z.infer<typeof serializedCellSchema>; | ||
|
||
type NullStackItem = ['null']; | ||
type NumStackItem = ['num', string]; | ||
type CellStackItem = ['cell', SerializedCell]; | ||
type SliceStackItem = ['slice', SerializedCell]; | ||
type BuilderStackItem = ['builder', SerializedCell]; | ||
const nullSchema = z.union([ | ||
z.tuple([z.literal('null')]), | ||
z.tuple([z.literal('null'), z.null().optional()]), | ||
]); | ||
type NullStackItem = z.infer<typeof nullSchema>; | ||
|
||
type TupleStackItem = ['tuple', TvmTuple]; | ||
type ListStackItem = ['list', TvmList]; | ||
const numSchema = z.tuple([z.literal('num'), z.string()]); | ||
type NumStackItem = z.infer<typeof numSchema>; | ||
|
||
export type StackItem = NullStackItem | NumStackItem | ||
| CellStackItem | SliceStackItem | BuilderStackItem | ||
| TupleStackItem | ListStackItem; | ||
const cellSchema = z.tuple([z.literal('cell'), serializedCellSchema]); | ||
type CellStackItem = z.infer<typeof cellSchema>; | ||
|
||
const sliceSchema = z.tuple([z.literal('slice'), serializedCellSchema]); | ||
type SliceStackItem = z.infer<typeof sliceSchema>; | ||
|
||
const builderSchema = z.tuple([z.literal('builder'), serializedCellSchema]); | ||
type BuilderStackItem = z.infer<typeof builderSchema>; | ||
|
||
const tupleSchema = z.tuple([z.literal('tuple'), z.unknown() as z.ZodType<TvmTuple>]); | ||
type TupleStackItem = z.infer<typeof tupleSchema>; | ||
|
||
const listSchema = z.tuple([z.literal('list'), z.unknown() as z.ZodType<TvmList>]); | ||
type ListStackItem = z.infer<typeof listSchema>; | ||
|
||
export const stackItemSchema = z.union([ | ||
nullSchema, | ||
numSchema, | ||
cellSchema, | ||
sliceSchema, | ||
builderSchema, | ||
tupleSchema, | ||
listSchema, | ||
]); | ||
export type StackItem = NullStackItem | NumStackItem | CellStackItem | SliceStackItem | BuilderStackItem | TupleStackItem | ListStackItem; |
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