PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@bitgo/sdk-coin-hbar/node_modules/@hashgraph/sdk/lib/query
Просмотр файла: CostQuery.cjs
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _TransactionId = _interopRequireDefault(require("../transaction/TransactionId.cjs"));
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
var _Executable = _interopRequireDefault(require("../Executable.cjs"));
var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
var _Query = require("./Query.cjs");
var HashgraphProto = _interopRequireWildcard(require("@hashgraph/proto"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*-
*
* Hedera JavaScript SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* @typedef {import("../channel/Channel.js").default} Channel
* @typedef {import("../Status.js").default} Status
* @typedef {import("../Executable.js").ExecutionState} ExecutionState
*/
/**
* @template OutputT
* @augments {Executable<HashgraphProto.proto.IQuery, HashgraphProto.proto.IResponse, Hbar>}
*/
class CostQuery extends _Executable.default {
/**
* @param {import("./Query.js").default<OutputT>} query
*/
constructor(query) {
super();
this._query = query;
this._grpcDeadline = query._grpcDeadline;
this._requestTimeout = query._requestTimeout;
this._nodeAccountIds = query._nodeAccountIds.clone();
this._operator = query._operator;
/**
* @type {HashgraphProto.proto.IQueryHeader | null}
*/
this._header = null;
}
/**
* @returns {TransactionId}
*/
_getTransactionId() {
return this._query._getTransactionId();
}
/**
* @returns {string}
*/
_getLogId() {
return `CostQuery:${this._query._getLogId()}`;
}
/**
* @abstract
* @protected
* @param {import("../client/Client.js").default<*, *>} client
* @returns {Promise<void>}
*/
async _beforeExecute(client) {
if (client == null) {
throw new Error("Cannot do CostQuery without Client");
}
const operator = this._operator != null ? this._operator : client._operator;
if (operator == null) {
throw new Error("`client` must have an `operator` or an explicit payment transaction must be provided");
}
if (this._query._nodeAccountIds.isEmpty) {
this._query._nodeAccountIds.setList(client._network.getNodeAccountIdsForExecute());
}
// operator.accountId
const transactionId = _TransactionId.default.generate(operator.accountId);
if (this._query.paymentTransactionId == null) {
this._query.setPaymentTransactionId(transactionId);
}
const logId = this._getLogId();
const nodeId = new _AccountId.default(0);
const paymentTransactionId = /** @type {import("../transaction/TransactionId.js").default} */
_TransactionId.default.generate(new _AccountId.default(0));
const paymentAmount = new _Hbar.default(0);
if (this._logger) {
this._logger.debug(`[${logId}] making a payment transaction for node ${nodeId.toString()} and transaction ID ${paymentTransactionId.toString()} with amount ${paymentAmount.toString()}`);
}
this._header = {
payment: await (0, _Query._makePaymentTransaction)(paymentTransactionId, new _AccountId.default(0), operator, paymentAmount),
responseType: HashgraphProto.proto.ResponseType.COST_ANSWER
};
}
/**
* @abstract
* @internal
* @returns {Promise<HashgraphProto.proto.IQuery>}
*/
_makeRequestAsync() {
return Promise.resolve(this._query._onMakeRequest( /** @type {HashgraphProto.proto.IQueryHeader} */this._header));
}
/**
* @abstract
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @returns {[Status, ExecutionState]}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_shouldRetry(request, response) {
return this._query._shouldRetry(request, response);
}
/**
* @abstract
* @internal
* @param {HashgraphProto.proto.IQuery} request
* @param {HashgraphProto.proto.IResponse} response
* @returns {Error}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapStatusError(request, response) {
return this._query._mapStatusError(request, response);
}
/**
* @override
* @internal
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeAccountId
* @param {HashgraphProto.proto.IQuery} request
* @returns {Promise<Hbar>}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapResponse(response, nodeAccountId, request) {
const cost = this._query._mapResponseHeader(response).cost;
return Promise.resolve(_Hbar.default.fromTinybars( /** @type {Long | number} */cost));
}
/**
* @override
* @internal
* @param {Channel} channel
* @param {HashgraphProto.proto.IQuery} request
* @returns {Promise<HashgraphProto.proto.IResponse>}
*/
_execute(channel, request) {
return this._query._execute(channel, request);
}
/**
* @param {HashgraphProto.proto.Query} request
* @returns {Uint8Array}
*/
_requestToBytes(request) {
return this._query._requestToBytes(request);
}
/**
* @param {HashgraphProto.proto.Response} response
* @returns {Uint8Array}
*/
_responseToBytes(response) {
return this._query._responseToBytes(response);
}
}
exports.default = CostQuery;
_Query.COST_QUERY.push(query => new CostQuery(query));Выполнить команду
Для локальной разработки. Не используйте в интернете!