1515package babbage
1616
1717import (
18- "encoding/hex"
1918 "encoding/json"
2019 "errors"
2120 "fmt"
@@ -66,15 +65,15 @@ func (BabbageBlock) Type() int {
6665 return BlockTypeBabbage
6766}
6867
69- func (b * BabbageBlock ) Hash () string {
68+ func (b * BabbageBlock ) Hash () common. Blake2b256 {
7069 return b .BlockHeader .Hash ()
7170}
7271
7372func (b * BabbageBlock ) Header () common.BlockHeader {
7473 return b .BlockHeader
7574}
7675
77- func (b * BabbageBlock ) PrevHash () string {
76+ func (b * BabbageBlock ) PrevHash () common. Blake2b256 {
7877 return b .BlockHeader .PrevHash ()
7978}
8079
@@ -119,7 +118,6 @@ func (b *BabbageBlock) Transactions() []common.Transaction {
119118
120119func (b * BabbageBlock ) Utxorpc () * utxorpc.Block {
121120 txs := []* utxorpc.Tx {}
122- tmpHash , _ := hex .DecodeString (b .Hash ())
123121 for _ , t := range b .Transactions () {
124122 tx := t .Utxorpc ()
125123 txs = append (txs , tx )
@@ -128,7 +126,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
128126 Tx : txs ,
129127 }
130128 header := & utxorpc.BlockHeader {
131- Hash : tmpHash ,
129+ Hash : b . Hash (). Bytes () ,
132130 Height : b .BlockNumber (),
133131 Slot : b .SlotNumber (),
134132 }
@@ -142,7 +140,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
142140type BabbageBlockHeader struct {
143141 cbor.StructAsArray
144142 cbor.DecodeStoreCbor
145- hash string
143+ hash * common. Blake2b256
146144 Body BabbageBlockHeaderBody
147145 Signature []byte
148146}
@@ -179,16 +177,16 @@ func (h *BabbageBlockHeader) UnmarshalCBOR(cborData []byte) error {
179177 return h .UnmarshalCbor (cborData , h )
180178}
181179
182- func (h * BabbageBlockHeader ) Hash () string {
183- if h .hash == "" {
180+ func (h * BabbageBlockHeader ) Hash () common. Blake2b256 {
181+ if h .hash == nil {
184182 tmpHash := common .Blake2b256Hash (h .Cbor ())
185- h .hash = hex . EncodeToString ( tmpHash . Bytes ())
183+ h .hash = & tmpHash
186184 }
187- return h .hash
185+ return * h .hash
188186}
189187
190- func (h * BabbageBlockHeader ) PrevHash () string {
191- return h .Body .PrevHash . String ()
188+ func (h * BabbageBlockHeader ) PrevHash () common. Blake2b256 {
189+ return h .Body .PrevHash
192190}
193191
194192func (h * BabbageBlockHeader ) BlockNumber () uint64 {
@@ -282,10 +280,6 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
282280 input := ri .Utxorpc ()
283281 txri = append (txri , input )
284282 }
285- tmpHash , err := hex .DecodeString (b .Hash ())
286- if err != nil {
287- return & utxorpc.Tx {}
288- }
289283 tx := & utxorpc.Tx {
290284 Inputs : txi ,
291285 Outputs : txo ,
@@ -299,7 +293,7 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
299293 // Successful: b.Successful(),
300294 // Auxiliary: b.AuxData(),
301295 // Validity: b.Validity(),
302- Hash : tmpHash ,
296+ Hash : b . Hash (). Bytes () ,
303297 }
304298 return tx
305299}
@@ -523,7 +517,7 @@ func (BabbageTransaction) Type() int {
523517 return TxTypeBabbage
524518}
525519
526- func (t BabbageTransaction ) Hash () string {
520+ func (t BabbageTransaction ) Hash () common. Blake2b256 {
527521 return t .Body .Hash ()
528522}
529523
@@ -630,7 +624,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
630624 ret = append (
631625 ret ,
632626 common.Utxo {
633- Id : shelley .NewShelleyTransactionInput (t .Hash (), idx ),
627+ Id : shelley .NewShelleyTransactionInput (t .Hash (). String () , idx ),
634628 Output : output ,
635629 },
636630 )
@@ -642,7 +636,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
642636 }
643637 return []common.Utxo {
644638 {
645- Id : shelley .NewShelleyTransactionInput (t .Hash (), len (t .Outputs ())),
639+ Id : shelley .NewShelleyTransactionInput (t .Hash (). String () , len (t .Outputs ())),
646640 Output : t .CollateralReturn (),
647641 },
648642 }
0 commit comments