Skip to content

Commit

Permalink
Merge branch 'main' into invalid_certificate_temp_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann authored Jan 21, 2025
2 parents 2ad73e6 + 52b2710 commit aa35f48
Show file tree
Hide file tree
Showing 49 changed files with 149 additions and 183 deletions.
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
14 changes: 9 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, caller, id, IDL, Principal, update } from 'azle';
import { call, id, IDL, msgCaller, Principal, update } from 'azle';
import { Account, TransferArgs, TransferResult } from 'azle/canisters/icrc_1';

import {
Expand All @@ -23,7 +23,9 @@ export default class {
args: [
{
owner: id(),
subaccount: [padPrincipalWithZeros(caller().toUint8Array())]
subaccount: [
padPrincipalWithZeros(msgCaller().toUint8Array())
]
}
]
});
Expand All @@ -41,7 +43,7 @@ export default class {
{
owner: [id()],
subaccount: [
padPrincipalWithZeros(caller().toUint8Array())
padPrincipalWithZeros(msgCaller().toUint8Array())
]
}
]
Expand All @@ -59,7 +61,9 @@ export default class {
args: [
{
owner: [id()],
subaccount: [padPrincipalWithZeros(caller().toUint8Array())]
subaccount: [
padPrincipalWithZeros(msgCaller().toUint8Array())
]
}
]
});
Expand All @@ -74,7 +78,7 @@ export default class {
args: [
{
from_subaccount: [
padPrincipalWithZeros(caller().toUint8Array())
padPrincipalWithZeros(msgCaller().toUint8Array())
],
to: {
owner: id(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default Canister({
owner: ic.id(),
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -58,7 +58,7 @@ export default Canister({
{
owner: ic.id(),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -77,7 +77,7 @@ export default Canister({
owner: [ic.id()],
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -94,7 +94,7 @@ export default Canister({
{
owner: Some(ic.id()),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -113,7 +113,7 @@ export default Canister({
owner: [ic.id()],
subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
]
}
Expand All @@ -130,7 +130,7 @@ export default Canister({
{
owner: Some(ic.id()),
subaccount: Some(
padPrincipalWithZeros(ic.caller().toUint8Array())
padPrincipalWithZeros(ic.msgCaller().toUint8Array())
)
}
]
Expand All @@ -151,7 +151,7 @@ export default Canister({
{
from_subaccount: [
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
],
to: {
Expand Down Expand Up @@ -182,7 +182,7 @@ export default Canister({
{
from_subaccount: Some(
padPrincipalWithZeros(
ic.caller().toUint8Array()
ic.msgCaller().toUint8Array()
)
),
to: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ export default Canister({
// ),

// returns the argument data as bytes.
argDataRaw: query(
msgArgData: query(
[blob, int8, bool, text],
blob,
(_arg1, _arg2, _arg3, _arg4) => {
return ic.argDataRaw();
return ic.msgArgData();
}
),
// returns the principal of the identity that called this function
caller: query([], Principal, () => {
return ic.caller();
msgCaller: query([], Principal, () => {
return ic.msgCaller();
}),
// returns the amount of cycles available in the canister
canisterBalance: query([], nat, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
);
});

it('calls argDataRaw on the ic object', async () => {
it('calls msgArgData on the ic object', async () => {
const blobString = 'Surprise!';
const blob = Uint8Array.from(
blobString.split('').map((char) => char.charCodeAt(0))
Expand All @@ -26,7 +26,7 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
const string = 'test';
const candidString = `(blob "${blobString}", ${int} : int8, ${bool}, "${string}")`;

const resultBytes = await icApiCanister.argDataRaw(
const resultBytes = await icApiCanister.msgArgData(
blob,
int,
bool,
Expand All @@ -37,8 +37,8 @@ export function getTests(icApiCanister: ActorSubclass<_SERVICE>): Test {
expect(result).toBe(candidString);
});

it('calls caller on the ic object', async () => {
const result = await icApiCanister.caller();
it('calls msgCaller on the ic object', async () => {
const result = await icApiCanister.msgCaller();

expect(result.toText()).toBe('2vxsx-fae');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default Canister({
});

async function getPublicKeyResult(): Promise<any> {
const caller = ic.caller().toUint8Array();
const caller = ic.msgCaller().toUint8Array();

if (process.env.AZLE_TEST_FETCH === 'true') {
const publicKeyResponse = await fetch(
Expand Down Expand Up @@ -77,7 +77,7 @@ async function getPublicKeyResult(): Promise<any> {
}

async function getSignatureResult(messageHash: Uint8Array): Promise<any> {
const caller = ic.caller().toUint8Array();
const caller = ic.msgCaller().toUint8Array();

if (process.env.AZLE_TEST_FETCH === 'true') {
const publicKeyResponse = await fetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ let someone: Principal = Principal.fromText('aaaaa-aa');
const WhoAmI = Canister({
// Manually save the calling principal and argument for later access.
init: init([Principal], (somebody) => {
install = ic.caller();
install = ic.msgCaller();
someone = somebody;
}),
// Manually re-save these variables after new deploys.
postUpgrade: postUpgrade([Principal], (somebody) => {
install = ic.caller();
install = ic.msgCaller();
someone = somebody;
}),
// Return the principal identifier of the wallet canister that installed this
Expand All @@ -36,7 +36,7 @@ const WhoAmI = Canister({
}),
// Return the principal identifier of the caller of this method.
whoami: update([], Principal, () => {
return ic.caller();
return ic.msgCaller();
}),
// Return the principal identifier of this canister.
id: update([], Principal, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ app.use(express.json());
app.get('/caller-address', async (_req, res) => {
const wallet = new ThresholdWallet(
{
derivationPath: [ic.caller().toUint8Array()]
derivationPath: [ic.msgCaller().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.get('/headers-array', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.headers
});
});
Expand All @@ -22,7 +22,7 @@ app.get('/headers-object', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.headers
});
});
Expand All @@ -33,7 +33,7 @@ app.post('/body-uint8array', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -44,7 +44,7 @@ app.put('/body-string', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -55,7 +55,7 @@ app.patch('/body-array-buffer', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -66,7 +66,7 @@ app.delete('/body-blob', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -77,7 +77,7 @@ app.post('/body-data-view', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.body
});
});
Expand All @@ -88,7 +88,7 @@ app.get('/url-query-params-get', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.query
});
});
Expand All @@ -99,7 +99,7 @@ app.post('/url-query-params-post', (req, res) => {
res.setHeader('X-Azle-Response-Key-2', 'X-Azle-Response-Value-2');

res.json({
whoami: ic.caller().toString(),
whoami: ic.msgCaller().toString(),
value: req.query
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.use(express.json());

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

res.send(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import express from 'express';
const app = express();

app.get('/whoami', (req, res) => {
res.send(ic.caller().toString());
res.send(ic.msgCaller().toString());
});

app.use(express.static('/dist'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TODO we should pull the wallet out into its own repo

import {
caller,
IDL,
msgCaller,
msgCyclesAccept,
msgCyclesAvailable,
Principal,
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class {
console.info(`cycles available: ${msgCyclesAvailable()}`);

const callerInWhitelist = this.principalsWhitelist.includes(
caller().toText()
msgCaller().toText()
);

if (callerInWhitelist === true) {
Expand All @@ -69,7 +69,7 @@ export default class {
this.payments.push({
time: time(),
amount: cyclesAvailable,
principal: caller()
principal: msgCaller()
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function generateInspectMessageMethodBody(): string {
const returnPrincipal = getPrincipal(AZLE_RETURN_IDENTITY_NAME);
const throwPrincipal = getPrincipal(AZLE_THROW_IDENTITY_NAME);
return `
if (ic.caller().toText() === "${acceptPrincipal}") {
if (ic.msgCaller().toText() === "${acceptPrincipal}") {
ic.acceptMessage();
return;
}
if (ic.caller().toText() === "${returnPrincipal}") {
if (ic.msgCaller().toText() === "${returnPrincipal}") {
return;
}
if (ic.caller().toText() === "${throwPrincipal}") {
if (ic.msgCaller().toText() === "${throwPrincipal}") {
throw new Error(\`Method "$\{ic.methodName()}" not allowed\`);
}
throw new Error("Unexpected caller");
Expand Down
Loading

0 comments on commit aa35f48

Please sign in to comment.