@@ -392,51 +392,100 @@ type PoolRegistrationCertificate struct {
392
392
393
393
func (p * PoolRegistrationCertificate ) UnmarshalJSON (data []byte ) error {
394
394
type Alias PoolRegistrationCertificate
395
+
396
+ // Temporary struct for initial unmarshaling
395
397
aux := & struct {
396
- Margin interface {} `json:"margin"`
397
- RewardAccount struct {
398
- Credential struct {
399
- KeyHash string `json:"key hash"`
400
- } `json:"credential"`
401
- Network string `json:"network"`
402
- } `json:"rewardAccount"`
398
+ Operator string `json:"operator"`
399
+ VrfKeyHash string `json:"vrfKeyHash"`
400
+ Pledge uint64 `json:"pledge"`
401
+ Cost uint64 `json:"cost"`
402
+ Margin json.RawMessage `json:"margin"`
403
+ RewardAccount json.RawMessage `json:"rewardAccount"`
404
+ PoolOwners []string `json:"poolOwners"`
405
+ Relays []PoolRelay `json:"relays"`
406
+ PoolMetadata * PoolMetadata `json:"poolMetadata,omitempty"`
403
407
* Alias
404
408
}{
405
409
Alias : (* Alias )(p ),
406
410
}
407
411
408
- if err := json .Unmarshal (data , & aux ); err != nil {
409
- return err
412
+ if err := json .Unmarshal (data , aux ); err != nil {
413
+ return fmt . Errorf ( "failed to unmarshal pool registration: %w" , err )
410
414
}
411
415
416
+ p .Cost = aux .Cost
417
+
412
418
// Handle margin field
413
- switch v := aux .Margin .(type ) {
414
- case float64 :
415
- p .Margin .Rat = new (big.Rat ).SetFloat64 (v )
416
- case []interface {}:
417
- if len (v ) == 2 {
418
- if num , ok := v [0 ].(float64 ); ok {
419
- if den , ok := v [1 ].(float64 ); ok {
420
- p .Margin .Rat = new (big.Rat ).SetFrac64 (int64 (num ), int64 (den ))
419
+ if len (aux .Margin ) > 0 {
420
+ var marginValue interface {}
421
+ if err := json .Unmarshal (aux .Margin , & marginValue ); err != nil {
422
+ return fmt .Errorf ("failed to unmarshal margin: %w" , err )
423
+ }
424
+
425
+ switch v := marginValue .(type ) {
426
+ case float64 :
427
+ p .Margin .Rat = new (big.Rat ).SetFloat64 (v )
428
+ case []interface {}:
429
+ if len (v ) == 2 {
430
+ if num , ok := v [0 ].(float64 ); ok {
431
+ if den , ok := v [1 ].(float64 ); ok && den != 0 {
432
+ p .Margin .Rat = new (big.Rat ).SetFrac64 (int64 (num ), int64 (den ))
433
+ }
421
434
}
422
435
}
423
436
}
424
- default :
425
- p .Margin .Rat = new (big.Rat ).SetInt64 (0 )
426
437
}
427
438
428
439
// Handle reward account
429
- if aux .RewardAccount .Credential .KeyHash != "" {
430
- hashBytes , err := hex .DecodeString (aux .RewardAccount .Credential .KeyHash )
440
+ if len (aux .RewardAccount ) > 0 {
441
+ var rewardAccount struct {
442
+ Credential struct {
443
+ KeyHash string `json:"key hash"`
444
+ } `json:"credential"`
445
+ }
446
+ if err := json .Unmarshal (aux .RewardAccount , & rewardAccount ); err != nil {
447
+ return fmt .Errorf ("failed to unmarshal reward account: %w" , err )
448
+ }
449
+
450
+ if rewardAccount .Credential .KeyHash != "" {
451
+ hashBytes , err := hex .DecodeString (rewardAccount .Credential .KeyHash )
452
+ if err != nil {
453
+ return fmt .Errorf ("failed to decode reward account key hash: %w" , err )
454
+ }
455
+ var hash Blake2b224
456
+ copy (hash [:], hashBytes )
457
+ p .RewardAccount = AddrKeyHash (hash )
458
+ }
459
+ }
460
+
461
+ // Convert string fields to binary types
462
+ if aux .Operator != "" {
463
+ opBytes , err := hex .DecodeString (aux .Operator )
431
464
if err != nil {
432
- return fmt .Errorf ("failed to decode reward account key hash : %w" , err )
465
+ return fmt .Errorf ("invalid operator key: %w" , err )
433
466
}
434
- if len (hashBytes ) != 28 {
435
- return fmt .Errorf ("invalid key hash length: expected 28, got %d" , len (hashBytes ))
467
+ p .Operator = PoolKeyHash (Blake2b224 (opBytes ))
468
+ }
469
+
470
+ if aux .VrfKeyHash != "" {
471
+ vrfBytes , err := hex .DecodeString (aux .VrfKeyHash )
472
+ if err != nil {
473
+ return fmt .Errorf ("invalid VRF key hash: %w" , err )
474
+ }
475
+ p .VrfKeyHash = VrfKeyHash (Blake2b256 (vrfBytes ))
476
+ }
477
+
478
+ // Convert pool owners
479
+ if len (aux .PoolOwners ) > 0 {
480
+ owners := make ([]AddrKeyHash , len (aux .PoolOwners ))
481
+ for i , owner := range aux .PoolOwners {
482
+ ownerBytes , err := hex .DecodeString (owner )
483
+ if err != nil {
484
+ return fmt .Errorf ("invalid pool owner key: %w" , err )
485
+ }
486
+ owners [i ] = AddrKeyHash (Blake2b224 (ownerBytes ))
436
487
}
437
- var hash Blake2b224
438
- copy (hash [:], hashBytes )
439
- p .RewardAccount = hash
488
+ p .PoolOwners = owners
440
489
}
441
490
442
491
return nil
0 commit comments