Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 191 additions & 27 deletions ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -610,8 +610,11 @@ func (c *RegistrationCertificate) UnmarshalCBOR(
}

func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_StakeRegistration{
StakeRegistration: c.StakeCredential.Utxorpc(),
},
}
}

func (c *RegistrationCertificate) Type() uint {
Expand Down Expand Up @@ -642,8 +645,11 @@ func (c *DeregistrationCertificate) UnmarshalCBOR(
}

func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_StakeDeregistration{
StakeDeregistration: c.StakeCredential.Utxorpc(),
},
}
}

func (c *DeregistrationCertificate) Type() uint {
Expand Down Expand Up @@ -674,8 +680,29 @@ func (c *VoteDelegationCertificate) UnmarshalCBOR(
}

func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
// 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{
StakeCredential: c.StakeCredential.Utxorpc(),
PoolKeyhash: drepBytes,
},
},
}
}

func (c *VoteDelegationCertificate) Type() uint {
Expand Down Expand Up @@ -707,8 +734,34 @@ func (c *StakeVoteDelegationCertificate) UnmarshalCBOR(
}

func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
drepProto := c.Drep.Utxorpc()
var drepBytes []byte

// Extract DRep credential if it exists (AddrKeyHash or ScriptHash)
if drepProto != nil {
switch v := drepProto.GetDrep().(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: encodedKey,
},
},
}
}

func (c *StakeVoteDelegationCertificate) Type() uint {
Expand Down Expand Up @@ -740,8 +793,14 @@ func (c *StakeRegistrationDelegationCertificate) UnmarshalCBOR(
}

func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_StakeDelegation{
StakeDelegation: &utxorpc.StakeDelegationCert{
StakeCredential: c.StakeCredential.Utxorpc(),
PoolKeyhash: c.PoolKeyHash,
},
},
}
}

func (c *StakeRegistrationDelegationCertificate) Type() uint {
Expand Down Expand Up @@ -773,8 +832,26 @@ func (c *VoteRegistrationDelegationCertificate) UnmarshalCBOR(
}

func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
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{
StakeCredential: c.StakeCredential.Utxorpc(),
PoolKeyhash: drepBytes,
},
},
}
}

func (c *VoteRegistrationDelegationCertificate) Type() uint {
Expand Down Expand Up @@ -807,8 +884,26 @@ func (c *StakeVoteRegistrationDelegationCertificate) UnmarshalCBOR(
}

func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
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{
StakeCredential: c.StakeCredential.Utxorpc(),
PoolKeyhash: drepBytes,
},
},
}
}

func (c *StakeVoteRegistrationDelegationCertificate) Type() uint {
Expand Down Expand Up @@ -839,8 +934,14 @@ func (c *AuthCommitteeHotCertificate) UnmarshalCBOR(
}

func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_GenesisKeyDelegation{
GenesisKeyDelegation: &utxorpc.GenesisKeyDelegationCert{
GenesisHash: c.ColdCredential.Credential[:],
GenesisDelegateHash: c.HostCredential.Credential[:],
},
},
}
}

func (c *AuthCommitteeHotCertificate) Type() uint {
Expand Down Expand Up @@ -871,8 +972,13 @@ func (c *ResignCommitteeColdCertificate) UnmarshalCBOR(
}

func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_PoolRetirement{
PoolRetirement: &utxorpc.PoolRetirementCert{
PoolKeyhash: c.ColdCredential.Credential[:],
},
},
}
}

func (c *ResignCommitteeColdCertificate) Type() uint {
Expand Down Expand Up @@ -904,8 +1010,11 @@ func (c *RegistrationDrepCertificate) UnmarshalCBOR(
}

func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_StakeRegistration{
StakeRegistration: c.DrepCredential.Utxorpc(),
},
}
}

func (c *RegistrationDrepCertificate) Type() uint {
Expand Down Expand Up @@ -936,8 +1045,11 @@ func (c *DeregistrationDrepCertificate) UnmarshalCBOR(
}

func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
return &utxorpc.Certificate{
Certificate: &utxorpc.Certificate_StakeDeregistration{
StakeDeregistration: c.DrepCredential.Utxorpc(),
},
}
}

func (c *DeregistrationDrepCertificate) Type() uint {
Expand Down Expand Up @@ -968,10 +1080,62 @@ func (c *UpdateDrepCertificate) UnmarshalCBOR(
}

func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
// Handle anchor data if present
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{
// 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,
},
},
}
}

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
}
}
Loading