-
Hey, I am trying to use this library in order to use it. For example In order to create a transaction that resembeles a sale of NFT i need to create a datum that consists of:
If i understand correctly, PlutusData is the interface that resemebles the Datum. You have implemented multiple versions of that interface so our datum instance can be either a list,map,big int or ByteString. I thought on using the list plutus data but that is a problem since our datum needs to have multiple different datatypes and lists in java can only hold one datatype. So is it possible to create a PlutusData object that contains multiple different datatypes objects and if it is then how? And lastly, each class that implements PlutusData has the function ConstrPlutusData: can you please give us a short explaination as to what is alternative. I have seen in your examples that you give it a value of 0 and i am not sure why. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @ofekron33,
Yes, PlutusData is the main interface which is used to represent both Datum and Redeemer data . And as you mentioned, BigIntPlutusData, BytesPlutusData, ListPlutusData, MapPlutusData, ContrPlutusData are different implementations and only supported types in datum or redeemers according to the spec. You can check cbor serialization spec here for more details https://github.com/input-output-hk/cardano-ledger/blob/master/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L274
You can use ListPlutusData with different types. It needs PlutusData. Plz check some examples here
"alternative" is used in ConstrPlutusData which is an another implementation of PlutusData which has two fields alternative and list of fields. This represents a constructor in validator code. If you compare that with cardano-cli's datum json format, alternative = constructor (constructor's no). Heres' a sample json for cardano-cli compatible datum
For above datum, you need to use ConstrPlutusData. You can check these tests. How to use CosntrPlutusData You can also use regular POJO with some annotations to define Datum. But make sure to use allowed types for the POJO's fields (Integer, BigInteger, Long, byte[], String) Check this POJO here BTW, String type is converted to BytesPlutusData.. so String == byte[] For your use case (Martify contract), I think you need to use ConstrPlutusData. If I am not wrong NFTSell is the datum data type here in Haskell.
So in Java, you need to use ConstrPlutusData with alternative=0 as there is only one constructor. All fields except nPrice and nRoyPrct are bytes. You can also implement this in POJO with annotation. I will try datum conversion code in Java for this contract and post later to this discussion. Hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi @ofekron33,
Yes, PlutusData is the main interface which is used to represent both Datum and Redeemer data . And as you mentioned, BigIntPlutusData, BytesPlutusData, ListPlutusData, MapPlutusData, ContrPlutusData are different implementations and only supported types in datum or redeemers according to the spec.
You can check cbor serialization spec here for more details https://github.com/input-output-hk/cardano-ledger/blob/master/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L274