Skip to content

Add CIP-159 account balance intervals to builders and debug views - #1483

Open
Jimbo4350 wants to merge 3 commits into
masterfrom
feature/cip159-account-balance-intervals
Open

Jimbo4350 wants to merge 3 commits into
masterfrom
feature/cip159-account-balance-intervals

Conversation

@Jimbo4350

Copy link
Copy Markdown
Contributor

Context

Expose CIP-159 account balance assertions in Dijkstra transaction builders and debug views. Transactions can specify exact, lower-bound, upper-bound, or two-bound assertions using quoted comparison syntax:

--account-balance-interval 'stake_test1...>=100,<200'
--starting-account-balance-interval 'stake_test1...=300'

Amounts are in lovelace. Both options are supported by transaction build, build-raw, and build-estimate; sub-transaction build-raw supports ordinary intervals only. Starting assertions refer to the balance before the whole transaction; ordinary assertions refer to the balance before that level’s own changes, after earlier sub-transactions.

JSON/YAML transaction views now show both top-level fields and an ordered summary of embedded sub-transaction IDs and ordinary intervals.

How to trust this PR

  • Reuses the ledger interval types and existing API setters before balancing and script evaluation. Exact assertions remain distinct from ranges.
  • Rejects malformed expressions, unsupported address formats, out-of-range amounts, and duplicate accounts within each field. Online builds reject duplicate assertions before querying the node. Equal or reversed bounds remain encodable, matching the ledger representation.
  • Tests decode constructed transactions to verify preservation through building, signing, and embedding, and check offline fee/change estimation. Help and JSON/YAML goldens cover syntax, era gating, both interval fields, and nested output.

Validation completed locally:

  • CLI and both test executables built successfully with warnings treated as errors.
  • 49 focused transaction tests passed, including interval, direct-deposit, and sub-transaction coverage.
  • 627 help/view golden tests passed with regeneration disabled after reviewing updated fixtures.
  • Fourmolu and git diff --check passed.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

Jimbo4350 added a commit that referenced this pull request Oct 23, 2026
@Jimbo4350
Jimbo4350 force-pushed the feature/cip159-account-balance-intervals branch from 5ac4a12 to 10b6474 Compare October 23, 2026 19:21
Comment on lines +132 to +135
concat
[ ["dijkstra", "sub-transaction", "sign"]
, ["--sub-tx-file", body, "--signing-key-file", key, "--out-file", out]
]
Comment on lines +139 to +142
concat
[ ["--account-balance-interval", account ++ ">=100,<200"]
, ["--account-balance-interval", otherAccount ++ "=42"]
]
Comment on lines +159 to +162
concat
[ ["dijkstra", "transaction", "sign"]
, ["--tx-body-file", bodyFile, "--signing-key-file", key, "--out-file", signedFile]
]
@Jimbo4350
Jimbo4350 force-pushed the feature/cip159-account-balance-intervals branch 2 times, most recently from 81c3596 to 7c42061 Compare October 23, 2026 19:37
@Jimbo4350
Jimbo4350 marked this pull request as ready for review October 23, 2026 19:37
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Ledger-facing changes across balancing, signing, and embedding warrant human confirmation of the reported runtime validation.

No open issues 🎉

What changed in this PR

Adds CIP-159 account balance assertions to Dijkstra transaction builders and exposes them in debug views, using existing ledger types and API setters.

Changes:

  • Adds comparison-based interval options, era gating, and duplicate-account validation.
  • Displays ordinary and starting intervals, plus ordered sub-transaction summaries, in JSON/YAML views.
  • Adds round-trip, rejection, estimation, and golden coverage; simplifies existing direct-deposit tests.
File Description
cardano-cli/​test/​cardano-cli-test/​Test/​Cli/​Transaction/​DirectDeposit.hs Simplifies existing tests without changing their assertions.
cardano-cli/​test/​cardano-cli-test/​Test/​Cli/​Transaction/​AccountBalanceInterval.hs Tests interval preservation, validation, gating, and estimation.
cardano-cli/​test/​cardano-cli-golden/​Test/​Golden/​Debug/​TransactionView.hs Tests signed and unsigned interval views.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_build.cli Records interval options and help for online builds.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_build-raw.cli Records interval options and help for raw builds.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_build-estimate.cli Records interval options and help for estimated builds.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_sub-transaction_build-raw.cli Records ordinary interval support for sub-transactions.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help.cli Updates combined help output.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction/​build-raw-plutus-v4-script-witnesses.out Adds empty interval and sub-transaction fields.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-intervals.yaml Adds unsigned YAML interval output.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-intervals.json Adds unsigned JSON interval output.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-intervals-signed.yaml Adds signed YAML interval output.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-intervals-signed.json Adds signed JSON interval output.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-direct-deposits.yaml Updates deposit views with empty interval fields.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction-view-direct-deposits.json Updates deposit views with empty interval fields.
cardano-cli/​src/​Cardano/​CLI/​Type/​Error/​TxCmdError.hs Adds duplicate-interval account errors.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Run.hs Validates and applies sub-transaction intervals.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Option.hs Wires ordinary interval parsing into sub-transactions.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Command.hs Adds interval arguments to sub-transaction commands.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Run.hs Propagates both interval fields through transaction builders.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Option.hs Wires both interval options into all three builders.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Internal/​Common.hs Adds interval conversion and shared duplicate detection.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Command.hs Adds both interval fields to builder arguments.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Common/​Option.hs Defines comparison parsing, era gating, and help text.
cardano-cli/​src/​Cardano/​CLI/​Compatible/​Json/​Friendly.hs Renders interval fields and ordered sub-transaction summaries.
cardano-cli/​cardano-cli.cabal Registers the interval test module.
.changes/​20261023_account_balance_intervals.yml Documents the new feature.

Review effort: Balanced

Comment thread cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs Outdated
Comment thread cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs Outdated
Comment thread .changes/20261023_account_balance_intervals.yml Outdated
assertInvalidOption flag [era, "transaction", command]
assertInvalidOption "--starting-account-balance-interval" subTransactionArgs

hprop_account_balance_intervals_validate_before_node_query :: Property

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test runs the online transaction build path only up to the duplicate-account rejection, which fires before the node is queried, and hprop_account_balance_intervals_build_estimate builds without a script. Nothing here covers balancing or script evaluation with intervals set. Is a cardano-testnet test planned for a successful online build with intervals?

Comment thread cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs Outdated
Comment thread cardano-cli/test/cardano-cli-test/Test/Cli/Transaction/AccountBalanceInterval.hs Outdated
Comment thread cardano-cli/src/Cardano/CLI/EraBased/Transaction/Internal/Common.hs
Comment thread cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs Outdated

@palas palas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid. I wrote a couple of small potential improvements

Comment thread cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs Outdated
Comment thread cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs Outdated
Comment thread cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs Outdated
Comment thread cardano-cli/test/cardano-cli-test/Test/Cli/Transaction/AccountBalanceInterval.hs Outdated
@Jimbo4350
Jimbo4350 force-pushed the feature/cip159-account-balance-intervals branch from 5fc8a3c to 4a1d814 Compare October 26, 2026 21:04
@Jimbo4350
Jimbo4350 force-pushed the feature/cip159-account-balance-intervals branch from 4a1d814 to 9003c63 Compare October 26, 2026 21:15
@Jimbo4350
Jimbo4350 enabled auto-merge October 26, 2026 21:16
@Jimbo4350
Jimbo4350 added this pull request to the merge queue Oct 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants