[CLI] remove select_full_bridge!() macro

Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
Serban Iorga
2022-07-06 15:45:30 +03:00
committed by Bastian Köcher
parent 88e95388bb
commit f89eeb920a
5 changed files with 323 additions and 259 deletions
@@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use crate::{
cli::{
bridge::FullBridge, relay_headers_and_messages::CONVERSION_RATE_ALLOWED_DIFFERENCE_RATIO,
Balance, HexBytes, HexLaneId, SourceConnectionParams,
},
select_full_bridge,
use crate::cli::{
bridge::{FullBridge, MessagesCliBridge, *},
relay_headers_and_messages::CONVERSION_RATE_ALLOWED_DIFFERENCE_RATIO,
Balance, HexBytes, HexLaneId, SourceConnectionParams,
};
use async_trait::async_trait;
use bp_runtime::BalanceOf;
use codec::{Decode, Encode};
use relay_substrate_client::Chain;
use relay_substrate_client::{Chain, ChainBase};
use sp_runtime::FixedU128;
use std::fmt::Display;
use structopt::StructOpt;
use strum::VariantNames;
use substrate_relay_helper::helpers::tokens_conversion_rate_from_metrics;
@@ -74,30 +74,50 @@ impl std::str::FromStr for ConversionRateOverride {
}
}
#[async_trait]
trait FeeEstimator: MessagesCliBridge
where
<Self::Source as ChainBase>::Balance: Display + Into<u128>,
{
async fn estimate_fee(data: EstimateFee) -> anyhow::Result<()> {
let source_client = data.source.to_client::<Self::Source>().await?;
let lane = data.lane.into();
let payload =
crate::cli::encode_message::encode_message::<Self::Source, Self::Target>(&data.payload)
.map_err(|e| anyhow::format_err!("{:?}", e))?;
let fee = estimate_message_delivery_and_dispatch_fee::<Self::Source, Self::Target, _>(
&source_client,
data.conversion_rate_override,
Self::ESTIMATE_MESSAGE_FEE_METHOD,
lane,
payload,
)
.await?;
log::info!(target: "bridge", "Fee: {:?}", Balance(fee.into()));
println!("{}", fee);
Ok(())
}
}
impl FeeEstimator for MillauToRialtoCliBridge {}
impl FeeEstimator for RialtoToMillauCliBridge {}
impl FeeEstimator for MillauToRialtoParachainCliBridge {}
impl FeeEstimator for RialtoParachainToMillauCliBridge {}
impl EstimateFee {
/// Run the command.
pub async fn run(self) -> anyhow::Result<()> {
let Self { source, bridge, lane, conversion_rate_override, payload } = self;
select_full_bridge!(bridge, {
let source_client = source.to_client::<Source>().await?;
let lane = lane.into();
let payload = crate::cli::encode_message::encode_message::<Source, Target>(&payload)
.map_err(|e| anyhow::format_err!("{:?}", e))?;
let fee = estimate_message_delivery_and_dispatch_fee::<Source, Target, _>(
&source_client,
conversion_rate_override,
ESTIMATE_MESSAGE_FEE_METHOD,
lane,
payload,
)
.await?;
log::info!(target: "bridge", "Fee: {:?}", Balance(fee as _));
println!("{}", fee);
Ok(())
})
match self.bridge {
FullBridge::MillauToRialto => MillauToRialtoCliBridge::estimate_fee(self),
FullBridge::RialtoToMillau => RialtoToMillauCliBridge::estimate_fee(self),
FullBridge::MillauToRialtoParachain =>
MillauToRialtoParachainCliBridge::estimate_fee(self),
FullBridge::RialtoParachainToMillau =>
RialtoParachainToMillauCliBridge::estimate_fee(self),
}
.await
}
}