Skip to content

Commit

Permalink
Layouts: Add boolItem, export NamedLayoutItem (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored Apr 22, 2024
1 parent 5799264 commit 882a913
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/base/src/utils/layout/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export type BytesLayoutItem =
LengthPrefixedLayoutBytes;
export type ArrayLayoutItem = FixedLengthArray | LengthPrefixedArray | RemainderArray;
export type LayoutItem = NumLayoutItem | BytesLayoutItem | ArrayLayoutItem | SwitchLayoutItem;
type NamedLayoutItem = LayoutItem & { readonly name: string };
export type NamedLayoutItem = LayoutItem & { readonly name: string };
export type ProperLayout = readonly NamedLayoutItem[];
export type Layout = LayoutItem | ProperLayout;

Expand Down
10 changes: 10 additions & 0 deletions core/definitions/src/layout-items/boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CustomConversion, UintLayoutItem } from "@wormhole-foundation/sdk-base";

export const boolItem = {
binary: "uint",
size: 1,
custom: {
to: (encoded: number): boolean => encoded > 0,
from: (val: boolean): number => (val ? 1 : 0),
} satisfies CustomConversion<number, boolean>,
} as const satisfies UintLayoutItem;
1 change: 1 addition & 0 deletions core/definitions/src/layout-items/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./amount.js";
export * from "./boolean.js";
export * from "./chain.js";
export * from "./circle.js";
export * from "./guardianSet.js";
Expand Down

0 comments on commit 882a913

Please sign in to comment.