-
Notifications
You must be signed in to change notification settings - Fork 72
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
Resolve identity from default config. #1711
Conversation
750bcc9
to
b71134d
Compare
long, | ||
visible_alias = "source", | ||
env = "STELLAR_ACCOUNT", | ||
default_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.
I think we should make the type an Option<String>
instead of having an empty string value. The empty string value is not common to see in Rust used in this way, and the interface is not so nice because the --help
prints out
Default 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.
+1 It was my suggestion because we were using FromStr
. I think perhaps the Address enum could add a Default
, case.
#[derive(Clone, Debug, Default)]
pub enum Address {
MuxedAccount(xdr::MuxedAccount),
AliasOrSecret(String),
#[default]
Config,
}
Then we can do self.source.unwrap_or_default()
.
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.
Using Option<String>
means we'll need to drop the current Address
type, right (link)? This is a "raw" value that's passed to the value parser.
I'll explore Willem's suggestion with the FromStr
trait.
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.
Btw, without setting a default value on the arg
macro, the --source-account
will always be required. We can explore using default_value_t
, but we'd need to return a Address
-typed object. I don't think we can get away with not setting a default value with clap.
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.
About the default value, clap has hide_default_value = true
, which hides it completely from the --help
output. Unfortunately, clap-markdown doesn't respect it (already have a ticket upstream for it).
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.
Sorry, my reference to String above was a mistake. I meant Option<Address>
.
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.
#[derive(Clone, Debug, Default)] pub enum Address { MuxedAccount(xdr::MuxedAccount), AliasOrSecret(String), #[default] Config, }
I would avoid ☝🏻 because it makes the type itself recursive. Anywhere you receive the Address
the consuming code would need to assume it could be Address::Config
and need to recurse to get a "resolved" Address
that wasn't Address::Config
, but then the type still contains that variant so any consuming code would be forced to handle it.
My main issue with the approach in the PR at the moment is really not to do with the type at all, but to do with the unpacking/resolving logic happening inside the type. I think the unpacking belongs outside the type, mostly because I'd prefer types to be largely data, rather than integrated with the presentation layer. But I understand it's convenient to put it there, and sort of awkward to do it the Option
way anwyay, and we already do resolution inside from_str anyway, so LGTM. 👍🏻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.
Going to merge it as is. If we can improve it, the improvement should be a no-op non-functional refactor and we can follow up with it.
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.
The only place where this Address
is pulled from the config is for the source account, so we could just handle the option is the source_account()
, method. If self.source_account
is None, then we use the config, otherwise it will be the Address
type and it resolves as normal. I do agree that using the empty string as a special case is not very idiomatic rust and Option is the preferred way to do it. Plus my recent work adding a ContractAddress
type make me realize that we need a unified approach between it and Address
because in contract invoke an ScAddress
could be either! So more reason not to handle the config at all in the Address
type.
long, | ||
visible_alias = "source", | ||
env = "STELLAR_ACCOUNT", | ||
default_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.
#[derive(Clone, Debug, Default)] pub enum Address { MuxedAccount(xdr::MuxedAccount), AliasOrSecret(String), #[default] Config, }
I would avoid ☝🏻 because it makes the type itself recursive. Anywhere you receive the Address
the consuming code would need to assume it could be Address::Config
and need to recurse to get a "resolved" Address
that wasn't Address::Config
, but then the type still contains that variant so any consuming code would be forced to handle it.
My main issue with the approach in the PR at the moment is really not to do with the type at all, but to do with the unpacking/resolving logic happening inside the type. I think the unpacking belongs outside the type, mostly because I'd prefer types to be largely data, rather than integrated with the presentation layer. But I understand it's convenient to put it there, and sort of awkward to do it the Option
way anwyay, and we already do resolution inside from_str anyway, so LGTM. 👍🏻
What
Resolve identity from default config.
Why
So you can actually use the value set by
stellar keys use
.Known limitations
N/A