PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/sdk/src/system
Просмотр файла: SystemDeleteTransaction.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 Transaction, {
TRANSACTION_REGISTRY,
} from "../transaction/Transaction.js";
import FileId from "../file/FileId.js";
import ContractId from "../contract/ContractId.js";
import Timestamp from "../Timestamp.js";
/**
* @namespace proto
* @typedef {import("@hashgraph/proto").proto.ITransaction} HashgraphProto.proto.ITransaction
* @typedef {import("@hashgraph/proto").proto.ISignedTransaction} HashgraphProto.proto.ISignedTransaction
* @typedef {import("@hashgraph/proto").proto.TransactionBody} HashgraphProto.proto.TransactionBody
* @typedef {import("@hashgraph/proto").proto.ITransactionBody} HashgraphProto.proto.ITransactionBody
* @typedef {import("@hashgraph/proto").proto.ITransactionResponse} HashgraphProto.proto.ITransactionResponse
* @typedef {import("@hashgraph/proto").proto.ISystemDeleteTransactionBody} HashgraphProto.proto.ISystemDeleteTransactionBody
* @typedef {import("@hashgraph/proto").proto.IContractID} HashgraphProto.proto.IContractID
* @typedef {import("@hashgraph/proto").proto.IFileID} HashgraphProto.proto.IFileID
*/
/**
* @typedef {import("../channel/Channel.js").default} Channel
* @typedef {import("../account/AccountId.js").default} AccountId
* @typedef {import("../transaction/TransactionId.js").default} TransactionId
*/
export default class SystemDeleteTransaction extends Transaction {
/**
* @param {object} [props]
* @param {FileId | string} [props.fileId]
* @param {ContractId | string} [props.contractId]
* @param {Timestamp} [props.expirationTime]
*/
constructor(props = {}) {
super();
/**
* @private
* @type {?FileId}
*/
this._fileId = null;
/**
* @private
* @type {?ContractId}
*/
this._contractId = null;
/**
* @private
* @type {?Timestamp}
*/
this._expirationTime = null;
if (props.fileId != null) {
this.setFileId(props.fileId);
}
if (props.contractId != null) {
this.setContractId(props.contractId);
}
if (props.expirationTime != null) {
this.setExpirationTime(props.expirationTime);
}
}
/**
* @internal
* @param {HashgraphProto.proto.ITransaction[]} transactions
* @param {HashgraphProto.proto.ISignedTransaction[]} signedTransactions
* @param {TransactionId[]} transactionIds
* @param {AccountId[]} nodeIds
* @param {HashgraphProto.proto.ITransactionBody[]} bodies
* @returns {SystemDeleteTransaction}
*/
static _fromProtobuf(
transactions,
signedTransactions,
transactionIds,
nodeIds,
bodies
) {
const body = bodies[0];
const systemDelete =
/** @type {HashgraphProto.proto.ISystemDeleteTransactionBody} */ (
body.systemDelete
);
return Transaction._fromProtobufTransactions(
new SystemDeleteTransaction({
fileId:
systemDelete.fileID != null
? FileId._fromProtobuf(
/** @type {HashgraphProto.proto.IFileID} */ (
systemDelete.fileID
)
)
: undefined,
contractId:
systemDelete.contractID != null
? ContractId._fromProtobuf(
/** @type {HashgraphProto.proto.IContractID} */ (
systemDelete.contractID
)
)
: undefined,
expirationTime:
systemDelete.expirationTime != null
? Timestamp._fromProtobuf(systemDelete.expirationTime)
: undefined,
}),
transactions,
signedTransactions,
transactionIds,
nodeIds,
bodies
);
}
/**
* @returns {?FileId}
*/
get fileId() {
return this._fileId;
}
/**
* @param {FileId | string} fileId
* @returns {this}
*/
setFileId(fileId) {
this._requireNotFrozen();
this._fileId =
fileId instanceof FileId ? fileId : FileId.fromString(fileId);
return this;
}
/**
* @returns {?ContractId}
*/
get contractId() {
return this._contractId;
}
/**
* @param {ContractId | string} contractId
* @returns {this}
*/
setContractId(contractId) {
this._requireNotFrozen();
this._contractId =
contractId instanceof ContractId
? contractId
: ContractId.fromString(contractId);
return this;
}
/**
* @returns {?Timestamp}
*/
get expirationTime() {
return this._expirationTime;
}
/**
* @param {Timestamp} expirationTime
* @returns {SystemDeleteTransaction}
*/
setExpirationTime(expirationTime) {
this._requireNotFrozen();
this._expirationTime = expirationTime;
return this;
}
/**
* @override
* @internal
* @param {Channel} channel
* @param {HashgraphProto.proto.ITransaction} request
* @returns {Promise<HashgraphProto.proto.ITransactionResponse>}
*/
_execute(channel, request) {
if (this._fileId != null) {
return channel.file.systemDelete(request);
} else {
return channel.smartContract.systemDelete(request);
}
}
/**
* @override
* @protected
* @returns {NonNullable<HashgraphProto.proto.TransactionBody["data"]>}
*/
_getTransactionDataCase() {
return "systemDelete";
}
/**
* @override
* @protected
* @returns {HashgraphProto.proto.ISystemDeleteTransactionBody}
*/
_makeTransactionData() {
return {
fileID: this._fileId != null ? this._fileId._toProtobuf() : null,
contractID:
this._contractId != null
? this._contractId._toProtobuf()
: null,
expirationTime:
this._expirationTime != null
? this._expirationTime._toProtobuf()
: null,
};
}
/**
* @returns {string}
*/
_getLogId() {
const timestamp = /** @type {import("../Timestamp.js").default} */ (
this._transactionIds.current.validStart
);
return `SystemDeleteTransaction:${timestamp.toString()}`;
}
}
// eslint-disable-next-line @typescript-eslint/unbound-method
TRANSACTION_REGISTRY.set("systemDelete", SystemDeleteTransaction._fromProtobuf);
Выполнить команду
Для локальной разработки. Не используйте в интернете!