Skip to content

Commit

Permalink
fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
open-junius committed Jan 20, 2025
1 parent 1341e7a commit 23f9b87
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions runtime/src/precompiles/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl SubnetPrecompile {
Self::register_network(handle, &method_input)
}
id if id == get_method_id("registerNetwork(bytes32)") => {
Self::register_network(handle, &[0_u8; 0])
Self::register_network(handle, &method_input)
}
_ => Err(PrecompileFailure::Error {
exit_status: ExitError::InvalidRange,
Expand All @@ -40,15 +40,17 @@ impl SubnetPrecompile {
}

fn register_network(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult {
let call = if data.is_empty() {
let hotkey = Self::parse_pub_key(data)?.into();
let call = if data.len() == 32 {
let mut hotkey = [0u8; 32];
hotkey.copy_from_slice(get_slice(data, 0, 32)?);

RuntimeCall::SubtensorModule(
pallet_subtensor::Call::<Runtime>::register_network_with_identity {
hotkey,
hotkey: hotkey.into(),
identity: None,
},
)
} else {
} else if data.len() > 32 {
let (pubkey, subnet_name, github_repo, subnet_contact) =
Self::parse_register_network_parameters(data)?;

Expand All @@ -65,23 +67,16 @@ impl SubnetPrecompile {
identity: Some(identity),
},
)
} else {
return Err(PrecompileFailure::Error {
exit_status: ExitError::InvalidRange,
});
};

// Dispatch the register_network call
dispatch(handle, call, STAKING_CONTRACT_ADDRESS)
}

fn parse_pub_key(data: &[u8]) -> Result<[u8; 32], PrecompileFailure> {
if data.len() < 32 {
return Err(PrecompileFailure::Error {
exit_status: ExitError::InvalidRange,
});
}
let mut pubkey = [0u8; 32];
pubkey.copy_from_slice(get_slice(data, 0, 32)?);
Ok(pubkey)
}

fn parse_register_network_parameters(
data: &[u8],
) -> Result<([u8; 32], vec::Vec<u8>, vec::Vec<u8>, vec::Vec<u8>), PrecompileFailure> {
Expand Down

0 comments on commit 23f9b87

Please sign in to comment.