Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions packages/protocol/src/model/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
Struct,
} from "o1js";

import { assert } from "../state/assert/assert";

export class ProvableOption extends Struct({
isSome: Bool,
value: Field,
Expand Down Expand Up @@ -154,6 +156,15 @@ export class Option<Value> 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<Value>).fromFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading