Skip to content

Commit a90c6a1

Browse files
author
Jenita
committed
feat: created genesis pools from shelly genesis
Signed-off-by: Jenita <[email protected]>
1 parent c874975 commit a90c6a1

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

ledger/common/certs.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ type PoolRegistrationCertificate struct {
393393
func (p *PoolRegistrationCertificate) UnmarshalJSON(data []byte) error {
394394
type Alias PoolRegistrationCertificate
395395

396-
// Temporary struct for initial unmarshaling
397396
aux := &struct {
398397
Operator string `json:"operator"`
399398
VrfKeyHash string `json:"vrfKeyHash"`
@@ -413,7 +412,10 @@ func (p *PoolRegistrationCertificate) UnmarshalJSON(data []byte) error {
413412
return fmt.Errorf("failed to unmarshal pool registration: %w", err)
414413
}
415414

415+
p.Pledge = aux.Pledge
416416
p.Cost = aux.Cost
417+
p.Relays = aux.Relays
418+
p.PoolMetadata = aux.PoolMetadata
417419

418420
// Handle margin field
419421
if len(aux.Margin) > 0 {
@@ -438,20 +440,27 @@ func (p *PoolRegistrationCertificate) UnmarshalJSON(data []byte) error {
438440

439441
// Handle reward account
440442
if len(aux.RewardAccount) > 0 {
441-
var rewardAccount struct {
442-
Credential struct {
443-
KeyHash string `json:"key hash"`
444-
} `json:"credential"`
443+
type credential struct {
444+
KeyHash string `json:"key hash"`
445445
}
446-
if err := json.Unmarshal(aux.RewardAccount, &rewardAccount); err != nil {
446+
type rewardAccount struct {
447+
Credential credential `json:"credential"`
448+
Network string `json:"network,omitempty"`
449+
}
450+
451+
var ra rewardAccount
452+
if err := json.Unmarshal(aux.RewardAccount, &ra); err != nil {
447453
return fmt.Errorf("failed to unmarshal reward account: %w", err)
448454
}
449455

450-
if rewardAccount.Credential.KeyHash != "" {
451-
hashBytes, err := hex.DecodeString(rewardAccount.Credential.KeyHash)
456+
if ra.Credential.KeyHash != "" {
457+
hashBytes, err := hex.DecodeString(ra.Credential.KeyHash)
452458
if err != nil {
453459
return fmt.Errorf("failed to decode reward account key hash: %w", err)
454460
}
461+
if len(hashBytes) != 28 {
462+
return fmt.Errorf("invalid key hash length: expected 28, got %d", len(hashBytes))
463+
}
455464
var hash Blake2b224
456465
copy(hash[:], hashBytes)
457466
p.RewardAccount = AddrKeyHash(hash)

0 commit comments

Comments
 (0)