Skip to content

Commit

Permalink
clean up bigint casting
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Oct 18, 2023
1 parent f67057d commit 86509a6
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/lib/ic/canister_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function canisterBalance(): nat64 {
}

const canisterBalanceCandidBytes = globalThis._azleIc.canisterBalance();
return BigInt(decode(nat64, canisterBalanceCandidBytes) as number);
return decode(nat64, canisterBalanceCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/canister_balance_128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export function canisterBalance128(): nat {

const canisterBalance128CandidBytes =
globalThis._azleIc.canisterBalance128();
return BigInt(decode(nat, canisterBalance128CandidBytes) as number);
return decode(nat, canisterBalance128CandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/canister_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export function canisterVersion(): nat64 {
}

const canisterVersionCandidBytes = globalThis._azleIc.canisterVersion();
return BigInt(decode(nat64, canisterVersionCandidBytes) as number);
return decode(nat64, canisterVersionCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/instruction_counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export function instructionCounter(): nat64 {

const instructionCounterCandidBytes =
globalThis._azleIc.instructionCounter();
return BigInt(decode(nat64, instructionCounterCandidBytes) as number);
return decode(nat64, instructionCounterCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export function msgCyclesAccept(maxAmount: nat64): nat64 {
const msgCyclesAcceptCandidBytes =
globalThis._azleIc.msgCyclesAccept(maxAmountCandidBytes);

return BigInt(decode(nat64, msgCyclesAcceptCandidBytes) as number);
return decode(nat64, msgCyclesAcceptCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_accept_128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export function msgCyclesAccept128(maxAmount: nat): nat {
const msgCyclesAccept128CandidBytes =
globalThis._azleIc.msgCyclesAccept128(maxAmountCandidBytes);

return BigInt(decode(nat, msgCyclesAccept128CandidBytes) as number);
return decode(nat, msgCyclesAccept128CandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export function msgCyclesAvailable(): nat64 {
const msgCyclesAvailableCandidBytes =
globalThis._azleIc.msgCyclesAvailable();

return BigInt(decode(nat64, msgCyclesAvailableCandidBytes) as number);
return decode(nat64, msgCyclesAvailableCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_available_128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export function msgCyclesAvailable128(): nat {
const msgCyclesAvailable128CandidBytes =
globalThis._azleIc.msgCyclesAvailable128();

return BigInt(decode(nat, msgCyclesAvailable128CandidBytes) as number);
return decode(nat, msgCyclesAvailable128CandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_refunded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function msgCyclesRefunded(): nat64 {

const msgCyclesRefundedCandidBytes = globalThis._azleIc.msgCyclesRefunded();

return BigInt(decode(nat64, msgCyclesRefundedCandidBytes) as number);
return decode(nat64, msgCyclesRefundedCandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/msg_cycles_refunded_128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export function msgCyclesRefunded128(): nat {
const msgCyclesRefunded128CandidBytes =
globalThis._azleIc.msgCyclesRefunded128();

return BigInt(decode(nat, msgCyclesRefunded128CandidBytes) as number);
return decode(nat, msgCyclesRefunded128CandidBytes);
}
2 changes: 1 addition & 1 deletion src/lib/ic/performance_counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export function performanceCounter(counterType: nat32): nat64 {
counterTypeCandidBytes
);

return BigInt(decode(nat64, performanceCounterCandidBytes) as number);
return decode(nat64, performanceCounterCandidBytes);
}
7 changes: 2 additions & 5 deletions src/lib/ic/set_timer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Duration, TimerId } from './types';
import { v4 } from 'uuid';
import { nat64 } from '../candid/types/primitive/nats/nat64';
import { encode, decode as azleDecode } from '../candid/serde';
import { encode, decode } from '../candid/serde';

/**
* Sets callback to be executed later, after delay. Panics if `delay` + time() is more than 2^64 - 1.
Expand All @@ -20,13 +20,10 @@ export function setTimer(
return undefined as any;
}

const decode = (value: ArrayBufferLike) => {
return BigInt(azleDecode(nat64, value) as number);
};

const timerCallbackId = `_timer_${v4()}`;

const timerId = decode(
nat64,
globalThis._azleIc.setTimer(
encode(nat64, delay).buffer,
timerCallbackId
Expand Down
9 changes: 3 additions & 6 deletions src/lib/ic/set_timer_interval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Duration, TimerId } from './types';
import { v4 } from 'uuid';
import { encode as azleEncode, decode as azleDecode } from '../candid/serde';
import { encode, decode } from '../candid/serde';
import { nat64 } from '../candid/types/primitive/nats/nat64';

/**
Expand All @@ -20,15 +20,12 @@ export function setTimerInterval(
return undefined as any;
}

const decode = (value: ArrayBufferLike) => {
return BigInt(azleDecode(nat64, value) as number);
};

const timerCallbackId = `_interval_timer_${v4()}`;

const timerId = decode(
nat64,
globalThis._azleIc.setTimerInterval(
azleEncode(nat64, interval).buffer,
encode(nat64, interval).buffer,
timerCallbackId
)
);
Expand Down
7 changes: 1 addition & 6 deletions src/lib/ic/stable_64_grow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ export function stable64Grow(newPages: nat64): nat64 {

const newPagesCandidBytes = encode(nat64, newPages).buffer;

return BigInt(
decode(
nat64,
globalThis._azleIc.stable64Grow(newPagesCandidBytes)
) as number
);
return decode(nat64, globalThis._azleIc.stable64Grow(newPagesCandidBytes));
}
2 changes: 1 addition & 1 deletion src/lib/ic/stable_64_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function stable64Size(): nat64 {
return undefined as any;
}

return BigInt(decode(nat64, globalThis._azleIc.stable64Size()) as number);
return decode(nat64, globalThis._azleIc.stable64Size());
}
2 changes: 1 addition & 1 deletion src/lib/ic/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function time(): nat64 {
}

const timeCandidBytes = globalThis._azleIc.time();
return BigInt(decode(nat64, timeCandidBytes) as number);
return decode(nat64, timeCandidBytes);
}

0 comments on commit 86509a6

Please sign in to comment.