Skip to content

Commit

Permalink
Merge branch 'master' into release-0.15.3-promote
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity authored Jan 8, 2024
2 parents 68b4f66 + 4399f83 commit 7819c77
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 121 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# UNRELEASED

### feat!: update `dfx cycles` commands with mainnet `cycles-ledger` canister ID

The `dfx cycles` command no longer needs nor accepts the `--cycles-ledger-canister-id <canister id>` parameter.

# 0.15.3

### fix: allow `http://localhost:*` as `connect-src` in the asset canister's CSP

This will enable browsing the asset canister at `http://<canister-id>.localhost:<port>` in most browsers.
Expand Down
3 changes: 0 additions & 3 deletions docs/cli-reference/dfx-cycles.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ You can specify the following arguments for the `dfx cycles balance` command.
| `--owner <principal>` | Display the balance of this principal |
| `--subaccount <subaccount>` | Display the balance of this subaccount |
| `--precise` | Displays the exact balance, without scaling to trillions of cycles. |
| `--cycles-ledger-canister-id <canister id>` | Specify the ID of the cycles ledger canister. |

### Examples

> **NOTE**: None of the examples below specify the `--cycles-ledger-canister-id` option, but it is required until the cycles ledger canister ID is known.
Check the cycles balance of the selected identity.

```
Expand Down
4 changes: 1 addition & 3 deletions docs/cli-reference/dfx-ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,14 @@ If no amount is specified, 10T cycles are used by default.
If you are developing locally and want to add 8T cycles to all your canisters in your procject, you can do so like this:

```
dfx ledger fabricate-cycles --all --amount 8000000000000
dfx ledger fabricate-cycles --all --cycles 8000000000000
```

The command displays output similar to the following:

```
Fabricating 8000000000000 cycles onto hello_backend
Fabricated 8000000000000 cycles, updated balance: 11_899_662_119_932 cycles
Fabricating 8000000000000 cycles onto hello_frontend
Fabricated 8000000000000 cycles, updated balance: 11_899_075_504_924 cycles
```

If you would rather only add the cycles to the canister called 'hello' and don't want to type all the zeros, you can do it like this:
Expand Down
173 changes: 86 additions & 87 deletions e2e/tests-dfx/cycles-ledger.bash

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions src/dfx/src/commands/cycles/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub struct CyclesBalanceOpts {
/// Get balance raw value (without upscaling to trillions of cycles).
#[arg(long)]
precise: bool,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult {
Expand All @@ -41,8 +35,7 @@ pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult {

let subaccount = opts.subaccount.map(|x| x.0);

let balance =
cycles_ledger::balance(agent, owner, subaccount, opts.cycles_ledger_canister_id).await?;
let balance = cycles_ledger::balance(agent, owner, subaccount).await?;

if opts.precise {
println!("{} cycles.", balance);
Expand Down
7 changes: 0 additions & 7 deletions src/dfx/src/commands/cycles/top_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ pub struct TopUpOpts {
/// https://internetcomputer.org/docs/current/developer-docs/integrations/icrc-1/#transaction-deduplication-
#[arg(long)]
created_at_time: Option<u64>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult {
Expand All @@ -58,7 +52,6 @@ pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult {
amount,
created_at_time,
from_subaccount,
opts.cycles_ledger_canister_id,
)
.await;
if result.is_err() && opts.created_at_time.is_none() {
Expand Down
7 changes: 0 additions & 7 deletions src/dfx/src/commands/cycles/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ pub struct TransferOpts {
/// Memo.
#[arg(long)]
memo: Option<u64>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult {
Expand Down Expand Up @@ -68,7 +62,6 @@ pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult {
to_subaccount,
created_at_time,
opts.memo,
opts.cycles_ledger_canister_id,
)
.await;
if result.is_err() && opts.created_at_time.is_none() {
Expand Down
19 changes: 13 additions & 6 deletions src/dfx/src/lib/operations/cycles_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ use slog::{info, Logger};
const ICRC1_BALANCE_OF_METHOD: &str = "icrc1_balance_of";
const ICRC1_TRANSFER_METHOD: &str = "icrc1_transfer";
const SEND_METHOD: &str = "send";
const CYCLES_LEDGER_CANISTER_ID: Principal =
Principal::from_slice(&[0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x02, 0x01, 0x01]);

pub async fn balance(
agent: &Agent,
owner: Principal,
subaccount: Option<icrc1::account::Subaccount>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<u128> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;
let arg = icrc1::account::Account { owner, subaccount };

Expand Down Expand Up @@ -58,11 +59,10 @@ pub async fn transfer(
to_subaccount: Option<icrc1::account::Subaccount>,
created_at_time: u64,
memo: Option<u64>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<BlockIndex> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;

let retry_policy = ExponentialBackoff::default();
Expand Down Expand Up @@ -118,11 +118,10 @@ pub async fn send(
amount: u128,
created_at_time: u64,
from_subaccount: Option<icrc1::account::Subaccount>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<BlockIndex> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;

let retry_policy = ExponentialBackoff::default();
Expand Down Expand Up @@ -170,3 +169,11 @@ pub async fn send(

Ok(block_index)
}

#[test]
fn ledger_canister_id_text_representation() {
assert_eq!(
Principal::from_text("um5iw-rqaaa-aaaaq-qaaba-cai").unwrap(),
CYCLES_LEDGER_CANISTER_ID
);
}

0 comments on commit 7819c77

Please sign in to comment.