UNPKG

@hashgraph/sdk

Version:
235 lines (216 loc) 9.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Transaction = _interopRequireWildcard(require("../transaction/Transaction.cjs")); var _ContractId = _interopRequireDefault(require("./ContractId.cjs")); var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } // SPDX-License-Identifier: Apache-2.0 /** * @namespace proto * @typedef {import("@hashgraph/proto").proto.ITransaction} HieroProto.proto.ITransaction * @typedef {import("@hashgraph/proto").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction * @typedef {import("@hashgraph/proto").proto.TransactionBody} HieroProto.proto.TransactionBody * @typedef {import("@hashgraph/proto").proto.ITransactionBody} HieroProto.proto.ITransactionBody * @typedef {import("@hashgraph/proto").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse * @typedef {import("@hashgraph/proto").proto.IContractDeleteTransactionBody} HieroProto.proto.IContractDeleteTransactionBody * @typedef {import("@hashgraph/proto").proto.IContractID} HieroProto.proto.IContractID * @typedef {import("@hashgraph/proto").proto.IAccountID} HieroProto.proto.IAccountID */ /** * @typedef {import("../channel/Channel.js").default} Channel * @typedef {import("../client/Client.js").default<*, *>} Client * @typedef {import("../transaction/TransactionId.js").default} TransactionId */ /** * Delete a smart contract, and transfer any remaining HBAR balance to a * designated account. * * If this call succeeds then all subsequent calls to that smart contract * SHALL execute the `0x0` opcode, as required for EVM equivalence. * * ### Requirements * - An account or smart contract MUST be designated to receive all remaining * account balances. * - The smart contract MUST have an admin key set. If the contract does not * have `admin_key` set, then this transaction SHALL fail and response code * `MODIFYING_IMMUTABLE_CONTRACT` SHALL be set. * - If `admin_key` is, or contains, an empty `KeyList` key, it SHALL be * treated the same as an admin key that is not set. * - The `Key` set for `admin_key` on the smart contract MUST have a valid * signature set on this transaction. * - The designated receiving account MAY have `receiver_sig_required` set. If * that field is set, the receiver account MUST also sign this transaction. * - The field `permanent_removal` MUST NOT be set. That field is reserved for * internal system use when purging the smart contract from state. Any user * transaction with that field set SHALL be rejected and a response code * `PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION` SHALL be set. */ class ContractDeleteTransaction extends _Transaction.default { /** * @param {object} [props] * @param {ContractId | string} [props.contractId] * @param {ContractId | string} [props.transferContractId] * @param {AccountId | string} [props.transferAccountId] */ constructor(props = {}) { super(); /** * @private * @type {?ContractId} */ this._contractId = null; /** * @private * @type {?AccountId} */ this._transferAccountId = null; /** * @private * @type {?ContractId} */ this._transferContractId = null; if (props.contractId != null) { this.setContractId(props.contractId); } if (props.transferAccountId != null) { this.setTransferAccountId(props.transferAccountId); } if (props.transferContractId != null) { this.setTransferContractId(props.transferContractId); } } /** * @internal * @param {HieroProto.proto.ITransaction[]} transactions * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions * @param {TransactionId[]} transactionIds * @param {AccountId[]} nodeIds * @param {HieroProto.proto.ITransactionBody[]} bodies * @returns {ContractDeleteTransaction} */ static _fromProtobuf(transactions, signedTransactions, transactionIds, nodeIds, bodies) { const body = bodies[0]; const contractDelete = /** @type {HieroProto.proto.IContractDeleteTransactionBody} */ body.contractDeleteInstance; return _Transaction.default._fromProtobufTransactions(new ContractDeleteTransaction({ contractId: contractDelete.contractID != null ? _ContractId.default._fromProtobuf(/** @type {HieroProto.proto.IContractID} */ contractDelete.contractID) : undefined, transferAccountId: contractDelete.transferAccountID != null ? _AccountId.default._fromProtobuf(/** @type {HieroProto.proto.IAccountID} */ contractDelete.transferAccountID) : undefined, transferContractId: contractDelete.transferContractID != null ? _ContractId.default._fromProtobuf(/** @type {HieroProto.proto.IContractID} */ contractDelete.transferContractID) : undefined }), transactions, signedTransactions, transactionIds, nodeIds, bodies); } /** * @returns {?ContractId} */ get contractId() { return this._contractId; } /** * Sets the contract ID which is being deleted in this transaction. * * @param {ContractId | string} contractId * @returns {ContractDeleteTransaction} */ setContractId(contractId) { this._requireNotFrozen(); this._contractId = typeof contractId === "string" ? _ContractId.default.fromString(contractId) : contractId.clone(); return this; } /** * @returns {?ContractId} */ get transferContractId() { return this._transferContractId; } /** * Sets the contract ID which will receive all remaining hbars. * * @param {ContractId | string} transferContractId * @returns {ContractDeleteTransaction} */ setTransferContractId(transferContractId) { this._requireNotFrozen(); this._transferContractId = transferContractId instanceof _ContractId.default ? transferContractId : _ContractId.default.fromString(transferContractId); return this; } /** * @returns {?AccountId} */ get transferAccountId() { return this._transferAccountId; } /** * Sets the account ID which will receive all remaining hbars. * * @param {AccountId | string} transferAccountId * @returns {ContractDeleteTransaction} */ setTransferAccountId(transferAccountId) { this._requireNotFrozen(); this._transferAccountId = transferAccountId instanceof _AccountId.default ? transferAccountId : _AccountId.default.fromString(transferAccountId); return this; } /** * @param {Client} client */ _validateChecksums(client) { if (this._contractId != null) { this._contractId.validateChecksum(client); } if (this._transferAccountId != null) { this._transferAccountId.validateChecksum(client); } if (this._transferContractId != null) { this._transferContractId.validateChecksum(client); } } /** * @override * @internal * @param {Channel} channel * @param {HieroProto.proto.ITransaction} request * @returns {Promise<HieroProto.proto.ITransactionResponse>} */ _execute(channel, request) { return channel.smartContract.deleteContract(request); } /** * @override * @protected * @returns {NonNullable<HieroProto.proto.TransactionBody["data"]>} */ _getTransactionDataCase() { return "contractDeleteInstance"; } /** * @override * @protected * @returns {HieroProto.proto.IContractDeleteTransactionBody} */ _makeTransactionData() { return { contractID: this._contractId != null ? this._contractId._toProtobuf() : null, transferAccountID: this._transferAccountId ? this._transferAccountId._toProtobuf() : null, transferContractID: this._transferContractId != null ? this._transferContractId._toProtobuf() : null }; } /** * @returns {string} */ _getLogId() { const timestamp = /** @type {import("../Timestamp.js").default} */ this._transactionIds.current.validStart; return `ContractDeleteTransaction:${timestamp.toString()}`; } } exports.default = ContractDeleteTransaction; _Transaction.TRANSACTION_REGISTRY.set("contractDeleteInstance", // eslint-disable-next-line @typescript-eslint/unbound-method ContractDeleteTransaction._fromProtobuf);