Skip to content

Commit 96ccf52

Browse files
authored
Merge pull request #304 from blinklabs-io/fix/ledger-address-stake-address
fix: generate stake address for script address
2 parents a651fa0 + e48332e commit 96ccf52

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ledger/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func (a *Address) MarshalCBOR() ([]byte, error) {
251251
}
252252

253253
// StakeAddress returns a new Address with only the stake key portion. This will return nil if the address is not a payment/staking key pair
254-
func (a *Address) StakeAddress() *Address {
255-
if a.addressType != addressTypeKeyKey {
254+
func (a Address) StakeAddress() *Address {
255+
if a.addressType != addressTypeKeyKey && a.addressType != addressTypeScriptKey {
256256
return nil
257257
}
258258
newAddr := &Address{

ledger/common_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func TestAddressStakeAddress(t *testing.T) {
152152
address: "addr1q9h4f2vhh5vnqgnsejan3psw6mj3a504fxlqm2eh3262qufesdvfs83ulr22vprsv9mwnt0vgkfwxlflxkns32twqzdqjpq2na",
153153
expectedStakeAddress: "stake1uyucxkycrc70349xq3cxzahf4hkytyhr05lntfcg49hqpxsqlrayk",
154154
},
155+
// Script address
156+
{
157+
address: "addr1z8snz7c4974vzdpxu65ruphl3zjdvtxw8strf2c2tmqnxz2j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq0xmsha",
158+
expectedStakeAddress: "stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz",
159+
},
155160
}
156161
for _, testDef := range testDefs {
157162
addr, err := NewAddress(testDef.address)

0 commit comments

Comments
 (0)