-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting constants via manifest (#1030)
* Add constants to manifest * fmt * fix nit * clippy * Add custom parsing for consts
- Loading branch information
1 parent
0890fd1
commit 484a0e3
Showing
8 changed files
with
301 additions
and
31 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use syn::parse::Parse; | ||
use syn::{Attribute, Ident, Token, Type, Visibility}; | ||
|
||
use crate::manifest::Manifest; | ||
|
||
/// A partial const declaration: `const MAX: u16;`. | ||
pub struct PartialItemConst { | ||
pub attrs: Vec<Attribute>, | ||
pub vis: Visibility, | ||
pub const_token: Token![const], | ||
pub ident: Ident, | ||
pub colon_token: Token![:], | ||
pub ty: Type, | ||
pub semi_token: Token![;], | ||
} | ||
|
||
impl Parse for PartialItemConst { | ||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { | ||
Ok(Self { | ||
attrs: Attribute::parse_outer(input)?, | ||
vis: input.parse()?, | ||
const_token: input.parse()?, | ||
ident: input.parse()?, | ||
colon_token: input.parse()?, | ||
ty: input.parse()?, | ||
semi_token: input.parse()?, | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) fn make_const( | ||
field_ident: &Ident, | ||
ty: &Type, | ||
vis: syn::Visibility, | ||
attrs: &[syn::Attribute], | ||
) -> Result<proc_macro2::TokenStream, syn::Error> { | ||
Manifest::read_constants(field_ident)?.parse_constant(ty, field_ident, vis, attrs) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"comment": "Sovereign SDK constants", | ||
"constants": { | ||
"TEST_U32": 42, | ||
"TEST_BOOL": true, | ||
"TEST_STRING": "Some Other String", | ||
"TEST_NESTED_ARRAY": [ | ||
[ | ||
7, | ||
7, | ||
7 | ||
], | ||
[ | ||
7, | ||
7, | ||
7 | ||
] | ||
], | ||
"TEST_ARRAY_OF_U8": [ | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11, | ||
11 | ||
] | ||
}, | ||
"gas": { | ||
"Bank": { | ||
"create_token": [ | ||
4, | ||
4 | ||
], | ||
"transfer": [ | ||
5, | ||
5 | ||
], | ||
"burn": [ | ||
2, | ||
2 | ||
], | ||
"mint": [ | ||
2, | ||
2 | ||
], | ||
"freeze": [ | ||
1, | ||
1 | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.