UNPKG

@hiero-ledger/sdk

Version:
145 lines (132 loc) 5.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Transaction = _interopRequireWildcard(require("../transaction/Transaction.cjs")); var _TopicId = _interopRequireDefault(require("./TopicId.cjs")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } // SPDX-License-Identifier: Apache-2.0 /** * @namespace proto * @typedef {import("@hiero-ledger/proto").proto.IConsensusDeleteTopicTransactionBody} HieroProto.proto.IConsensusDeleteTopicTransactionBody * @typedef {import("@hiero-ledger/proto").proto.ITransaction} HieroProto.proto.ITransaction * @typedef {import("@hiero-ledger/proto").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction * @typedef {import("@hiero-ledger/proto").proto.TransactionBody} HieroProto.proto.TransactionBody * @typedef {import("@hiero-ledger/proto").proto.ITransactionBody} HieroProto.proto.ITransactionBody * @typedef {import("@hiero-ledger/proto").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse */ /** * @typedef {import("../channel/Channel.js").default} Channel * @typedef {import("../client/Client.js").default<*, *>} Client * @typedef {import("../account/AccountId.js").default} AccountId * @typedef {import("../transaction/TransactionId.js").default} TransactionId */ /** * Delete a topic. * * No more transactions or queries on the topic will succeed. * * If an adminKey is set, this transaction must be signed by that key. * If there is no adminKey, this transaction will fail with Status#Unautorized. */ class TopicDeleteTransaction extends _Transaction.default { /** * @param {object} props * @param {TopicId | string} [props.topicId] */ constructor(props = {}) { super(); /** * @private * @type {?TopicId} */ this._topicId = null; if (props.topicId != null) { this.setTopicId(props.topicId); } } /** * @internal * @param {HieroProto.proto.ITransaction[]} transactions * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions * @param {TransactionId[]} transactionIds * @param {AccountId[]} nodeIds * @param {HieroProto.proto.ITransactionBody[]} bodies * @returns {TopicDeleteTransaction} */ static _fromProtobuf(transactions, signedTransactions, transactionIds, nodeIds, bodies) { const body = bodies[0]; const topicDelete = /** @type {HieroProto.proto.IConsensusDeleteTopicTransactionBody} */ body.consensusDeleteTopic; return _Transaction.default._fromProtobufTransactions(new TopicDeleteTransaction({ topicId: topicDelete.topicID != null ? _TopicId.default._fromProtobuf(topicDelete.topicID) : undefined }), transactions, signedTransactions, transactionIds, nodeIds, bodies); } /** * @returns {?TopicId} */ get topicId() { return this._topicId; } /** * Set the topic ID which is being deleted in this transaction. * * @param {TopicId | string} topicId * @returns {TopicDeleteTransaction} */ setTopicId(topicId) { this._requireNotFrozen(); this._topicId = typeof topicId === "string" ? _TopicId.default.fromString(topicId) : topicId.clone(); return this; } /** * @param {Client} client */ _validateChecksums(client) { if (this._topicId != null) { this._topicId.validateChecksum(client); } } /** * @override * @internal * @param {Channel} channel * @param {HieroProto.proto.ITransaction} request * @returns {Promise<HieroProto.proto.ITransactionResponse>} */ _execute(channel, request) { return channel.consensus.deleteTopic(request); } /** * @override * @protected * @returns {NonNullable<HieroProto.proto.TransactionBody["data"]>} */ _getTransactionDataCase() { return "consensusDeleteTopic"; } /** * @override * @protected * @returns {HieroProto.proto.IConsensusDeleteTopicTransactionBody} */ _makeTransactionData() { return { topicID: this._topicId != null ? this._topicId._toProtobuf() : null }; } /** * @returns {string} */ _getLogId() { const timestamp = /** @type {import("../Timestamp.js").default} */ this._transactionIds.current.validStart; return `TopicDeleteTransaction:${timestamp.toString()}`; } } exports.default = TopicDeleteTransaction; _Transaction.TRANSACTION_REGISTRY.set("consensusDeleteTopic", // eslint-disable-next-line @typescript-eslint/unbound-method TopicDeleteTransaction._fromProtobuf);