Skip to content

Commit

Permalink
flexible fromValue
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Nov 27, 2023
1 parent 07d117e commit 4fb53e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/from-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function ProvableFromLayout<
toValue(value: T): TValue {
return toValue(typeData, value);
},
fromValue(value: TValue): T {
fromValue(value: TValue | T): T {
return fromValue(typeData, value);
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type GenericProvable<T, TValue, Field> = {
sizeInFields(): number;
check: (x: T) => void;
toValue: (x: T) => TValue;
fromValue: (x: TValue) => T;
fromValue: (x: T | TValue) => T;
};
interface GenericProvablePure<T, TValue, Field>
extends GenericProvable<T, TValue, Field> {
Expand Down
7 changes: 5 additions & 2 deletions mina-transaction/derived-leaves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ function createTokenSymbol<
toValue(t: TokenSymbol<Field>): string {
return self.toJSON(t);
},
fromValue(s: string): TokenSymbol<Field> {
return self.fromJSON(s);
fromValue(s: string | TokenSymbol<Field>): TokenSymbol<Field> {
if (typeof s === 'string') {
return self.fromJSON(s);
}
return s;
},
};
return self;
Expand Down

0 comments on commit 4fb53e4

Please sign in to comment.