PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@dfinity/agent/lib/cjs/polling
Просмотр файла: index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pollForResponse = exports.defaultStrategy = exports.strategy = void 0;
const agent_1 = require("../agent");
const certificate_1 = require("../certificate");
const buffer_1 = require("../utils/buffer");
exports.strategy = __importStar(require("./strategy"));
const strategy_1 = require("./strategy");
var strategy_2 = require("./strategy");
Object.defineProperty(exports, "defaultStrategy", { enumerable: true, get: function () { return strategy_2.defaultStrategy; } });
/**
* Check if an object has a property
* @param value the object that might have the property
* @param property the key of property we're looking for
*/
function hasProperty(value, property) {
return Object.prototype.hasOwnProperty.call(value, property);
}
/**
* Check if value is a signed read state request with expiry
* @param value to check
*/
function isSignedReadStateRequestWithExpiry(value) {
return (value !== null &&
typeof value === 'object' &&
hasProperty(value, 'body') &&
value.body !== null &&
typeof value.body === 'object' &&
hasProperty(value.body, 'content') &&
value.body.content !== null &&
typeof value.body.content === 'object' &&
hasProperty(value.body.content, 'request_type') &&
value.body.content.request_type === "read_state" /* ReadRequestType.ReadState */ &&
hasProperty(value.body.content, 'ingress_expiry') &&
typeof value.body.content.ingress_expiry === 'object' &&
value.body.content.ingress_expiry !== null &&
hasProperty(value.body.content.ingress_expiry, 'toCBOR') &&
typeof value.body.content.ingress_expiry.toCBOR === 'function' &&
hasProperty(value.body.content.ingress_expiry, 'toHash') &&
typeof value.body.content.ingress_expiry.toHash === 'function');
}
/**
* Polls the IC to check the status of the given request then
* returns the response bytes once the request has been processed.
* @param agent The agent to use to poll read_state.
* @param canisterId The effective canister ID.
* @param requestId The Request ID to poll status for.
* @param strategy A polling strategy.
* @param request Request for the repeated readState call.
* @param blsVerify - optional replacement function that verifies the BLS signature of a certificate.
*/
async function pollForResponse(agent, canisterId, requestId, strategy = (0, strategy_1.defaultStrategy)(), request, blsVerify) {
var _a;
const path = [new TextEncoder().encode('request_status'), requestId];
const currentRequest = request !== null && request !== void 0 ? request : (await ((_a = agent.createReadStateRequest) === null || _a === void 0 ? void 0 : _a.call(agent, { paths: [path] })));
const state = await agent.readState(canisterId, { paths: [path] }, undefined, currentRequest);
if (agent.rootKey == null)
throw new Error('Agent root key not initialized before polling');
const cert = await certificate_1.Certificate.create({
certificate: state.certificate,
rootKey: agent.rootKey,
canisterId: canisterId,
blsVerify,
});
const maybeBuf = (0, certificate_1.lookupResultToBuffer)(cert.lookup([...path, new TextEncoder().encode('status')]));
let status;
if (typeof maybeBuf === 'undefined') {
// Missing requestId means we need to wait
status = agent_1.RequestStatusResponseStatus.Unknown;
}
else {
status = new TextDecoder().decode(maybeBuf);
}
switch (status) {
case agent_1.RequestStatusResponseStatus.Replied: {
return {
reply: (0, certificate_1.lookupResultToBuffer)(cert.lookup([...path, 'reply'])),
certificate: cert,
};
}
case agent_1.RequestStatusResponseStatus.Received:
case agent_1.RequestStatusResponseStatus.Unknown:
case agent_1.RequestStatusResponseStatus.Processing:
// Execute the polling strategy, then retry.
await strategy(canisterId, requestId, status);
return pollForResponse(agent, canisterId, requestId, strategy, currentRequest, blsVerify);
case agent_1.RequestStatusResponseStatus.Rejected: {
const rejectCode = new Uint8Array((0, certificate_1.lookupResultToBuffer)(cert.lookup([...path, 'reject_code'])))[0];
const rejectMessage = new TextDecoder().decode((0, certificate_1.lookupResultToBuffer)(cert.lookup([...path, 'reject_message'])));
throw new Error(`Call was rejected:\n` +
` Request ID: ${(0, buffer_1.toHex)(requestId)}\n` +
` Reject code: ${rejectCode}\n` +
` Reject text: ${rejectMessage}\n`);
}
case agent_1.RequestStatusResponseStatus.Done:
// This is _technically_ not an error, but we still didn't see the `Replied` status so
// we don't know the result and cannot decode it.
throw new Error(`Call was marked as done but we never saw the reply:\n` +
` Request ID: ${(0, buffer_1.toHex)(requestId)}\n`);
}
throw new Error('unreachable');
}
exports.pollForResponse = pollForResponse;
//# sourceMappingURL=index.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!