@@ -269,7 +269,11 @@ func (a *Address) UnmarshalCBOR(data []byte) error {
269269}
270270
271271func (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+
273277 if a .addressType == AddressTypeByron {
274278 return addrBytes , nil
275279 }
@@ -376,7 +380,7 @@ func (a Address) generateHRP() string {
376380}
377381
378382// Bytes returns the underlying bytes for the address
379- func (a Address ) Bytes () []byte {
383+ func (a Address ) Bytes () ( []byte , error ) {
380384 if a .addressType == AddressTypeByron {
381385 tmpPayload := []any {
382386 a .paymentAddress ,
@@ -385,8 +389,7 @@ func (a Address) Bytes() []byte {
385389 }
386390 rawPayload , err := cbor .Encode (tmpPayload )
387391 if err != nil {
388- // TODO: handle error (#851)
389- return nil
392+ return nil , fmt .Errorf ("failed to encode Byron address payload: %w" , err )
390393 }
391394 tmpData := []any {
392395 cbor.Tag {
@@ -397,10 +400,9 @@ func (a Address) Bytes() []byte {
397400 }
398401 ret , err := cbor .Encode (tmpData )
399402 if err != nil {
400- // TODO: handle error (#851)
401- return nil
403+ return nil , fmt .Errorf ("failed to encode Byron address data: %w" , err )
402404 }
403- return ret
405+ return ret , nil
404406 }
405407 ret := []byte {}
406408 ret = append (
@@ -410,12 +412,15 @@ func (a Address) Bytes() []byte {
410412 ret = append (ret , a .paymentAddress ... )
411413 ret = append (ret , a .stakingAddress ... )
412414 ret = append (ret , a .extraData ... )
413- return ret
415+ return ret , nil
414416}
415417
416418// String returns the bech32-encoded version of the address
417419func (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+ }
419424 if a .addressType == AddressTypeByron {
420425 // Encode data to base58
421426 encoded := base58 .Encode (data )
0 commit comments