Skip to content

Commit bfd0554

Browse files
authored
chore(ledger): move drep function near others (#1194)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent a57c097 commit bfd0554

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

ledger/common/certs.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,29 @@ func (d *Drep) UnmarshalCBOR(data []byte) error {
160160
return nil
161161
}
162162

163+
func (d *Drep) Utxorpc() (*utxorpc.DRep, error) {
164+
switch d.Type {
165+
case DrepTypeAddrKeyHash:
166+
return &utxorpc.DRep{
167+
Drep: &utxorpc.DRep_AddrKeyHash{AddrKeyHash: d.Credential},
168+
}, nil
169+
case DrepTypeScriptHash:
170+
return &utxorpc.DRep{
171+
Drep: &utxorpc.DRep_ScriptHash{ScriptHash: d.Credential},
172+
}, nil
173+
case DrepTypeAbstain:
174+
return &utxorpc.DRep{
175+
Drep: &utxorpc.DRep_Abstain{Abstain: true},
176+
}, nil
177+
case DrepTypeNoConfidence:
178+
return &utxorpc.DRep{
179+
Drep: &utxorpc.DRep_NoConfidence{NoConfidence: true},
180+
}, nil
181+
default:
182+
return nil, fmt.Errorf("unknown DRep type: %d", d.Type)
183+
}
184+
}
185+
163186
func (d *Drep) ToPlutusData() data.PlutusData {
164187
switch d.Type {
165188
case DrepTypeAddrKeyHash:
@@ -1338,27 +1361,3 @@ func (c *UpdateDrepCertificate) Utxorpc() (*utxorpc.Certificate, error) {
13381361
func (c *UpdateDrepCertificate) Type() uint {
13391362
return c.CertType
13401363
}
1341-
1342-
// DRep implementation
1343-
func (d *Drep) Utxorpc() (*utxorpc.DRep, error) {
1344-
switch d.Type {
1345-
case DrepTypeAddrKeyHash:
1346-
return &utxorpc.DRep{
1347-
Drep: &utxorpc.DRep_AddrKeyHash{AddrKeyHash: d.Credential},
1348-
}, nil
1349-
case DrepTypeScriptHash:
1350-
return &utxorpc.DRep{
1351-
Drep: &utxorpc.DRep_ScriptHash{ScriptHash: d.Credential},
1352-
}, nil
1353-
case DrepTypeAbstain:
1354-
return &utxorpc.DRep{
1355-
Drep: &utxorpc.DRep_Abstain{Abstain: true},
1356-
}, nil
1357-
case DrepTypeNoConfidence:
1358-
return &utxorpc.DRep{
1359-
Drep: &utxorpc.DRep_NoConfidence{NoConfidence: true},
1360-
}, nil
1361-
default:
1362-
return nil, fmt.Errorf("unknown DRep type: %d", d.Type)
1363-
}
1364-
}

0 commit comments

Comments
 (0)