@@ -269,7 +269,11 @@ func (a *Address) UnmarshalCBOR(data []byte) error {
269
269
}
270
270
271
271
func (a * Address ) MarshalCBOR () ([]byte , error ) {
272
- addrBytes := a .Bytes ()
272
+ addrBytes , err := a .Bytes ()
273
+ if err != nil {
274
+ return nil , fmt .Errorf ("failed to get address bytes: %w" , err )
275
+ }
276
+
273
277
if a .addressType == AddressTypeByron {
274
278
return addrBytes , nil
275
279
}
@@ -376,7 +380,7 @@ func (a Address) generateHRP() string {
376
380
}
377
381
378
382
// Bytes returns the underlying bytes for the address
379
- func (a Address ) Bytes () []byte {
383
+ func (a Address ) Bytes () ( []byte , error ) {
380
384
if a .addressType == AddressTypeByron {
381
385
tmpPayload := []any {
382
386
a .paymentAddress ,
@@ -385,8 +389,7 @@ func (a Address) Bytes() []byte {
385
389
}
386
390
rawPayload , err := cbor .Encode (tmpPayload )
387
391
if err != nil {
388
- // TODO: handle error (#851)
389
- return nil
392
+ return nil , fmt .Errorf ("failed to encode Byron address payload: %w" , err )
390
393
}
391
394
tmpData := []any {
392
395
cbor.Tag {
@@ -397,10 +400,9 @@ func (a Address) Bytes() []byte {
397
400
}
398
401
ret , err := cbor .Encode (tmpData )
399
402
if err != nil {
400
- // TODO: handle error (#851)
401
- return nil
403
+ return nil , fmt .Errorf ("failed to encode Byron address data: %w" , err )
402
404
}
403
- return ret
405
+ return ret , nil
404
406
}
405
407
ret := []byte {}
406
408
ret = append (
@@ -410,12 +412,15 @@ func (a Address) Bytes() []byte {
410
412
ret = append (ret , a .paymentAddress ... )
411
413
ret = append (ret , a .stakingAddress ... )
412
414
ret = append (ret , a .extraData ... )
413
- return ret
415
+ return ret , nil
414
416
}
415
417
416
418
// String returns the bech32-encoded version of the address
417
419
func (a Address ) String () string {
418
- data := a .Bytes ()
420
+ data , err := a .Bytes ()
421
+ if err != nil {
422
+ panic (fmt .Sprintf ("failed to get address bytes: %v" , err ))
423
+ }
419
424
if a .addressType == AddressTypeByron {
420
425
// Encode data to base58
421
426
encoded := base58 .Encode (data )
0 commit comments