Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
234 stars 125 forks source link

How could I add Mint instance to TransactionBuilder without setting there mint witnesses? #622

Closed zxpectre closed 1 year ago

zxpectre commented 1 year ago

Hi! How could I add a Mint instance to TransactionBuilder without the associated mint witnesses in 11.3.1 version?

This is because since 2021 I'm handling all witnesses and fee manually later and seems redundant to duplicate script witness definitions just for mint code and again later at the end of my code.

I know I could be calling txBody.set_mint() but txBuilder help us calculate the change taking mints into account, i wish to keep relying on your change calculation.

Would be nice to let old "raw or direct" methods to coexist on TransactionBuilder with all the new builder-assisted methods to allow some degree of backward compatibility or manual low level tx handling.

Ideas: Could a dummy MintBuilder that only sets Mint instance work well with txBuilder.set_mint_builder(dummy) ? How could it be implemented on typescript to actually work?

vsubhuman commented 1 year ago

I'm handling all witnesses and fee manually later

i wish to keep relying on your change calculation.

@zxpectre , these two parts contradict each other a bit, because the fee handling and the change calculation is basically the same thing. Overall the fee/change handling is the root issue why all updates to mint-related features are leading toward the witnesses being specified as early as possible, because in order to be able to estimate the size of the transaction as best as possible the builder must know the sizes of native scripts, plutus scripts, and redeemers, and those cannot be mocked.

zxpectre commented 1 year ago

Thanks @vsubhuman , I know I know, I had to ask because I was trying to avoid recoding a lot , code that was already working for me.

Finally I discarded all the old manual minter code I had and start using MintBuilder

Does MintBuilder.add_asset() takes CIP21 (HW) into account right?

lisicky commented 1 year ago

Hi @zxpectre ! Which case do you mean ?

zxpectre commented 1 year ago

Hi @lisicky !

Not sure what else could be taken into consideration but at least anti-duplication and sorting may apply?

Since multiassets (policy_id and asset_name) are represented as maps, both need to be sorted in accordance with the specified canonical CBOR format. Also, an output or the mint field must not contain duplicate policy_ids and a policy must not contain duplicate asset_names.
lisicky commented 1 year ago

@zxpectre policy_id and asset_name are sorted, but policy_id can be duplicated if you mint something with the same script but with different redeemers.

zxpectre commented 1 year ago

Thanks for clarifying that @lisicky ! Ok then, will close this now :)