File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import { EntryFunctionArgumentTypes } from "../transactions" ;
2+ import { SimpleEntryFunctionArgumentTypes } from "../transactions" ;
3+ import { TypeTag } from "../transactions/typeTag" ;
4+ import { Bool } from "./serializable/movePrimitives" ;
5+
6+ export function serialize ( typeTag : TypeTag , arg : SimpleEntryFunctionArgumentTypes ) : EntryFunctionArgumentTypes {
7+ if ( typeTag . isBool ( ) ) {
8+ if ( typeof arg === "boolean" ) {
9+ return new Bool ( arg ) ;
10+ }
11+ // Accept number 1/0
12+ if ( typeof arg === "number" && ( arg === 1 || arg === 0 ) ) {
13+ return new Bool ( arg === 1 ) ;
14+ }
15+ // Accept string '1'/'0'
16+ if ( typeof arg === "string" && ( arg === "1" || arg === "0" ) ) {
17+ return new Bool ( arg === "1" ) ;
18+ }
19+ throw new Error ( `Cannot serialize argument as bool: ${ arg } ` ) ;
20+ }
21+ // TODO: Implement other types
22+ throw new Error ( `Cannot serialize argument for typeTag: ${ typeTag } ` ) ;
23+ }
24+
25+ export function deserialize ( typeTag : TypeTag , arg : EntryFunctionArgumentTypes ) : SimpleEntryFunctionArgumentTypes {
26+ if ( typeTag . isBool ( ) ) {
27+ if ( arg instanceof Bool ) {
28+ return arg . value ;
29+ }
30+ throw new Error ( `Cannot deserialize argument as bool: ${ arg } ` ) ;
31+ }
32+ // TODO: Implement other types
33+ throw new Error ( `Cannot deserialize argument for typeTag: ${ typeTag } ` ) ;
34+ }
You can’t perform that action at this time.
0 commit comments