Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename id to canisterSelf (breaking changes) #2618

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions examples/experimental/demo/ckbtc/wallet/backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO maybe this should be Ledger? We should look into making the Ledger
// better using the latest Wasm and did that I know of

import { call, id, IDL, msgCaller, Principal, update } from 'azle';
import { call, canisterSelf, IDL, msgCaller, Principal, update } from 'azle';
import { Account, TransferArgs, TransferResult } from 'azle/canisters/icrc_1';

import {
Expand All @@ -22,7 +22,7 @@ export default class {
returnIdlType: IDL.Nat,
args: [
{
owner: id(),
owner: canisterSelf(),
subaccount: [
padPrincipalWithZeros(msgCaller().toUint8Array())
]
Expand All @@ -41,7 +41,7 @@ export default class {
returnIdlType: UpdateBalanceResult,
args: [
{
owner: [id()],
owner: [canisterSelf()],
subaccount: [
padPrincipalWithZeros(msgCaller().toUint8Array())
]
Expand All @@ -60,7 +60,7 @@ export default class {
returnIdlType: IDL.Text,
args: [
{
owner: [id()],
owner: [canisterSelf()],
subaccount: [
padPrincipalWithZeros(msgCaller().toUint8Array())
]
Expand All @@ -81,7 +81,7 @@ export default class {
padPrincipalWithZeros(msgCaller().toUint8Array())
],
to: {
owner: id(),
owner: canisterSelf(),
subaccount: [
padPrincipalWithZeros(
Principal.fromText(to).toUint8Array()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO maybe this should be Ledger? We should look into making the Ledger
// better using the latest Wasm and did that I know of

import { call, id, IDL, msgCaller } from 'azle';
import { call, canisterSelf, IDL, msgCaller } from 'azle';
import { Account, TransferArgs, TransferResult } from 'azle/canisters/icrc_1';
import {
blob,
Expand Down Expand Up @@ -82,7 +82,7 @@ type UpdateBalanceResult = { Ok: UtxoStatus[] } | { Err: UpdateBalanceError };
export default Canister({
getBalance: update([], nat64, async () => {
const arg: Account = {
owner: id(),
owner: canisterSelf(),
subaccount: [padPrincipalWithZeros(msgCaller().toUint8Array())]
};

Expand Down Expand Up @@ -113,7 +113,7 @@ export default Canister({
}),
updateBalance: update([], UpdateBalanceResultExperimental, async () => {
const arg: AccountArg = {
owner: [id()],
owner: [canisterSelf()],
subaccount: [padPrincipalWithZeros(msgCaller().toUint8Array())]
};

Expand Down Expand Up @@ -144,7 +144,7 @@ export default Canister({
}),
getDepositAddress: update([], text, async () => {
const arg: AccountArg = {
owner: [id()],
owner: [canisterSelf()],
subaccount: [padPrincipalWithZeros(msgCaller().toUint8Array())]
};

Expand Down Expand Up @@ -182,7 +182,7 @@ export default Canister({
padPrincipalWithZeros(msgCaller().toUint8Array())
],
to: {
owner: id(),
owner: canisterSelf(),
subaccount: [
padPrincipalWithZeros(
Principal.fromText(to).toUint8Array()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, id, IDL, msgReply } from 'azle';
import { call, canisterSelf, IDL, msgReply } from 'azle';
import {
Canister,
Manual,
Expand Down Expand Up @@ -203,7 +203,7 @@ const CompQueryCanister = Canister({
}),
// Composite query calling queries on the same canister
incCanister1: query([], nat, async () => {
const self = CompQueryCanister(id());
const self = CompQueryCanister(canisterSelf());

counter += 1n;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, id } from 'azle';
import { call, canisterSelf } from 'azle';
import {
http_request_args,
http_request_result
Expand Down Expand Up @@ -102,7 +102,7 @@ async function getBalance(
],
transform: [
{
function: [id(), 'ethTransform'] as [
function: [canisterSelf(), 'ethTransform'] as [
Principal,
string
],
Expand Down Expand Up @@ -166,7 +166,7 @@ async function getBlockByNumber(url: string, number: number): Promise<string> {
],
transform: [
{
function: [id(), 'ethTransform'] as [
function: [canisterSelf(), 'ethTransform'] as [
Principal,
string
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
canisterCycleBalance,
canisterSelf,
canisterVersion,
dataCertificate,
id,
isController,
msgArgData,
msgCaller,
Expand Down Expand Up @@ -65,8 +65,8 @@ export default Canister({
return cert === undefined ? { None: null } : { Some: cert };
}),
// returns this canister's id
id: query([], Principal, () => {
return id();
canisterSelf: query([], Principal, () => {
return canisterSelf();
}),
// determines whether the given principal is a controller of the canister
isController: query([Principal], bool, (principal) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
expect(result).toHaveLength(0);
});

it('calls id on the ic object', async () => {
it('calls canisterSelf on the ic object', async () => {
const icApiCanisterId = execSync(`dfx canister id ic_api`)
.toString()
.trim();

const result = await icApiCanister.id();
const result = await icApiCanister.canisterSelf();

expect(result.toText()).toBe(icApiCanisterId);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { id, trap } from 'azle';
import { canisterSelf, trap } from 'azle';
import {
blob,
Canister,
Expand Down Expand Up @@ -38,7 +38,7 @@ export default Canister({
body: encode('Counter'),
streaming_strategy: Some({
Callback: {
callback: [id(), 'http_streaming'],
callback: [canisterSelf(), 'http_streaming'],
token: {
arbitrary_data: 'start'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, id, IDL, msgCaller } from 'azle';
import { call, canisterSelf, IDL, msgCaller } from 'azle';
import {
Canister,
init,
Expand Down Expand Up @@ -40,7 +40,7 @@ const WhoAmI = Canister({
}),
// Return the principal identifier of this canister.
id: update([], Principal, async () => {
const self: any = WhoAmI(id());
const self: any = WhoAmI(canisterSelf());

if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(
Expand All @@ -64,7 +64,7 @@ const WhoAmI = Canister({
// canister call to itself. Additionally, it can now be a `Query` which means it
// doesn't have to go through consensus.
idQuick: query([], Principal, () => {
return id();
return canisterSelf();
})
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, candidEncode, id, msgReply } from 'azle';
import { call, candidEncode, canisterSelf, msgReply } from 'azle';
import {
http_request_args,
http_request_result
Expand Down Expand Up @@ -48,7 +48,7 @@ export default Canister({
body: [],
transform: [
{
function: [id(), 'xkcdTransform'] as [
function: [canisterSelf(), 'xkcdTransform'] as [
Principal,
string
],
Expand Down Expand Up @@ -79,7 +79,7 @@ export default Canister({
method = variant { get };
headers = vec {};
body = null;
transform = record { function = func "${id().toString()}".xkcdTransform; context = vec {} };
transform = record { function = func "${canisterSelf().toString()}".xkcdTransform; context = vec {} };
}
)
`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { id, msgCaller } from 'azle';
import { canisterSelf, msgCaller } from 'azle';
import { jsonStringify, ThresholdWallet } from 'azle/experimental';
import { ethers } from 'ethers';
import express, { Request } from 'express';
Expand All @@ -21,7 +21,7 @@ app.get('/caller-address', async (_req, res) => {
app.get('/canister-address', async (_req, res) => {
const wallet = new ThresholdWallet(
{
derivationPath: [id().toUint8Array()]
derivationPath: [canisterSelf().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);
Expand Down Expand Up @@ -69,7 +69,7 @@ app.post(
try {
const wallet = new ThresholdWallet(
{
derivationPath: [id().toUint8Array()]
derivationPath: [canisterSelf().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ic, jsonStringify } from 'azle/experimental';
import { canisterSelf, msgCaller } from 'azle';
import { jsonStringify } from 'azle/experimental';
import { ethers } from 'ethers';
import express, { Request } from 'express';

Expand All @@ -18,7 +19,7 @@ app.use(express.json());

app.get('/caller-address', async (_req, res) => {
const address = ethers.computeAddress(
ethers.hexlify(await ecdsaPublicKey([ic.msgCaller().toUint8Array()]))
ethers.hexlify(await ecdsaPublicKey([msgCaller().toUint8Array()]))
);

res.send(address);
Expand All @@ -27,7 +28,9 @@ app.get('/caller-address', async (_req, res) => {
app.get('/canister-address', async (_req, res) => {
if (canisterAddress.value === null) {
canisterAddress.value = ethers.computeAddress(
ethers.hexlify(await ecdsaPublicKey([ic.id().toUint8Array()]))
ethers.hexlify(
await ecdsaPublicKey([canisterSelf().toUint8Array()])
)
);
}

Expand Down Expand Up @@ -87,7 +90,7 @@ app.post(
if (canisterAddress.value === null) {
canisterAddress.value = ethers.computeAddress(
ethers.hexlify(
await ecdsaPublicKey([ic.id().toUint8Array()])
await ecdsaPublicKey([canisterSelf().toUint8Array()])
)
);
}
Expand Down Expand Up @@ -117,7 +120,7 @@ app.post(
ethers.keccak256(unsignedSerializedTx);

const signedSerializedTxHash = await signWithEcdsa(
[ic.id().toUint8Array()],
[canisterSelf().toUint8Array()],
ethers.getBytes(unsignedSerializedTxHash)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { id } from 'azle';
import { canisterSelf } from 'azle';
import { readdir, stat } from 'fs/promises';
import { basename, join } from 'path';

Expand Down Expand Up @@ -65,7 +65,7 @@ async function getFileDetails(filePath: string): Promise<string> {
const hardLinks = stats.nlink;

// Get owner and group names using 'id' command
const owner = id();
const owner = canisterSelf();

// Get file size
const size = stats.size.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, id, IDL, msgReply, query, update } from 'azle';
import { call, canisterSelf, IDL, msgReply, query, update } from 'azle';

export default class Canister {
canister2Id: string = getCanister2Id();
Expand Down Expand Up @@ -125,7 +125,7 @@ function getCanister2Id(): string {
}

async function incCanister(): Promise<bigint> {
return await call(id(), 'incCounter', {
return await call(canisterSelf(), 'incCounter', {
returnIdlType: IDL.Nat
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
call,
id,
canisterSelf,
IDL,
init,
Principal,
Expand Down Expand Up @@ -85,7 +85,7 @@ async function getBalance(
],
transform: [
{
function: [id(), 'ethTransform'] as [
function: [canisterSelf(), 'ethTransform'] as [
Principal,
string
],
Expand Down Expand Up @@ -127,7 +127,7 @@ async function getBlockByNumber(url: string, number: number): Promise<string> {
],
transform: [
{
function: [id(), 'ethTransform'] as [
function: [canisterSelf(), 'ethTransform'] as [
Principal,
string
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
canisterCycleBalance,
canisterSelf,
canisterVersion,
dataCertificate,
id,
IDL,
isController,
msgArgData,
Expand Down Expand Up @@ -77,8 +77,8 @@ export default class {

// returns this canister's id
@query([], IDL.Principal)
id(): Principal {
return id();
canisterSelf(): Principal {
return canisterSelf();
}

// determines whether the given principal is a controller of the canister
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
id,
canisterSelf,
IDL,
init,
Principal,
Expand Down Expand Up @@ -117,7 +117,10 @@ export default class {
streaming_strategy: [
{
Callback: {
callback: [id(), 'http_streaming'],
callback: [
canisterSelf(),
'http_streaming'
],
token: {
arbitrary_data: 'start'
}
Expand Down
Loading