-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Implement DRepState bootstrapping - 264 #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3352242
Implement DRepState bootstrapping
buddhisthead c4dc150
Reorganize modules in lib.rs per check
buddhisthead 16d6e08
Clippy
buddhisthead 252dc2f
Revert startup method to mithril for main branch
buddhisthead 03d92eb
Apply PR feedback
buddhisthead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| //! DRep (Delegated Representative) types and structures | ||
|
|
||
| use crate::rational_number::RationalNumber; | ||
| use crate::types::{Credential, Lovelace}; | ||
| use serde_with::{hex::Hex, serde_as}; | ||
|
|
||
| pub type DRepCredential = Credential; | ||
|
|
||
| /// Anchor - verifiable link on-chain identifiers with off-chain content, | ||
| /// typically metadata that describes a DRep's identity, platform, or governance | ||
| /// philosophy. | ||
| #[serde_as] | ||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] | ||
| pub struct Anchor { | ||
| /// Metadata URL | ||
| pub url: String, | ||
|
|
||
| /// Metadata hash | ||
| #[serde_as(as = "Hex")] | ||
| pub data_hash: Vec<u8>, | ||
| } | ||
|
|
||
| impl<'b, C> minicbor::Decode<'b, C> for Anchor { | ||
| fn decode( | ||
| d: &mut minicbor::Decoder<'b>, | ||
| _ctx: &mut C, | ||
| ) -> Result<Self, minicbor::decode::Error> { | ||
| d.array()?; | ||
|
|
||
| // URL can be either bytes or text string (snapshot format uses bytes) | ||
| let url = match d.datatype()? { | ||
| minicbor::data::Type::Bytes => { | ||
| let url_bytes = d.bytes()?; | ||
| String::from_utf8_lossy(url_bytes).to_string() | ||
| } | ||
| minicbor::data::Type::String => d.str()?.to_string(), | ||
| _ => { | ||
| return Err(minicbor::decode::Error::message( | ||
| "Expected bytes or string for URL", | ||
buddhisthead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )) | ||
| } | ||
| }; | ||
|
|
||
| // data_hash is encoded as direct bytes, not an array | ||
| let data_hash = d.bytes()?.to_vec(); | ||
|
|
||
| Ok(Self { url, data_hash }) | ||
| } | ||
| } | ||
|
|
||
| /// DRep Record - represents the current state of a DRep in the ledger | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct DRepRecord { | ||
| /// Deposit amount in lovelace | ||
| pub deposit: Lovelace, | ||
| /// Optional anchor (metadata reference) | ||
| pub anchor: Option<Anchor>, | ||
| } | ||
|
|
||
| impl DRepRecord { | ||
| pub fn new(deposit: Lovelace, anchor: Option<Anchor>) -> Self { | ||
| Self { deposit, anchor } | ||
| } | ||
| } | ||
|
|
||
| /// DRepChoice (=CDDL drep, badly named) | ||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] | ||
| pub enum DRepChoice { | ||
| /// Address key | ||
| Key(crate::KeyHash), | ||
|
|
||
| /// Script key | ||
| Script(crate::KeyHash), | ||
|
|
||
| /// Abstain | ||
| Abstain, | ||
|
|
||
| /// No confidence | ||
| NoConfidence, | ||
| } | ||
|
|
||
| /// DRep Registration = reg_drep_cert | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct DRepRegistration { | ||
| /// DRep credential | ||
| pub credential: DRepCredential, | ||
|
|
||
| /// Deposit paid | ||
| pub deposit: Lovelace, | ||
|
|
||
| /// Optional anchor | ||
| pub anchor: Option<Anchor>, | ||
| } | ||
|
|
||
| /// DRep Deregistration = unreg_drep_cert | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct DRepDeregistration { | ||
| /// DRep credential | ||
| pub credential: DRepCredential, | ||
|
|
||
| /// Deposit to refund | ||
| pub refund: Lovelace, | ||
| } | ||
|
|
||
| /// DRep Update = update_drep_cert | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct DRepUpdate { | ||
| /// DRep credential | ||
| pub credential: DRepCredential, | ||
|
|
||
| /// Optional anchor | ||
| pub anchor: Option<Anchor>, | ||
| } | ||
|
|
||
| /// DRep voting thresholds for governance actions | ||
| #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone, minicbor::Decode)] | ||
| pub struct DRepVotingThresholds { | ||
| #[n(0)] | ||
| pub motion_no_confidence: RationalNumber, | ||
| #[n(1)] | ||
| pub committee_normal: RationalNumber, | ||
| #[n(2)] | ||
| pub committee_no_confidence: RationalNumber, | ||
| #[n(3)] | ||
| pub update_constitution: RationalNumber, | ||
| #[n(4)] | ||
| pub hard_fork_initiation: RationalNumber, | ||
| #[n(5)] | ||
| pub pp_network_group: RationalNumber, | ||
| #[n(6)] | ||
| pub pp_economic_group: RationalNumber, | ||
| #[n(7)] | ||
| pub pp_technical_group: RationalNumber, | ||
| #[n(8)] | ||
| pub pp_governance_group: RationalNumber, | ||
| #[n(9)] | ||
| pub treasury_withdrawal: RationalNumber, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.