diff --git a/chia-tools/src/bin/run-spend.rs b/chia-tools/src/bin/run-spend.rs index a3f73991c..a386380c0 100644 --- a/chia-tools/src/bin/run-spend.rs +++ b/chia-tools/src/bin/run-spend.rs @@ -130,14 +130,14 @@ pub struct SingletonStruct { } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct SingletonArgs { pub singleton_struct: SingletonStruct, pub inner_puzzle: NodePtr, } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct LineageProof { pub parent_parent_coin_id: Bytes32, pub parent_inner_puzzle_hash: Bytes32, @@ -145,14 +145,14 @@ pub struct LineageProof { } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct EveProof { pub parent_parent_coin_id: Bytes32, pub parent_amount: u64, } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct SingletonSolution { pub lineage_proof: LineageProof, pub amount: u64, @@ -160,7 +160,7 @@ pub struct SingletonSolution { } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct EveSingletonSolution { pub lineage_proof: EveProof, pub amount: u64, diff --git a/chia-wallet/src/proof.rs b/chia-wallet/src/proof.rs index 69c421db7..aadc97cf8 100644 --- a/chia-wallet/src/proof.rs +++ b/chia-wallet/src/proof.rs @@ -44,7 +44,7 @@ impl<'a> Arbitrary<'a> for Proof { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct LineageProof { pub parent_coin_info: [u8; 32], pub inner_puzzle_hash: [u8; 32], @@ -52,7 +52,7 @@ pub struct LineageProof { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct EveProof { pub parent_coin_info: [u8; 32], pub amount: u64, diff --git a/chia-wallet/src/puzzles/cat.rs b/chia-wallet/src/puzzles/cat.rs index 7f2a97d99..9be53ce9d 100644 --- a/chia-wallet/src/puzzles/cat.rs +++ b/chia-wallet/src/puzzles/cat.rs @@ -7,7 +7,7 @@ use hex_literal::hex; use crate::LineageProof; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct CatArgs { pub mod_hash: [u8; 32], pub tail_program_hash: [u8; 32], @@ -15,13 +15,13 @@ pub struct CatArgs { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct EverythingWithSignatureTailArgs { pub public_key: PublicKey, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct CatSolution { pub inner_puzzle_solution: NodePtr, pub lineage_proof: Option, @@ -33,7 +33,7 @@ pub struct CatSolution { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct CoinProof { pub parent_coin_info: [u8; 32], pub inner_puzzle_hash: [u8; 32], diff --git a/chia-wallet/src/puzzles/did.rs b/chia-wallet/src/puzzles/did.rs index e9c61f099..dc260f64f 100644 --- a/chia-wallet/src/puzzles/did.rs +++ b/chia-wallet/src/puzzles/did.rs @@ -5,7 +5,7 @@ use hex_literal::hex; use crate::singleton::SingletonStruct; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct DidArgs { pub inner_puzzle: NodePtr, pub recovery_did_list_hash: [u8; 32], diff --git a/chia-wallet/src/puzzles/nft.rs b/chia-wallet/src/puzzles/nft.rs index 5b8a1a9d6..4a9bf68b5 100644 --- a/chia-wallet/src/puzzles/nft.rs +++ b/chia-wallet/src/puzzles/nft.rs @@ -6,7 +6,7 @@ use hex_literal::hex; use crate::singleton::SingletonStruct; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct NftIntermediateLauncherArgs { pub launcher_puzzle_hash: [u8; 32], pub mint_number: usize, @@ -14,7 +14,7 @@ pub struct NftIntermediateLauncherArgs { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct NftStateLayerArgs { pub mod_hash: [u8; 32], pub metadata: NodePtr, @@ -23,13 +23,13 @@ pub struct NftStateLayerArgs { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct NftStateLayerSolution { pub inner_solution: NodePtr, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct NftOwnershipLayerArgs { pub mod_hash: [u8; 32], pub current_owner: Option<[u8; 32]>, @@ -38,13 +38,13 @@ pub struct NftOwnershipLayerArgs { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct NftOwnershipLayerSolution { pub inner_solution: NodePtr, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct NftRoyaltyTransferPuzzleArgs { pub singleton_struct: SingletonStruct, pub royalty_puzzle_hash: [u8; 32], diff --git a/chia-wallet/src/puzzles/singleton.rs b/chia-wallet/src/puzzles/singleton.rs index a56606e4a..58bdb046d 100644 --- a/chia-wallet/src/puzzles/singleton.rs +++ b/chia-wallet/src/puzzles/singleton.rs @@ -5,7 +5,7 @@ use hex_literal::hex; use crate::Proof; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct SingletonArgs { pub singleton_struct: SingletonStruct, pub inner_puzzle: NodePtr, @@ -20,7 +20,7 @@ pub struct SingletonStruct { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct SingletonSolution { pub proof: Proof, pub amount: u64, @@ -28,7 +28,7 @@ pub struct SingletonSolution { } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct LauncherSolution { pub singleton_puzzle_hash: [u8; 32], pub amount: u64, diff --git a/chia-wallet/src/puzzles/standard.rs b/chia-wallet/src/puzzles/standard.rs index e9e0e61c2..90e6c2a54 100644 --- a/chia-wallet/src/puzzles/standard.rs +++ b/chia-wallet/src/puzzles/standard.rs @@ -5,13 +5,13 @@ use clvmr::allocator::NodePtr; use hex_literal::hex; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct StandardArgs { pub synthetic_key: PublicKey, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] -#[clvm(proper_list)] +#[clvm(list)] pub struct StandardSolution { pub original_public_key: Option, pub delegated_puzzle: NodePtr, diff --git a/clvm-derive/src/from_clvm.rs b/clvm-derive/src/from_clvm.rs index b561f887a..4d295b398 100644 --- a/clvm-derive/src/from_clvm.rs +++ b/clvm-derive/src/from_clvm.rs @@ -43,7 +43,7 @@ pub fn from_clvm(mut ast: DeriveInput) -> TokenStream { // `match_macro` decodes a nested tuple containing each of the struct field types within. // `destructure_macro` destructures the values into the field names, to be stored in the struct. let (match_macro, destructure_macro) = match args.repr { - Repr::ProperList => ( + Repr::List => ( quote!( #crate_name::match_list ), quote!( #crate_name::destructure_list ), ), @@ -51,7 +51,7 @@ pub fn from_clvm(mut ast: DeriveInput) -> TokenStream { quote!( #crate_name::match_tuple ), quote!( #crate_name::destructure_tuple ), ), - Repr::CurriedArgs => ( + Repr::Curry => ( quote!( #crate_name::match_curried_args ), quote!( #crate_name::destructure_curried_args ), ), diff --git a/clvm-derive/src/helpers.rs b/clvm-derive/src/helpers.rs index 7f0bfce59..4f126be02 100644 --- a/clvm-derive/src/helpers.rs +++ b/clvm-derive/src/helpers.rs @@ -1,20 +1,22 @@ +use std::fmt; + use proc_macro2::Ident; use syn::{punctuated::Punctuated, Attribute, GenericParam, Generics, Token, TypeParamBound}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Repr { Tuple, - ProperList, - CurriedArgs, + List, + Curry, } -impl ToString for Repr { - fn to_string(&self) -> String { - match self { - Self::Tuple => "tuple".to_string(), - Self::ProperList => "proper_list".to_string(), - Self::CurriedArgs => "curried_args".to_string(), - } +impl fmt::Display for Repr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Self::Tuple => "tuple", + Self::List => "list", + Self::Curry => "curry", + }) } } @@ -23,8 +25,15 @@ pub struct ClvmDeriveArgs { } pub fn parse_args(attrs: &[Attribute]) -> ClvmDeriveArgs { - let mut repr: Option = None; + let repr = parse_repr(attrs); + ClvmDeriveArgs { + repr: repr + .expect("expected clvm attribute parameter of either `tuple`, `list`, or `curry`"), + } +} +pub fn parse_repr(attrs: &[Attribute]) -> Option { + let mut repr: Option = None; for attr in attrs { if let Some(ident) = attr.path().get_ident() { if ident == "clvm" { @@ -33,37 +42,23 @@ pub fn parse_args(attrs: &[Attribute]) -> ClvmDeriveArgs { .unwrap(); for arg in args { - match arg.to_string().as_str() { - "tuple" => { - if let Some(existing) = repr { - panic!("`tuple` conflicts with `{}`", existing.to_string()); - } - repr = Some(Repr::Tuple); - } - "proper_list" => { - if let Some(existing) = repr { - panic!("`proper_list` conflicts with `{}`", existing.to_string()); - } - repr = Some(Repr::ProperList); - } - "curried_args" => { - if let Some(existing) = repr { - panic!("`curried_args` conflicts with `{}`", existing.to_string()); - } - repr = Some(Repr::CurriedArgs); - } - ident => panic!("unknown argument `{}`", ident), + let existing = repr; + + repr = Some(match arg.to_string().as_str() { + "tuple" => Repr::Tuple, + "list" => Repr::List, + "curry" => Repr::Curry, + ident => panic!("unknown argument `{ident}`"), + }); + + if let Some(existing) = existing { + panic!("`{arg}` conflicts with `{existing}`"); } } } } } - - ClvmDeriveArgs { - repr: repr.expect( - "expected clvm attribute parameter of either `tuple`, `proper_list`, or `curried_args`", - ), - } + repr } pub fn add_trait_bounds(generics: &mut Generics, bound: TypeParamBound) { diff --git a/clvm-derive/src/to_clvm.rs b/clvm-derive/src/to_clvm.rs index ab7a25f0d..32c228ae0 100644 --- a/clvm-derive/src/to_clvm.rs +++ b/clvm-derive/src/to_clvm.rs @@ -42,9 +42,9 @@ pub fn to_clvm(mut ast: DeriveInput) -> TokenStream { // `list_macro` encodes a nested tuple containing each of the struct field values within. let list_macro = match args.repr { - Repr::ProperList => quote!( #crate_name::clvm_list ), + Repr::List => quote!( #crate_name::clvm_list ), Repr::Tuple => quote!( #crate_name::clvm_tuple ), - Repr::CurriedArgs => quote!( #crate_name::clvm_curried_args ), + Repr::Curry => quote!( #crate_name::clvm_curried_args ), }; add_trait_bounds(&mut ast.generics, parse_quote!(#crate_name::ToClvm)); diff --git a/clvm-traits/src/lib.rs b/clvm-traits/src/lib.rs index 35d3c51cf..bb860438a 100644 --- a/clvm-traits/src/lib.rs +++ b/clvm-traits/src/lib.rs @@ -8,8 +8,8 @@ //! with one of the following encodings: //! //! * `#[clvm(tuple)]` for unterminated lists such as `(A . (B . C))`. -//! * `#[clvm(proper_list)]` for proper lists such as `(A B C)`, or in other words `(A . (B . (C . ())))`. -//! * `#[clvm(curried_args)]` for curried arguments such as `(c (q . A) (c (q . B) (c (q . C) 1)))`. +//! * `#[clvm(list)]` for proper lists such as `(A B C)`, or in other words `(A . (B . (C . ())))`. +//! * `#[clvm(curry)]` for curried arguments such as `(c (q . A) (c (q . B) (c (q . C) 1)))`. #![cfg_attr( feature = "derive", @@ -90,28 +90,28 @@ mod tests { } #[test] - fn test_proper_list() { + fn test_list() { #[derive(Debug, ToClvm, FromClvm, PartialEq, Eq)] - #[clvm(proper_list)] - struct ProperListStruct { + #[clvm(list)] + struct ListStruct { a: u64, b: i32, } - check(ProperListStruct { a: 52, b: -32 }, "ff34ff81e080"); + check(ListStruct { a: 52, b: -32 }, "ff34ff81e080"); } #[test] - fn test_curried_args() { + fn test_curry() { #[derive(Debug, ToClvm, FromClvm, PartialEq, Eq)] - #[clvm(curried_args)] - struct CurriedArgsStruct { + #[clvm(curry)] + struct CurryStruct { a: u64, b: i32, } check( - CurriedArgsStruct { a: 52, b: -32 }, + CurryStruct { a: 52, b: -32 }, "ff04ffff0134ffff04ffff0181e0ff018080", ); } diff --git a/src/fast_forward.rs b/src/fast_forward.rs index 733912c45..49d20e7ed 100644 --- a/src/fast_forward.rs +++ b/src/fast_forward.rs @@ -16,14 +16,14 @@ pub struct SingletonStruct { } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(curried_args)] +#[clvm(curry)] pub struct SingletonArgs { pub singleton_struct: SingletonStruct, pub inner_puzzle: NodePtr, } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct LineageProof { pub parent_parent_coin_id: Bytes32, pub parent_inner_puzzle_hash: Bytes32, @@ -31,7 +31,7 @@ pub struct LineageProof { } #[derive(FromClvm, ToClvm, Debug)] -#[clvm(proper_list)] +#[clvm(list)] pub struct SingletonSolution { pub lineage_proof: LineageProof, pub amount: u64,