From 28f231e70151910b929f8baed09b768f3aadbad4 Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 5 May 2025 10:08:33 +0545 Subject: [PATCH 1/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 161 ++++++++++++++++++++++++++++++++--------- 1 file changed, 128 insertions(+), 33 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 35081093..f1e351fd 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -258,9 +258,9 @@ func (c *StakeDelegationCertificate) Type() uint { } type ( - PoolKeyHash = Blake2b224 - PoolMetadataHash = Blake2b256 - VrfKeyHash = Blake2b256 + PoolKeyHash Blake2b224 + PoolMetadataHash Blake2b256 + VrfKeyHash Blake2b256 ) type PoolMetadata struct { @@ -610,8 +610,12 @@ func (c *RegistrationCertificate) UnmarshalCBOR( } func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeRegistration as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeRegistration{ + StakeRegistration: c.StakeCredential.Utxorpc(), + }, + } } func (c *RegistrationCertificate) Type() uint { @@ -642,8 +646,12 @@ func (c *DeregistrationCertificate) UnmarshalCBOR( } func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeDeregistration as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDeregistration{ + StakeDeregistration: c.StakeCredential.Utxorpc(), + }, + } } func (c *DeregistrationCertificate) Type() uint { @@ -674,8 +682,19 @@ func (c *VoteDelegationCertificate) UnmarshalCBOR( } func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeDelegation as fallback, storing Drep in PoolKeyhash + var drepData []byte + if c.Drep.Type == DrepTypeAddrKeyHash || c.Drep.Type == DrepTypeScriptHash { + drepData = c.Drep.Credential + } + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDelegation{ + StakeDelegation: &utxorpc.StakeDelegationCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + PoolKeyhash: drepData, + }, + }, + } } func (c *VoteDelegationCertificate) Type() uint { @@ -707,8 +726,15 @@ func (c *StakeVoteDelegationCertificate) UnmarshalCBOR( } func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeDelegation + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDelegation{ + StakeDelegation: &utxorpc.StakeDelegationCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + PoolKeyhash: c.PoolKeyHash, + }, + }, + } } func (c *StakeVoteDelegationCertificate) Type() uint { @@ -740,8 +766,15 @@ func (c *StakeRegistrationDelegationCertificate) UnmarshalCBOR( } func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeDelegation as base + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDelegation{ + StakeDelegation: &utxorpc.StakeDelegationCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + PoolKeyhash: c.PoolKeyHash, + }, + }, + } } func (c *StakeRegistrationDelegationCertificate) Type() uint { @@ -773,8 +806,15 @@ func (c *VoteRegistrationDelegationCertificate) UnmarshalCBOR( } func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Similar to VoteDelegation + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDelegation{ + StakeDelegation: &utxorpc.StakeDelegationCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + PoolKeyhash: c.Drep.Credential, + }, + }, + } } func (c *VoteRegistrationDelegationCertificate) Type() uint { @@ -793,22 +833,43 @@ type StakeVoteRegistrationDelegationCertificate struct { func (c StakeVoteRegistrationDelegationCertificate) isCertificate() {} -func (c *StakeVoteRegistrationDelegationCertificate) UnmarshalCBOR( - cborData []byte, -) error { - type tStakeVoteRegistrationDelegationCertificate StakeVoteRegistrationDelegationCertificate - var tmp tStakeVoteRegistrationDelegationCertificate +func (c *StakeVoteRegistrationDelegationCertificate) UnmarshalCBOR(cborData []byte) error { + // Temporary struct that matches the CBOR structure + tmp := struct { + cbor.StructAsArray + CertType uint + StakeCredential Credential + Drep Drep + Amount int64 + }{} + if _, err := cbor.Decode(cborData, &tmp); err != nil { return err } - *c = StakeVoteRegistrationDelegationCertificate(tmp) + + // Manually copy fields + c.CertType = tmp.CertType + c.StakeCredential = tmp.StakeCredential + c.Drep = tmp.Drep + c.Amount = tmp.Amount c.SetCbor(cborData) return nil } func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using PoolRegistration as a container since it has more fields available + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_PoolRegistration{ + PoolRegistration: &utxorpc.PoolRegistrationCert{ + Operator: c.StakeCredential.Credential[:], // Stake cred + VrfKeyhash: []byte{}, // Empty + PoolMetadata: &utxorpc.PoolMetadata{ + Url: fmt.Sprintf("drep:%x/pool:%x", + c.Drep.Credential, c.StakeCredential.Credential), + }, + }, + }, + } } func (c *StakeVoteRegistrationDelegationCertificate) Type() uint { @@ -839,8 +900,15 @@ func (c *AuthCommitteeHotCertificate) UnmarshalCBOR( } func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using GenesisKeyDelegation as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_GenesisKeyDelegation{ + GenesisKeyDelegation: &utxorpc.GenesisKeyDelegationCert{ + GenesisHash: c.ColdCredential.Credential[:], + GenesisDelegateHash: c.HostCredential.Credential[:], + }, + }, + } } func (c *AuthCommitteeHotCertificate) Type() uint { @@ -871,8 +939,14 @@ func (c *ResignCommitteeColdCertificate) UnmarshalCBOR( } func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using PoolRetirement as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_PoolRetirement{ + PoolRetirement: &utxorpc.PoolRetirementCert{ + PoolKeyhash: c.ColdCredential.Credential[:], + }, + }, + } } func (c *ResignCommitteeColdCertificate) Type() uint { @@ -904,8 +978,12 @@ func (c *RegistrationDrepCertificate) UnmarshalCBOR( } func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeRegistration as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeRegistration{ + StakeRegistration: c.DrepCredential.Utxorpc(), + }, + } } func (c *RegistrationDrepCertificate) Type() uint { @@ -936,8 +1014,12 @@ func (c *DeregistrationDrepCertificate) UnmarshalCBOR( } func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + // Using StakeDeregistration as fallback + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_StakeDeregistration{ + StakeDeregistration: c.DrepCredential.Utxorpc(), + }, + } } func (c *DeregistrationDrepCertificate) Type() uint { @@ -968,8 +1050,21 @@ func (c *UpdateDrepCertificate) UnmarshalCBOR( } func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { - // TODO (#850) - return nil + var metadata *utxorpc.PoolMetadata + if c.Anchor != nil { + metadata = &utxorpc.PoolMetadata{ + Url: c.Anchor.Url, + Hash: c.Anchor.DataHash[:], + } + } + return &utxorpc.Certificate{ + Certificate: &utxorpc.Certificate_PoolRegistration{ + PoolRegistration: &utxorpc.PoolRegistrationCert{ + Operator: c.DrepCredential.Credential[:], + PoolMetadata: metadata, + }, + }, + } } func (c *UpdateDrepCertificate) Type() uint { From f1afa41f2363b8f0c55cfb59ffba383fff2d0cde Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 5 May 2025 12:52:36 +0545 Subject: [PATCH 2/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 153 ++++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 42 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index f1e351fd..3a307ca7 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -610,7 +610,6 @@ func (c *RegistrationCertificate) UnmarshalCBOR( } func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeRegistration as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeRegistration{ StakeRegistration: c.StakeCredential.Utxorpc(), @@ -646,7 +645,6 @@ func (c *DeregistrationCertificate) UnmarshalCBOR( } func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeDeregistration as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDeregistration{ StakeDeregistration: c.StakeCredential.Utxorpc(), @@ -682,16 +680,26 @@ func (c *VoteDelegationCertificate) UnmarshalCBOR( } func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeDelegation as fallback, storing Drep in PoolKeyhash - var drepData []byte - if c.Drep.Type == DrepTypeAddrKeyHash || c.Drep.Type == DrepTypeScriptHash { - drepData = c.Drep.Credential + // Get the DRep proto + drepProto := c.Drep.Utxorpc() + + // Extract the credential bytes if available + var drepBytes []byte + if drepProto != nil { + switch v := drepProto.Drep.(type) { + case *utxorpc.DRep_AddrKeyHash: + drepBytes = v.AddrKeyHash + case *utxorpc.DRep_ScriptHash: + drepBytes = v.ScriptHash + default: + drepBytes = nil + } } return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDelegation{ StakeDelegation: &utxorpc.StakeDelegationCert{ StakeCredential: c.StakeCredential.Utxorpc(), - PoolKeyhash: drepData, + PoolKeyhash: drepBytes, }, }, } @@ -726,12 +734,31 @@ func (c *StakeVoteDelegationCertificate) UnmarshalCBOR( } func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeDelegation + drepProto := c.Drep.Utxorpc() + var drepBytes []byte + + // Extract DRep credential if it exists (AddrKeyHash or ScriptHash) + if drepProto != nil { + switch v := drepProto.Drep.(type) { + case *utxorpc.DRep_AddrKeyHash: + drepBytes = v.AddrKeyHash + case *utxorpc.DRep_ScriptHash: + drepBytes = v.ScriptHash + } + } + + // Encode both PoolKeyHash and DRep in PoolKeyhash field + // Format: [1-byte type][poolKeyHash][drepBytes] + encodedKey := make([]byte, 0, 1+len(c.PoolKeyHash)+len(drepBytes)) + encodedKey = append(encodedKey, byte(0x01)) // Version byte + encodedKey = append(encodedKey, c.PoolKeyHash...) + encodedKey = append(encodedKey, drepBytes...) + return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDelegation{ StakeDelegation: &utxorpc.StakeDelegationCert{ StakeCredential: c.StakeCredential.Utxorpc(), - PoolKeyhash: c.PoolKeyHash, + PoolKeyhash: encodedKey, }, }, } @@ -766,7 +793,6 @@ func (c *StakeRegistrationDelegationCertificate) UnmarshalCBOR( } func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeDelegation as base return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDelegation{ StakeDelegation: &utxorpc.StakeDelegationCert{ @@ -806,12 +832,23 @@ func (c *VoteRegistrationDelegationCertificate) UnmarshalCBOR( } func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Similar to VoteDelegation + drepProto := c.Drep.Utxorpc() + var drepBytes []byte + + if drepProto != nil { + switch v := drepProto.Drep.(type) { + case *utxorpc.DRep_AddrKeyHash: + drepBytes = v.AddrKeyHash + case *utxorpc.DRep_ScriptHash: + drepBytes = v.ScriptHash + } + } + return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDelegation{ StakeDelegation: &utxorpc.StakeDelegationCert{ StakeCredential: c.StakeCredential.Utxorpc(), - PoolKeyhash: c.Drep.Credential, + PoolKeyhash: drepBytes, }, }, } @@ -833,40 +870,37 @@ type StakeVoteRegistrationDelegationCertificate struct { func (c StakeVoteRegistrationDelegationCertificate) isCertificate() {} -func (c *StakeVoteRegistrationDelegationCertificate) UnmarshalCBOR(cborData []byte) error { - // Temporary struct that matches the CBOR structure - tmp := struct { - cbor.StructAsArray - CertType uint - StakeCredential Credential - Drep Drep - Amount int64 - }{} - +func (c *StakeVoteRegistrationDelegationCertificate) UnmarshalCBOR( + cborData []byte, +) error { + type tStakeVoteRegistrationDelegationCertificate StakeVoteRegistrationDelegationCertificate + var tmp tStakeVoteRegistrationDelegationCertificate if _, err := cbor.Decode(cborData, &tmp); err != nil { return err } - - // Manually copy fields - c.CertType = tmp.CertType - c.StakeCredential = tmp.StakeCredential - c.Drep = tmp.Drep - c.Amount = tmp.Amount + *c = StakeVoteRegistrationDelegationCertificate(tmp) c.SetCbor(cborData) return nil } func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Using PoolRegistration as a container since it has more fields available + drepProto := c.Drep.Utxorpc() + var drepBytes []byte + + if drepProto != nil { + switch v := drepProto.Drep.(type) { + case *utxorpc.DRep_AddrKeyHash: + drepBytes = v.AddrKeyHash + case *utxorpc.DRep_ScriptHash: + drepBytes = v.ScriptHash + } + } + return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_PoolRegistration{ - PoolRegistration: &utxorpc.PoolRegistrationCert{ - Operator: c.StakeCredential.Credential[:], // Stake cred - VrfKeyhash: []byte{}, // Empty - PoolMetadata: &utxorpc.PoolMetadata{ - Url: fmt.Sprintf("drep:%x/pool:%x", - c.Drep.Credential, c.StakeCredential.Credential), - }, + Certificate: &utxorpc.Certificate_StakeDelegation{ + StakeDelegation: &utxorpc.StakeDelegationCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + PoolKeyhash: drepBytes, }, }, } @@ -900,7 +934,6 @@ func (c *AuthCommitteeHotCertificate) UnmarshalCBOR( } func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate { - // Using GenesisKeyDelegation as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_GenesisKeyDelegation{ GenesisKeyDelegation: &utxorpc.GenesisKeyDelegationCert{ @@ -939,7 +972,6 @@ func (c *ResignCommitteeColdCertificate) UnmarshalCBOR( } func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate { - // Using PoolRetirement as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_PoolRetirement{ PoolRetirement: &utxorpc.PoolRetirementCert{ @@ -978,7 +1010,6 @@ func (c *RegistrationDrepCertificate) UnmarshalCBOR( } func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeRegistration as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeRegistration{ StakeRegistration: c.DrepCredential.Utxorpc(), @@ -1014,7 +1045,6 @@ func (c *DeregistrationDrepCertificate) UnmarshalCBOR( } func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { - // Using StakeDeregistration as fallback return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_StakeDeregistration{ StakeDeregistration: c.DrepCredential.Utxorpc(), @@ -1050,6 +1080,7 @@ func (c *UpdateDrepCertificate) UnmarshalCBOR( } func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { + // Handle anchor data if present var metadata *utxorpc.PoolMetadata if c.Anchor != nil { metadata = &utxorpc.PoolMetadata{ @@ -1057,11 +1088,25 @@ func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { Hash: c.Anchor.DataHash[:], } } + return &utxorpc.Certificate{ Certificate: &utxorpc.Certificate_PoolRegistration{ PoolRegistration: &utxorpc.PoolRegistrationCert{ - Operator: c.DrepCredential.Credential[:], + // Store DRep credential hash bytes in operator field + Operator: c.DrepCredential.Credential[:], + // Store anchor info in metadata PoolMetadata: metadata, + // Set minimal required fields + VrfKeyhash: []byte{}, + Pledge: 0, + Cost: 0, + Margin: &utxorpc.RationalNumber{ + Numerator: 0, + Denominator: 1, + }, + RewardAccount: nil, + PoolOwners: nil, + Relays: nil, }, }, } @@ -1070,3 +1115,27 @@ func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { func (c *UpdateDrepCertificate) Type() uint { return c.CertType } + +// DRep implementation +func (d *Drep) Utxorpc() *utxorpc.DRep { + switch d.Type { + case DrepTypeAddrKeyHash: + return &utxorpc.DRep{ + Drep: &utxorpc.DRep_AddrKeyHash{AddrKeyHash: d.Credential}, + } + case DrepTypeScriptHash: + return &utxorpc.DRep{ + Drep: &utxorpc.DRep_ScriptHash{ScriptHash: d.Credential}, + } + case DrepTypeAbstain: + return &utxorpc.DRep{ + Drep: &utxorpc.DRep_Abstain{Abstain: true}, + } + case DrepTypeNoConfidence: + return &utxorpc.DRep{ + Drep: &utxorpc.DRep_NoConfidence{NoConfidence: true}, + } + default: + return nil + } +} From 76f62886ef7118cd9305467938629e001a2dd0ad Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 5 May 2025 12:57:50 +0545 Subject: [PATCH 3/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 3a307ca7..8c308bfe 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -686,7 +686,7 @@ func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { // Extract the credential bytes if available var drepBytes []byte if drepProto != nil { - switch v := drepProto.Drep.(type) { + switch v := drepProto.GetDrep().(type) { case *utxorpc.DRep_AddrKeyHash: drepBytes = v.AddrKeyHash case *utxorpc.DRep_ScriptHash: @@ -739,7 +739,7 @@ func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { // Extract DRep credential if it exists (AddrKeyHash or ScriptHash) if drepProto != nil { - switch v := drepProto.Drep.(type) { + switch v := drepProto.GetDrep().(type) { case *utxorpc.DRep_AddrKeyHash: drepBytes = v.AddrKeyHash case *utxorpc.DRep_ScriptHash: @@ -836,7 +836,7 @@ func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { var drepBytes []byte if drepProto != nil { - switch v := drepProto.Drep.(type) { + switch v := drepProto.GetDrep().(type) { case *utxorpc.DRep_AddrKeyHash: drepBytes = v.AddrKeyHash case *utxorpc.DRep_ScriptHash: @@ -888,7 +888,7 @@ func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certific var drepBytes []byte if drepProto != nil { - switch v := drepProto.Drep.(type) { + switch v := drepProto.GetDrep().(type) { case *utxorpc.DRep_AddrKeyHash: drepBytes = v.AddrKeyHash case *utxorpc.DRep_ScriptHash: From 8a06d7e57ecd1b44abed9e59ea59d92abc4ec937 Mon Sep 17 00:00:00 2001 From: Jenita Date: Fri, 16 May 2025 20:15:25 +0545 Subject: [PATCH 4/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 8c308bfe..c863b58a 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -258,9 +258,9 @@ func (c *StakeDelegationCertificate) Type() uint { } type ( - PoolKeyHash Blake2b224 - PoolMetadataHash Blake2b256 - VrfKeyHash Blake2b256 + PoolKeyHash = Blake2b224 + PoolMetadataHash = Blake2b256 + VrfKeyHash = Blake2b256 ) type PoolMetadata struct { @@ -611,8 +611,11 @@ func (c *RegistrationCertificate) UnmarshalCBOR( func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate { return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeRegistration{ - StakeRegistration: c.StakeCredential.Utxorpc(), + Certificate: &utxorpc.Certificate_RegCert{ + RegCert: &utxorpc.RegCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + Coin: uint64(c.Amount), + }, }, } } @@ -646,8 +649,11 @@ func (c *DeregistrationCertificate) UnmarshalCBOR( func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate { return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDeregistration{ - StakeDeregistration: c.StakeCredential.Utxorpc(), + Certificate: &utxorpc.Certificate_UnregCert{ + UnregCert: &utxorpc.UnRegCert{ + StakeCredential: c.StakeCredential.Utxorpc(), + Coin: uint64(c.Amount), + }, }, } } From c8c46ad6aa5962291a1aae64821aeedbe3fa163d Mon Sep 17 00:00:00 2001 From: Jenita Date: Fri, 16 May 2025 23:34:06 +0545 Subject: [PATCH 5/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index c863b58a..5c0b3a39 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -614,7 +614,6 @@ func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate { Certificate: &utxorpc.Certificate_RegCert{ RegCert: &utxorpc.RegCert{ StakeCredential: c.StakeCredential.Utxorpc(), - Coin: uint64(c.Amount), }, }, } @@ -652,7 +651,6 @@ func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate { Certificate: &utxorpc.Certificate_UnregCert{ UnregCert: &utxorpc.UnRegCert{ StakeCredential: c.StakeCredential.Utxorpc(), - Coin: uint64(c.Amount), }, }, } From e884502985a3e85f0cff919549c45ee0f33e6b69 Mon Sep 17 00:00:00 2001 From: Jenita Date: Sun, 18 May 2025 00:24:53 +0545 Subject: [PATCH 6/6] feat(certs): implemented Utxorpc() for Conway governance certs Signed-off-by: Jenita --- ledger/common/certs.go | 127 ++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 73 deletions(-) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 5c0b3a39..21794866 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -684,26 +684,11 @@ func (c *VoteDelegationCertificate) UnmarshalCBOR( } func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { - // Get the DRep proto - drepProto := c.Drep.Utxorpc() - - // Extract the credential bytes if available - var drepBytes []byte - if drepProto != nil { - switch v := drepProto.GetDrep().(type) { - case *utxorpc.DRep_AddrKeyHash: - drepBytes = v.AddrKeyHash - case *utxorpc.DRep_ScriptHash: - drepBytes = v.ScriptHash - default: - drepBytes = nil - } - } return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDelegation{ - StakeDelegation: &utxorpc.StakeDelegationCert{ + Certificate: &utxorpc.Certificate_VoteDelegCert{ + VoteDelegCert: &utxorpc.VoteDelegCert{ StakeCredential: c.StakeCredential.Utxorpc(), - PoolKeyhash: drepBytes, + Drep: c.Drep.Utxorpc(), }, }, } @@ -759,10 +744,11 @@ func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { encodedKey = append(encodedKey, drepBytes...) return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDelegation{ - StakeDelegation: &utxorpc.StakeDelegationCert{ + Certificate: &utxorpc.Certificate_StakeVoteDelegCert{ + StakeVoteDelegCert: &utxorpc.StakeVoteDelegCert{ StakeCredential: c.StakeCredential.Utxorpc(), PoolKeyhash: encodedKey, + Drep: c.Drep.Utxorpc(), }, }, } @@ -798,8 +784,8 @@ func (c *StakeRegistrationDelegationCertificate) UnmarshalCBOR( func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDelegation{ - StakeDelegation: &utxorpc.StakeDelegationCert{ + Certificate: &utxorpc.Certificate_StakeVoteDelegCert{ + StakeVoteDelegCert: &utxorpc.StakeVoteDelegCert{ StakeCredential: c.StakeCredential.Utxorpc(), PoolKeyhash: c.PoolKeyHash, }, @@ -836,23 +822,11 @@ func (c *VoteRegistrationDelegationCertificate) UnmarshalCBOR( } func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { - drepProto := c.Drep.Utxorpc() - var drepBytes []byte - - if drepProto != nil { - switch v := drepProto.GetDrep().(type) { - case *utxorpc.DRep_AddrKeyHash: - drepBytes = v.AddrKeyHash - case *utxorpc.DRep_ScriptHash: - drepBytes = v.ScriptHash - } - } - return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDelegation{ - StakeDelegation: &utxorpc.StakeDelegationCert{ + Certificate: &utxorpc.Certificate_VoteRegDelegCert{ + VoteRegDelegCert: &utxorpc.VoteRegDelegCert{ StakeCredential: c.StakeCredential.Utxorpc(), - PoolKeyhash: drepBytes, + Drep: c.Drep.Utxorpc(), }, }, } @@ -901,10 +875,11 @@ func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certific } return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDelegation{ - StakeDelegation: &utxorpc.StakeDelegationCert{ + Certificate: &utxorpc.Certificate_StakeVoteRegDelegCert{ + StakeVoteRegDelegCert: &utxorpc.StakeVoteRegDelegCert{ StakeCredential: c.StakeCredential.Utxorpc(), PoolKeyhash: drepBytes, + Drep: c.Drep.Utxorpc(), }, }, } @@ -939,10 +914,10 @@ func (c *AuthCommitteeHotCertificate) UnmarshalCBOR( func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate { return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_GenesisKeyDelegation{ - GenesisKeyDelegation: &utxorpc.GenesisKeyDelegationCert{ - GenesisHash: c.ColdCredential.Credential[:], - GenesisDelegateHash: c.HostCredential.Credential[:], + Certificate: &utxorpc.Certificate_AuthCommitteeHotCert{ + AuthCommitteeHotCert: &utxorpc.AuthCommitteeHotCert{ + CommitteeColdCredential: c.ColdCredential.Utxorpc(), + CommitteeHotCredential: c.HostCredential.Utxorpc(), }, }, } @@ -976,10 +951,18 @@ func (c *ResignCommitteeColdCertificate) UnmarshalCBOR( } func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate { + var anchor *utxorpc.Anchor + if c.Anchor != nil { + anchor = &utxorpc.Anchor{ + Url: c.Anchor.Url, + ContentHash: c.Anchor.DataHash[:], + } + } return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_PoolRetirement{ - PoolRetirement: &utxorpc.PoolRetirementCert{ - PoolKeyhash: c.ColdCredential.Credential[:], + Certificate: &utxorpc.Certificate_ResignCommitteeColdCert{ + ResignCommitteeColdCert: &utxorpc.ResignCommitteeColdCert{ + CommitteeColdCredential: c.ColdCredential.Utxorpc(), + Anchor: anchor, }, }, } @@ -1014,9 +997,20 @@ func (c *RegistrationDrepCertificate) UnmarshalCBOR( } func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { + // Handle anchor data if present + var anchor *utxorpc.Anchor + if c.Anchor != nil { + anchor = &utxorpc.Anchor{ + Url: c.Anchor.Url, + ContentHash: c.Anchor.DataHash[:], + } + } return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeRegistration{ - StakeRegistration: c.DrepCredential.Utxorpc(), + Certificate: &utxorpc.Certificate_RegDrepCert{ + RegDrepCert: &utxorpc.RegDRepCert{ + DrepCredential: c.DrepCredential.Utxorpc(), + Anchor: anchor, + }, }, } } @@ -1050,8 +1044,10 @@ func (c *DeregistrationDrepCertificate) UnmarshalCBOR( func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_StakeDeregistration{ - StakeDeregistration: c.DrepCredential.Utxorpc(), + Certificate: &utxorpc.Certificate_UnregDrepCert{ + UnregDrepCert: &utxorpc.UnRegDRepCert{ + DrepCredential: c.DrepCredential.Utxorpc(), + }, }, } } @@ -1084,33 +1080,18 @@ func (c *UpdateDrepCertificate) UnmarshalCBOR( } func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { - // Handle anchor data if present - var metadata *utxorpc.PoolMetadata + var anchor *utxorpc.Anchor if c.Anchor != nil { - metadata = &utxorpc.PoolMetadata{ - Url: c.Anchor.Url, - Hash: c.Anchor.DataHash[:], + anchor = &utxorpc.Anchor{ + Url: c.Anchor.Url, + ContentHash: c.Anchor.DataHash[:], } } - return &utxorpc.Certificate{ - Certificate: &utxorpc.Certificate_PoolRegistration{ - PoolRegistration: &utxorpc.PoolRegistrationCert{ - // Store DRep credential hash bytes in operator field - Operator: c.DrepCredential.Credential[:], - // Store anchor info in metadata - PoolMetadata: metadata, - // Set minimal required fields - VrfKeyhash: []byte{}, - Pledge: 0, - Cost: 0, - Margin: &utxorpc.RationalNumber{ - Numerator: 0, - Denominator: 1, - }, - RewardAccount: nil, - PoolOwners: nil, - Relays: nil, + Certificate: &utxorpc.Certificate_UpdateDrepCert{ + UpdateDrepCert: &utxorpc.UpdateDRepCert{ + DrepCredential: c.DrepCredential.Utxorpc(), + Anchor: anchor, }, }, }