Skip to content

Commit

Permalink
Simplify the whole thing.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Oct 2, 2024
1 parent 6315714 commit fd4a7c9
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ pub struct Args {
pub locator: locator::Args,
}

#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
pub struct ArgsLocatorAndNetwork {
#[command(flatten)]
pub network: network::Args,

#[command(flatten)]
pub locator: locator::Args,
}

impl Args {
// TODO: Replace PublicKey with MuxedAccount once https://github.com/stellar/rs-stellar-xdr/pull/396 is merged.
pub fn source_account(&self) -> Result<xdr::MuxedAccount, Error> {
Expand Down Expand Up @@ -121,7 +111,7 @@ impl Args {
}

pub fn get_network(&self) -> Result<Network, Error> {
HasNetwork::get_network(self)
Ok(self.network.get(&self.locator)?)
}

pub async fn next_sequence_number(&self, account_str: &str) -> Result<SequenceNumber, Error> {
Expand All @@ -140,37 +130,18 @@ impl Pwd for Args {
#[derive(Default, Serialize, Deserialize)]
pub struct Config {}

trait HasNetwork {
fn network_args(&self) -> &network::Args;
fn locator_args(&self) -> &locator::Args;

fn get_network(&self) -> Result<Network, Error> {
Ok(self.network_args().get(self.locator_args())?)
}
}

impl HasNetwork for Args {
fn network_args(&self) -> &network::Args {
&self.network
}

fn locator_args(&self) -> &locator::Args {
&self.locator
}
}

impl HasNetwork for ArgsLocatorAndNetwork {
fn network_args(&self) -> &network::Args {
&self.network
}
#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
pub struct ArgsLocatorAndNetwork {
#[command(flatten)]
pub network: network::Args,

fn locator_args(&self) -> &locator::Args {
&self.locator
}
#[command(flatten)]
pub locator: locator::Args,
}

impl ArgsLocatorAndNetwork {
pub fn get_network(&self) -> Result<Network, Error> {
HasNetwork::get_network(self)
Ok(self.network.get(&self.locator)?)
}
}

0 comments on commit fd4a7c9

Please sign in to comment.