Skip to content

Commit

Permalink
Feature: Add dry run CLI and use it in register_account_role (#3992)
Browse files Browse the repository at this point in the history
  • Loading branch information
syan095 authored and dandanlen committed Sep 21, 2023
1 parent 6e87a6d commit 90a0cc5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ cf-amm = { path = "../../state-chain/amm" }
sp-consensus-aura = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
sp-core = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
sp-consensus-grandpa = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
codec = { package = "parity-scale-codec", version = "3.6.1" }
28 changes: 27 additions & 1 deletion api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cf_chains::{
CcmChannelMetadata, ForeignChain,
};
use cf_primitives::{AccountRole, Asset, BasisPoints, ChannelId};
use codec::Encode;
use futures::FutureExt;
use pallet_cf_governance::ExecutionMode;
use pallet_cf_validator::MAX_LENGTH_FOR_VANITY_NAME;
Expand Down Expand Up @@ -138,7 +139,24 @@ impl StateChainApi {
}

#[async_trait]
impl OperatorApi for StateChainClient {}
impl<
SignedExtrinsicClient: Send + Sync + 'static + SignedExtrinsicApi,
RawRpcClient: Send + Sync + 'static + RawRpcApi,
> OperatorApi for StateChainClient<SignedExtrinsicClient, BaseRpcClient<RawRpcClient>>
{
async fn dry_run(
&self,
call: RuntimeCall,
at: Option<state_chain_runtime::Hash>,
) -> Result<Bytes> {
Ok(self
.base_rpc_client
.raw_rpc_client
.dry_run(Encode::encode(&call).into(), at)
.await?)
}
}

#[async_trait]
impl GovernanceApi for StateChainClient {}
#[async_trait]
Expand Down Expand Up @@ -187,6 +205,8 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
AccountRole::None => bail!("Cannot register account role None"),
};

let _ = self.dry_run(call.clone(), None).await?;

let (tx_hash, ..) = self
.submit_signed_extrinsic(call)
.await
Expand Down Expand Up @@ -258,6 +278,12 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
println!("Vanity name set at tx {tx_hash:#x}.");
Ok(())
}

async fn dry_run(
&self,
call: RuntimeCall,
at: Option<state_chain_runtime::Hash>,
) -> Result<Bytes>;
}

#[async_trait]
Expand Down
1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ sp-core = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainf
sp-rpc = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sp-runtime = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sp-version = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
substrate-frame-rpc-system = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }

[dependencies.rocksdb]
version = "0.21.0"
Expand Down
18 changes: 18 additions & 0 deletions engine/src/state_chain_observer/client/base_rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub trait RawRpcApi:
state_chain_runtime::Hash,
state_chain_runtime::Header,
state_chain_runtime::SignedBlock,
> + substrate_frame_rpc_system::SystemApiClient<
state_chain_runtime::Hash,
state_chain_runtime::AccountId,
state_chain_runtime::Nonce,
>
{
}
Expand Down Expand Up @@ -119,6 +123,12 @@ pub trait BaseRpcApi {
asset: Asset,
at: state_chain_runtime::Hash,
) -> RpcResult<Vec<(Tick, Tick, Liquidity)>>;

async fn dry_run(
&self,
extrinsic: Bytes,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<Bytes>;
}

pub struct BaseRpcClient<RawRpcClient> {
Expand Down Expand Up @@ -215,4 +225,12 @@ impl<RawRpcClient: RawRpcApi + Send + Sync> BaseRpcApi for BaseRpcClient<RawRpcC
//self.raw_rpc_client.cf_pool_minted_positions(lp, asset, Some(at)).await
Err(jsonrpsee::core::Error::Custom("Not implemented".to_string()))
}

async fn dry_run(
&self,
extrinsic: Bytes,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<Bytes> {
self.raw_rpc_client.dry_run(extrinsic, at).await
}
}

0 comments on commit 90a0cc5

Please sign in to comment.