Skip to content

Commit

Permalink
Merge branch 'master' into update-frontend-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
dfx-json authored Nov 21, 2024
2 parents 47be031 + 1c22db8 commit c62e88b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
4 changes: 3 additions & 1 deletion docs/cli-reference/dfx-cycles.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ The following subcommands are available:

| Command | Description |
|---------------------------------------|--------------------------------------------------------------------------------------|
| [`approve`](#dfx-cycles-approve) | Approves a principal to spend cycles on your behalf. |
| [`balance`](#dfx-cycles-balance) | Prints the account balance of the user. |
| [`convert`](#dfx-cycles-convert) | Convert some of the user's ICP balance into cycles. |
| [`top-up`](#dfx-cycles-top-up) | Deposit cycles into a canister. |
| [`transfer`](#dfx-cycles-transfer) | Send cycles to another account. |
| `help` | Displays usage information message for a specified subcommand. |

Expand Down Expand Up @@ -133,7 +135,7 @@ You can specify the following arguments for the `dfx cycles convert` command.
| `--e8s <e8s>` | Specify ICP token fractional units—called e8s—as a whole number, where one e8 is the smallest fraction of an ICP token. For example, 1.05000000 is 1 ICP and 5000000 e8s. You can use this option on its own or in conjunction with the `--icp` option. |
| `--fee <fee>` | Specify a transaction fee. The default is 10000 e8s. |
| `--icp <icp>` | Specify ICP tokens as a whole number. You can use this option on its own or in conjunction with `--e8s`. |
| `--memo <memo>` | Memo used when depositing the minted cycles. |
| `--deposit-memo <memo>` | Memo used when depositing the minted cycles. |
| `--to-subaccount <subaccount>` | Subaccount where the cycles are deposited. |

### Examples
Expand Down
60 changes: 44 additions & 16 deletions src/dfx/src/actors/pocketic_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,26 @@ fn pocketic_proxy_start_thread(
}
}
};
if let Err(e) = initialize_gateway(
let instance = match initialize_gateway(
format!("http://localhost:{port}").parse().unwrap(),
replica_url.clone(),
domains.clone(),
address,
logger.clone(),
) {
error!(logger, "Failed to initialize HTTP gateway: {e:#}");
let _ = child.kill();
let _ = child.wait();
if receiver.try_recv().is_ok() {
debug!(logger, "Got signal to stop.");
break;
} else {
continue;
Err(e) => {
error!(logger, "Failed to initialize HTTP gateway: {e:#}");
let _ = child.kill();
let _ = child.wait();
if receiver.try_recv().is_ok() {
debug!(logger, "Got signal to stop.");
break;
} else {
continue;
}
}
}
Ok(i) => i,
};
info!(logger, "Replica API running on {address}");

// Send PocketIcProxyReadySignal to PocketIcProxy.
Expand All @@ -314,6 +317,9 @@ fn pocketic_proxy_start_thread(
logger,
"Got signal to stop. Killing pocket-ic gateway process..."
);
if let Err(e) = shutdown_pocketic_proxy(port, instance, logger.clone()) {
error!(logger, "Error shutting down PocketIC gracefully: {e}");
}
let _ = child.kill();
let _ = child.wait();
break;
Expand Down Expand Up @@ -349,7 +355,7 @@ async fn initialize_gateway(
domains: Option<Vec<String>>,
addr: SocketAddr,
logger: Logger,
) -> DfxResult {
) -> DfxResult<usize> {
use pocket_ic::common::rest::{
CreateHttpGatewayResponse, HttpGatewayBackend, HttpGatewayConfig,
};
Expand All @@ -369,11 +375,12 @@ async fn initialize_gateway(
.await?
.error_for_status()?;
let resp = resp.json::<CreateHttpGatewayResponse>().await?;
if let CreateHttpGatewayResponse::Error { message } = resp {
bail!("Gateway init error: {message}")
}
let instance = match resp {
CreateHttpGatewayResponse::Created(info) => info.instance_id,
CreateHttpGatewayResponse::Error { message } => bail!("Gateway init error: {message}"),
};
info!(logger, "Initialized HTTP gateway.");
Ok(())
Ok(instance)
}

#[cfg(not(unix))]
Expand All @@ -383,6 +390,27 @@ fn initialize_gateway(
_: Option<Vec<String>>,
_: SocketAddr,
_: Logger,
) -> DfxResult {
) -> DfxResult<usize> {
bail!("PocketIC gateway not supported on this platform")
}

#[cfg(unix)]
#[tokio::main(flavor = "current_thread")]
async fn shutdown_pocketic_proxy(port: u16, instance: usize, logger: Logger) -> DfxResult {
use reqwest::Client;
let shutdown_client = Client::new();
debug!(logger, "Sending shutdown request to HTTP gateway");
shutdown_client
.post(format!(
"http://localhost:{port}/http_gateway/{instance}/stop"
))
.send()
.await?
.error_for_status()?;
Ok(())
}

#[cfg(not(unix))]
fn shutdown_pocketic_proxy(_: u16, _: usize, _: Logger) -> DfxResult {
bail!("PocketIC not supported on this platform")
}

0 comments on commit c62e88b

Please sign in to comment.