PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/sdk/lib/account

Просмотр файла: AccountAllowanceAdjustTransaction.cjs

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _Transaction = _interopRequireDefault(require("../transaction/Transaction.cjs"));
var _AccountId = _interopRequireDefault(require("./AccountId.cjs"));
var _ContractId = _interopRequireDefault(require("../contract/ContractId.cjs"));
var _TokenId = _interopRequireDefault(require("../token/TokenId.cjs"));
var _NftId = _interopRequireDefault(require("../token/NftId.cjs"));
var _long = _interopRequireDefault(require("long"));
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
var _HbarAllowance = _interopRequireDefault(require("./HbarAllowance.cjs"));
var _TokenAllowance = _interopRequireDefault(require("./TokenAllowance.cjs"));
var _TokenNftAllowance = _interopRequireDefault(require("./TokenNftAllowance.cjs"));
var util = _interopRequireWildcard(require("../util.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.
 * ‍
 */

/**
 * @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.IAccountID} HashgraphProto.proto.IAccountID
 * @typedef {import("@hashgraph/proto").proto.IContractID} HashgraphProto.proto.IContractID
 */

/**
 * @typedef {import("../channel/Channel.js").default} Channel
 * @typedef {import("../client/Client.js").default<*, *>} Client
 * @typedef {import("../transaction/TransactionId.js").default} TransactionId
 * @typedef {import("bignumber.js").default} BigNumber
 * @typedef {import("../long.js").LongObject} LongObject
 */
/**
 * @deprecated - No longer supported via Hedera Protobufs
 * Change properties for the given account.
 */
class AccountAllowanceAdjustTransaction extends _Transaction.default {
  /**
   * @param {object} [props]
   * @param {HbarAllowance[]} [props.hbarAllowances]
   * @param {TokenAllowance[]} [props.tokenAllowances]
   * @param {TokenNftAllowance[]} [props.nftAllowances]
   */
  constructor(props = {}) {
    super();

    /**
     * @private
     * @type {HbarAllowance[]}
     */
    this._hbarAllowances = props.hbarAllowances != null ? props.hbarAllowances : [];

    /**
     * @private
     * @type {TokenAllowance[]}
     */
    this._tokenAllowances = props.tokenAllowances != null ? props.tokenAllowances : [];

    /**
     * @private
     * @type {TokenNftAllowance[]}
     */
    this._nftAllowances = props.nftAllowances != null ? props.nftAllowances : [];
  }

  /**
   * @returns {HbarAllowance[]}
   */
  get hbarAllowances() {
    return this._hbarAllowances;
  }

  /**
   * @deprecated
   * @param {AccountId | string} spenderAccountId
   * @param {number | string | Long | LongObject | BigNumber | Hbar} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  addHbarAllowance(spenderAccountId, amount) {
    const value = amount instanceof _Hbar.default ? amount : new _Hbar.default(amount);
    return this._adjustHbarAllowance(null, spenderAccountId, util.requireNotNegative(value));
  }

  /**
   * @param {AccountId | string | null} ownerAccountId
   * @param {AccountId | ContractId | string} spenderAccountId
   * @param {Hbar} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  _adjustHbarAllowance(ownerAccountId, spenderAccountId, amount) {
    this._requireNotFrozen();
    this._hbarAllowances.push(new _HbarAllowance.default({
      spenderAccountId: typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(spenderAccountId.toSolidityAddress()) : spenderAccountId,
      ownerAccountId: typeof ownerAccountId === "string" ? _AccountId.default.fromString(ownerAccountId) : ownerAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(ownerAccountId.toSolidityAddress()) : ownerAccountId,
      amount: amount
    }));
    return this;
  }

  /**
   * @deprecated
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @param {number | string | Long | LongObject | BigNumber | Hbar} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  grantHbarAllowance(ownerAccountId, spenderAccountId, amount) {
    const value = amount instanceof _Hbar.default ? amount : new _Hbar.default(amount);
    return this._adjustHbarAllowance(ownerAccountId, spenderAccountId, util.requireNotNegative(value));
  }

  /**
   * @deprecated
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @param {number | string | Long | LongObject | BigNumber | Hbar} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  revokeHbarAllowance(ownerAccountId, spenderAccountId, amount) {
    const value = amount instanceof _Hbar.default ? amount : new _Hbar.default(amount);
    return this._adjustHbarAllowance(ownerAccountId, spenderAccountId, util.requireNotNegative(value).negated());
  }

  /**
   * @returns {TokenAllowance[]}
   */
  get tokenAllowances() {
    return this._tokenAllowances;
  }

  /**
   * @deprecated
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} spenderAccountId
   * @param {Long | number} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  addTokenAllowance(tokenId, spenderAccountId, amount) {
    return this._adjustTokenAllowance(tokenId, null, spenderAccountId, util.requireNotNegative(_long.default.fromValue(amount)));
  }

  /**
   * @param {TokenId | string} tokenId
   * @param {AccountId | string | null} ownerAccountId
   * @param {AccountId | ContractId | string} spenderAccountId
   * @param {Long | number} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  _adjustTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {
    this._requireNotFrozen();
    this._tokenAllowances.push(new _TokenAllowance.default({
      tokenId: typeof tokenId === "string" ? _TokenId.default.fromString(tokenId) : tokenId,
      spenderAccountId: typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(spenderAccountId.toSolidityAddress()) : spenderAccountId,
      ownerAccountId: typeof ownerAccountId === "string" ? _AccountId.default.fromString(ownerAccountId) : ownerAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(ownerAccountId.toSolidityAddress()) : ownerAccountId,
      amount: typeof amount === "number" ? _long.default.fromNumber(amount) : amount
    }));
    return this;
  }

  /**
   * @deprecated
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @param {Long | number} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  grantTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {
    return this._adjustTokenAllowance(tokenId, ownerAccountId, spenderAccountId, util.requireNotNegative(_long.default.fromValue(amount)));
  }

  /**
   * @deprecated
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @param {Long | number} amount
   * @returns {AccountAllowanceAdjustTransaction}
   */
  revokeTokenAllowance(tokenId, ownerAccountId, spenderAccountId, amount) {
    return this._adjustTokenAllowance(tokenId, ownerAccountId, spenderAccountId, util.requireNotNegative(_long.default.fromValue(amount)));
  }

  /**
   * @deprecated
   * @param {NftId | string} nftId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  addTokenNftAllowance(nftId, spenderAccountId) {
    const id = typeof nftId === "string" ? _NftId.default.fromString(nftId) : nftId;
    return this._adjustTokenNftAllowance(id, null, spenderAccountId);
  }

  /**
   * @param {NftId} nftId
   * @param {AccountId | string | null} ownerAccountId
   * @param {AccountId | ContractId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  _adjustTokenNftAllowance(nftId, ownerAccountId, spenderAccountId) {
    this._requireNotFrozen();
    const spender = typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(spenderAccountId.toSolidityAddress()) : spenderAccountId;
    const owner = typeof ownerAccountId === "string" ? _AccountId.default.fromString(ownerAccountId) : ownerAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(ownerAccountId.toSolidityAddress()) : ownerAccountId;
    let found = false;
    for (const allowance of this._nftAllowances) {
      if (allowance.tokenId.compare(nftId.tokenId) === 0 && allowance.spenderAccountId != null && allowance.spenderAccountId.compare(spender) === 0) {
        if (allowance.serialNumbers != null) {
          allowance.serialNumbers.push(nftId.serial);
        }
        found = true;
        break;
      }
    }
    if (!found) {
      this._nftAllowances.push(new _TokenNftAllowance.default({
        tokenId: nftId.tokenId,
        spenderAccountId: spender,
        serialNumbers: [nftId.serial],
        ownerAccountId: owner,
        allSerials: false,
        delegatingSpender: null
      }));
    }
    return this;
  }

  /**
   * @deprecated
   * @param {NftId | string} nftId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  grantTokenNftAllowance(nftId, ownerAccountId, spenderAccountId) {
    const id = typeof nftId === "string" ? _NftId.default.fromString(nftId) : nftId;
    util.requireNotNegative(id.serial);
    return this._adjustTokenNftAllowance(id, ownerAccountId, spenderAccountId);
  }

  /**
   * @deprecated
   * @param {NftId | string} nftId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  revokeTokenNftAllowance(nftId, ownerAccountId, spenderAccountId) {
    const id = typeof nftId === "string" ? _NftId.default.fromString(nftId) : nftId;
    util.requireNotNegative(id.serial);
    return this._adjustTokenNftAllowance(new _NftId.default(id.tokenId, id.serial.negate()), ownerAccountId, spenderAccountId);
  }

  /**
   * @deprecated - use `grantTokenNftAllowanceAllSerials()` instead
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  addAllTokenNftAllowance(tokenId, spenderAccountId) {
    return this._adjustTokenNftAllowanceAllSerials(tokenId, null, spenderAccountId, true);
  }

  /**
   * @deprecated
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  grantTokenNftAllowanceAllSerials(tokenId, ownerAccountId, spenderAccountId) {
    return this._adjustTokenNftAllowanceAllSerials(tokenId, ownerAccountId, spenderAccountId, true);
  }

  /**
   * @deprecated
   * @param {TokenId | string} tokenId
   * @param {AccountId | string} ownerAccountId
   * @param {AccountId | string} spenderAccountId
   * @returns {AccountAllowanceAdjustTransaction}
   */
  revokeTokenNftAllowanceAllSerials(tokenId, ownerAccountId, spenderAccountId) {
    return this._adjustTokenNftAllowanceAllSerials(tokenId, ownerAccountId, spenderAccountId, false);
  }

  /**
   * @param {TokenId | string} tokenId
   * @param {AccountId | string | null} ownerAccountId
   * @param {AccountId | ContractId | string} spenderAccountId
   * @param {boolean} allSerials
   * @returns {AccountAllowanceAdjustTransaction}
   */
  _adjustTokenNftAllowanceAllSerials(tokenId, ownerAccountId, spenderAccountId, allSerials) {
    this._requireNotFrozen();
    this._nftAllowances.push(new _TokenNftAllowance.default({
      tokenId: typeof tokenId === "string" ? _TokenId.default.fromString(tokenId) : tokenId,
      ownerAccountId: ownerAccountId != null ? typeof ownerAccountId === "string" ? _AccountId.default.fromString(ownerAccountId) : ownerAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(ownerAccountId.toSolidityAddress()) : ownerAccountId : null,
      spenderAccountId: typeof spenderAccountId === "string" ? _AccountId.default.fromString(spenderAccountId) : spenderAccountId instanceof _ContractId.default ? _AccountId.default.fromSolidityAddress(spenderAccountId.toSolidityAddress()) : spenderAccountId,
      serialNumbers: null,
      allSerials,
      delegatingSpender: null
    }));
    return this;
  }

  /**
   * @param {Client} client
   */
  _validateChecksums(client) {
    this._hbarAllowances.map(allowance => allowance._validateChecksums(client));
    this._tokenAllowances.map(allowance => allowance._validateChecksums(client));
    this._nftAllowances.map(allowance => allowance._validateChecksums(client));
  }

  /**
   * @override
   * @internal
   * @param {Channel} channel
   * @param {HashgraphProto.proto.ITransaction} request
   * @returns {Promise<HashgraphProto.proto.ITransactionResponse>}
   */
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  _execute(channel, request) {
    return Promise.reject(new Error("This feature has been deprecated for this class."));
  }

  // eslint-disable-next-line jsdoc/require-returns-check
  /**
   * @deprecated
   * @override
   * @protected
   * @returns {NonNullable<HashgraphProto.proto.TransactionBody["data"]>}
   */
  _getTransactionDataCase() {
    throw new Error("This feature has been deprecated for this class.");
  }

  // eslint-disable-next-line jsdoc/require-returns-check
  /**
   * @override
   * @protected
   * @returns {object}
   */
  _makeTransactionData() {
    throw new Error("This feature has been deprecated.");
  }

  /**
   * @returns {string}
   */
  _getLogId() {
    const timestamp = /** @type {import("../Timestamp.js").default} */
    this._transactionIds.current.validStart;
    return `AccountAllowanceAdjustTransaction:${timestamp.toString()}`;
  }
}
exports.default = AccountAllowanceAdjustTransaction;

Выполнить команду


Для локальной разработки. Не используйте в интернете!