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

redirect transform in http outcall #247

Merged
merged 16 commits into from
Sep 5, 2024
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);
chenyan-dfinity marked this conversation as resolved.
Show resolved Hide resolved
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
Loading