Skip to content

Commit 0572aa3

Browse files
committed
Reintegrated generic IO support.
1 parent 9f06a4b commit 0572aa3

File tree

26 files changed

+1767
-1821
lines changed

26 files changed

+1767
-1821
lines changed

apps/src/bin/namada-client/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async fn main() -> Result<()> {
1616
CliApi::<CliIo>::handle_client_command::<HttpClient>(
1717
None,
1818
cli::namada_client_cli()?,
19+
&CliIo,
1920
)
2021
.await
2122
}

apps/src/bin/namada-relayer/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ async fn main() -> Result<()> {
1414

1515
let cmd = cli::namada_relayer_cli()?;
1616
// run the CLI
17-
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd).await
17+
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd, &CliIo)
18+
.await
1819
}

apps/src/bin/namada-wallet/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub fn main() -> Result<()> {
66
color_eyre::install()?;
77
let (cmd, ctx) = cli::namada_wallet_cli()?;
88
// run the CLI
9-
CliApi::<CliIo>::handle_wallet_command(cmd, ctx)
9+
CliApi::<CliIo>::handle_wallet_command(cmd, ctx, &CliIo)
1010
}

apps/src/lib/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,7 @@ pub mod args {
25342534
use super::context::*;
25352535
use super::utils::*;
25362536
use super::{ArgGroup, ArgMatches};
2537+
use crate::cli::context::FromContext;
25372538
use crate::config::{self, Action, ActionAtHeight};
25382539
use crate::facade::tendermint::Timeout;
25392540
use crate::facade::tendermint_config::net::Address as TendermintAddress;

apps/src/lib/cli/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::client::utils;
1313
#[async_trait::async_trait(?Send)]
1414
pub trait CliClient: Client + Sync {
1515
fn from_tendermint_address(address: &mut TendermintAddress) -> Self;
16-
async fn wait_until_node_is_synced<IO: Io>(&self) -> Halt<()>;
16+
async fn wait_until_node_is_synced(&self, io: &impl Io) -> Halt<()>;
1717
}
1818

1919
#[async_trait::async_trait(?Send)]
@@ -22,8 +22,8 @@ impl CliClient for HttpClient {
2222
HttpClient::new(utils::take_config_address(address)).unwrap()
2323
}
2424

25-
async fn wait_until_node_is_synced<IO: Io>(&self) -> Halt<()> {
26-
wait_until_node_is_synched::<_, IO>(self).await
25+
async fn wait_until_node_is_synced(&self, io: &impl Io) -> Halt<()> {
26+
wait_until_node_is_synched(self, io).await
2727
}
2828
}
2929

apps/src/lib/cli/client.rs

Lines changed: 143 additions & 162 deletions
Large diffs are not rendered by default.

apps/src/lib/cli/context.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use std::path::{Path, PathBuf};
66
use std::str::FromStr;
77

88
use color_eyre::eyre::Result;
9+
use namada::ledger::{Namada, NamadaImpl};
10+
use namada::sdk::masp::fs::FsShieldedUtils;
911
use namada::sdk::masp::ShieldedContext;
1012
use namada::sdk::wallet::Wallet;
11-
use namada::sdk::masp::fs::FsShieldedUtils;
1213
use namada::types::address::{Address, InternalAddress};
1314
use namada::types::chain::ChainId;
1415
use namada::types::ethereum_events::EthAddress;
@@ -150,6 +151,19 @@ impl Context {
150151
})
151152
}
152153

154+
/// Make an implementation of Namada from this object and parameters.
155+
pub fn to_sdk<'a, C, IO>(
156+
&'a mut self,
157+
client: &'a C,
158+
io: &'a IO,
159+
) -> impl Namada
160+
where
161+
C: namada::ledger::queries::Client + Sync,
162+
IO: Io,
163+
{
164+
NamadaImpl::new(client, &mut self.wallet, &mut self.shielded, io)
165+
}
166+
153167
/// Parse and/or look-up the value from the context.
154168
pub fn get<T>(&self, from_context: &FromContext<T>) -> T
155169
where

apps/src/lib/cli/relayer.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl<IO: Io> CliApi<IO> {
1919
pub async fn handle_relayer_command<C>(
2020
client: Option<C>,
2121
cmd: cli::NamadaRelayer,
22+
io: &IO,
2223
) -> Result<()>
2324
where
2425
C: CliClient,
@@ -36,11 +37,12 @@ impl<IO: Io> CliApi<IO> {
3637
)
3738
});
3839
client
39-
.wait_until_node_is_synced::<IO>()
40+
.wait_until_node_is_synced(io)
4041
.await
4142
.proceed_or_else(error)?;
4243
let args = args.to_sdk(&mut ctx);
43-
bridge_pool::recommend_batch::<_, IO>(&client, args)
44+
let namada = ctx.to_sdk(&client, io);
45+
bridge_pool::recommend_batch(&namada, args)
4446
.await
4547
.proceed_or_else(error)?;
4648
}
@@ -56,11 +58,11 @@ impl<IO: Io> CliApi<IO> {
5658
)
5759
});
5860
client
59-
.wait_until_node_is_synced::<IO>()
61+
.wait_until_node_is_synced(io)
6062
.await
6163
.proceed_or_else(error)?;
6264
let args = args.to_sdk_ctxless();
63-
bridge_pool::construct_proof::<_, IO>(&client, args)
65+
bridge_pool::construct_proof(&client, io, args)
6466
.await
6567
.proceed_or_else(error)?;
6668
}
@@ -71,16 +73,16 @@ impl<IO: Io> CliApi<IO> {
7173
)
7274
});
7375
client
74-
.wait_until_node_is_synced::<IO>()
76+
.wait_until_node_is_synced(io)
7577
.await
7678
.proceed_or_else(error)?;
7779
let eth_client = Arc::new(
7880
Provider::<Http>::try_from(&args.eth_rpc_endpoint)
7981
.unwrap(),
8082
);
8183
let args = args.to_sdk_ctxless();
82-
bridge_pool::relay_bridge_pool_proof::<_, _, IO>(
83-
eth_client, &client, args,
84+
bridge_pool::relay_bridge_pool_proof(
85+
eth_client, &client, io, args,
8486
)
8587
.await
8688
.proceed_or_else(error)?;
@@ -92,10 +94,10 @@ impl<IO: Io> CliApi<IO> {
9294
C::from_tendermint_address(&mut query.ledger_address)
9395
});
9496
client
95-
.wait_until_node_is_synced::<IO>()
97+
.wait_until_node_is_synced(io)
9698
.await
9799
.proceed_or_else(error)?;
98-
bridge_pool::query_bridge_pool::<_, IO>(&client).await;
100+
bridge_pool::query_bridge_pool(&client, io).await;
99101
}
100102
EthBridgePoolWithoutCtx::QuerySigned(
101103
QuerySignedBridgePool(mut query),
@@ -104,10 +106,10 @@ impl<IO: Io> CliApi<IO> {
104106
C::from_tendermint_address(&mut query.ledger_address)
105107
});
106108
client
107-
.wait_until_node_is_synced::<IO>()
109+
.wait_until_node_is_synced(io)
108110
.await
109111
.proceed_or_else(error)?;
110-
bridge_pool::query_signed_bridge_pool::<_, IO>(&client)
112+
bridge_pool::query_signed_bridge_pool(&client, io)
111113
.await
112114
.proceed_or_else(error)?;
113115
}
@@ -118,10 +120,10 @@ impl<IO: Io> CliApi<IO> {
118120
C::from_tendermint_address(&mut query.ledger_address)
119121
});
120122
client
121-
.wait_until_node_is_synced::<IO>()
123+
.wait_until_node_is_synced(io)
122124
.await
123125
.proceed_or_else(error)?;
124-
bridge_pool::query_relay_progress::<_, IO>(&client).await;
126+
bridge_pool::query_relay_progress(&client, io).await;
125127
}
126128
},
127129
cli::NamadaRelayer::ValidatorSet(sub) => match sub {
@@ -134,12 +136,12 @@ impl<IO: Io> CliApi<IO> {
134136
)
135137
});
136138
client
137-
.wait_until_node_is_synced::<IO>()
139+
.wait_until_node_is_synced(io)
138140
.await
139141
.proceed_or_else(error)?;
140142
let args = args.to_sdk_ctxless();
141-
validator_set::query_bridge_validator_set::<_, IO>(
142-
&client, args,
143+
validator_set::query_bridge_validator_set(
144+
&client, io, args,
143145
)
144146
.await;
145147
}
@@ -152,12 +154,12 @@ impl<IO: Io> CliApi<IO> {
152154
)
153155
});
154156
client
155-
.wait_until_node_is_synced::<IO>()
157+
.wait_until_node_is_synced(io)
156158
.await
157159
.proceed_or_else(error)?;
158160
let args = args.to_sdk_ctxless();
159-
validator_set::query_governnace_validator_set::<_, IO>(
160-
&client, args,
161+
validator_set::query_governnace_validator_set(
162+
&client, io, args,
161163
)
162164
.await;
163165
}
@@ -170,12 +172,12 @@ impl<IO: Io> CliApi<IO> {
170172
)
171173
});
172174
client
173-
.wait_until_node_is_synced::<IO>()
175+
.wait_until_node_is_synced(io)
174176
.await
175177
.proceed_or_else(error)?;
176178
let args = args.to_sdk_ctxless();
177-
validator_set::query_validator_set_update_proof::<_, IO>(
178-
&client, args,
179+
validator_set::query_validator_set_update_proof(
180+
&client, io, args,
179181
)
180182
.await;
181183
}
@@ -188,16 +190,16 @@ impl<IO: Io> CliApi<IO> {
188190
)
189191
});
190192
client
191-
.wait_until_node_is_synced::<IO>()
193+
.wait_until_node_is_synced(io)
192194
.await
193195
.proceed_or_else(error)?;
194196
let eth_client = Arc::new(
195197
Provider::<Http>::try_from(&args.eth_rpc_endpoint)
196198
.unwrap(),
197199
);
198200
let args = args.to_sdk_ctxless();
199-
validator_set::relay_validator_set_update::<_, _, IO>(
200-
eth_client, &client, args,
201+
validator_set::relay_validator_set_update(
202+
eth_client, &client, io, args,
201203
)
202204
.await
203205
.proceed_or_else(error)?;

apps/src/lib/cli/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use clap::{ArgAction, ArgMatches};
88
use color_eyre::eyre::Result;
99

1010
use super::args;
11-
use super::context::{Context, FromContext};
11+
use super::context::Context;
1212
use crate::cli::api::CliIo;
13+
use crate::cli::context::FromContext;
1314

1415
// We only use static strings
1516
pub type App = clap::Command;

0 commit comments

Comments
 (0)