-
Notifications
You must be signed in to change notification settings - Fork 8
Feat/party serialization into datum #239
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
e799254
5d19fbe
6695bfe
799df1a
aaf131a
c6d3908
ab56b75
c8bf732
db6e291
5a225df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -740,6 +740,7 @@ pub enum DataExpr { | |
| NegateOp(NegateOp), | ||
| PropertyOp(PropertyOp), | ||
| UtxoRef(UtxoRef), | ||
| CardanoFunctions(crate::cardano::CardanoFunctions), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add individual functions instead of aggregating as a single enum variant. |
||
| } | ||
|
|
||
| impl DataExpr { | ||
|
|
@@ -775,6 +776,7 @@ impl DataExpr { | |
| DataExpr::UtxoRef(_) => Some(Type::UtxoRef), | ||
| DataExpr::MinUtxo(_) => Some(Type::AnyAsset), | ||
| DataExpr::ComputeTipSlot => Some(Type::Int), | ||
| DataExpr::CardanoFunctions(_) => Some(Type::Bytes), // Payment/staking parts return bytes | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -724,6 +724,24 @@ impl IntoLower for CardanoPublishBlock { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub struct CardanoPaymentPart { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
| pub address: Box<DataExpr>, | ||
| pub span: Span, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub struct CardanoStakingPart { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
| pub address: Box<DataExpr>, | ||
| pub span: Span, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub enum CardanoFunctions { | ||
| PaymentPart(CardanoPaymentPart), | ||
| StakingPart(CardanoStakingPart), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub enum CardanoBlock { | ||
| VoteDelegationCertificate(VoteDelegationCertificate), | ||
|
|
@@ -735,6 +753,38 @@ pub enum CardanoBlock { | |
| Publish(CardanoPublishBlock), | ||
| } | ||
|
|
||
| impl AstNode for CardanoPaymentPart { | ||
| const RULE: Rule = Rule::cardano_payment_part; | ||
|
|
||
| fn parse(pair: Pair<Rule>) -> Result<Self, Error> { | ||
| let span = pair.as_span().into(); | ||
| let mut inner = pair.into_inner(); | ||
| let address = DataExpr::parse(inner.next().unwrap())?.into(); | ||
|
|
||
| Ok(CardanoPaymentPart { address, span }) | ||
| } | ||
|
|
||
| fn span(&self) -> &Span { | ||
| &self.span | ||
| } | ||
| } | ||
|
|
||
| impl AstNode for CardanoStakingPart { | ||
| const RULE: Rule = Rule::cardano_staking_part; | ||
|
|
||
| fn parse(pair: Pair<Rule>) -> Result<Self, Error> { | ||
| let span = pair.as_span().into(); | ||
| let mut inner = pair.into_inner(); | ||
| let address = DataExpr::parse(inner.next().unwrap())?.into(); | ||
|
|
||
| Ok(CardanoStakingPart { address, span }) | ||
| } | ||
|
|
||
| fn span(&self) -> &Span { | ||
| &self.span | ||
| } | ||
| } | ||
|
|
||
| impl AstNode for CardanoBlock { | ||
| const RULE: Rule = Rule::cardano_block; | ||
|
|
||
|
|
@@ -781,6 +831,26 @@ impl AstNode for CardanoBlock { | |
| } | ||
| } | ||
|
|
||
| impl Analyzable for CardanoPaymentPart { | ||
| fn analyze(&mut self, parent: Option<Rc<Scope>>) -> AnalyzeReport { | ||
| self.address.analyze(parent) | ||
| } | ||
|
|
||
| fn is_resolved(&self) -> bool { | ||
| self.address.is_resolved() | ||
| } | ||
| } | ||
|
|
||
| impl Analyzable for CardanoStakingPart { | ||
| fn analyze(&mut self, parent: Option<Rc<Scope>>) -> AnalyzeReport { | ||
| self.address.analyze(parent) | ||
| } | ||
|
|
||
| fn is_resolved(&self) -> bool { | ||
| self.address.is_resolved() | ||
| } | ||
| } | ||
|
|
||
| impl Analyzable for CardanoBlock { | ||
| fn analyze(&mut self, parent: Option<Rc<Scope>>) -> AnalyzeReport { | ||
| match self { | ||
|
|
@@ -807,6 +877,96 @@ impl Analyzable for CardanoBlock { | |
| } | ||
| } | ||
|
|
||
| impl IntoLower for CardanoPaymentPart { | ||
| type Output = ir::AdHocDirective; | ||
|
|
||
| fn into_lower( | ||
| &self, | ||
| ctx: &crate::lowering::Context, | ||
| ) -> Result<Self::Output, crate::lowering::Error> { | ||
| let address_expr = self.address.into_lower(ctx)?; | ||
| let mut data = std::collections::HashMap::new(); | ||
| data.insert("address".to_string(), address_expr); | ||
| Ok(ir::AdHocDirective { | ||
| name: "cardano_payment_part".to_string(), | ||
| data, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl IntoLower for CardanoStakingPart { | ||
| type Output = ir::AdHocDirective; | ||
|
|
||
| fn into_lower( | ||
| &self, | ||
| ctx: &crate::lowering::Context, | ||
| ) -> Result<Self::Output, crate::lowering::Error> { | ||
| let address_expr = self.address.into_lower(ctx)?; | ||
| let mut data = std::collections::HashMap::new(); | ||
| data.insert("address".to_string(), address_expr); | ||
| Ok(ir::AdHocDirective { | ||
| name: "cardano_staking_part".to_string(), | ||
| data, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl AstNode for CardanoFunctions { | ||
| const RULE: Rule = Rule::cardano_functions; | ||
|
|
||
| fn parse(pair: Pair<Rule>) -> Result<Self, Error> { | ||
| let mut inner = pair.into_inner(); | ||
| let function_pair = inner.next().unwrap(); | ||
|
|
||
| match function_pair.as_rule() { | ||
| Rule::cardano_payment_part => { | ||
| Ok(CardanoFunctions::PaymentPart(CardanoPaymentPart::parse(function_pair)?)) | ||
| } | ||
| Rule::cardano_staking_part => { | ||
| Ok(CardanoFunctions::StakingPart(CardanoStakingPart::parse(function_pair)?)) | ||
| } | ||
| x => unreachable!("Unexpected rule in cardano_functions: {:?}", x), | ||
| } | ||
| } | ||
|
|
||
| fn span(&self) -> &Span { | ||
| match self { | ||
| CardanoFunctions::PaymentPart(x) => x.span(), | ||
| CardanoFunctions::StakingPart(x) => x.span(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Analyzable for CardanoFunctions { | ||
| fn analyze(&mut self, parent: Option<Rc<Scope>>) -> AnalyzeReport { | ||
| match self { | ||
| CardanoFunctions::PaymentPart(x) => x.analyze(parent), | ||
| CardanoFunctions::StakingPart(x) => x.analyze(parent), | ||
| } | ||
| } | ||
|
|
||
| fn is_resolved(&self) -> bool { | ||
| match self { | ||
| CardanoFunctions::PaymentPart(x) => x.is_resolved(), | ||
| CardanoFunctions::StakingPart(x) => x.is_resolved(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl IntoLower for CardanoFunctions { | ||
| type Output = ir::AdHocDirective; | ||
|
|
||
| fn into_lower( | ||
| &self, | ||
| ctx: &crate::lowering::Context, | ||
| ) -> Result<Self::Output, crate::lowering::Error> { | ||
| match self { | ||
| CardanoFunctions::PaymentPart(x) => x.into_lower(ctx), | ||
| CardanoFunctions::StakingPart(x) => x.into_lower(ctx), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl IntoLower for CardanoBlock { | ||
| type Output = ir::AdHocDirective; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,7 @@ data_expr = { data_prefix* ~ data_primary ~ data_postfix* ~ (data_infix ~ data_p | |
| string | | ||
| min_utxo | | ||
| tip_slot | | ||
| cardano_functions | | ||
| struct_constructor | | ||
| list_constructor | | ||
| map_constructor | | ||
|
|
@@ -390,6 +391,17 @@ cardano_publish_block = { | |
| "}" | ||
| } | ||
|
|
||
| cardano_payment_part = { "payment_part" ~ "(" ~ data_expr ~ ")" } | ||
| cardano_staking_part = { "staking_part" ~ "(" ~ data_expr ~ ")" } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
|
|
||
| cardano_functions = { | ||
| "cardano" ~ "::" ~ ( | ||
| cardano_payment_part | | ||
| cardano_staking_part | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| cardano_block = { | ||
| "cardano" ~ "::" ~ ( | ||
| cardano_stake_delegation_certificate | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relying on byte positions is too risky. Use
pallas::ledger::addresses::Addressto parse the bytes and return the data fragment we need.