-
Notifications
You must be signed in to change notification settings - Fork 428
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
Custom signature topic #2031
Merged
Merged
Custom signature topic #2031
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8df58c3
basic setup
SkymanOne ff82dcb
successful parsing of args
SkymanOne 6706b96
working specification
SkymanOne 14429ac
fix tests
SkymanOne 5d3333b
add changelog
SkymanOne 48cec1f
fmt
SkymanOne b802df2
add signature_topic macro
SkymanOne ac0d28c
simpligy argument parsing
SkymanOne 8feaf2d
add tests
SkymanOne 21994a2
remove links
SkymanOne 683e180
use const array
SkymanOne 91b3f91
remove hex crate
SkymanOne 3c788c3
Refactor. Remove signature topic macro in favor of local custom ink a…
SkymanOne 490e5a6
Merge branch 'master' into gn/custom-signature-topic
SkymanOne 1c92ba8
minor fixes
SkymanOne 9e67b3e
remove trailing code
SkymanOne c1168e7
fix UI tests
SkymanOne 764443c
add UI tests
SkymanOne 67ed065
extra UI tests and improved error reporting
SkymanOne 07433cb
uncomment tests
SkymanOne 7eba6a8
rename function
SkymanOne c5e5e9f
Merge branch 'master' into gn/custom-signature-topic
SkymanOne 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -24,17 +24,21 @@ pub struct EventConfig { | |
/// If set to `true`, **no** signature topic is generated or emitted for this event., | ||
/// This is the default value. | ||
anonymous: bool, | ||
|
||
/// Manually specified signature topic hash. | ||
signature_topic_hash: Option<String>, | ||
} | ||
|
||
impl TryFrom<ast::AttributeArgs> for EventConfig { | ||
type Error = syn::Error; | ||
|
||
fn try_from(args: ast::AttributeArgs) -> Result<Self, Self::Error> { | ||
let mut anonymous: Option<syn::LitBool> = None; | ||
let mut signature_topic: Option<syn::LitStr> = None; | ||
for arg in args.into_iter() { | ||
if arg.name.is_ident("anonymous") { | ||
if let Some(lit_bool) = anonymous { | ||
return Err(duplicate_config_err(lit_bool, arg, "anonymous", "event")) | ||
return Err(duplicate_config_err(lit_bool, arg, "anonymous", "event")); | ||
} | ||
if let ast::MetaValue::Lit(syn::Lit::Bool(lit_bool)) = &arg.value { | ||
anonymous = Some(lit_bool.clone()) | ||
|
@@ -44,27 +48,56 @@ impl TryFrom<ast::AttributeArgs> for EventConfig { | |
"expected a bool literal for `anonymous` ink! event item configuration argument", | ||
)); | ||
} | ||
} else if arg.name.is_ident("signature_topic") { | ||
if anonymous.is_some() { | ||
return Err(format_err_spanned!( | ||
arg, | ||
"cannot specify `signature_topic` with `anonymous` in ink! event item configuration argument", | ||
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. I guess this is the error we want to see in those ui tests |
||
)); | ||
} | ||
|
||
if let Some(lit_str) = signature_topic { | ||
return Err(duplicate_config_err(lit_str, arg, "anonymous", "event")); | ||
} | ||
if let ast::MetaValue::Lit(syn::Lit::Str(lis_str)) = &arg.value { | ||
signature_topic = Some(lis_str.clone()) | ||
} else { | ||
return Err(format_err_spanned!( | ||
arg, | ||
"expected a bool literal for `anonymous` ink! event item configuration argument", | ||
)); | ||
} | ||
} else { | ||
return Err(format_err_spanned!( | ||
arg, | ||
"encountered unknown or unsupported ink! storage item configuration argument", | ||
)); | ||
} | ||
} | ||
|
||
Ok(EventConfig::new( | ||
anonymous.map(|lit_bool| lit_bool.value).unwrap_or(false), | ||
signature_topic.map(|lit_str| lit_str.value()), | ||
)) | ||
} | ||
} | ||
|
||
impl EventConfig { | ||
/// Construct a new [`EventConfig`]. | ||
pub fn new(anonymous: bool) -> Self { | ||
Self { anonymous } | ||
pub fn new(anonymous: bool, signature_topic_hash: Option<String>) -> Self { | ||
Self { | ||
anonymous, | ||
signature_topic_hash, | ||
} | ||
} | ||
|
||
/// Returns the anonymous configuration argument. | ||
pub fn anonymous(&self) -> bool { | ||
self.anonymous | ||
} | ||
|
||
/// Returns the manually specified signature topic. | ||
pub fn signature_topic_hash(&self) -> Option<String> { | ||
self.signature_topic_hash.clone() | ||
ascjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
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.
hash
again here