Skip to content
Merged
Changes from all 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
47 changes: 23 additions & 24 deletions ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ func (d *Drep) UnmarshalCBOR(data []byte) error {
return nil
}

func (d *Drep) Utxorpc() (*utxorpc.DRep, error) {
switch d.Type {
case DrepTypeAddrKeyHash:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_AddrKeyHash{AddrKeyHash: d.Credential},
}, nil
case DrepTypeScriptHash:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_ScriptHash{ScriptHash: d.Credential},
}, nil
case DrepTypeAbstain:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_Abstain{Abstain: true},
}, nil
case DrepTypeNoConfidence:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_NoConfidence{NoConfidence: true},
}, nil
default:
return nil, fmt.Errorf("unknown DRep type: %d", d.Type)
}
}

func (d *Drep) ToPlutusData() data.PlutusData {
switch d.Type {
case DrepTypeAddrKeyHash:
Expand Down Expand Up @@ -1338,27 +1361,3 @@ func (c *UpdateDrepCertificate) Utxorpc() (*utxorpc.Certificate, error) {
func (c *UpdateDrepCertificate) Type() uint {
return c.CertType
}

// DRep implementation
func (d *Drep) Utxorpc() (*utxorpc.DRep, error) {
switch d.Type {
case DrepTypeAddrKeyHash:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_AddrKeyHash{AddrKeyHash: d.Credential},
}, nil
case DrepTypeScriptHash:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_ScriptHash{ScriptHash: d.Credential},
}, nil
case DrepTypeAbstain:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_Abstain{Abstain: true},
}, nil
case DrepTypeNoConfidence:
return &utxorpc.DRep{
Drep: &utxorpc.DRep_NoConfidence{NoConfidence: true},
}, nil
default:
return nil, fmt.Errorf("unknown DRep type: %d", d.Type)
}
}