Skip to content

Commit

Permalink
Merge pull request #15 from bitcoinscalinglabs/btc-create-subnet-sender
Browse files Browse the repository at this point in the history
Don't require `from` when creating btc subnet
  • Loading branch information
OrestisAlpos authored Feb 6, 2025
2 parents 4f6a861 + c087a56 commit a07e7ec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
14 changes: 10 additions & 4 deletions ipc/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,17 @@ impl IpcProvider {
params: ConstructParams,
) -> anyhow::Result<Address> {
let conn = self.get_connection(&parent)?;
let parent = conn.subnet();

let subnet = conn.subnet();
let sender = self.check_sender(subnet, from)?;

conn.manager().create_subnet(sender, params).await
match parent.config {
config::subnet::SubnetConfig::Fevm(_) => {
let sender = self.check_sender(parent, from)?;
conn.manager().create_subnet(Some(sender), params).await
}
config::subnet::SubnetConfig::Btc(_) => {
conn.manager().create_subnet(None, params).await
}
}
}

pub async fn join_subnet(
Expand Down
6 changes: 5 additions & 1 deletion ipc/provider/src/manager/btc/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ impl BtcSubnetManager {
}
#[async_trait]
impl SubnetManager for BtcSubnetManager {
async fn create_subnet(&self, _from: Address, params: ConstructParams) -> Result<Address> {
async fn create_subnet(
&self,
_from: Option<Address>,
params: ConstructParams,
) -> Result<Address> {
let params: BtcConstructParams = match params {
ConstructParams::Eth(_) => return Err(anyhow!("Unsupported subnet configuration")),
ConstructParams::Btc(params) => params,
Expand Down
11 changes: 10 additions & 1 deletion ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,22 @@ impl TopDownFinalityQuery for EthSubnetManager {

#[async_trait]
impl SubnetManager for EthSubnetManager {
async fn create_subnet(&self, from: Address, params: ConstructParams) -> Result<Address> {
async fn create_subnet(
&self,
from: Option<Address>,
params: ConstructParams,
) -> Result<Address> {
let params: EthConstructParams = match params {
ConstructParams::Eth(params) => params,
ConstructParams::Btc(_) => return Err(anyhow!("Unsupported subnet configuration")),
};
self.ensure_same_gateway(&params.ipc_gateway_addr)?;

let from = match from {
Some(f) => f,
None => return Err(anyhow!("missing from address")),
};

let min_validator_stake = params
.min_validator_stake
.atto()
Expand Down
6 changes: 5 additions & 1 deletion ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ pub trait SubnetManager:
/// configuration passed in `ConstructParams`.
/// The result of the function is the ID of the subnet child from which the final
/// subnet ID can be inferred.
async fn create_subnet(&self, from: Address, params: ConstructParams) -> Result<Address>;
async fn create_subnet(
&self,
from: Option<Address>,
params: ConstructParams,
) -> Result<Address>;

/// Performs the call to join a subnet from a wallet address and staking an amount
/// of collateral. This function, as well as all of the ones on this trait, can infer
Expand Down

0 comments on commit a07e7ec

Please sign in to comment.