@@ -120,16 +120,11 @@ func NewAddressFromParts(
120
120
if len (stakingAddr ) != AddressHashSize {
121
121
return Address {}, fmt .Errorf ("staking key must be exactly %d bytes" , AddressHashSize )
122
122
}
123
-
124
- if addrType == AddressTypeNoneScript && networkId == AddressNetworkTestnet {
125
- header := byte (0xF1 )
126
- addrBytes := append ([]byte {header }, stakingAddr ... )
127
- return NewAddressFromBytes (addrBytes )
128
- }
129
-
130
- header := addrType << 4 | networkId
131
- addrBytes := append ([]byte {header }, stakingAddr ... )
132
- return NewAddressFromBytes (addrBytes )
123
+ return Address {
124
+ addressType : addrType ,
125
+ networkId : networkId ,
126
+ stakingAddress : stakingAddr ,
127
+ }, nil
133
128
}
134
129
135
130
// Handle regular addresses
@@ -141,13 +136,12 @@ func NewAddressFromParts(
141
136
return Address {}, fmt .Errorf ("staking address must be empty or exactly %d bytes" , AddressHashSize )
142
137
}
143
138
144
- header := addrType << 4 | networkId
145
- addrBytes := append ([]byte {header }, paymentAddr ... )
146
- if len (stakingAddr ) > 0 {
147
- addrBytes = append (addrBytes , stakingAddr ... )
148
- }
149
-
150
- return NewAddressFromBytes (addrBytes )
139
+ return Address {
140
+ addressType : addrType ,
141
+ networkId : networkId ,
142
+ paymentAddress : paymentAddr ,
143
+ stakingAddress : stakingAddr ,
144
+ }, nil
151
145
}
152
146
153
147
func NewByronAddressFromParts (
@@ -433,23 +427,33 @@ func (a Address) Bytes() ([]byte, error) {
433
427
},
434
428
crc32 .ChecksumIEEE (rawPayload ),
435
429
}
436
- ret , err := cbor .Encode (tmpData )
437
- if err != nil {
438
- return nil , fmt .Errorf (
439
- "failed to encode Byron address data: %w" ,
440
- err ,
441
- )
430
+ return cbor .Encode (tmpData )
431
+ }
432
+
433
+ // Calculate header byte
434
+ header := (a .addressType << 4 ) | (a .networkId & AddressHeaderNetworkMask )
435
+
436
+ if a .addressType == AddressTypeNoneScript && a .networkId == AddressNetworkTestnet {
437
+ header = (AddressTypeNoneScript << 4 ) | 1
438
+ }
439
+
440
+ // Build address bytes
441
+ ret := []byte {header }
442
+ if a .addressType != AddressTypeNoneKey && a .addressType != AddressTypeNoneScript {
443
+ if len (a .paymentAddress ) != AddressHashSize {
444
+ return nil , fmt .Errorf ("invalid payment address length: %d (expected %d)" ,
445
+ len (a .paymentAddress ), AddressHashSize )
442
446
}
443
- return ret , nil
444
- }
445
- ret := [] byte {}
446
- ret = append (
447
- ret ,
448
- ( a . addressType << 4 ) | ( a . networkId & AddressHeaderNetworkMask ) ,
449
- )
450
- ret = append ( ret , a . paymentAddress ... )
451
- ret = append (ret , a .stakingAddress ... )
452
- ret = append ( ret , a . extraData ... )
447
+ ret = append ( ret , a . paymentAddress ... )
448
+ }
449
+
450
+ if len ( a . stakingAddress ) > 0 {
451
+ if len ( a . stakingAddress ) != AddressHashSize {
452
+ return nil , fmt . Errorf ( "invalid staking address length: %d (expected %d)" ,
453
+ len ( a . stakingAddress ), AddressHashSize )
454
+ }
455
+ ret = append (ret , a .stakingAddress ... )
456
+ }
453
457
return ret , nil
454
458
}
455
459
0 commit comments