Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 5, 2024
1 parent b813f75 commit 7e67078
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions service/pool/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
throw Error.reject "Only a canister managed by the Motoko Playground can call http_request";
};
let cycles = 250_000_000_000;
try {
if (pool.spendCycles(caller, cycles)) {
Cycles.add<system> cycles;
let new_request = switch (request.transform) {
Expand All @@ -639,16 +638,17 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
{ request with transform = new_transform };
};
};
let res = await IC.http_request(new_request);
let refunded = -Cycles.refunded();
assert(pool.spendCycles(caller, refunded) == true);
res;
try {
let res = await IC.http_request(new_request);
let refunded = -Cycles.refunded();
assert(pool.spendCycles(caller, refunded) == true);
res;
} finally {
pool.removeTransform(caller);
};
} else {
throw Error.reject "http_request exceeds cycle spend limit";
};
} finally {
pool.removeTransform(caller);
};
};
public shared composite query({ caller }) func __transform({context: Blob; response: ICType.http_request_result}) : async ICType.http_request_result {
if (caller != Principal.fromText("aaaaa-aa") and caller != Principal.fromText("2vxsx-fae")) {
Expand Down

0 comments on commit 7e67078

Please sign in to comment.