15
15
package babbage
16
16
17
17
import (
18
- "encoding/hex"
19
18
"encoding/json"
20
19
"errors"
21
20
"fmt"
@@ -66,15 +65,15 @@ func (BabbageBlock) Type() int {
66
65
return BlockTypeBabbage
67
66
}
68
67
69
- func (b * BabbageBlock ) Hash () string {
68
+ func (b * BabbageBlock ) Hash () common. Blake2b256 {
70
69
return b .BlockHeader .Hash ()
71
70
}
72
71
73
72
func (b * BabbageBlock ) Header () common.BlockHeader {
74
73
return b .BlockHeader
75
74
}
76
75
77
- func (b * BabbageBlock ) PrevHash () string {
76
+ func (b * BabbageBlock ) PrevHash () common. Blake2b256 {
78
77
return b .BlockHeader .PrevHash ()
79
78
}
80
79
@@ -119,7 +118,6 @@ func (b *BabbageBlock) Transactions() []common.Transaction {
119
118
120
119
func (b * BabbageBlock ) Utxorpc () * utxorpc.Block {
121
120
txs := []* utxorpc.Tx {}
122
- tmpHash , _ := hex .DecodeString (b .Hash ())
123
121
for _ , t := range b .Transactions () {
124
122
tx := t .Utxorpc ()
125
123
txs = append (txs , tx )
@@ -128,7 +126,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
128
126
Tx : txs ,
129
127
}
130
128
header := & utxorpc.BlockHeader {
131
- Hash : tmpHash ,
129
+ Hash : b . Hash (). Bytes () ,
132
130
Height : b .BlockNumber (),
133
131
Slot : b .SlotNumber (),
134
132
}
@@ -142,7 +140,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
142
140
type BabbageBlockHeader struct {
143
141
cbor.StructAsArray
144
142
cbor.DecodeStoreCbor
145
- hash string
143
+ hash * common. Blake2b256
146
144
Body BabbageBlockHeaderBody
147
145
Signature []byte
148
146
}
@@ -179,16 +177,16 @@ func (h *BabbageBlockHeader) UnmarshalCBOR(cborData []byte) error {
179
177
return h .UnmarshalCbor (cborData , h )
180
178
}
181
179
182
- func (h * BabbageBlockHeader ) Hash () string {
183
- if h .hash == "" {
180
+ func (h * BabbageBlockHeader ) Hash () common. Blake2b256 {
181
+ if h .hash == nil {
184
182
tmpHash := common .Blake2b256Hash (h .Cbor ())
185
- h .hash = hex . EncodeToString ( tmpHash . Bytes ())
183
+ h .hash = & tmpHash
186
184
}
187
- return h .hash
185
+ return * h .hash
188
186
}
189
187
190
- func (h * BabbageBlockHeader ) PrevHash () string {
191
- return h .Body .PrevHash . String ()
188
+ func (h * BabbageBlockHeader ) PrevHash () common. Blake2b256 {
189
+ return h .Body .PrevHash
192
190
}
193
191
194
192
func (h * BabbageBlockHeader ) BlockNumber () uint64 {
@@ -282,10 +280,6 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
282
280
input := ri .Utxorpc ()
283
281
txri = append (txri , input )
284
282
}
285
- tmpHash , err := hex .DecodeString (b .Hash ())
286
- if err != nil {
287
- return & utxorpc.Tx {}
288
- }
289
283
tx := & utxorpc.Tx {
290
284
Inputs : txi ,
291
285
Outputs : txo ,
@@ -299,7 +293,7 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
299
293
// Successful: b.Successful(),
300
294
// Auxiliary: b.AuxData(),
301
295
// Validity: b.Validity(),
302
- Hash : tmpHash ,
296
+ Hash : b . Hash (). Bytes () ,
303
297
}
304
298
return tx
305
299
}
@@ -523,7 +517,7 @@ func (BabbageTransaction) Type() int {
523
517
return TxTypeBabbage
524
518
}
525
519
526
- func (t BabbageTransaction ) Hash () string {
520
+ func (t BabbageTransaction ) Hash () common. Blake2b256 {
527
521
return t .Body .Hash ()
528
522
}
529
523
@@ -630,7 +624,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
630
624
ret = append (
631
625
ret ,
632
626
common.Utxo {
633
- Id : shelley .NewShelleyTransactionInput (t .Hash (), idx ),
627
+ Id : shelley .NewShelleyTransactionInput (t .Hash (). String () , idx ),
634
628
Output : output ,
635
629
},
636
630
)
@@ -642,7 +636,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
642
636
}
643
637
return []common.Utxo {
644
638
{
645
- Id : shelley .NewShelleyTransactionInput (t .Hash (), len (t .Outputs ())),
639
+ Id : shelley .NewShelleyTransactionInput (t .Hash (). String () , len (t .Outputs ())),
646
640
Output : t .CollateralReturn (),
647
641
},
648
642
}
0 commit comments