Skip to content

Commit

Permalink
rename stable call payment property to cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Oct 30, 2024
1 parent 05ecd68 commit 8e952fc
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult<Function> {
canister_id_bytes: TypedArray<u8>,
method: String,
args_raw: TypedArray<u8>,
payment_string: String|
cycles_string: String|
-> QuickJsResult<()> {
let canister_id = Principal::from_slice(canister_id_bytes.as_ref());
let args_raw = args_raw
Expand All @@ -28,7 +28,7 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult<Function> {
"args_raw could not be converted into bytes",
))?
.to_vec();
let payment: u128 = payment_string
let payment: u128 = cycles_string
.parse()
.map_err(|e| throw_error(ctx.clone(), e))?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn get_function(ctx: Ctx) -> Result<Function> {
move |canister_id_bytes: TypedArray<u8>,
method: String,
args_raw: TypedArray<u8>,
payment_string: String|
cycles_string: String|
-> Result<Value> {
let canister_id = Principal::from_slice(canister_id_bytes.as_ref());
let args_raw = args_raw
Expand All @@ -20,7 +20,7 @@ pub fn get_function(ctx: Ctx) -> Result<Function> {
"args_raw could not be converted into bytes",
))?
.to_vec();
let payment: u128 = payment_string
let payment: u128 = cycles_string
.parse()
.map_err(|e| throw_error(ctx.clone(), e))?;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/azle_ic_stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type AzleIcStable = {
canisterIdBytes: Uint8Array,
method: string,
argsRaw: Uint8Array,
paymentString: string
cyclesString: string
) => void;
caller: () => Uint8Array;
candidCompiler: (candidPath: string) => string;
Expand All @@ -30,7 +30,7 @@ export type AzleIcStable = {
canisterIdBytes: Uint8Array,
method: string,
argsRawBuffer: Uint8Array,
paymentString: string
cyclesString: string
) => void;
performanceCounter: (counterType: number) => bigint;
rejectCode: () => number;
Expand Down
12 changes: 6 additions & 6 deletions src/lib/stable/ic_apis/call.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDL } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import { v4 } from 'uuid'; // TODO is uuid experimental?
import { v4 } from 'uuid';

export async function call<Args extends any[] | undefined, Return = any>(
canisterId: Principal | string,
Expand All @@ -9,7 +9,7 @@ export async function call<Args extends any[] | undefined, Return = any>(
paramIdlTypes?: IDL.Type[];
returnIdlType?: IDL.Type;
args?: Args;
payment?: bigint; // TODO this should be called cycles: https://github.com/demergent-labs/azle/issues/2104
cycles?: bigint;
raw?: Uint8Array;
}
): Promise<Return> {
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function call<Args extends any[] | undefined, Return = any>(

const paramIdlTypes = options?.paramIdlTypes ?? [];
const args = options?.args ?? [];
const payment = options?.payment ?? 0n;
const cycles = options?.cycles ?? 0n;

const canisterIdPrincipal =
typeof canisterId === 'string'
Expand All @@ -67,7 +67,7 @@ export async function call<Args extends any[] | undefined, Return = any>(
raw === undefined
? new Uint8Array(IDL.encode(paramIdlTypes, args))
: raw;
const paymentString = payment.toString();
const cyclesString = cycles.toString();

// TODO consider finally, what if deletion goes wrong
try {
Expand All @@ -77,15 +77,15 @@ export async function call<Args extends any[] | undefined, Return = any>(
canisterIdBytes.buffer,
method,
argsRaw.buffer,
paymentString
cyclesString
);
} else {
globalThis._azleIcStable.callRaw(
promiseId,
canisterIdBytes,
method,
argsRaw,
paymentString
cyclesString
);
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export async function chunk(): Promise<void> {
return undefined;
}

await call(id(), '_azle_chunk', { raw: candidEncode('()'), payment: 0n });
await call(id(), '_azle_chunk', { raw: candidEncode('()'), cycles: 0n });
}
10 changes: 5 additions & 5 deletions src/lib/stable/ic_apis/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function notify(
options?: {
paramIdlTypes?: IDL.Type[];
args?: any[];
payment?: bigint;
cycles?: bigint;
raw?: Uint8Array;
}
): void {
Expand All @@ -27,7 +27,7 @@ export function notify(

const paramIdlTypes = options?.paramIdlTypes ?? [];
const args = options?.args ?? [];
const payment = options?.payment ?? 0n;
const cycles = options?.cycles ?? 0n;
const raw = options?.raw;

const canisterIdPrincipal =
Expand All @@ -39,21 +39,21 @@ export function notify(
raw === undefined
? new Uint8Array(IDL.encode(paramIdlTypes, args))
: raw;
const paymentString = payment.toString();
const cyclesString = cycles.toString();

if (globalThis._azleIcExperimental !== undefined) {
return globalThis._azleIcExperimental.notifyRaw(
canisterIdBytes.buffer,
method,
argsRaw.buffer,
paymentString
cyclesString
);
}

return globalThis._azleIcStable.notifyRaw(
canisterIdBytes,
method,
argsRaw,
paymentString
cyclesString
);
}
8 changes: 4 additions & 4 deletions tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class {
network: { regtest: null }
}
],
payment: BITCOIN_API_CYCLE_COST
cycles: BITCOIN_API_CYCLE_COST
});
}

Expand All @@ -46,7 +46,7 @@ export default class {
network: { regtest: null }
}
],
payment: BITCOIN_API_CYCLE_COST
cycles: BITCOIN_API_CYCLE_COST
});
}

Expand All @@ -65,7 +65,7 @@ export default class {
network: { regtest: null }
}
],
payment: BITCOIN_API_CYCLE_COST
cycles: BITCOIN_API_CYCLE_COST
}
);
}
Expand All @@ -88,7 +88,7 @@ export default class {
network: { regtest: null }
}
],
payment: transactionFee
cycles: transactionFee
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default class {
canisterId: Principal,
method: string,
candidArgs: string,
payment: bigint
cycles: bigint
): Promise<string> {
const result = await call<undefined>(canisterId, method, {
raw: candidEncode(candidArgs),
payment
cycles
});

return candidDecode(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export default class {
async sendCycles(): Promise<bigint> {
return await call(getCyclesPrincipal(), 'receiveCycles', {
returnIdlType: IDL.Nat64,
payment: 1_000_000n
cycles: 1_000_000n
});
}

@update([])
sendCyclesNotify(): void {
return notify(getCyclesPrincipal(), 'receiveCycles', {
payment: 1_000_000n
cycles: 1_000_000n
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function getBalance(
]
}
],
payment: 50_000_000n
cycles: 50_000_000n
}
);

Expand Down Expand Up @@ -136,7 +136,7 @@ async function getBlockByNumber(url: string, number: number): Promise<string> {
]
}
],
payment: 50_000_000n
cycles: 50_000_000n
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class {
sender_canister_version: []
}
],
payment: 100_000_000_000n
cycles: 100_000_000_000n
});

return true;
Expand Down Expand Up @@ -178,7 +178,7 @@ export default class {
sender_canister_version: []
}
],
payment: 100_000_000_000n
cycles: 100_000_000_000n
}
);

Expand Down Expand Up @@ -285,7 +285,7 @@ export default class {
canister_id: canisterId
}
],
payment: 10_000_000n
cycles: 10_000_000n
});

return true;
Expand Down Expand Up @@ -355,7 +355,7 @@ async function createCanister(): Promise<create_canister_result> {
paramIdlTypes: [create_canister_args],
returnIdlType: create_canister_result,
args: [{ settings: [], sender_canister_version: [] }],
payment: 50_000_000_000_000n
cycles: 50_000_000_000_000n
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function getSignatureResult(
}
}
],
payment: 10_000_000_000n
cycles: 10_000_000_000n
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class {
]
}
],
payment: 50_000_000n
cycles: 50_000_000n
});

return new TextDecoder().decode(Uint8Array.from(httpResponse.body));
Expand All @@ -67,7 +67,7 @@ export default class {
}
)
`),
payment: 50_000_000n
cycles: 50_000_000n
}
);

Expand Down

0 comments on commit 8e952fc

Please sign in to comment.