Skip to content

Commit

Permalink
Add endpoint for marking btc tx as tainted.
Browse files Browse the repository at this point in the history
  • Loading branch information
MxmUrw committed Oct 28, 2024
1 parent 6cbcde1 commit a3835f1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 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/bin/chainflip-broker-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ workspace = true

[dependencies]
chainflip-api = { workspace = true }
cf-chains = { workspace = true, default-features = true }
cf-utilities = { workspace = true, default-features = true }
custom-rpc = { workspace = true }

Expand Down
15 changes: 13 additions & 2 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use chainflip_api::{
self,
primitives::{AccountRole, Affiliates, Asset, BasisPoints, CcmChannelMetadata, DcaParameters},
settings::StateChain,
AccountId32, AddressString, BrokerApi, OperatorApi, RefundParameters, StateChainApi,
SwapDepositAddress, SwapPayload, WithdrawFeesDetail,
AccountId32, AddressString, BrokerApi, DepositMonitorApi, OperatorApi, RefundParameters,
StateChainApi, SwapDepositAddress, SwapPayload, WithdrawFeesDetail,
};
use clap::Parser;
use futures::FutureExt;
Expand Down Expand Up @@ -100,6 +100,9 @@ pub trait Rpc {
affiliate_fees: Option<Affiliates<AccountId32>>,
dca_parameters: Option<DcaParameters>,
) -> RpcResult<SwapPayload>;

#[method(name = "mark_btc_transaction_as_tainted", aliases = ["broker_markBtcTransactionAsTainted"])]
async fn mark_btc_transaction_as_tainted(&self, tx_id: cf_chains::btc::Hash) -> RpcResult<()>;
}

pub struct RpcServerImpl {
Expand Down Expand Up @@ -194,6 +197,14 @@ impl RpcServer for RpcServerImpl {
)
.await?)
}

async fn mark_btc_transaction_as_tainted(&self, tx_id: cf_chains::btc::Hash) -> RpcResult<()> {
self.api
.deposit_monitor_api()
.mark_btc_transaction_as_tainted(tx_id)
.await
.map_err(BrokerApiError::Other)
}
}

#[derive(Parser, Debug, Clone, Default)]
Expand Down
20 changes: 20 additions & 0 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ impl StateChainApi {
self.state_chain_client.clone()
}

pub fn deposit_monitor_api(&self) -> Arc<impl DepositMonitorApi> {
self.state_chain_client.clone()
}

pub fn query_api(&self) -> queries::QueryApi {
queries::QueryApi { state_chain_client: self.state_chain_client.clone() }
}
Expand All @@ -175,6 +179,8 @@ impl BrokerApi for StateChainClient {
impl OperatorApi for StateChainClient {}
#[async_trait]
impl ValidatorApi for StateChainClient {}
#[async_trait]
impl DepositMonitorApi for StateChainClient {}

#[async_trait]
pub trait ValidatorApi: SimpleSubmissionApi {
Expand Down Expand Up @@ -628,6 +634,20 @@ pub fn clean_foreign_chain_address(chain: ForeignChain, address: &str) -> Result
})
}

#[async_trait]
pub trait DepositMonitorApi:
SignedExtrinsicApi + StorageApi + Sized + Send + Sync + 'static
{
async fn mark_btc_transaction_as_tainted(&self, tx_id: cf_chains::btc::Hash) -> Result<()> {
let _ = self
.submit_signed_extrinsic(state_chain_runtime::RuntimeCall::BitcoinIngressEgress(
pallet_cf_ingress_egress::Call::mark_transaction_as_tainted { tx_id },
))
.await;
Ok(())
}
}

#[derive(Debug, Zeroize, PartialEq, Eq)]
/// Public and Secret keys as bytes
pub struct KeyPair {
Expand Down

0 comments on commit a3835f1

Please sign in to comment.