diff --git a/CHANGELOG.md b/CHANGELOG.md index fe9fd131e..a41e355d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased ### Added +- Added `Option.unwrap()` [#508](https://github.com/proto-kit/framework/pull/508) - Added createdAt timestamp to block, batch and settlement models.[#502](https://github.com/proto-kit/framework/pull/502) - Added missing block detection and recovery in the indexer.[#488](https://github.com/proto-kit/framework/pull/488) - `@dependencyFactory` for static dependency factory type safety diff --git a/packages/protocol/src/model/Option.ts b/packages/protocol/src/model/Option.ts index 818a19cc3..c02e3180b 100644 --- a/packages/protocol/src/model/Option.ts +++ b/packages/protocol/src/model/Option.ts @@ -8,6 +8,8 @@ import { Struct, } from "o1js"; +import { assert } from "../state/assert/assert"; + export class ProvableOption extends Struct({ isSome: Bool, value: Field, @@ -154,6 +156,15 @@ export class Option extends OptionBase { ); } + public isNone(): Bool { + return this.isSome.not(); + } + + public unwrap(): Value { + assert(this.isSome, "Unwrap called on None option"); + return this.value; + } + public toConstant() { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const valueConstant = (this.valueType as ProvablePure).fromFields( diff --git a/packages/protocol/src/state/context/RuntimeMethodExecutionContext.ts b/packages/protocol/src/state/context/RuntimeMethodExecutionContext.ts index a497533c0..dad44f69b 100644 --- a/packages/protocol/src/state/context/RuntimeMethodExecutionContext.ts +++ b/packages/protocol/src/state/context/RuntimeMethodExecutionContext.ts @@ -5,7 +5,7 @@ import { ProvableMethodExecutionResult, } from "@proto-kit/common"; -import { StateTransition } from "../../model/StateTransition"; +import type { StateTransition } from "../../model/StateTransition"; import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction"; import { NetworkState } from "../../model/network/NetworkState";