PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/sdk/lib/transaction
Просмотр файла: TransactionRecord.cjs
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _TransactionReceipt = _interopRequireDefault(require("./TransactionReceipt.cjs"));
var _TransactionId = _interopRequireDefault(require("./TransactionId.cjs"));
var _Timestamp = _interopRequireDefault(require("../Timestamp.cjs"));
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
var _Transfer = _interopRequireDefault(require("../Transfer.cjs"));
var _ContractFunctionResult = _interopRequireDefault(require("../contract/ContractFunctionResult.cjs"));
var _TokenTransferMap = _interopRequireDefault(require("../account/TokenTransferMap.cjs"));
var _TokenNftTransferMap = _interopRequireDefault(require("../account/TokenNftTransferMap.cjs"));
var HashgraphProto = _interopRequireWildcard(require("@hashgraph/proto"));
var _ScheduleId = _interopRequireDefault(require("../schedule/ScheduleId.cjs"));
var _AssessedCustomFee = _interopRequireDefault(require("../token/AssessedCustomFee.cjs"));
var _TokenAssociation = _interopRequireDefault(require("../token/TokenAssociation.cjs"));
var _Key = _interopRequireDefault(require("../Key.cjs"));
var _PublicKey = _interopRequireDefault(require("../PublicKey.cjs"));
var _TokenTransfer = _interopRequireDefault(require("../token/TokenTransfer.cjs"));
var _EvmAddress = _interopRequireDefault(require("../EvmAddress.cjs"));
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("../token/TokenId.js").default} TokenId
* @typedef {import("../account/HbarAllowance.js").default} HbarAllowance
* @typedef {import("../account/TokenAllowance.js").default} TokenAllowance
* @typedef {import("../account/TokenNftAllowance.js").default} TokenNftAllowance
*/
/**
* Either the record of processing the first consensus transaction with the given id whose
* status was neither <tt>INVALID_NODE_ACCOUNT</tt> nor <tt>INVALID_PAYER_SIGNATURE</tt>;
* <b>or</b>, if no such record exists, the record of processing the first transaction to reach
* consensus with the given transaction id.
*/
class TransactionRecord {
/**
* @private
* @param {object} props
* @param {ContractFunctionResult} [props.contractFunctionResult]
* @param {TransactionReceipt} props.receipt
* @param {Uint8Array} props.transactionHash
* @param {Timestamp} props.consensusTimestamp
* @param {TransactionId} props.transactionId
* @param {string} props.transactionMemo
* @param {Hbar} props.transactionFee
* @param {Transfer[]} props.transfers
* @param {TokenTransferMap} props.tokenTransfers
* @param {TokenTransfer[]} props.tokenTransfersList
* @param {?ScheduleId} props.scheduleRef
* @param {AssessedCustomFee[]} props.assessedCustomFees
* @param {TokenNftTransferMap} props.nftTransfers
* @param {TokenAssocation[]} props.automaticTokenAssociations
* @param {Timestamp | null} props.parentConsensusTimestamp
* @param {PublicKey | null} props.aliasKey
* @param {TransactionRecord[]} props.duplicates
* @param {TransactionRecord[]} props.children
* @param {HbarAllowance[]} props.hbarAllowanceAdjustments
* @param {TokenAllowance[]} props.tokenAllowanceAdjustments
* @param {TokenNftAllowance[]} props.nftAllowanceAdjustments
* @param {?Uint8Array} props.ethereumHash
* @param {Transfer[]} props.paidStakingRewards
* @param {?Uint8Array} props.prngBytes
* @param {?number} props.prngNumber
* @param {?EvmAddress} props.evmAddress
*/
constructor(props) {
/**
* The status (reach consensus, or failed, or is unknown) and the ID of
* any new account/file/instance created.
*
* @readonly
*/
this.receipt = props.receipt;
/**
* The hash of the Transaction that executed (not the hash of any Transaction that failed
* for having a duplicate TransactionID).
*
* @readonly
*/
this.transactionHash = props.transactionHash;
/**
* The consensus timestamp (or null if didn't reach consensus yet).
*
* @readonly
*/
this.consensusTimestamp = props.consensusTimestamp;
/**
* The ID of the transaction this record represents.
*
* @readonly
*/
this.transactionId = props.transactionId;
/**
* The memo that was submitted as part of the transaction (max 100 bytes).
*
* @readonly
*/
this.transactionMemo = props.transactionMemo;
/**
* The actual transaction fee charged,
* not the original transactionFee value from TransactionBody.
*
* @readonly
*/
this.transactionFee = props.transactionFee;
/**
* All hbar transfers as a result of this transaction, such as fees, or transfers performed
* by the transaction, or by a smart contract it calls, or by the creation of threshold
* records that it triggers.
*
* @readonly
*/
this.transfers = props.transfers;
/**
* Record of the value returned by the smart contract function or constructor.
*
* @readonly
*/
this.contractFunctionResult = props.contractFunctionResult != null ? props.contractFunctionResult : null;
/**
* All the token transfers from this account
*
* @readonly
*/
this.tokenTransfers = props.tokenTransfers;
/**
* All the token transfers from this account
*
* @readonly
*/
this.tokenTransfersList = props.tokenTransfersList;
/**
* Reference to the scheduled transaction ID that this transaction record represent
*
* @readonly
*/
this.scheduleRef = props.scheduleRef;
/**
* All custom fees that were assessed during a CryptoTransfer, and must be paid if the
* transaction status resolved to SUCCESS
*
* @readonly
*/
this.assessedCustomFees = props.assessedCustomFees;
/** @readonly */
this.nftTransfers = props.nftTransfers;
/**
* All token associations implicitly created while handling this transaction
*
* @readonly
*/
this.automaticTokenAssociations = props.automaticTokenAssociations;
/**
* In the record of an internal transaction, the consensus timestamp of the user
* transaction that spawned it.
*
* @readonly
*/
this.parentConsensusTimestamp = props.parentConsensusTimestamp;
/**
* In the record of an internal CryptoCreate transaction triggered by a user
* transaction with a (previously unused) alias, the new account's alias.
*
* @readonly
*/
this.aliasKey = props.aliasKey;
/**
* The records of processing all consensus transaction with the same id as the distinguished
* record above, in chronological order.
*
* @readonly
*/
this.duplicates = props.duplicates;
/**
* The records of processing all child transaction spawned by the transaction with the given
* top-level id, in consensus order. Always empty if the top-level status is UNKNOWN.
*
* @readonly
*/
this.children = props.children;
/**
* @deprecated
* @readonly
*/
// eslint-disable-next-line deprecation/deprecation
this.hbarAllowanceAdjustments = props.hbarAllowanceAdjustments;
/**
* @deprecated
* @readonly
*/
// eslint-disable-next-line deprecation/deprecation
this.tokenAllowanceAdjustments = props.tokenAllowanceAdjustments;
/**
* @deprecated
* @readonly
*/
// eslint-disable-next-line deprecation/deprecation
this.nftAllowanceAdjustments = props.nftAllowanceAdjustments;
/**
* The keccak256 hash of the ethereumData. This field will only be populated for
* EthereumTransaction.
*
* @readonly
*/
this.ethereumHash = props.ethereumHash;
/**
* List of accounts with the corresponding staking rewards paid as a result of a transaction.
*
* @readonly
*/
this.paidStakingRewards = props.paidStakingRewards;
/**
* In the record of a PRNG transaction with no output range, a pseudorandom 384-bit string.
*
* @readonly
*/
this.prngBytes = props.prngBytes;
/**
* In the record of a PRNG transaction with an output range, the output of a PRNG whose input was a 384-bit string.
*
* @readonly
*/
this.prngNumber = props.prngNumber;
/**
* The new default EVM address of the account created by this transaction.
* This field is populated only when the EVM address is not specified in the related transaction body.
*
* @readonly
*/
this.evmAddress = props.evmAddress;
Object.freeze(this);
}
/**
* @internal
* @returns {HashgraphProto.proto.ITransactionGetRecordResponse}
*/
_toProtobuf() {
const tokenTransfers = this.tokenTransfers._toProtobuf();
const nftTransfers = this.nftTransfers._toProtobuf();
const tokenTransferLists = [];
for (const tokenTransfer of tokenTransfers) {
for (const nftTransfer of nftTransfers) {
if (tokenTransfer.token != null && nftTransfer.token != null && tokenTransfer.token.shardNum === nftTransfer.token.shardNum && tokenTransfer.token.realmNum === nftTransfer.token.realmNum && tokenTransfer.token.tokenNum === nftTransfer.token.tokenNum) {
tokenTransferLists.push({
token: tokenTransfer.token,
transfers: tokenTransfer.transfers,
nftTransfers: tokenTransfer.nftTransfers
});
} else {
tokenTransferLists.push(tokenTransfer);
tokenTransferLists.push(nftTransfer);
}
}
}
const duplicates = this.duplicates.map(record => /** @type {HashgraphProto.proto.ITransactionRecord} */
record._toProtobuf().transactionRecord);
const children = this.children.map(record => /** @type {HashgraphProto.proto.ITransactionRecord} */
record._toProtobuf().transactionRecord);
return {
duplicateTransactionRecords: duplicates,
childTransactionRecords: children,
transactionRecord: {
receipt: this.receipt._toProtobuf().receipt,
transactionHash: this.transactionHash != null ? this.transactionHash : null,
consensusTimestamp: this.consensusTimestamp != null ? this.consensusTimestamp._toProtobuf() : null,
transactionID: this.transactionId != null ? this.transactionId._toProtobuf() : null,
memo: this.transactionMemo != null ? this.transactionMemo : null,
transactionFee: this.transactionFee != null ? this.transactionFee.toTinybars() : null,
contractCallResult: this.contractFunctionResult != null && !this.contractFunctionResult._createResult ? this.contractFunctionResult._toProtobuf() : null,
contractCreateResult: this.contractFunctionResult != null && this.contractFunctionResult._createResult ? this.contractFunctionResult._toProtobuf() : null,
transferList: this.transfers != null ? {
accountAmounts: this.transfers.map(transfer => transfer._toProtobuf())
} : null,
tokenTransferLists,
scheduleRef: this.scheduleRef != null ? this.scheduleRef._toProtobuf() : null,
assessedCustomFees: this.assessedCustomFees.map(fee => fee._toProtobuf()),
automaticTokenAssociations: this.automaticTokenAssociations.map(association => association._toProtobuf()),
parentConsensusTimestamp: this.parentConsensusTimestamp != null ? this.parentConsensusTimestamp._toProtobuf() : null,
alias: this.aliasKey != null ? HashgraphProto.proto.Key.encode(this.aliasKey._toProtobufKey()).finish() : null,
ethereumHash: this.ethereumHash,
paidStakingRewards: this.paidStakingRewards.map(transfer => transfer._toProtobuf()),
prngBytes: this.prngBytes,
prngNumber: this.prngNumber != null ? this.prngNumber : null,
evmAddress: this.evmAddress != null ? this.evmAddress.toBytes() : null
}
};
}
/**
* @internal
* @param {HashgraphProto.proto.ITransactionGetRecordResponse} response
* @returns {TransactionRecord}
*/
static _fromProtobuf(response) {
const record = /** @type {HashgraphProto.proto.ITransactionRecord} */
response.transactionRecord;
let aliasKey = record.alias != null && record.alias.length > 0 ? _Key.default._fromProtobufKey(HashgraphProto.proto.Key.decode(record.alias)) : null;
if (!(aliasKey instanceof _PublicKey.default)) {
aliasKey = null;
}
const children = response.childTransactionRecords != null ? response.childTransactionRecords.map(child => TransactionRecord._fromProtobuf({
transactionRecord: child
})) : [];
const duplicates = response.duplicateTransactionRecords != null ? response.duplicateTransactionRecords.map(duplicate => TransactionRecord._fromProtobuf({
transactionRecord: duplicate
})) : [];
const contractFunctionResult = record.contractCallResult != null ? _ContractFunctionResult.default._fromProtobuf(record.contractCallResult, false) : record.contractCreateResult != null ? _ContractFunctionResult.default._fromProtobuf(record.contractCreateResult, true) : undefined;
return new TransactionRecord({
receipt: _TransactionReceipt.default._fromProtobuf({
receipt: /** @type {HashgraphProto.proto.ITransactionReceipt} */
record.receipt
}),
transactionHash: record.transactionHash != null ? record.transactionHash : new Uint8Array(),
consensusTimestamp: _Timestamp.default._fromProtobuf( /** @type {HashgraphProto.proto.ITimestamp} */
record.consensusTimestamp),
transactionId: _TransactionId.default._fromProtobuf( /** @type {HashgraphProto.proto.ITransactionID} */
record.transactionID),
transactionMemo: record.memo != null ? record.memo : "",
transactionFee: _Hbar.default.fromTinybars(record.transactionFee != null ? record.transactionFee : 0),
transfers: _Transfer.default._fromProtobuf(record.transferList != null ? record.transferList.accountAmounts != null ? record.transferList.accountAmounts : [] : []),
contractFunctionResult,
tokenTransfers: _TokenTransferMap.default._fromProtobuf(record.tokenTransferLists != null ? record.tokenTransferLists : []),
tokenTransfersList: _TokenTransfer.default._fromProtobuf(record.tokenTransferLists != null ? record.tokenTransferLists : []),
scheduleRef: record.scheduleRef != null ? _ScheduleId.default._fromProtobuf(record.scheduleRef) : null,
assessedCustomFees: record.assessedCustomFees != null ? record.assessedCustomFees.map(fee => _AssessedCustomFee.default._fromProtobuf(fee)) : [],
nftTransfers: _TokenNftTransferMap.default._fromProtobuf(record.tokenTransferLists != null ? record.tokenTransferLists : []),
automaticTokenAssociations: record.automaticTokenAssociations != null ? record.automaticTokenAssociations.map(association => _TokenAssociation.default._fromProtobuf(association)) : [],
parentConsensusTimestamp: record.parentConsensusTimestamp != null ? _Timestamp.default._fromProtobuf(record.parentConsensusTimestamp) : null,
aliasKey,
duplicates,
children,
hbarAllowanceAdjustments: [],
tokenAllowanceAdjustments: [],
nftAllowanceAdjustments: [],
ethereumHash: record.ethereumHash != null ? record.ethereumHash : null,
paidStakingRewards: record.paidStakingRewards != null ? _Transfer.default._fromProtobuf(record.paidStakingRewards) : [],
prngBytes: record.prngBytes != null ? record.prngBytes : null,
prngNumber: record.prngNumber != null ? record.prngNumber : null,
evmAddress: record.evmAddress != null ? _EvmAddress.default.fromBytes(record.evmAddress) : null
});
}
/**
* @param {Uint8Array} bytes
* @returns {TransactionRecord}
*/
static fromBytes(bytes) {
return TransactionRecord._fromProtobuf(HashgraphProto.proto.TransactionGetRecordResponse.decode(bytes));
}
/**
* @returns {Uint8Array}
*/
toBytes() {
return HashgraphProto.proto.TransactionGetRecordResponse.encode(this._toProtobuf()).finish();
}
}
exports.default = TransactionRecord;Выполнить команду
Для локальной разработки. Не используйте в интернете!