Skip to content

Plutus V4 ledger api types as per #7342#7846

Open
SeungheonOh wants to merge 1 commit into
masterfrom
sho/pv4
Open

Plutus V4 ledger api types as per #7342#7846
SeungheonOh wants to merge 1 commit into
masterfrom
sho/pv4

Conversation

@SeungheonOh

@SeungheonOh SeungheonOh commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Adds Plutus Ledger Api types for PlutusV4 as per #7342

ledger API types are not fully finalized yet

@lehins lehins 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 great! Thank you!
Just a few last moment changes that I thought of during the review.

data AccountBalanceInterval
= AccountBalanceLowerBound V2.Lovelace
| AccountBalanceUpperBound V2.Lovelace
| AccountBalanceBothBounds V2.Lovelace V2.Lovelace

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.

Let's add one more case, which will be a nice optimization, so instead of specifying AccountBalanceBothBounds x (x+1), one can simply say AccountBalanceExact x. This seem s like can be a common case and it will be better for Tx serialization size and probably for DApp execution too.
We already have it in the works on the ledger side: IntersectMBO/cardano-ledger#5922

Suggested change
| AccountBalanceBothBounds V2.Lovelace V2.Lovelace
| AccountBalanceBothBounds V2.Lovelace V2.Lovelace
| AccountBalanceExact V2.Lovelace


data TopTxInfo = TopTxInfo
{ topTxInfoSubTransactions :: [TxInfo]
, topTxInfoDatums :: Map V3.TxId V2.Datum

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.

Question about this field.
Considering that topTxInfoSubTransactions will contain the TxId, getting it would be as simple as:

getTxId txIx = txInfoId (topTxInfoSubTransactions txInfos !! txIx)

Finding an index is also possible, but arguably is more expensive:

getTxIx txId = fromJust $ txInfoSubTxIx =<< find ((== txId) . txInfoId) (topTxInfoSubTransactions txInfos)

So, the question is, would it be better to supply the index of sub transaction instead of TxId in this Map?

Suggested change
, topTxInfoDatums :: Map V3.TxId V2.Datum
, topTxInfoDatums :: Map Haskell.Integer V2.Datum

Comment on lines +207 to +208
, txInfoWithdrawals :: Map V2.Credential V2.Lovelace
, txInfoDirectDeposits :: Map V2.Credential V2.Lovelace

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.

Let's change these to AccountId

Suggested change
, txInfoWithdrawals :: Map V2.Credential V2.Lovelace
, txInfoDirectDeposits :: Map V2.Credential V2.Lovelace
, txInfoWithdrawals :: Map AccountId V2.Lovelace
, txInfoDirectDeposits :: Map AccountId V2.Lovelace

Comment on lines +256 to +257
, ttisWithdrawals :: Map V2.Credential V2.Lovelace
, ttisDirectDeposits :: Map V2.Credential V2.Lovelace

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.

Ditto

Suggested change
, ttisWithdrawals :: Map V2.Credential V2.Lovelace
, ttisDirectDeposits :: Map V2.Credential V2.Lovelace
, ttisWithdrawals :: Map AccountId V2.Lovelace
, ttisDirectDeposits :: Map AccountId V2.Lovelace

Comment on lines +259 to +260
, ttisGuards :: [V2.Credential]
, ttisRequiredTopLevelGuards :: Map V2.Credential ()

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.

Actually, now looking at this, makes me realize there is no point in having ttisRequiredTopLevelGuards, since they all will be also present in the ttisGuards field. So, instead we'll turn ttisGuards into a Set and remove ttisRequiredTopLevelGuards

Suggested change
, ttisGuards :: [V2.Credential]
, ttisRequiredTopLevelGuards :: Map V2.Credential ()
, ttisGuards :: Map V2.Credential ()

findContinuingOutputs _ = PlutusTx.traceError "Le"
{-# INLINEABLE findContinuingOutputs #-}

getContinuingOutputs :: ScriptContext -> [V2.TxOut]

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.

It is important to point out that "ContinuingOutputs" functions only look into individual sub-transaction/top level transaction, not at the whole transaction, which is technically all that they can do for the "Spending" purpose

@zliu41 zliu41 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM once Alexey's comments are incorporated.

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.

3 participants