Skip to content

Commit

Permalink
Add broker API endpoint for marking txs as tainted.
Browse files Browse the repository at this point in the history
  • Loading branch information
MxmUrw committed Oct 21, 2024
1 parent 53edef2 commit af966d1
Showing 4 changed files with 39 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
@@ -24,6 +24,7 @@ workspace = true
[dependencies]
chainflip-api = { path = "../../lib" }
cf-utilities = { package = "utilities", path = "../../../utilities" }
cf-chains = { path = "../../../state-chain/chains" }
custom-rpc = { path = "../../../state-chain/custom-rpc" }

anyhow = "1.0"
18 changes: 16 additions & 2 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cf_chains::btc::UtxoId;
use cf_utilities::{
health::{self, HealthCheckOptions},
task_scope::{task_scope, Scope},
@@ -6,8 +7,8 @@ use chainflip_api::{
self,
primitives::{AccountRole, Affiliates, Asset, BasisPoints, CcmChannelMetadata, DcaParameters},
settings::StateChain,
AccountId32, AddressString, BrokerApi, OperatorApi, RefundParameters, StateChainApi,
SwapDepositAddress, WithdrawFeesDetail,
AccountId32, AddressString, BrokerApi, DepositMonitorApi, OperatorApi, RefundParameters,
StateChainApi, SwapDepositAddress, WithdrawFeesDetail,
};
use clap::Parser;
use custom_rpc::to_rpc_error;
@@ -17,6 +18,7 @@ use jsonrpsee::{
proc_macros::rpc,
server::ServerBuilder,
};
use sp_core::H256;
use std::{
path::PathBuf,
sync::{atomic::AtomicBool, Arc},
@@ -48,6 +50,9 @@ pub trait Rpc {
asset: Asset,
destination_address: AddressString,
) -> RpcResult<WithdrawFeesDetail>;

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

pub struct RpcServerImpl {
@@ -120,6 +125,15 @@ impl RpcServer for RpcServerImpl {
.await
.map_err(to_rpc_error)?)
}

async fn mark_btc_transaction_as_tainted(&self, tx_id: H256, vout: u32) -> RpcResult<()> {
Ok(self
.api
.deposit_monitor_api()
.mark_btc_transaction_as_tainted(UtxoId { tx_id, vout })
.await
.map_err(to_rpc_error)?)
}
}

#[derive(Parser, Debug, Clone, Default)]
21 changes: 21 additions & 0 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use anyhow::{anyhow, bail, Context, Result};
use async_trait::async_trait;
use cf_chains::{
address::{try_from_encoded_address, EncodedAddress},
btc::UtxoId,
dot::PolkadotAccountId,
evm::to_evm_address,
sol::SolAddress,
@@ -150,6 +151,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() }
}
@@ -167,6 +172,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 {
@@ -548,6 +555,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: UtxoId) -> 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 {

0 comments on commit af966d1

Please sign in to comment.