PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/sdk/src/contract
Просмотр файла: ContractInfoQuery.js
/*-
*
* 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.
*
*/
import Query, { QUERY_REGISTRY } from "../query/Query.js";
import ContractId from "./ContractId.js";
import ContractInfo from "./ContractInfo.js";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Hbar from "../Hbar.js";
/**
* @namespace proto
* @typedef {import("@hashgraph/proto").proto.IQuery} HashgraphProto.proto.IQuery
* @typedef {import("@hashgraph/proto").proto.IQueryHeader} HashgraphProto.proto.IQueryHeader
* @typedef {import("@hashgraph/proto").proto.IResponse} HashgraphProto.proto.IResponse
* @typedef {import("@hashgraph/proto").proto.IResponseHeader} HashgraphProto.proto.IResponseHeader
* @typedef {import("@hashgraph/proto").proto.IContractGetInfoQuery} HashgraphProto.proto.IContractGetInfoQuery
* @typedef {import("@hashgraph/proto").proto.IContractGetInfoResponse} HashgraphProto.proto.IContractGetInfoResponse
* @typedef {import("@hashgraph/proto").proto.ContractGetInfoResponse.IContractInfo} HashgraphProto.proto.ContractGetInfoResponse.IContractInfo
*/
/**
* @typedef {import("../channel/Channel.js").default} Channel
* @typedef {import("../client/Client.js").default<*, *>} Client
* @typedef {import("../account/AccountId.js").default} AccountId
*/
/**
* @augments {Query<ContractInfo>}
*/
export default class ContractInfoQuery extends Query {
/**
* @param {object} [props]
* @param {ContractId | string} [props.contractId]
*/
constructor(props = {}) {
super();
/**
* @type {?ContractId}
* @private
*/
this._contractId = null;
if (props.contractId != null) {
this.setContractId(props.contractId);
}
}
/**
* @internal
* @param {HashgraphProto.proto.IQuery} query
* @returns {ContractInfoQuery}
*/
static _fromProtobuf(query) {
const info = /** @type {HashgraphProto.proto.IContractGetInfoQuery} */ (
query.contractGetInfo
);
return new ContractInfoQuery({
contractId:
info.contractID != null
? ContractId._fromProtobuf(info.contractID)
: undefined,
});
}
/**
* @returns {?ContractId}
*/
get contractId() {
return this._contractId;
}
/**
* Set the contract ID for which the info is being requested.
*
* @param {ContractId | string} contractId
* @returns {ContractInfoQuery}
*/
setContractId(contractId) {
this._contractId =
typeof contractId === "string"
? ContractId.fromString(contractId)
: contractId.clone();
return this;
}
/**
* @param {Client} client
*/
_validateChecksums(client) {
if (this._contractId != null) {
this._contractId.validateChecksum(client);
}
}
/**
* @override
* @internal
* @param {Channel} channel
* @param {HashgraphProto.proto.IQuery} request
* @returns {Promise<HashgraphProto.proto.IResponse>}
*/
_execute(channel, request) {
return channel.smartContract.getContractInfo(request);
}
/**
* @override
* @param {import("../client/Client.js").default<Channel, *>} client
* @returns {Promise<Hbar>}
*/
async getCost(client) {
return super.getCost(client);
}
/**
* @override
* @internal
* @param {HashgraphProto.proto.IResponse} response
* @returns {HashgraphProto.proto.IResponseHeader}
*/
_mapResponseHeader(response) {
const contractGetInfo =
/** @type {HashgraphProto.proto.IContractGetInfoResponse} */ (
response.contractGetInfo
);
return /** @type {HashgraphProto.proto.IResponseHeader} */ (
contractGetInfo.header
);
}
/**
* @protected
* @override
* @param {HashgraphProto.proto.IResponse} response
* @param {AccountId} nodeAccountId
* @param {HashgraphProto.proto.IQuery} request
* @returns {Promise<ContractInfo>}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapResponse(response, nodeAccountId, request) {
const info =
/** @type {HashgraphProto.proto.IContractGetInfoResponse} */ (
response.contractGetInfo
);
return Promise.resolve(
ContractInfo._fromProtobuf(
/** @type {HashgraphProto.proto.ContractGetInfoResponse.IContractInfo} */ (
info.contractInfo
)
)
);
}
/**
* @override
* @internal
* @param {HashgraphProto.proto.IQueryHeader} header
* @returns {HashgraphProto.proto.IQuery}
*/
_onMakeRequest(header) {
return {
contractGetInfo: {
header,
contractID:
this._contractId != null
? this._contractId._toProtobuf()
: null,
},
};
}
/**
* @returns {string}
*/
_getLogId() {
const timestamp =
this._paymentTransactionId != null &&
this._paymentTransactionId.validStart != null
? this._paymentTransactionId.validStart
: this._timestamp;
return `ContractInfoQuery:${timestamp.toString()}`;
}
}
// eslint-disable-next-line @typescript-eslint/unbound-method
QUERY_REGISTRY.set("contractGetInfo", ContractInfoQuery._fromProtobuf);
Выполнить команду
Для локальной разработки. Не используйте в интернете!