@@ -155,11 +155,69 @@ func (b *BabbageTransactionBody) Outputs() []TransactionOutput {
155155 return ret
156156}
157157
158+ const (
159+ DatumOptionTypeHash = 0
160+ DatumOptionTypeData = 1
161+ )
162+
163+ type BabbageTransactionOutputDatumOption struct {
164+ hash * Blake2b256
165+ data * cbor.LazyValue
166+ }
167+
168+ func (d * BabbageTransactionOutputDatumOption ) UnmarshalCBOR (data []byte ) error {
169+ datumOptionType , err := cbor .DecodeIdFromList (data )
170+ if err != nil {
171+ return err
172+ }
173+ switch datumOptionType {
174+ case DatumOptionTypeHash :
175+ var tmpDatumHash struct {
176+ cbor.StructAsArray
177+ Type int
178+ Hash Blake2b256
179+ }
180+ if _ , err := cbor .Decode (data , & tmpDatumHash ); err != nil {
181+ return err
182+ }
183+ d .hash = & (tmpDatumHash .Hash )
184+ case DatumOptionTypeData :
185+ var tmpDatumData struct {
186+ cbor.StructAsArray
187+ Type int
188+ DataCbor []byte
189+ }
190+ if _ , err := cbor .Decode (data , & tmpDatumData ); err != nil {
191+ return err
192+ }
193+ var datumValue cbor.LazyValue
194+ if _ , err := cbor .Decode (tmpDatumData .DataCbor , & datumValue ); err != nil {
195+ return err
196+ }
197+ d .data = & (datumValue )
198+ default :
199+ return fmt .Errorf ("unsupported datum option type: %d" , datumOptionType )
200+ }
201+ return nil
202+ }
203+
204+ func (d * BabbageTransactionOutputDatumOption ) MarshalCBOR () ([]byte , error ) {
205+ var tmpObj []interface {}
206+ if d .hash != nil {
207+ tmpObj = []interface {}{DatumOptionTypeHash , d .hash }
208+ } else if d .data != nil {
209+ tmpObj = []interface {}{DatumOptionTypeData , cbor.Tag {Number : 24 , Content : d .data .Cbor ()}}
210+ } else {
211+ return nil , fmt .Errorf ("unknown datum option type" )
212+ }
213+ return cbor .Encode (& tmpObj )
214+ }
215+
158216type BabbageTransactionOutput struct {
159- OutputAddress Address `cbor:"0,keyasint,omitempty"`
160- OutputAmount MaryTransactionOutputValue `cbor:"1,keyasint,omitempty"`
161- DatumOption []cbor. RawMessage `cbor:"2,keyasint,omitempty"`
162- ScriptRef cbor.Tag `cbor:"3,keyasint,omitempty"`
217+ OutputAddress Address `cbor:"0,keyasint,omitempty"`
218+ OutputAmount MaryTransactionOutputValue `cbor:"1,keyasint,omitempty"`
219+ DatumOption * BabbageTransactionOutputDatumOption `cbor:"2,keyasint,omitempty"`
220+ ScriptRef * cbor.Tag `cbor:"3,keyasint,omitempty"`
163221 legacyOutput bool
164222}
165223
@@ -202,6 +260,20 @@ func (o BabbageTransactionOutput) Assets() *MultiAsset[MultiAssetTypeOutput] {
202260 return o .OutputAmount .Assets
203261}
204262
263+ func (o BabbageTransactionOutput ) DatumHash () * Blake2b256 {
264+ if o .DatumOption != nil {
265+ return o .DatumOption .hash
266+ }
267+ return nil
268+ }
269+
270+ func (o BabbageTransactionOutput ) Datum () * cbor.LazyValue {
271+ if o .DatumOption != nil {
272+ return o .DatumOption .data
273+ }
274+ return nil
275+ }
276+
205277type BabbageTransactionWitnessSet struct {
206278 AlonzoTransactionWitnessSet
207279 PlutusV2Scripts []cbor.RawMessage `cbor:"6,keyasint,omitempty"`
0 commit comments