-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add ChainId type #171
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?
Conversation
4133d80
to
037d445
Compare
037d445
to
ef2ad22
Compare
f687ffe
to
d8e659e
Compare
b6b62ab
to
d5b2972
Compare
if value.as_ref() == SN_MAIN_STR { | ||
ChainId::Mainnet | ||
} else if value.as_ref() == SN_SEPOLIA_STR { | ||
ChainId::Sepolia | ||
} else { | ||
ChainId::Devnet(value) | ||
} |
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.
if value.as_ref() == SN_MAIN_STR { | |
ChainId::Mainnet | |
} else if value.as_ref() == SN_SEPOLIA_STR { | |
ChainId::Sepolia | |
} else { | |
ChainId::Devnet(value) | |
} | |
match value.as_ref() { | |
SN_MAIN_STR => ChainId::Mainnet, | |
SN_SEPOLIA_STR => ChainId::Sepolia, | |
_ => ChainId::Devnet(value), | |
} |
Also, why does conversion from ChainId
to ShortString
is possible but not the other way around if feature devnet
is disabled?
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.
It becomes failable when no feature devnet
, so we implement TryFrom
instead.
See below:
impl TryFrom<ShortString> for ChainId
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.
So this means that without the devnet
feature we only can convert a ShortString
to ChainId
with try_into
and not with into
? Even if the ShortString
may be SN_MAIN_STR
or SN_SEPOLIA_STR
Add the type
ChainId
What is the new behavior?
The
ChainId
type allows for representing the two starknet chains, SN_MAIN and SN_SEPOLIA.It offers type conversion from and into Felt, ShortString, String.
A new Rust feature
devnet
allows adding a custom local devnet with any validShortString
as name (eg.SN_DEVNET
).Also, add a new
short_string!
macro, for compile-time creation ofShortString
sDoes this introduce a breaking change?
Yes. Replace
TryFrom<&str> for ShortString
byFromStr for ShortString
.More idiomatic