Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
92 stars 50 forks source link

Add multi-token-minting constraint #1571

Closed jankun4 closed 8 months ago

jankun4 commented 9 months ago

Currently, if you want to mint two tokens with the same CurrencySymbol but with different TokenNames in one transaction you need to do something like this:

TxConstraints.mustMintCurrencyWithRedeemerUsingScriptRef
          mintingPolicyHash
          redeemer
          tokenName1
          amount1
          ( RefInput $ mkTxUnspentOut
              txInput
              txOutput
          )
  <> TxConstraints.mustMintCurrencyWithRedeemerUsingScriptRef
          mintingPolicyHash
          redeemer
          tokenName2
          amount2
          ( RefInput $ mkTxUnspentOut
              txInput
              txOutput
          )

Note that redeemer must be the same in both cases, so we can predict which branch of OnChain script will be used to validate minting of all of the tokens.

It would be much simpler if instead, we could do something like:

TxConstraints.mustMintCurrencyWithRedeemerUsingScriptRef'
          mintingPolicyHash
          redeemer
          [tokenName1 /\ amount1, tokenName2 /\ amount2]
          ( RefInput $ mkTxUnspentOut
              txInput
              txOutput
          )
klntsky commented 8 months ago

Note that redeemer must be the same in both cases, so we can predict which branch of OnChain script will be used to validate minting of all of the tokens.

This is your product requirements. But others may want to use different redeemers. In any case, there will be some duplication: be it in the list of tokens or in the number of constraints. I think the current interface follows the "keep it simple" principle quite well (in this specific regard, but generally it's poorly designed)

klntsky commented 8 months ago

Your change request is based on the assumption that the same redeemer should be used, which is not true in general for every user. For code clarity, you can trivially define this constraint by yourself.