@hiero-ledger/sdk 2.73.2 → 2.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd.js +368 -202
- package/dist/umd.min.js +3 -3
- package/lib/MirrorNode.cjs +46 -0
- package/lib/MirrorNode.d.ts +16 -0
- package/lib/MirrorNode.js +1 -1
- package/lib/MirrorNode.js.map +1 -1
- package/lib/account/AccountAllowanceApproveTransaction.cjs +11 -5
- package/lib/account/AccountAllowanceApproveTransaction.d.ts +4 -5
- package/lib/account/AccountAllowanceApproveTransaction.js +1 -1
- package/lib/account/AccountAllowanceApproveTransaction.js.map +1 -1
- package/lib/account/TokenAllowance.cjs +4 -2
- package/lib/account/TokenAllowance.d.ts +4 -2
- package/lib/account/TokenAllowance.js +1 -1
- package/lib/account/TokenAllowance.js.map +1 -1
- package/lib/account/TokenTransferMap.cjs +7 -2
- package/lib/account/TokenTransferMap.d.ts +6 -2
- package/lib/account/TokenTransferMap.js +1 -1
- package/lib/account/TokenTransferMap.js.map +1 -1
- package/lib/client/Client.cjs +13 -44
- package/lib/client/Client.d.ts +12 -12
- package/lib/client/Client.js +1 -1
- package/lib/client/Client.js.map +1 -1
- package/lib/client/MirrorNetwork.cjs +16 -0
- package/lib/client/MirrorNetwork.d.ts +7 -0
- package/lib/client/MirrorNetwork.js +1 -1
- package/lib/client/MirrorNetwork.js.map +1 -1
- package/lib/client/addressbooks/mainnet.cjs +1 -1
- package/lib/client/addressbooks/mainnet.d.ts +1 -1
- package/lib/client/addressbooks/mainnet.js +1 -1
- package/lib/client/addressbooks/mainnet.js.map +1 -1
- package/lib/client/addressbooks/previewnet.cjs +1 -1
- package/lib/client/addressbooks/previewnet.d.ts +1 -1
- package/lib/client/addressbooks/previewnet.js +1 -1
- package/lib/client/addressbooks/previewnet.js.map +1 -1
- package/lib/client/addressbooks/testnet.cjs +1 -1
- package/lib/client/addressbooks/testnet.d.ts +1 -1
- package/lib/client/addressbooks/testnet.js +1 -1
- package/lib/client/addressbooks/testnet.js.map +1 -1
- package/lib/constants/ClientConstants.cjs +4 -1
- package/lib/constants/ClientConstants.d.ts +2 -0
- package/lib/constants/ClientConstants.js +1 -1
- package/lib/constants/ClientConstants.js.map +1 -1
- package/lib/contract/ContractId.cjs +2 -5
- package/lib/contract/ContractId.js +1 -1
- package/lib/contract/ContractId.js.map +1 -1
- package/lib/network/AddressBookQueryWeb.cjs +88 -60
- package/lib/network/AddressBookQueryWeb.d.ts +7 -37
- package/lib/network/AddressBookQueryWeb.js +1 -1
- package/lib/network/AddressBookQueryWeb.js.map +1 -1
- package/lib/query/MirrorNodeContractQuery.cjs +2 -1
- package/lib/query/MirrorNodeContractQuery.js.map +1 -1
- package/lib/token/AbstractTokenTransferTransaction.cjs +12 -8
- package/lib/token/AbstractTokenTransferTransaction.d.ts +14 -11
- package/lib/token/AbstractTokenTransferTransaction.js +1 -1
- package/lib/token/AbstractTokenTransferTransaction.js.map +1 -1
- package/lib/token/AssessedCustomFee.cjs +8 -4
- package/lib/token/AssessedCustomFee.d.ts +8 -5
- package/lib/token/AssessedCustomFee.js +1 -1
- package/lib/token/AssessedCustomFee.js.map +1 -1
- package/lib/token/CustomFixedFee.cjs +8 -4
- package/lib/token/CustomFixedFee.d.ts +8 -5
- package/lib/token/CustomFixedFee.js +1 -1
- package/lib/token/CustomFixedFee.js.map +1 -1
- package/lib/token/PendingAirdropRecord.cjs +7 -2
- package/lib/token/PendingAirdropRecord.d.ts +6 -2
- package/lib/token/PendingAirdropRecord.js +1 -1
- package/lib/token/PendingAirdropRecord.js.map +1 -1
- package/lib/token/TokenAirdropTransaction.cjs +2 -1
- package/lib/token/TokenAirdropTransaction.d.ts +4 -2
- package/lib/token/TokenAirdropTransaction.js.map +1 -1
- package/lib/token/TokenBurnTransaction.cjs +5 -3
- package/lib/token/TokenBurnTransaction.d.ts +6 -4
- package/lib/token/TokenBurnTransaction.js +1 -1
- package/lib/token/TokenBurnTransaction.js.map +1 -1
- package/lib/token/TokenCreateTransaction.cjs +7 -6
- package/lib/token/TokenCreateTransaction.d.ts +8 -8
- package/lib/token/TokenCreateTransaction.js +1 -1
- package/lib/token/TokenCreateTransaction.js.map +1 -1
- package/lib/token/TokenMintTransaction.cjs +5 -4
- package/lib/token/TokenMintTransaction.d.ts +6 -5
- package/lib/token/TokenMintTransaction.js +1 -1
- package/lib/token/TokenMintTransaction.js.map +1 -1
- package/lib/token/TokenTransfer.cjs +3 -2
- package/lib/token/TokenTransfer.d.ts +2 -2
- package/lib/token/TokenTransfer.js +1 -1
- package/lib/token/TokenTransfer.js.map +1 -1
- package/lib/token/TokenWipeTransaction.cjs +5 -3
- package/lib/token/TokenWipeTransaction.d.ts +6 -4
- package/lib/token/TokenWipeTransaction.js +1 -1
- package/lib/token/TokenWipeTransaction.js.map +1 -1
- package/lib/transaction/Transaction.cjs +54 -0
- package/lib/transaction/Transaction.d.ts +10 -0
- package/lib/transaction/Transaction.js +1 -1
- package/lib/transaction/Transaction.js.map +1 -1
- package/lib/util.cjs +25 -0
- package/lib/util.d.ts +8 -0
- package/lib/util.js +1 -1
- package/lib/util.js.map +1 -1
- package/lib/version.js +1 -1
- package/package.json +16 -12
- package/src/MirrorNode.js +49 -0
- package/src/account/AccountAllowanceApproveTransaction.js +11 -11
- package/src/account/TokenAllowance.js +5 -2
- package/src/account/TokenTransferMap.js +7 -2
- package/src/client/Client.js +13 -51
- package/src/client/MirrorNetwork.js +18 -0
- package/src/client/addressbooks/mainnet.js +1 -1
- package/src/client/addressbooks/previewnet.js +1 -1
- package/src/client/addressbooks/testnet.js +1 -1
- package/src/constants/ClientConstants.js +3 -0
- package/src/contract/ContractId.js +2 -10
- package/src/network/AddressBookQueryWeb.js +122 -91
- package/src/query/MirrorNodeContractQuery.js +2 -1
- package/src/token/AbstractTokenTransferTransaction.js +12 -8
- package/src/token/AssessedCustomFee.js +8 -5
- package/src/token/CustomFixedFee.js +8 -5
- package/src/token/PendingAirdropRecord.js +7 -2
- package/src/token/TokenAirdropTransaction.js +2 -1
- package/src/token/TokenBurnTransaction.js +5 -3
- package/src/token/TokenCreateTransaction.js +7 -9
- package/src/token/TokenMintTransaction.js +5 -4
- package/src/token/TokenTransfer.js +3 -2
- package/src/token/TokenWipeTransaction.js +5 -3
- package/src/transaction/Transaction.js +63 -0
- package/src/util.js +26 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenMintTransaction.js","sources":["../../src/token/TokenMintTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport TokenId from \"./TokenId.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport
|
|
1
|
+
{"version":3,"file":"TokenMintTransaction.js","sources":["../../src/token/TokenMintTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport TokenId from \"./TokenId.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport * as hex from \"../encoding/hex.js\";\nimport { convertAmountToLong } from \"../util.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hashgraph/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hashgraph/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionBody} HieroProto.proto.ITransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenMintTransactionBody} HieroProto.proto.ITokenMintTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n * @typedef {import(\"../account/AccountId.js\").default} AccountId\n * @typedef {import(\"../transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * Mint a new Hedera™ crypto-currency token.\n */\nexport default class TokenMintTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {TokenId | string} [props.tokenId]\n * @param {Long | number | BigNumber | bigint} [props.amount]\n * @param {Uint8Array[]} [props.metadata]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?TokenId}\n */\n this._tokenId = null;\n\n /**\n * @private\n * @type {?Long}\n */\n this._amount = null;\n\n /**\n * @private\n * @type {Uint8Array[]}\n */\n this._metadata = [];\n\n if (props.tokenId != null) {\n this.setTokenId(props.tokenId);\n }\n\n if (props.amount != null) {\n this.setAmount(props.amount);\n }\n\n if (props.metadata != null) {\n this.setMetadata(props.metadata);\n }\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITransaction[]} transactions\n * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions\n * @param {TransactionId[]} transactionIds\n * @param {AccountId[]} nodeIds\n * @param {HieroProto.proto.ITransactionBody[]} bodies\n * @returns {TokenMintTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const mintToken =\n /** @type {HieroProto.proto.ITokenMintTransactionBody} */ (\n body.tokenMint\n );\n\n return Transaction._fromProtobufTransactions(\n new TokenMintTransaction({\n tokenId:\n mintToken.token != null\n ? TokenId._fromProtobuf(mintToken.token)\n : undefined,\n amount: mintToken.amount != null ? mintToken.amount : undefined,\n metadata:\n mintToken.metadata != null ? mintToken.metadata : undefined,\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {?TokenId}\n */\n get tokenId() {\n return this._tokenId;\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @returns {this}\n */\n setTokenId(tokenId) {\n this._requireNotFrozen();\n this._tokenId =\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId.clone();\n\n return this;\n }\n\n /**\n * @returns {?Long}\n */\n get amount() {\n return this._amount;\n }\n\n /**\n * @param {Long | number | BigNumber | bigint} amount\n * @returns {this}\n */\n setAmount(amount) {\n this._requireNotFrozen();\n this._amount = convertAmountToLong(amount);\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._tokenId != null) {\n this._tokenId.validateChecksum(client);\n }\n }\n\n /**\n * @returns {Uint8Array[]}\n */\n get metadata() {\n return this._metadata;\n }\n\n /**\n * @param {Uint8Array | string} metadata\n * @returns {this}\n */\n addMetadata(metadata) {\n this._requireNotFrozen();\n\n if (typeof metadata === \"string\") {\n console.warn(\n \"Passing a `string` for token metadata is considered a bug, and has been removed. Please provide a `Uint8Array` instead.\",\n );\n }\n\n this._metadata.push(\n typeof metadata === \"string\" ? hex.decode(metadata) : metadata,\n );\n\n return this;\n }\n\n /**\n * @param {Uint8Array[]} metadata\n * @returns {this}\n */\n setMetadata(metadata) {\n this._requireNotFrozen();\n\n for (const data of metadata) {\n if (typeof data === \"string\") {\n console.warn(\n \"Passing a `string` for token metadata is considered a bug, and has been removed. Please provide a `Uint8Array` instead.\",\n );\n break;\n }\n }\n\n this._metadata = metadata.map((data) =>\n typeof data === \"string\" ? hex.decode(data) : data,\n );\n\n return this;\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.ITransaction} request\n * @returns {Promise<HieroProto.proto.ITransactionResponse>}\n */\n _execute(channel, request) {\n return channel.token.mintToken(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"tokenMint\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.ITokenMintTransactionBody}\n */\n _makeTransactionData() {\n return {\n amount: this._amount,\n token: this._tokenId != null ? this._tokenId._toProtobuf() : null,\n metadata: this._metadata,\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp = /** @type {import(\"../Timestamp.js\").default} */ (\n this._transactionIds.current.validStart\n );\n return `TokenMintTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"tokenMint\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n TokenMintTransaction._fromProtobuf,\n);\n"],"names":["TokenMintTransaction","Transaction","constructor","props","super","this","_tokenId","_amount","_metadata","tokenId","setTokenId","amount","setAmount","metadata","setMetadata","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","mintToken","_fromProtobufTransactions","token","TokenId","undefined","_requireNotFrozen","fromString","clone","convertAmountToLong","_validateChecksums","client","validateChecksum","addMetadata","console","warn","push","hex.decode","data","map","_execute","channel","request","_getTransactionDataCase","_makeTransactionData","_toProtobuf","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"iMA+Be,MAAMA,UAA6BC,EAO9C,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,SAAW,KAMhBD,KAAKE,QAAU,KAMfF,KAAKG,UAAY,GAEI,MAAjBL,EAAMM,SACNJ,KAAKK,WAAWP,EAAMM,SAGN,MAAhBN,EAAMQ,QACNN,KAAKO,UAAUT,EAAMQ,QAGH,MAAlBR,EAAMU,UACNR,KAAKS,YAAYX,EAAMU,SAEnC,CAWI,oBAAOE,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,UAEL,OAAOnB,EAAYqB,0BACf,IAAItB,EAAqB,CACrBS,QACuB,MAAnBY,EAAUE,MACJC,EAAQT,cAAcM,EAAUE,YAChCE,EACVd,OAA4B,MAApBU,EAAUV,OAAiBU,EAAUV,YAASc,EACtDZ,SAC0B,MAAtBQ,EAAUR,SAAmBQ,EAAUR,cAAWY,IAE1DT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,WAAIX,GACA,OAAOJ,KAAKC,QACpB,CAMI,UAAAI,CAAWD,GAOP,OANAJ,KAAKqB,oBACLrB,KAAKC,SACkB,iBAAZG,EACDe,EAAQG,WAAWlB,GACnBA,EAAQmB,QAEXvB,IACf,CAKI,UAAIM,GACA,OAAON,KAAKE,OACpB,CAMI,SAAAK,CAAUD,GAIN,OAHAN,KAAKqB,oBACLrB,KAAKE,QAAUsB,EAAoBlB,GAE5BN,IACf,CAKI,kBAAAyB,CAAmBC,GACM,MAAjB1B,KAAKC,UACLD,KAAKC,SAAS0B,iBAAiBD,EAE3C,CAKI,YAAIlB,GACA,OAAOR,KAAKG,SACpB,CAMI,WAAAyB,CAAYpB,GAaR,OAZAR,KAAKqB,oBAEmB,iBAAbb,GACPqB,QAAQC,KACJ,2HAIR9B,KAAKG,UAAU4B,KACS,iBAAbvB,EAAwBwB,EAAWxB,GAAYA,GAGnDR,IACf,CAMI,WAAAS,CAAYD,GACRR,KAAKqB,oBAEL,IAAK,MAAMY,KAAQzB,EACf,GAAoB,iBAATyB,EAAmB,CAC1BJ,QAAQC,KACJ,2HAEJ,KAChB,CAOQ,OAJA9B,KAAKG,UAAYK,EAAS0B,IAAKD,GACX,iBAATA,EAAoBD,EAAWC,GAAQA,GAG3CjC,IACf,CASI,QAAAmC,CAASC,EAASC,GACd,OAAOD,EAAQlB,MAAMF,UAAUqB,EACvC,CAOI,uBAAAC,GACI,MAAO,WACf,CAOI,oBAAAC,GACI,MAAO,CACHjC,OAAQN,KAAKE,QACbgB,MAAwB,MAAjBlB,KAAKC,SAAmBD,KAAKC,SAASuC,cAAgB,KAC7DhC,SAAUR,KAAKG,UAE3B,CAKI,SAAAsC,GAII,MAAO,wBAFHzC,KAAK0C,gBAAgBC,QACxB,WACwCC,YACjD,EAGAC,EAAqBC,IACjB,YAEAnD,EAAqBe"}
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _long = _interopRequireDefault(require("long"));
|
|
8
8
|
var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
|
|
9
9
|
var _TokenId = _interopRequireDefault(require("./TokenId.cjs"));
|
|
10
|
+
var _util = require("../util.cjs");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
13
|
|
|
@@ -41,7 +42,7 @@ class TokenTransfer {
|
|
|
41
42
|
* @param {TokenId | string} props.tokenId
|
|
42
43
|
* @param {AccountId | string} props.accountId
|
|
43
44
|
* @param {number | null} props.expectedDecimals
|
|
44
|
-
* @param {Long | number} props.amount
|
|
45
|
+
* @param {Long | number | BigNumber | bigint} props.amount
|
|
45
46
|
* @param {boolean} props.isApproved
|
|
46
47
|
*/
|
|
47
48
|
constructor(props) {
|
|
@@ -59,7 +60,7 @@ class TokenTransfer {
|
|
|
59
60
|
*/
|
|
60
61
|
this.accountId = props.accountId instanceof _AccountId.default ? props.accountId : _AccountId.default.fromString(props.accountId);
|
|
61
62
|
this.expectedDecimals = props.expectedDecimals;
|
|
62
|
-
this.amount =
|
|
63
|
+
this.amount = (0, _util.convertAmountToLong)(props.amount);
|
|
63
64
|
this.isApproved = props.isApproved;
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -32,14 +32,14 @@ export default class TokenTransfer {
|
|
|
32
32
|
* @param {TokenId | string} props.tokenId
|
|
33
33
|
* @param {AccountId | string} props.accountId
|
|
34
34
|
* @param {number | null} props.expectedDecimals
|
|
35
|
-
* @param {Long | number} props.amount
|
|
35
|
+
* @param {Long | number | BigNumber | bigint} props.amount
|
|
36
36
|
* @param {boolean} props.isApproved
|
|
37
37
|
*/
|
|
38
38
|
constructor(props: {
|
|
39
39
|
tokenId: TokenId | string;
|
|
40
40
|
accountId: AccountId | string;
|
|
41
41
|
expectedDecimals: number | null;
|
|
42
|
-
amount: Long | number;
|
|
42
|
+
amount: Long | number | BigNumber | bigint;
|
|
43
43
|
isApproved: boolean;
|
|
44
44
|
});
|
|
45
45
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"long";import o from"../account/AccountId.js";import e from"./TokenId.js";class
|
|
1
|
+
import t from"long";import o from"../account/AccountId.js";import e from"./TokenId.js";import{convertAmountToLong as n}from"../util.js";class c{constructor(t){this.tokenId=t.tokenId instanceof e?t.tokenId:e.fromString(t.tokenId),this.accountId=t.accountId instanceof o?t.accountId:o.fromString(t.accountId),this.expectedDecimals=t.expectedDecimals,this.amount=n(t.amount),this.isApproved=t.isApproved}static _fromProtobuf(n){const s=[];for(const r of n){const n=e._fromProtobuf(r.token),i=null!=r.expectedDecimals&&Object.hasOwn(r.expectedDecimals,"value")?r.expectedDecimals.value:null;for(const e of null!=r.transfers?r.transfers:[])s.push(new c({tokenId:n,accountId:o._fromProtobuf(e.accountID),expectedDecimals:i||null,amount:null!=e.amount?e.amount:t.ZERO,isApproved:1==e.isApproval}))}return s}_toProtobuf(){return{accountID:this.accountId._toProtobuf(),amount:this.amount,isApproval:this.isApproved}}toJSON(){return{tokenId:this.tokenId.toString(),accountId:this.accountId.toString(),expectedDecimals:this.expectedDecimals,amount:this.amount.toString(),isApproved:this.isApproved}}toString(){return JSON.stringify(this.toJSON())}}export{c as default};
|
|
2
2
|
//# sourceMappingURL=TokenTransfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenTransfer.js","sources":["../../src/token/TokenTransfer.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport AccountId from \"../account/AccountId.js\";\nimport TokenId from \"./TokenId.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * @typedef {object} TokenTransferJSON\n * @property {string} tokenId\n * @property {string} accountId\n * @property {?number} expectedDecimals\n * @property {string} amount\n * @property {boolean} isApproved\n */\n\n/**\n * An account, and the amount that it sends or receives during a cryptocurrency tokentransfer.\n */\nexport default class TokenTransfer {\n /**\n * @internal\n * @param {object} props\n * @param {TokenId | string} props.tokenId\n * @param {AccountId | string} props.accountId\n * @param {number | null} props.expectedDecimals\n * @param {Long | number} props.amount\n * @param {boolean} props.isApproved\n */\n constructor(props) {\n /**\n * The Token ID that sends or receives cryptocurrency.\n *\n * @readonly\n */\n this.tokenId =\n props.tokenId instanceof TokenId\n ? props.tokenId\n : TokenId.fromString(props.tokenId);\n\n /**\n * The Account ID that sends or receives cryptocurrency.\n *\n * @readonly\n */\n this.accountId =\n props.accountId instanceof AccountId\n ? props.accountId\n : AccountId.fromString(props.accountId);\n\n this.expectedDecimals = props.expectedDecimals;\n this.amount =
|
|
1
|
+
{"version":3,"file":"TokenTransfer.js","sources":["../../src/token/TokenTransfer.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Long from \"long\";\nimport AccountId from \"../account/AccountId.js\";\nimport TokenId from \"./TokenId.js\";\nimport { convertAmountToLong } from \"../util.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * @typedef {object} TokenTransferJSON\n * @property {string} tokenId\n * @property {string} accountId\n * @property {?number} expectedDecimals\n * @property {string} amount\n * @property {boolean} isApproved\n */\n\n/**\n * An account, and the amount that it sends or receives during a cryptocurrency tokentransfer.\n */\nexport default class TokenTransfer {\n /**\n * @internal\n * @param {object} props\n * @param {TokenId | string} props.tokenId\n * @param {AccountId | string} props.accountId\n * @param {number | null} props.expectedDecimals\n * @param {Long | number | BigNumber | bigint} props.amount\n * @param {boolean} props.isApproved\n */\n constructor(props) {\n /**\n * The Token ID that sends or receives cryptocurrency.\n *\n * @readonly\n */\n this.tokenId =\n props.tokenId instanceof TokenId\n ? props.tokenId\n : TokenId.fromString(props.tokenId);\n\n /**\n * The Account ID that sends or receives cryptocurrency.\n *\n * @readonly\n */\n this.accountId =\n props.accountId instanceof AccountId\n ? props.accountId\n : AccountId.fromString(props.accountId);\n\n this.expectedDecimals = props.expectedDecimals;\n this.amount = convertAmountToLong(props.amount);\n this.isApproved = props.isApproved;\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITokenTransferList[]} tokenTransfers\n * @returns {TokenTransfer[]}\n */\n static _fromProtobuf(tokenTransfers) {\n const transfers = [];\n\n for (const tokenTransfer of tokenTransfers) {\n const tokenId = TokenId._fromProtobuf(\n /** @type {HieroProto.proto.ITokenID} */ (tokenTransfer.token),\n );\n const expectedDecimals =\n tokenTransfer.expectedDecimals != null\n ? Object.hasOwn(tokenTransfer.expectedDecimals, \"value\")\n ? tokenTransfer.expectedDecimals.value\n : null\n : null;\n\n for (const transfer of tokenTransfer.transfers != null\n ? tokenTransfer.transfers\n : []) {\n transfers.push(\n new TokenTransfer({\n tokenId,\n accountId: AccountId._fromProtobuf(\n /** @type {HieroProto.proto.IAccountID} */ (\n transfer.accountID\n ),\n ),\n expectedDecimals: expectedDecimals || null,\n amount:\n transfer.amount != null\n ? transfer.amount\n : Long.ZERO,\n isApproved: transfer.isApproval == true,\n }),\n );\n }\n }\n\n return transfers;\n }\n\n /**\n * @internal\n * @returns {HieroProto.proto.IAccountAmount}\n */\n _toProtobuf() {\n return {\n accountID: this.accountId._toProtobuf(),\n amount: this.amount,\n isApproval: this.isApproved,\n };\n }\n\n /**\n * @returns {TokenTransferJSON}\n */\n toJSON() {\n return {\n tokenId: this.tokenId.toString(),\n accountId: this.accountId.toString(),\n expectedDecimals: this.expectedDecimals,\n amount: this.amount.toString(),\n isApproved: this.isApproved,\n };\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return JSON.stringify(this.toJSON());\n }\n}\n"],"names":["TokenTransfer","constructor","props","this","tokenId","TokenId","fromString","accountId","AccountId","expectedDecimals","amount","convertAmountToLong","isApproved","_fromProtobuf","tokenTransfers","transfers","tokenTransfer","Object","hasOwn","value","transfer","push","Long","ZERO","isApproval","_toProtobuf","accountID","toJSON","toString","JSON","stringify"],"mappings":"wIA+Be,MAAMA,EAUjB,WAAAC,CAAYC,GAMRC,KAAKC,QACDF,EAAME,mBAAmBC,EACnBH,EAAME,QACNC,EAAQC,WAAWJ,EAAME,SAOnCD,KAAKI,UACDL,EAAMK,qBAAqBC,EACrBN,EAAMK,UACNC,EAAUF,WAAWJ,EAAMK,WAErCJ,KAAKM,iBAAmBP,EAAMO,iBAC9BN,KAAKO,OAASC,EAAoBT,EAAMQ,QACxCP,KAAKS,WAAaV,EAAMU,UAChC,CAOI,oBAAOC,CAAcC,GACjB,MAAMC,EAAY,GAElB,IAAK,MAAMC,KAAiBF,EAAgB,CACxC,MAAMV,EAAUC,EAAQQ,cACsBG,EAAmB,OAE3DP,EACgC,MAAlCO,EAAcP,kBACRQ,OAAOC,OAAOF,EAAcP,iBAAkB,SAC1CO,EAAcP,iBAAiBU,MAEnC,KAEV,IAAK,MAAMC,KAAuC,MAA3BJ,EAAcD,UAC/BC,EAAcD,UACd,GACFA,EAAUM,KACN,IAAIrB,EAAc,CACdI,UACAG,UAAWC,EAAUK,cAEbO,EAChC,WAEwBX,iBAAkBA,GAAoB,KACtCC,OACuB,MAAnBU,EAASV,OACHU,EAASV,OACTY,EAAKC,KACfX,WAAmC,GAAvBQ,EAASI,aAI7C,CAEQ,OAAOT,CACf,CAMI,WAAAU,GACI,MAAO,CACHC,UAAWvB,KAAKI,UAAUkB,cAC1Bf,OAAQP,KAAKO,OACbc,WAAYrB,KAAKS,WAE7B,CAKI,MAAAe,GACI,MAAO,CACHvB,QAASD,KAAKC,QAAQwB,WACtBrB,UAAWJ,KAAKI,UAAUqB,WAC1BnB,iBAAkBN,KAAKM,iBACvBC,OAAQP,KAAKO,OAAOkB,WACpBhB,WAAYT,KAAKS,WAE7B,CAKI,QAAAgB,GACI,OAAOC,KAAKC,UAAU3B,KAAKwB,SACnC"}
|
|
@@ -8,6 +8,7 @@ var _TokenId = _interopRequireDefault(require("./TokenId.cjs"));
|
|
|
8
8
|
var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
|
|
9
9
|
var _Transaction = _interopRequireWildcard(require("../transaction/Transaction.cjs"));
|
|
10
10
|
var _long = _interopRequireDefault(require("long"));
|
|
11
|
+
var _util = require("../util.cjs");
|
|
11
12
|
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); }
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -27,6 +28,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
27
28
|
* @typedef {import("../channel/Channel.js").default} Channel
|
|
28
29
|
* @typedef {import("../client/Client.js").default<*, *>} Client
|
|
29
30
|
* @typedef {import("../transaction/TransactionId.js").default} TransactionId
|
|
31
|
+
* @typedef {import("bignumber.js").default} BigNumber
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -37,7 +39,7 @@ class TokenWipeTransaction extends _Transaction.default {
|
|
|
37
39
|
* @param {object} [props]
|
|
38
40
|
* @param {TokenId | string} [props.tokenId]
|
|
39
41
|
* @param {AccountId | string} [props.accountId]
|
|
40
|
-
* @param {Long | number} [props.amount]
|
|
42
|
+
* @param {Long | number | BigNumber | bigint} [props.amount]
|
|
41
43
|
* @param {(Long | number)[]} [props.serials]
|
|
42
44
|
*/
|
|
43
45
|
constructor(props = {}) {
|
|
@@ -143,12 +145,12 @@ class TokenWipeTransaction extends _Transaction.default {
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
* @param {Long | number} amount
|
|
148
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
147
149
|
* @returns {this}
|
|
148
150
|
*/
|
|
149
151
|
setAmount(amount) {
|
|
150
152
|
this._requireNotFrozen();
|
|
151
|
-
this._amount =
|
|
153
|
+
this._amount = (0, _util.convertAmountToLong)(amount);
|
|
152
154
|
return this;
|
|
153
155
|
}
|
|
154
156
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* @typedef {import("../channel/Channel.js").default} Channel
|
|
13
13
|
* @typedef {import("../client/Client.js").default<*, *>} Client
|
|
14
14
|
* @typedef {import("../transaction/TransactionId.js").default} TransactionId
|
|
15
|
+
* @typedef {import("bignumber.js").default} BigNumber
|
|
15
16
|
*/
|
|
16
17
|
/**
|
|
17
18
|
* Wipe a new Hedera™ crypto-currency token.
|
|
@@ -31,13 +32,13 @@ export default class TokenWipeTransaction extends Transaction {
|
|
|
31
32
|
* @param {object} [props]
|
|
32
33
|
* @param {TokenId | string} [props.tokenId]
|
|
33
34
|
* @param {AccountId | string} [props.accountId]
|
|
34
|
-
* @param {Long | number} [props.amount]
|
|
35
|
+
* @param {Long | number | BigNumber | bigint} [props.amount]
|
|
35
36
|
* @param {(Long | number)[]} [props.serials]
|
|
36
37
|
*/
|
|
37
38
|
constructor(props?: {
|
|
38
39
|
tokenId?: string | TokenId | undefined;
|
|
39
40
|
accountId?: string | AccountId | undefined;
|
|
40
|
-
amount?: number | Long | undefined;
|
|
41
|
+
amount?: number | bigint | Long | import("bignumber.js").BigNumber | undefined;
|
|
41
42
|
serials?: (number | Long)[] | undefined;
|
|
42
43
|
});
|
|
43
44
|
/**
|
|
@@ -83,10 +84,10 @@ export default class TokenWipeTransaction extends Transaction {
|
|
|
83
84
|
*/
|
|
84
85
|
get amount(): Long | null;
|
|
85
86
|
/**
|
|
86
|
-
* @param {Long | number} amount
|
|
87
|
+
* @param {Long | number | BigNumber | bigint} amount
|
|
87
88
|
* @returns {this}
|
|
88
89
|
*/
|
|
89
|
-
setAmount(amount: Long | number): this;
|
|
90
|
+
setAmount(amount: Long | number | BigNumber | bigint): this;
|
|
90
91
|
/**
|
|
91
92
|
* @returns {?Long[]}
|
|
92
93
|
*/
|
|
@@ -117,6 +118,7 @@ export namespace HieroProto {
|
|
|
117
118
|
export type Channel = import("../channel/Channel.js").default;
|
|
118
119
|
export type Client = import("../client/Client.js").default<any, any>;
|
|
119
120
|
export type TransactionId = import("../transaction/TransactionId.js").default;
|
|
121
|
+
export type BigNumber = import("bignumber.js").default;
|
|
120
122
|
import Transaction from "../transaction/Transaction.js";
|
|
121
123
|
import TokenId from "./TokenId.js";
|
|
122
124
|
import AccountId from "../account/AccountId.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"./TokenId.js";import o from"../account/AccountId.js";import n,{TRANSACTION_REGISTRY as e}from"../transaction/Transaction.js";import r from"long";
|
|
1
|
+
import t from"./TokenId.js";import o from"../account/AccountId.js";import n,{TRANSACTION_REGISTRY as e}from"../transaction/Transaction.js";import r from"long";import{convertAmountToLong as s}from"../util.js";class u extends n{constructor(t={}){super(),this._tokenId=null,this._accountId=null,this._serials=[],this._amount=null,null!=t.tokenId&&this.setTokenId(t.tokenId),null!=t.accountId&&this.setAccountId(t.accountId),null!=t.amount&&this.setAmount(t.amount),null!=t.serials&&this.setSerials(t.serials)}static _fromProtobuf(e,r,s,i,a){const c=a[0].tokenWipe;return n._fromProtobufTransactions(new u({tokenId:null!=c.token?t._fromProtobuf(c.token):void 0,accountId:null!=c.account?o._fromProtobuf(c.account):void 0,amount:null!=c.amount?c.amount:void 0,serials:null!=c.serialNumbers?c.serialNumbers:void 0}),e,r,s,i,a)}get tokenId(){return this._tokenId}setTokenId(o){return this._requireNotFrozen(),this._tokenId="string"==typeof o?t.fromString(o):o.clone(),this}get accountId(){return this._accountId}setAccountId(t){return this._requireNotFrozen(),this._accountId="string"==typeof t?o.fromString(t):t.clone(),this}get amount(){return this._amount}setAmount(t){return this._requireNotFrozen(),this._amount=s(t),this}_validateChecksums(t){null!=this._tokenId&&this._tokenId.validateChecksum(t),null!=this._accountId&&this._accountId.validateChecksum(t)}get serials(){return this._serials}setSerials(t){return this._requireNotFrozen(),this._serials=t.map(t=>"number"==typeof t?r.fromNumber(t):t),this}_execute(t,o){return t.token.wipeTokenAccount(o)}_getTransactionDataCase(){return"tokenWipe"}_makeTransactionData(){return{amount:this._amount,token:null!=this._tokenId?this._tokenId._toProtobuf():null,account:null!=this._accountId?this._accountId._toProtobuf():null,serialNumbers:this.serials}}_getLogId(){return`TokenWipeTransaction:${this._transactionIds.current.validStart.toString()}`}}e.set("tokenWipe",u._fromProtobuf);export{u as default};
|
|
2
2
|
//# sourceMappingURL=TokenWipeTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenWipeTransaction.js","sources":["../../src/token/TokenWipeTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport TokenId from \"./TokenId.js\";\nimport AccountId from \"../account/AccountId.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport Long from \"long\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hashgraph/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hashgraph/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionBody} HieroProto.proto.ITransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenWipeAccountTransactionBody} HieroProto.proto.ITokenWipeAccountTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n * @typedef {import(\"../transaction/TransactionId.js\").default} TransactionId\n */\n\n/**\n * Wipe a new Hedera™ crypto-currency token.\n */\nexport default class TokenWipeTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {TokenId | string} [props.tokenId]\n * @param {AccountId | string} [props.accountId]\n * @param {Long | number} [props.amount]\n * @param {(Long | number)[]} [props.serials]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?TokenId}\n */\n this._tokenId = null;\n\n /**\n * @private\n * @type {?AccountId}\n */\n this._accountId = null;\n\n /**\n * @private\n * @type {?Long[]}\n */\n this._serials = [];\n\n /**\n * @private\n * @type {?Long}\n */\n this._amount = null;\n\n if (props.tokenId != null) {\n this.setTokenId(props.tokenId);\n }\n\n if (props.accountId != null) {\n this.setAccountId(props.accountId);\n }\n\n if (props.amount != null) {\n this.setAmount(props.amount);\n }\n\n if (props.serials != null) {\n this.setSerials(props.serials);\n }\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITransaction[]} transactions\n * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions\n * @param {TransactionId[]} transactionIds\n * @param {AccountId[]} nodeIds\n * @param {HieroProto.proto.ITransactionBody[]} bodies\n * @returns {TokenWipeTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const wipeToken =\n /** @type {HieroProto.proto.ITokenWipeAccountTransactionBody} */ (\n body.tokenWipe\n );\n\n return Transaction._fromProtobufTransactions(\n new TokenWipeTransaction({\n tokenId:\n wipeToken.token != null\n ? TokenId._fromProtobuf(wipeToken.token)\n : undefined,\n accountId:\n wipeToken.account != null\n ? AccountId._fromProtobuf(wipeToken.account)\n : undefined,\n amount: wipeToken.amount != null ? wipeToken.amount : undefined,\n serials:\n wipeToken.serialNumbers != null\n ? wipeToken.serialNumbers\n : undefined,\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {?TokenId}\n */\n get tokenId() {\n return this._tokenId;\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @returns {this}\n */\n setTokenId(tokenId) {\n this._requireNotFrozen();\n this._tokenId =\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId.clone();\n\n return this;\n }\n\n /**\n * @returns {?AccountId}\n */\n get accountId() {\n return this._accountId;\n }\n\n /**\n * @param {AccountId | string} accountId\n * @returns {this}\n */\n setAccountId(accountId) {\n this._requireNotFrozen();\n this._accountId =\n typeof accountId === \"string\"\n ? AccountId.fromString(accountId)\n : accountId.clone();\n\n return this;\n }\n\n /**\n * @returns {?Long}\n */\n get amount() {\n return this._amount;\n }\n\n /**\n * @param {Long | number} amount\n * @returns {this}\n */\n setAmount(amount) {\n this._requireNotFrozen();\n this._amount = amount instanceof Long ? amount : Long.fromValue(amount);\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._tokenId != null) {\n this._tokenId.validateChecksum(client);\n }\n\n if (this._accountId != null) {\n this._accountId.validateChecksum(client);\n }\n }\n\n /**\n * @returns {?Long[]}\n */\n get serials() {\n return this._serials;\n }\n\n /**\n * @param {(Long | number)[]} serials\n * @returns {this}\n */\n setSerials(serials) {\n this._requireNotFrozen();\n this._serials = serials.map((serial) =>\n typeof serial === \"number\" ? Long.fromNumber(serial) : serial,\n );\n\n return this;\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.ITransaction} request\n * @returns {Promise<HieroProto.proto.ITransactionResponse>}\n */\n _execute(channel, request) {\n return channel.token.wipeTokenAccount(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"tokenWipe\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.ITokenWipeAccountTransactionBody}\n */\n _makeTransactionData() {\n return {\n amount: this._amount,\n token: this._tokenId != null ? this._tokenId._toProtobuf() : null,\n account:\n this._accountId != null ? this._accountId._toProtobuf() : null,\n serialNumbers: this.serials,\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp = /** @type {import(\"../Timestamp.js\").default} */ (\n this._transactionIds.current.validStart\n );\n return `TokenWipeTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"tokenWipe\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n TokenWipeTransaction._fromProtobuf,\n);\n"],"names":["TokenWipeTransaction","Transaction","constructor","props","super","this","_tokenId","_accountId","_serials","_amount","tokenId","setTokenId","accountId","setAccountId","amount","setAmount","serials","setSerials","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","wipeToken","_fromProtobufTransactions","token","TokenId","undefined","account","AccountId","serialNumbers","_requireNotFrozen","fromString","clone","Long","fromValue","_validateChecksums","client","validateChecksum","map","serial","fromNumber","_execute","channel","request","wipeTokenAccount","_getTransactionDataCase","_makeTransactionData","_toProtobuf","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"+JA6Be,MAAMA,UAA6BC,EAQ9C,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,SAAW,KAMhBD,KAAKE,WAAa,KAMlBF,KAAKG,SAAW,GAMhBH,KAAKI,QAAU,KAEM,MAAjBN,EAAMO,SACNL,KAAKM,WAAWR,EAAMO,SAGH,MAAnBP,EAAMS,WACNP,KAAKQ,aAAaV,EAAMS,WAGR,MAAhBT,EAAMW,QACNT,KAAKU,UAAUZ,EAAMW,QAGJ,MAAjBX,EAAMa,SACNX,KAAKY,WAAWd,EAAMa,QAElC,CAWI,oBAAOE,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,UAEL,OAAOtB,EAAYwB,0BACf,IAAIzB,EAAqB,CACrBU,QACuB,MAAnBc,EAAUE,MACJC,EAAQT,cAAcM,EAAUE,YAChCE,EACVhB,UACyB,MAArBY,EAAUK,QACJC,EAAUZ,cAAcM,EAAUK,cAClCD,EACVd,OAA4B,MAApBU,EAAUV,OAAiBU,EAAUV,YAASc,EACtDZ,QAC+B,MAA3BQ,EAAUO,cACJP,EAAUO,mBACVH,IAEdT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,WAAIb,GACA,OAAOL,KAAKC,QACpB,CAMI,UAAAK,CAAWD,GAOP,OANAL,KAAK2B,oBACL3B,KAAKC,SACkB,iBAAZI,EACDiB,EAAQM,WAAWvB,GACnBA,EAAQwB,QAEX7B,IACf,CAKI,aAAIO,GACA,OAAOP,KAAKE,UACpB,CAMI,YAAAM,CAAaD,GAOT,OANAP,KAAK2B,oBACL3B,KAAKE,WACoB,iBAAdK,EACDkB,EAAUG,WAAWrB,GACrBA,EAAUsB,QAEb7B,IACf,CAKI,UAAIS,GACA,OAAOT,KAAKI,OACpB,CAMI,SAAAM,CAAUD,GAIN,OAHAT,KAAK2B,oBACL3B,KAAKI,QAAUK,aAAkBqB,EAAOrB,EAASqB,EAAKC,UAAUtB,GAEzDT,IACf,CAKI,kBAAAgC,CAAmBC,GACM,MAAjBjC,KAAKC,UACLD,KAAKC,SAASiC,iBAAiBD,GAGZ,MAAnBjC,KAAKE,YACLF,KAAKE,WAAWgC,iBAAiBD,EAE7C,CAKI,WAAItB,GACA,OAAOX,KAAKG,QACpB,CAMI,UAAAS,CAAWD,GAMP,OALAX,KAAK2B,oBACL3B,KAAKG,SAAWQ,EAAQwB,IAAKC,GACP,iBAAXA,EAAsBN,EAAKO,WAAWD,GAAUA,GAGpDpC,IACf,CASI,QAAAsC,CAASC,EAASC,GACd,OAAOD,EAAQlB,MAAMoB,iBAAiBD,EAC9C,CAOI,uBAAAE,GACI,MAAO,WACf,CAOI,oBAAAC,GACI,MAAO,CACHlC,OAAQT,KAAKI,QACbiB,MAAwB,MAAjBrB,KAAKC,SAAmBD,KAAKC,SAAS2C,cAAgB,KAC7DpB,QACuB,MAAnBxB,KAAKE,WAAqBF,KAAKE,WAAW0C,cAAgB,KAC9DlB,cAAe1B,KAAKW,QAEhC,CAKI,SAAAkC,GAII,MAAO,wBAFH7C,KAAK8C,gBAAgBC,QACxB,WACwCC,YACjD,EAGAC,EAAqBC,IACjB,YAEAvD,EAAqBkB"}
|
|
1
|
+
{"version":3,"file":"TokenWipeTransaction.js","sources":["../../src/token/TokenWipeTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport TokenId from \"./TokenId.js\";\nimport AccountId from \"../account/AccountId.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport Long from \"long\";\nimport { convertAmountToLong } from \"../util.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hashgraph/proto\").proto.ITransaction} HieroProto.proto.ITransaction\n * @typedef {import(\"@hashgraph/proto\").proto.ISignedTransaction} HieroProto.proto.ISignedTransaction\n * @typedef {import(\"@hashgraph/proto\").proto.TransactionBody} HieroProto.proto.TransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionBody} HieroProto.proto.ITransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITransactionResponse} HieroProto.proto.ITransactionResponse\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenWipeAccountTransactionBody} HieroProto.proto.ITokenWipeAccountTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"../channel/Channel.js\").default} Channel\n * @typedef {import(\"../client/Client.js\").default<*, *>} Client\n * @typedef {import(\"../transaction/TransactionId.js\").default} TransactionId\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * Wipe a new Hedera™ crypto-currency token.\n */\nexport default class TokenWipeTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {TokenId | string} [props.tokenId]\n * @param {AccountId | string} [props.accountId]\n * @param {Long | number | BigNumber | bigint} [props.amount]\n * @param {(Long | number)[]} [props.serials]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?TokenId}\n */\n this._tokenId = null;\n\n /**\n * @private\n * @type {?AccountId}\n */\n this._accountId = null;\n\n /**\n * @private\n * @type {?Long[]}\n */\n this._serials = [];\n\n /**\n * @private\n * @type {?Long}\n */\n this._amount = null;\n\n if (props.tokenId != null) {\n this.setTokenId(props.tokenId);\n }\n\n if (props.accountId != null) {\n this.setAccountId(props.accountId);\n }\n\n if (props.amount != null) {\n this.setAmount(props.amount);\n }\n\n if (props.serials != null) {\n this.setSerials(props.serials);\n }\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITransaction[]} transactions\n * @param {HieroProto.proto.ISignedTransaction[]} signedTransactions\n * @param {TransactionId[]} transactionIds\n * @param {AccountId[]} nodeIds\n * @param {HieroProto.proto.ITransactionBody[]} bodies\n * @returns {TokenWipeTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const wipeToken =\n /** @type {HieroProto.proto.ITokenWipeAccountTransactionBody} */ (\n body.tokenWipe\n );\n\n return Transaction._fromProtobufTransactions(\n new TokenWipeTransaction({\n tokenId:\n wipeToken.token != null\n ? TokenId._fromProtobuf(wipeToken.token)\n : undefined,\n accountId:\n wipeToken.account != null\n ? AccountId._fromProtobuf(wipeToken.account)\n : undefined,\n amount: wipeToken.amount != null ? wipeToken.amount : undefined,\n serials:\n wipeToken.serialNumbers != null\n ? wipeToken.serialNumbers\n : undefined,\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {?TokenId}\n */\n get tokenId() {\n return this._tokenId;\n }\n\n /**\n * @param {TokenId | string} tokenId\n * @returns {this}\n */\n setTokenId(tokenId) {\n this._requireNotFrozen();\n this._tokenId =\n typeof tokenId === \"string\"\n ? TokenId.fromString(tokenId)\n : tokenId.clone();\n\n return this;\n }\n\n /**\n * @returns {?AccountId}\n */\n get accountId() {\n return this._accountId;\n }\n\n /**\n * @param {AccountId | string} accountId\n * @returns {this}\n */\n setAccountId(accountId) {\n this._requireNotFrozen();\n this._accountId =\n typeof accountId === \"string\"\n ? AccountId.fromString(accountId)\n : accountId.clone();\n\n return this;\n }\n\n /**\n * @returns {?Long}\n */\n get amount() {\n return this._amount;\n }\n\n /**\n * @param {Long | number | BigNumber | bigint} amount\n * @returns {this}\n */\n setAmount(amount) {\n this._requireNotFrozen();\n this._amount = convertAmountToLong(amount);\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._tokenId != null) {\n this._tokenId.validateChecksum(client);\n }\n\n if (this._accountId != null) {\n this._accountId.validateChecksum(client);\n }\n }\n\n /**\n * @returns {?Long[]}\n */\n get serials() {\n return this._serials;\n }\n\n /**\n * @param {(Long | number)[]} serials\n * @returns {this}\n */\n setSerials(serials) {\n this._requireNotFrozen();\n this._serials = serials.map((serial) =>\n typeof serial === \"number\" ? Long.fromNumber(serial) : serial,\n );\n\n return this;\n }\n\n /**\n * @override\n * @internal\n * @param {Channel} channel\n * @param {HieroProto.proto.ITransaction} request\n * @returns {Promise<HieroProto.proto.ITransactionResponse>}\n */\n _execute(channel, request) {\n return channel.token.wipeTokenAccount(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"tokenWipe\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.ITokenWipeAccountTransactionBody}\n */\n _makeTransactionData() {\n return {\n amount: this._amount,\n token: this._tokenId != null ? this._tokenId._toProtobuf() : null,\n account:\n this._accountId != null ? this._accountId._toProtobuf() : null,\n serialNumbers: this.serials,\n };\n }\n\n /**\n * @returns {string}\n */\n _getLogId() {\n const timestamp = /** @type {import(\"../Timestamp.js\").default} */ (\n this._transactionIds.current.validStart\n );\n return `TokenWipeTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"tokenWipe\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n TokenWipeTransaction._fromProtobuf,\n);\n"],"names":["TokenWipeTransaction","Transaction","constructor","props","super","this","_tokenId","_accountId","_serials","_amount","tokenId","setTokenId","accountId","setAccountId","amount","setAmount","serials","setSerials","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","wipeToken","_fromProtobufTransactions","token","TokenId","undefined","account","AccountId","serialNumbers","_requireNotFrozen","fromString","clone","convertAmountToLong","_validateChecksums","client","validateChecksum","map","serial","Long","fromNumber","_execute","channel","request","wipeTokenAccount","_getTransactionDataCase","_makeTransactionData","_toProtobuf","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"gNA+Be,MAAMA,UAA6BC,EAQ9C,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,SAAW,KAMhBD,KAAKE,WAAa,KAMlBF,KAAKG,SAAW,GAMhBH,KAAKI,QAAU,KAEM,MAAjBN,EAAMO,SACNL,KAAKM,WAAWR,EAAMO,SAGH,MAAnBP,EAAMS,WACNP,KAAKQ,aAAaV,EAAMS,WAGR,MAAhBT,EAAMW,QACNT,KAAKU,UAAUZ,EAAMW,QAGJ,MAAjBX,EAAMa,SACNX,KAAKY,WAAWd,EAAMa,QAElC,CAWI,oBAAOE,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,UAEL,OAAOtB,EAAYwB,0BACf,IAAIzB,EAAqB,CACrBU,QACuB,MAAnBc,EAAUE,MACJC,EAAQT,cAAcM,EAAUE,YAChCE,EACVhB,UACyB,MAArBY,EAAUK,QACJC,EAAUZ,cAAcM,EAAUK,cAClCD,EACVd,OAA4B,MAApBU,EAAUV,OAAiBU,EAAUV,YAASc,EACtDZ,QAC+B,MAA3BQ,EAAUO,cACJP,EAAUO,mBACVH,IAEdT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,WAAIb,GACA,OAAOL,KAAKC,QACpB,CAMI,UAAAK,CAAWD,GAOP,OANAL,KAAK2B,oBACL3B,KAAKC,SACkB,iBAAZI,EACDiB,EAAQM,WAAWvB,GACnBA,EAAQwB,QAEX7B,IACf,CAKI,aAAIO,GACA,OAAOP,KAAKE,UACpB,CAMI,YAAAM,CAAaD,GAOT,OANAP,KAAK2B,oBACL3B,KAAKE,WACoB,iBAAdK,EACDkB,EAAUG,WAAWrB,GACrBA,EAAUsB,QAEb7B,IACf,CAKI,UAAIS,GACA,OAAOT,KAAKI,OACpB,CAMI,SAAAM,CAAUD,GAIN,OAHAT,KAAK2B,oBACL3B,KAAKI,QAAU0B,EAAoBrB,GAE5BT,IACf,CAKI,kBAAA+B,CAAmBC,GACM,MAAjBhC,KAAKC,UACLD,KAAKC,SAASgC,iBAAiBD,GAGZ,MAAnBhC,KAAKE,YACLF,KAAKE,WAAW+B,iBAAiBD,EAE7C,CAKI,WAAIrB,GACA,OAAOX,KAAKG,QACpB,CAMI,UAAAS,CAAWD,GAMP,OALAX,KAAK2B,oBACL3B,KAAKG,SAAWQ,EAAQuB,IAAKC,GACP,iBAAXA,EAAsBC,EAAKC,WAAWF,GAAUA,GAGpDnC,IACf,CASI,QAAAsC,CAASC,EAASC,GACd,OAAOD,EAAQlB,MAAMoB,iBAAiBD,EAC9C,CAOI,uBAAAE,GACI,MAAO,WACf,CAOI,oBAAAC,GACI,MAAO,CACHlC,OAAQT,KAAKI,QACbiB,MAAwB,MAAjBrB,KAAKC,SAAmBD,KAAKC,SAAS2C,cAAgB,KAC7DpB,QACuB,MAAnBxB,KAAKE,WAAqBF,KAAKE,WAAW0C,cAAgB,KAC9DlB,cAAe1B,KAAKW,QAEhC,CAKI,SAAAkC,GAII,MAAO,wBAFH7C,KAAK8C,gBAAgBC,QACxB,WACwCC,YACjD,EAGAC,EAAqBC,IACjB,YAEAvD,EAAqBkB"}
|
|
@@ -1117,6 +1117,56 @@ class Transaction extends _Executable.default {
|
|
|
1117
1117
|
this._nodeAccountIds.setList(client._network.getNodeAccountIdsForExecute());
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
1120
|
+
/**
|
|
1121
|
+
* Apply maxNodesPerTransaction limit to an already frozen transaction.
|
|
1122
|
+
* This trims the node list to the first N nodes while preserving existing signatures.
|
|
1123
|
+
*
|
|
1124
|
+
* Note: This method assumes the caller has already verified that trimming is needed.
|
|
1125
|
+
*
|
|
1126
|
+
* @private
|
|
1127
|
+
* @param {import("../client/Client.js").default<Channel, *>} client
|
|
1128
|
+
*/
|
|
1129
|
+
_applyMaxNodesPerTransactionLimit(client) {
|
|
1130
|
+
const maxNodes = client.maxNodesPerTransaction;
|
|
1131
|
+
if (maxNodes <= 0 || this._nodeAccountIds.length <= maxNodes) {
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
if (this._logger) {
|
|
1135
|
+
this._logger.debug(`Trimming frozen transaction from ${this._nodeAccountIds.length} nodes to ${maxNodes} nodes based on maxNodesPerTransaction setting`);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// Trim the node account IDs to the first N nodes
|
|
1139
|
+
const trimmedNodeIds = this._nodeAccountIds.list.slice(0, maxNodes);
|
|
1140
|
+
|
|
1141
|
+
// Trim the signed transactions to match the trimmed node list
|
|
1142
|
+
// Each chunk has transactions for all nodes, so we need to trim each chunk
|
|
1143
|
+
const nodeCount = this._nodeAccountIds.length;
|
|
1144
|
+
const chunkCount = this._transactionIds.length;
|
|
1145
|
+
const trimmedSignedTransactions = [];
|
|
1146
|
+
for (let chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++) {
|
|
1147
|
+
const chunkStart = chunkIndex * nodeCount;
|
|
1148
|
+
|
|
1149
|
+
// Add the first maxNodes transactions from this chunk
|
|
1150
|
+
for (let nodeIndex = 0; nodeIndex < maxNodes; nodeIndex++) {
|
|
1151
|
+
const transactionIndex = chunkStart + nodeIndex;
|
|
1152
|
+
if (transactionIndex < this._signedTransactions.length) {
|
|
1153
|
+
trimmedSignedTransactions.push(this._signedTransactions.get(transactionIndex));
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// Clear and rebuild the transactions list since it's derived from signed transactions
|
|
1159
|
+
this._transactions.clear();
|
|
1160
|
+
|
|
1161
|
+
// Update the node account IDs (we need to unlock, update, and relock)
|
|
1162
|
+
this._nodeAccountIds.locked = false;
|
|
1163
|
+
this._nodeAccountIds.setList(trimmedNodeIds);
|
|
1164
|
+
this._nodeAccountIds.locked = true;
|
|
1165
|
+
|
|
1166
|
+
// Update the signed transactions
|
|
1167
|
+
this._signedTransactions.setList(trimmedSignedTransactions);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1120
1170
|
/**
|
|
1121
1171
|
* @description Set the key that will sign the batch of which this Transaction is a part of.
|
|
1122
1172
|
* @param {Key} batchKey
|
|
@@ -1440,6 +1490,10 @@ class Transaction extends _Executable.default {
|
|
|
1440
1490
|
this.freezeWith(client);
|
|
1441
1491
|
}
|
|
1442
1492
|
|
|
1493
|
+
// Apply maxNodesPerTransaction limit to already frozen transaction
|
|
1494
|
+
// This allows changing the node count even after freezing while preserving signatures
|
|
1495
|
+
this._applyMaxNodesPerTransactionLimit(client);
|
|
1496
|
+
|
|
1443
1497
|
// Valid checksums if the option is enabled
|
|
1444
1498
|
if (client.isAutoValidateChecksumsEnabled()) {
|
|
1445
1499
|
this._validateChecksums(client);
|
|
@@ -415,6 +415,16 @@ export default class Transaction extends Executable<HieroProto.proto.ITransactio
|
|
|
415
415
|
* @param {?import("../client/Client.js").default<Channel, *>} client
|
|
416
416
|
*/
|
|
417
417
|
_setNodeAccountIds(client: import("../client/Client.js").default<Channel, any> | null): void;
|
|
418
|
+
/**
|
|
419
|
+
* Apply maxNodesPerTransaction limit to an already frozen transaction.
|
|
420
|
+
* This trims the node list to the first N nodes while preserving existing signatures.
|
|
421
|
+
*
|
|
422
|
+
* Note: This method assumes the caller has already verified that trimming is needed.
|
|
423
|
+
*
|
|
424
|
+
* @private
|
|
425
|
+
* @param {import("../client/Client.js").default<Channel, *>} client
|
|
426
|
+
*/
|
|
427
|
+
private _applyMaxNodesPerTransactionLimit;
|
|
418
428
|
/**
|
|
419
429
|
* @description Set the key that will sign the batch of which this Transaction is a part of.
|
|
420
430
|
* @param {Key} batchKey
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"../Hbar.js";import s from"./TransactionResponse.js";import n from"./TransactionId.js";import i from"./TransactionHashMap.js";import e from"./SignatureMap.js";import o from"./SignatureMapLegacy.js";import r,{ExecutionState as a}from"../Executable.js";import c from"../Status.js";import h from"long";import{digest as u}from"../cryptography/sha384.js";import{encode as d}from"../encoding/hex.js";import*as l from"@hashgraph/proto";import g from"../PrecheckStatusError.js";import _ from"../account/AccountId.js";import f from"../PublicKey.js";import p from"./List.js";import m from"../Timestamp.js";import{compare as y}from"../util.js";import T from"./CustomFeeLimit.js";import b from"../Key.js";import I from"./SignableNodeTransactionBodyBytes.js";const w=h.fromValue(7776e3),S=t.fromTinybars(h.fromString("9223372036854775807")),A=new _(0,0,0),k=1024,P=new Map;class B extends r{constructor(){super(),this._transactions=new p,this._signedTransactions=new p,this._signerPublicKeys=new Set,this._transactionValidDuration=120,this._defaultMaxTransactionFee=new t(2),this._customFeeLimits=[],this._maxTransactionFee=null,this._transactionMemo="",this._transactionIds=new p,this._publicKeys=[],this._transactionSigners=[],this._regenerateTransactionId=null,this._batchKey=null,this._isThrottled=!1}static fromBytes(t){const s=[],i=[],e=[],o=[],r=[],a=[],c=l.proto.TransactionList.decode(t).transactionList;if(0===c.length){const s=l.proto.Transaction.decode(t);0!==s.signedTransactionBytes.length?c.push(s):c.push({signedTransactionBytes:l.proto.SignedTransaction.encode({sigMap:s.sigMap,bodyBytes:s.bodyBytes}).finish()})}for(const t of c){if(null==t.bodyBytes&&null==t.signedTransactionBytes)throw new Error("bodyBytes and signedTransactionBytes are null");if(t.bodyBytes&&0!=t.bodyBytes.length){const s=l.proto.TransactionBody.decode(t.bodyBytes);if(null!=s.transactionID){const t=n._fromProtobuf(s.transactionID);o.includes(t.toString())||(i.push(t),o.push(t.toString()))}if(null!=s.nodeAccountID){const t=_._fromProtobuf(s.nodeAccountID);r.includes(t.toString())||(e.push(t),r.push(t.toString()))}if(null==s.data)throw new Error("(BUG) body.data was not set in the protobuf");a.push(s)}if(t.signedTransactionBytes&&0!=t.signedTransactionBytes.length){const c=l.proto.SignedTransaction.decode(t.signedTransactionBytes);s.push(c);const h=l.proto.TransactionBody.decode(c.bodyBytes);if(null!=h.transactionID){const t=n._fromProtobuf(h.transactionID);o.includes(t.toString())||(i.push(t),o.push(t.toString()))}if(null!=h.nodeAccountID){const t=_._fromProtobuf(h.nodeAccountID);r.includes(t.toString())||(e.push(t),r.push(t.toString()))}if(null==h.data)throw new Error("(BUG) body.data was not set in the protobuf");a.push(h)}}const h=a[0];if(null==h||null==h.data)throw new Error("No transaction found in bytes or failed to decode TransactionBody");const u=P.get(h.data);if(null==u)throw new Error(`(BUG) Transaction.fromBytes() not implemented for type ${h.data}`);return u(c,s,i,e,a)}schedule(){if(this._requireNotFrozen(),1!=F.length)throw new Error("ScheduleCreateTransaction has not been loaded yet");return F[0]()._setScheduledTransaction(this)}async batchify(t,s){return this._requireNotFrozen(),this.setBatchKey(s),await this.signWithOperator(t)}static _fromProtobufTransactions(s,n,i,e,o,r){const a=r[0];for(let t=0;t<e.length;t++)for(let s=0;s<o.length-1;s++)if(!y(r[t*o.length+s],r[t*o.length+s+1],new Set(["nodeAccountID"])))throw new Error("failed to validate transaction bodies");const c=new _(0);for(let t=0;t<o.length;t++)o[t].equals(c)&&o.splice(t--,1);s._transactions.setList(n),s._signedTransactions.setList(i),s._transactionIds.setList(e),s._nodeAccountIds.setList(o),s._transactionValidDuration=null!=a.transactionValidDuration&&null!=a.transactionValidDuration.seconds?h.fromValue(a.transactionValidDuration.seconds).toInt():120,s._maxTransactionFee=null!=a.transactionFee&&a.transactionFee>new h(0,0,!0)?t.fromTinybars(a.transactionFee):null,s._customFeeLimits=null!=a.maxCustomFees?a.maxCustomFees?.map(t=>T._fromProtobuf(t)):[],s._batchKey=null!=a.batchKey?b._fromProtobufKey(a?.batchKey):null,s._transactionMemo=null!=a.memo?a.memo:"";for(let t=0;t<o.length;t++){const e=i[t]||n[t];if(null!=e.sigMap&&null!=e.sigMap.sigPair)for(const t of e.sigMap.sigPair)s._signerPublicKeys.add(d(t.pubKeyPrefix)),s._publicKeys.push(f.fromBytes(t.pubKeyPrefix)),s._transactionSigners.push(null)}return s}setNodeAccountIds(t){return this._requireNotFrozen(),super.setNodeAccountIds(t),this}get transactionValidDuration(){return this._transactionValidDuration}get size(){return this._requireFrozen(),this._makeRequestAsync().then(t=>l.proto.Transaction.encode(t).finish().length)}get bodySize(){const t=this._makeTransactionBody(_.fromString("0.0.0"));return l.proto.TransactionBody.encode(t).finish().length}setTransactionValidDuration(t){return this._requireNotFrozen(),this._transactionValidDuration=t,this}get maxTransactionFee(){return this._maxTransactionFee}setMaxTransactionFee(s){return this._requireNotFrozen(),this._maxTransactionFee=s instanceof t?s:new t(s),this}get regenerateTransactionId(){return this._regenerateTransactionId}setRegenerateTransactionId(t){return this._requireNotFrozen(),this._regenerateTransactionId=t,this}get transactionMemo(){return this._transactionMemo}setTransactionMemo(t){return this._requireNotFrozen(),this._transactionMemo=t,this}get transactionId(){return this._transactionIds.isEmpty?null:(this._transactionIds.setLocked(),this._transactionIds.current)}setTransactionId(t){return this._requireNotFrozen(),this._transactionIds.setList([t]).setLocked(),this}getRequiredChunks(){return 1}get bodySizeAllChunks(){const t=[];for(let s=0;s<this.getRequiredChunks();s++)this._transactionIds.index=s,t.push(this.bodySize);return this._transactionIds.index=0,t}sign(t){return this.signWith(t.publicKey,s=>Promise.resolve(t.sign(s)))}async signWith(t,s){this._signOnDemand||this._requireFrozen();const n=t.toBytesRaw(),i=d(n);if(this._signerPublicKeys.has(i))return this;if(this._transactions.clear(),this._signerPublicKeys.add(i),this._publicKeys.push(t),this._transactionSigners.push(s),this._signOnDemand)return this;this._transactionIds.setLocked(),this._nodeAccountIds.setLocked();for(const n of this._signedTransactions.list){const i=n.bodyBytes,e=await s(i);null==n.sigMap&&(n.sigMap={}),null==n.sigMap.sigPair&&(n.sigMap.sigPair=[]),n.sigMap.sigPair.push(t._toProtobufSignature(e))}return this}signWithOperator(t){const s=t._operator;if(null==s)throw new Error("`client` must have an operator to sign with the operator");return this._isFrozen()||this.freezeWith(t),this.signWith(s.publicKey,s.transactionSigner)}_resetTransaction(t){if(!t.operatorAccountId)throw new Error("Client must have an operator account ID");this.logger?.info("Resetting transaction id and resigning");const s=n.generate(t.operatorAccountId);this._transactionIds.clear(),this._signedTransactions.clear(),this._transactionIds.setList([s]),this._isThrottled=!0}addSignature(t,s){if(!(s instanceof e))return this._addSignatureLegacy(t,s);this.isFrozen()||this.freeze();const i=t.toBytesRaw(),o=d(i);if(this._signerPublicKeys.has(o))return this;this._transactions.clear(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._signedTransactions.setLocked();for(let i=0;i<this._signedTransactions.length;i++){const e=this._signedTransactions.get(i);if(null==e.sigMap&&(e.sigMap={}),null==e.sigMap.sigPair&&(e.sigMap.sigPair=[]),e.bodyBytes){const{transactionID:i,nodeAccountID:o}=l.proto.TransactionBody.decode(e.bodyBytes);if(!i||!o)throw new Error("Transaction ID or Node Account ID not found in the signed transaction");const r=n._fromProtobuf(i),a=_._fromProtobuf(o),c=s.get(a),h=c?.get(r),u=h?.get(t);if(!u)throw new Error("Signature not found for the transaction and public key");const d=t._toProtobufSignature(u);e.sigMap?.sigPair?.push(d)}}return this._signerPublicKeys.add(o),this._publicKeys.push(t),this._transactionSigners.push(null),this}_addSignatureLegacy(t,s){const n=s instanceof Uint8Array,i=Array.isArray(s);if(this.getRequiredChunks()>1)throw new Error("Add signature is not supported for chunked transactions");if(n&&1!==this._signedTransactions.length)throw new Error("Signature array must match the number of transactions");if(i&&s.length!==this._signedTransactions.length)throw new Error("Signature array must match the number of transactions");this.isFrozen()||this.freeze();const e=t.toBytesRaw(),o=d(e);if(this._signerPublicKeys.has(o))return this;this._transactions.clear(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._signedTransactions.setLocked();const r=n?[s]:s;for(let s=0;s<this._signedTransactions.length;s++){const n=this._signedTransactions.get(s);null==n.sigMap&&(n.sigMap={}),null==n.sigMap.sigPair&&(n.sigMap.sigPair=[]),n.sigMap.sigPair.push(t._toProtobufSignature(r[s]))}return this._signerPublicKeys.add(o),this._publicKeys.push(t),this._transactionSigners.push(null),this}getSignaturesLegacy(){return this._requireFrozen(),this._requireNotSignOnDemand(),this._buildAllTransactions(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),o._fromTransaction(this)}removeSignature(t){this.isFrozen()||this.freeze();const s=t.toBytesRaw(),n=d(s);if(!this._signerPublicKeys.has(n))throw new Error("The public key has not signed this transaction");const i=[];for(const t of this._signedTransactions.list){const s=this._removeSignaturesFromTransaction(t,n);i.push(...s)}return this._signerPublicKeys.delete(n),this._publicKeys=this._publicKeys.filter(s=>!s.equals(t)),this._transactionSigners.pop(),i}removeAllSignatures(){this.isFrozen()||this.freeze();const t=this._collectSignaturesByPublicKey();for(const t of this._signedTransactions.list)t.sigMap&&t.sigMap.sigPair&&(t.sigMap.sigPair=[]);return this._signerPublicKeys.clear(),this._publicKeys=[],this._transactionSigners=[],t}getSignatures(t){return t?this.getSignaturesLegacy():(this._requireFrozen(),this._requireNotSignOnDemand(),this._buildAllTransactions(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),e._fromTransaction(this))}async getSignaturesAsync(){return this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),e._fromTransaction(this)}_setTransactionId(){if(null==this._operatorAccountId&&this._transactionIds.isEmpty)throw new Error("`transactionId` must be set or `client` must be provided with `freezeWith`")}_setNodeAccountIds(t){if(this._nodeAccountIds.isEmpty){if(null==t)throw new Error("`nodeAccountId` must be set or `client` must be provided with `freezeWith`");this._nodeAccountIds.setList(t._network.getNodeAccountIdsForExecute())}}setBatchKey(t){return this._requireNotFrozen(),this._batchKey=t,this}get batchKey(){return this._batchKey}get signableNodeBodyBytesList(){return this._requireFrozen(),this._signedTransactions.list.map(t=>{if(!t.bodyBytes)throw new Error("Missing bodyBytes in signed transaction.");const s=l.proto.TransactionBody.decode(t.bodyBytes);if(!s.nodeAccountID)throw new Error("Missing nodeAccountID in transaction body.");const i=_._fromProtobuf(s.nodeAccountID);if(!s.transactionID)throw new Error("Missing transactionID in transaction body.");const e=n._fromProtobuf(s.transactionID);return new I(i,e,t.bodyBytes)})}_buildSignedTransactions(){this._signedTransactions.locked||this._signedTransactions.setList(this._nodeAccountIds.list.map(t=>this._makeSignedTransaction(t)))}_buildIncompleteTransactions(){0==this._nodeAccountIds.length?this._transactions.setList([this._makeSignedTransaction(null)]):this._transactions.setList(this._nodeAccountIds.list.map(t=>this._makeSignedTransaction(t)))}freeze(){return this.freezeWith(null)}_freezeWithAccountId(t){null==this._operatorAccountId&&(this._operatorAccountId=t)}freezeWith(t){if(this._signOnDemand=null!=t&&t.signOnDemand,this._operator=null!=t?t._operator:null,this._freezeWithAccountId(null!=t?t.operatorAccountId:null),this._maxTransactionFee=null==this._maxTransactionFee?null!=t&&null!=t.defaultMaxTransactionFee?t.defaultMaxTransactionFee:this._defaultMaxTransactionFee:this._maxTransactionFee,this._regenerateTransactionId=null!=t&&null==this._regenerateTransactionId?t.defaultRegenerateTransactionId:this._regenerateTransactionId,this.batchKey?this._nodeAccountIds.setList([A]):this._setNodeAccountIds(t),this._setTransactionId(),null!=t)for(const s of this._transactionIds.list)null!=s.accountId&&s.accountId.validateChecksum(t);return this._buildNewTransactionIdList(),this._signOnDemand||this._buildSignedTransactions(),this}async signWithSigner(t){return await t.signTransaction(this),this}async freezeWithSigner(t){return await t.populateTransaction(this),this.freeze(),this}toBytes(){return this._requireNotSignOnDemand(),this._isFrozen()?(this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._buildAllTransactions()):this._buildIncompleteTransactions(),l.proto.TransactionList.encode({transactionList:this._transactions.list}).finish()}async toBytesAsync(){return this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),l.proto.TransactionList.encode({transactionList:this._transactions.list}).finish()}async getTransactionHash(){return this._requireFrozen(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),u(this._transactions.get(0).signedTransactionBytes)}async getTransactionHashPerNode(){return this._requireFrozen(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),await i._fromTransaction(this)}isFrozen(){return this._signedTransactions.length>0}_getTransactionId(){const t=this.transactionId;if(null==t)throw new Error("transaction must have been frozen before getting the transaction ID, try calling `freeze`");return t}_validateChecksums(t){}async _beforeExecute(t){this.transactionNodeIds=Object.values(t.network).map(t=>t.toString()),this._logger&&this._logger.info(`Network used: ${t._network.networkName}`),this._isFrozen()||this.freezeWith(t),t.isAutoValidateChecksumsEnabled()&&this._validateChecksums(t),null!=this._operator&&null!=this._operator||(this._operator=null!=t?t._operator:null),null!=this._operatorAccountId&&null!=this._operatorAccountId||(this._operatorAccountId=null!=t&&null!=t._operator?t._operator.accountId:null),null!=this._operator&&await this.signWith(this._operator.publicKey,this._operator.transactionSigner)}async _makeRequestAsync(){const t=this._transactionIds.index*this._nodeAccountIds.length+this._nodeAccountIds.index;return this._signOnDemand||this._isThrottled?await this._buildTransactionAsync():(this._buildTransaction(t),this._transactions.get(t))}async _signTransaction(){const t=this._makeSignedTransaction(this._nodeAccountIds.next),s=t.bodyBytes;for(let n=0;n<this._publicKeys.length;n++){const i=this._publicKeys[n],e=this._transactionSigners[n];if(null==e)continue;const o=await e(s);null==t.sigMap&&(t.sigMap={}),null==t.sigMap.sigPair&&(t.sigMap.sigPair=[]),t.sigMap.sigPair.push(i._toProtobufSignature(o))}return t}_buildNewTransactionIdList(){if(this._transactionIds.locked||null==this._operatorAccountId)return;const t=n.withValidStart(this._operatorAccountId,m.generate());this._transactionIds.set(this._transactionIds.index,t)}_buildAllTransactions(){for(let t=0;t<this._signedTransactions.length;t++)this._buildTransaction(t)}async _buildAllTransactionsAsync(){if(this._signOnDemand){if(this._buildSignedTransactions(),!this._transactions.locked)for(let t=0;t<this._signedTransactions.length;t++)this._transactions.push(await this._buildTransactionAsync())}else this._buildAllTransactions()}_buildTransaction(t){if(this._transactions.length<t)for(let s=this._transactions.length;s<t;s++)this._transactions.push(null);null!=this._transactions.list[t]&&this._transactions.set(t,{signedTransactionBytes:l.proto.SignedTransaction.encode(this._signedTransactions.get(t)).finish()}),this._transactions.setIfAbsent(t,()=>({signedTransactionBytes:l.proto.SignedTransaction.encode(this._signedTransactions.get(t)).finish()}))}async _buildTransactionAsync(){return{signedTransactionBytes:l.proto.SignedTransaction.encode(await this._signTransaction()).finish()}}_shouldRetry(t,s){const{nodeTransactionPrecheckCode:n}=s,i=c._fromCode(null!=n?n:l.proto.ResponseCodeEnum.OK);switch(this._logger&&(this._logger.debug(`[${this._getLogId()}] received status ${i.toString()}`),this._logger.info(`SDK Transaction Status Response: ${i.toString()}`)),i){case c.Busy:case c.Unknown:case c.PlatformTransactionNotCreated:case c.PlatformNotActive:return[i,a.Retry];case c.Ok:return[i,a.Finished];case c.TransactionExpired:return this._transactionIds.locked||null!=this._regenerateTransactionId&&!this._regenerateTransactionId?[i,a.Error]:(this._buildNewTransactionIdList(),[i,a.Retry]);default:return[i,a.Error]}}_mapStatusError(t,s,n){const{nodeTransactionPrecheckCode:i}=s,e=c._fromCode(null!=i?i:l.proto.ResponseCodeEnum.OK);return this._logger&&this._logger.info(`Transaction Error Info: ${e.toString()}, ${this.transactionId.toString()}`),new g({nodeId:n,status:e,transactionId:this._getTransactionId(),contractFunctionResult:null})}async _mapResponse(t,n,i){const e=await u(i.signedTransactionBytes),o=this._getTransactionId();return this._transactionIds.advance(),this._logger&&this._logger.info(`Transaction Info: ${JSON.stringify(new s({nodeId:n,transactionHash:e,transactionId:o,logger:this._logger}).toJSON())}`),new s({nodeId:n,transactionHash:e,transactionId:o,transaction:this,logger:this._logger})}_makeSignedTransaction(t){const s=this._makeTransactionBody(t);this._logger&&this._logger.info(`Transaction Body: ${JSON.stringify(s)}`);return{sigMap:{sigPair:[]},bodyBytes:l.proto.TransactionBody.encode(s).finish()}}isBatchedAndNotBatchTransaction(){return null!=this.batchKey&&"atomicBatch"!=this._getTransactionDataCase()}_makeTransactionBody(t){return{[this._getTransactionDataCase()]:this._makeTransactionData(),transactionFee:null!=this._maxTransactionFee?this._maxTransactionFee.toTinybars():null,memo:this._transactionMemo,transactionID:null!=this._transactionIds.current?this._transactionIds.current._toProtobuf():null,nodeAccountID:null!=t?t._toProtobuf():null,transactionValidDuration:{seconds:h.fromNumber(this._transactionValidDuration)},maxCustomFees:null!=this._customFeeLimits?this._customFeeLimits.map(t=>t._toProtobuf()):null,batchKey:this.batchKey?._toProtobufKey()}}_getTransactionDataCase(){throw new Error("not implemented")}_getScheduledTransactionBody(){return{memo:this.transactionMemo,transactionFee:null==this._maxTransactionFee?this._defaultMaxTransactionFee.toTinybars():this._maxTransactionFee.toTinybars(),maxCustomFees:null!=this._customFeeLimits?this._customFeeLimits.map(t=>t._toProtobuf()):null,[this._getTransactionDataCase()]:this._makeTransactionData()}}_makeTransactionData(){throw new Error("not implemented")}_isFrozen(){return this._signOnDemand||this._signedTransactions.length>0}_requireNotFrozen(){if(this._isFrozen())throw new Error("transaction is immutable; it has at least one signature or has been explicitly frozen")}_requireNotSignOnDemand(){if(this._signOnDemand)throw new Error("Please use `toBytesAsync()` if `signOnDemand` is enabled")}_requireFrozen(){if(!this._isFrozen())throw new Error("transaction must have been frozen before calculating the hash will be stable, try calling `freeze`")}_requireOneNodeAccountId(){if(1!=this._nodeAccountIds.length)throw"transaction did not have exactly one node ID set"}_requestToBytes(t){return l.proto.Transaction.encode(t).finish()}_responseToBytes(t){return l.proto.TransactionResponse.encode(t).finish()}_removeSignaturesFromTransaction(t,s){const n=[];return t.sigMap&&t.sigMap.sigPair?(t.sigMap.sigPair=t.sigMap.sigPair.filter(t=>{const i=this._shouldRemoveSignature(t,s),e=t.ed25519??t.ECDSASecp256k1;return i&&e&&n.push(e),!i}),n):[]}_shouldRemoveSignature=(t,s)=>d(t?.pubKeyPrefix||new Uint8Array)===s;_collectSignaturesByPublicKey(){const t=new Map,s={};for(const n of this._signedTransactions.list){if(!n.sigMap||!n.sigMap.sigPair)return new Map;for(const i of n.sigMap.sigPair){const n=i.ed25519??i.ECDSASecp256k1;if(!n||!i.pubKeyPrefix)return new Map;const e=d(i.pubKeyPrefix);let o=s[e];o||(o=f.fromString(e),s[e]=o),t.has(o)||t.set(o,[]);const r=t.get(o);r&&r.push(n)}}return t}}const F=[];export{k as CHUNK_SIZE,w as DEFAULT_AUTO_RENEW_PERIOD,S as DEFAULT_RECORD_THRESHOLD,F as SCHEDULE_CREATE_TRANSACTION,P as TRANSACTION_REGISTRY,B as default};
|
|
1
|
+
import t from"../Hbar.js";import s from"./TransactionResponse.js";import n from"./TransactionId.js";import i from"./TransactionHashMap.js";import e from"./SignatureMap.js";import o from"./SignatureMapLegacy.js";import r,{ExecutionState as a}from"../Executable.js";import c from"../Status.js";import h from"long";import{digest as d}from"../cryptography/sha384.js";import{encode as u}from"../encoding/hex.js";import*as l from"@hashgraph/proto";import g from"../PrecheckStatusError.js";import _ from"../account/AccountId.js";import f from"../PublicKey.js";import p from"./List.js";import m from"../Timestamp.js";import{compare as y}from"../util.js";import T from"./CustomFeeLimit.js";import b from"../Key.js";import I from"./SignableNodeTransactionBodyBytes.js";const w=h.fromValue(7776e3),A=t.fromTinybars(h.fromString("9223372036854775807")),S=new _(0,0,0),P=1024,k=new Map;class L extends r{constructor(){super(),this._transactions=new p,this._signedTransactions=new p,this._signerPublicKeys=new Set,this._transactionValidDuration=120,this._defaultMaxTransactionFee=new t(2),this._customFeeLimits=[],this._maxTransactionFee=null,this._transactionMemo="",this._transactionIds=new p,this._publicKeys=[],this._transactionSigners=[],this._regenerateTransactionId=null,this._batchKey=null,this._isThrottled=!1}static fromBytes(t){const s=[],i=[],e=[],o=[],r=[],a=[],c=l.proto.TransactionList.decode(t).transactionList;if(0===c.length){const s=l.proto.Transaction.decode(t);0!==s.signedTransactionBytes.length?c.push(s):c.push({signedTransactionBytes:l.proto.SignedTransaction.encode({sigMap:s.sigMap,bodyBytes:s.bodyBytes}).finish()})}for(const t of c){if(null==t.bodyBytes&&null==t.signedTransactionBytes)throw new Error("bodyBytes and signedTransactionBytes are null");if(t.bodyBytes&&0!=t.bodyBytes.length){const s=l.proto.TransactionBody.decode(t.bodyBytes);if(null!=s.transactionID){const t=n._fromProtobuf(s.transactionID);o.includes(t.toString())||(i.push(t),o.push(t.toString()))}if(null!=s.nodeAccountID){const t=_._fromProtobuf(s.nodeAccountID);r.includes(t.toString())||(e.push(t),r.push(t.toString()))}if(null==s.data)throw new Error("(BUG) body.data was not set in the protobuf");a.push(s)}if(t.signedTransactionBytes&&0!=t.signedTransactionBytes.length){const c=l.proto.SignedTransaction.decode(t.signedTransactionBytes);s.push(c);const h=l.proto.TransactionBody.decode(c.bodyBytes);if(null!=h.transactionID){const t=n._fromProtobuf(h.transactionID);o.includes(t.toString())||(i.push(t),o.push(t.toString()))}if(null!=h.nodeAccountID){const t=_._fromProtobuf(h.nodeAccountID);r.includes(t.toString())||(e.push(t),r.push(t.toString()))}if(null==h.data)throw new Error("(BUG) body.data was not set in the protobuf");a.push(h)}}const h=a[0];if(null==h||null==h.data)throw new Error("No transaction found in bytes or failed to decode TransactionBody");const d=k.get(h.data);if(null==d)throw new Error(`(BUG) Transaction.fromBytes() not implemented for type ${h.data}`);return d(c,s,i,e,a)}schedule(){if(this._requireNotFrozen(),1!=B.length)throw new Error("ScheduleCreateTransaction has not been loaded yet");return B[0]()._setScheduledTransaction(this)}async batchify(t,s){return this._requireNotFrozen(),this.setBatchKey(s),await this.signWithOperator(t)}static _fromProtobufTransactions(s,n,i,e,o,r){const a=r[0];for(let t=0;t<e.length;t++)for(let s=0;s<o.length-1;s++)if(!y(r[t*o.length+s],r[t*o.length+s+1],new Set(["nodeAccountID"])))throw new Error("failed to validate transaction bodies");const c=new _(0);for(let t=0;t<o.length;t++)o[t].equals(c)&&o.splice(t--,1);s._transactions.setList(n),s._signedTransactions.setList(i),s._transactionIds.setList(e),s._nodeAccountIds.setList(o),s._transactionValidDuration=null!=a.transactionValidDuration&&null!=a.transactionValidDuration.seconds?h.fromValue(a.transactionValidDuration.seconds).toInt():120,s._maxTransactionFee=null!=a.transactionFee&&a.transactionFee>new h(0,0,!0)?t.fromTinybars(a.transactionFee):null,s._customFeeLimits=null!=a.maxCustomFees?a.maxCustomFees?.map(t=>T._fromProtobuf(t)):[],s._batchKey=null!=a.batchKey?b._fromProtobufKey(a?.batchKey):null,s._transactionMemo=null!=a.memo?a.memo:"";for(let t=0;t<o.length;t++){const e=i[t]||n[t];if(null!=e.sigMap&&null!=e.sigMap.sigPair)for(const t of e.sigMap.sigPair)s._signerPublicKeys.add(u(t.pubKeyPrefix)),s._publicKeys.push(f.fromBytes(t.pubKeyPrefix)),s._transactionSigners.push(null)}return s}setNodeAccountIds(t){return this._requireNotFrozen(),super.setNodeAccountIds(t),this}get transactionValidDuration(){return this._transactionValidDuration}get size(){return this._requireFrozen(),this._makeRequestAsync().then(t=>l.proto.Transaction.encode(t).finish().length)}get bodySize(){const t=this._makeTransactionBody(_.fromString("0.0.0"));return l.proto.TransactionBody.encode(t).finish().length}setTransactionValidDuration(t){return this._requireNotFrozen(),this._transactionValidDuration=t,this}get maxTransactionFee(){return this._maxTransactionFee}setMaxTransactionFee(s){return this._requireNotFrozen(),this._maxTransactionFee=s instanceof t?s:new t(s),this}get regenerateTransactionId(){return this._regenerateTransactionId}setRegenerateTransactionId(t){return this._requireNotFrozen(),this._regenerateTransactionId=t,this}get transactionMemo(){return this._transactionMemo}setTransactionMemo(t){return this._requireNotFrozen(),this._transactionMemo=t,this}get transactionId(){return this._transactionIds.isEmpty?null:(this._transactionIds.setLocked(),this._transactionIds.current)}setTransactionId(t){return this._requireNotFrozen(),this._transactionIds.setList([t]).setLocked(),this}getRequiredChunks(){return 1}get bodySizeAllChunks(){const t=[];for(let s=0;s<this.getRequiredChunks();s++)this._transactionIds.index=s,t.push(this.bodySize);return this._transactionIds.index=0,t}sign(t){return this.signWith(t.publicKey,s=>Promise.resolve(t.sign(s)))}async signWith(t,s){this._signOnDemand||this._requireFrozen();const n=t.toBytesRaw(),i=u(n);if(this._signerPublicKeys.has(i))return this;if(this._transactions.clear(),this._signerPublicKeys.add(i),this._publicKeys.push(t),this._transactionSigners.push(s),this._signOnDemand)return this;this._transactionIds.setLocked(),this._nodeAccountIds.setLocked();for(const n of this._signedTransactions.list){const i=n.bodyBytes,e=await s(i);null==n.sigMap&&(n.sigMap={}),null==n.sigMap.sigPair&&(n.sigMap.sigPair=[]),n.sigMap.sigPair.push(t._toProtobufSignature(e))}return this}signWithOperator(t){const s=t._operator;if(null==s)throw new Error("`client` must have an operator to sign with the operator");return this._isFrozen()||this.freezeWith(t),this.signWith(s.publicKey,s.transactionSigner)}_resetTransaction(t){if(!t.operatorAccountId)throw new Error("Client must have an operator account ID");this.logger?.info("Resetting transaction id and resigning");const s=n.generate(t.operatorAccountId);this._transactionIds.clear(),this._signedTransactions.clear(),this._transactionIds.setList([s]),this._isThrottled=!0}addSignature(t,s){if(!(s instanceof e))return this._addSignatureLegacy(t,s);this.isFrozen()||this.freeze();const i=t.toBytesRaw(),o=u(i);if(this._signerPublicKeys.has(o))return this;this._transactions.clear(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._signedTransactions.setLocked();for(let i=0;i<this._signedTransactions.length;i++){const e=this._signedTransactions.get(i);if(null==e.sigMap&&(e.sigMap={}),null==e.sigMap.sigPair&&(e.sigMap.sigPair=[]),e.bodyBytes){const{transactionID:i,nodeAccountID:o}=l.proto.TransactionBody.decode(e.bodyBytes);if(!i||!o)throw new Error("Transaction ID or Node Account ID not found in the signed transaction");const r=n._fromProtobuf(i),a=_._fromProtobuf(o),c=s.get(a),h=c?.get(r),d=h?.get(t);if(!d)throw new Error("Signature not found for the transaction and public key");const u=t._toProtobufSignature(d);e.sigMap?.sigPair?.push(u)}}return this._signerPublicKeys.add(o),this._publicKeys.push(t),this._transactionSigners.push(null),this}_addSignatureLegacy(t,s){const n=s instanceof Uint8Array,i=Array.isArray(s);if(this.getRequiredChunks()>1)throw new Error("Add signature is not supported for chunked transactions");if(n&&1!==this._signedTransactions.length)throw new Error("Signature array must match the number of transactions");if(i&&s.length!==this._signedTransactions.length)throw new Error("Signature array must match the number of transactions");this.isFrozen()||this.freeze();const e=t.toBytesRaw(),o=u(e);if(this._signerPublicKeys.has(o))return this;this._transactions.clear(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._signedTransactions.setLocked();const r=n?[s]:s;for(let s=0;s<this._signedTransactions.length;s++){const n=this._signedTransactions.get(s);null==n.sigMap&&(n.sigMap={}),null==n.sigMap.sigPair&&(n.sigMap.sigPair=[]),n.sigMap.sigPair.push(t._toProtobufSignature(r[s]))}return this._signerPublicKeys.add(o),this._publicKeys.push(t),this._transactionSigners.push(null),this}getSignaturesLegacy(){return this._requireFrozen(),this._requireNotSignOnDemand(),this._buildAllTransactions(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),o._fromTransaction(this)}removeSignature(t){this.isFrozen()||this.freeze();const s=t.toBytesRaw(),n=u(s);if(!this._signerPublicKeys.has(n))throw new Error("The public key has not signed this transaction");const i=[];for(const t of this._signedTransactions.list){const s=this._removeSignaturesFromTransaction(t,n);i.push(...s)}return this._signerPublicKeys.delete(n),this._publicKeys=this._publicKeys.filter(s=>!s.equals(t)),this._transactionSigners.pop(),i}removeAllSignatures(){this.isFrozen()||this.freeze();const t=this._collectSignaturesByPublicKey();for(const t of this._signedTransactions.list)t.sigMap&&t.sigMap.sigPair&&(t.sigMap.sigPair=[]);return this._signerPublicKeys.clear(),this._publicKeys=[],this._transactionSigners=[],t}getSignatures(t){return t?this.getSignaturesLegacy():(this._requireFrozen(),this._requireNotSignOnDemand(),this._buildAllTransactions(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),e._fromTransaction(this))}async getSignaturesAsync(){return this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),e._fromTransaction(this)}_setTransactionId(){if(null==this._operatorAccountId&&this._transactionIds.isEmpty)throw new Error("`transactionId` must be set or `client` must be provided with `freezeWith`")}_setNodeAccountIds(t){if(this._nodeAccountIds.isEmpty){if(null==t)throw new Error("`nodeAccountId` must be set or `client` must be provided with `freezeWith`");this._nodeAccountIds.setList(t._network.getNodeAccountIdsForExecute())}}_applyMaxNodesPerTransactionLimit(t){const s=t.maxNodesPerTransaction;if(s<=0||this._nodeAccountIds.length<=s)return;this._logger&&this._logger.debug(`Trimming frozen transaction from ${this._nodeAccountIds.length} nodes to ${s} nodes based on maxNodesPerTransaction setting`);const n=this._nodeAccountIds.list.slice(0,s),i=this._nodeAccountIds.length,e=this._transactionIds.length,o=[];for(let t=0;t<e;t++){const n=t*i;for(let t=0;t<s;t++){const s=n+t;s<this._signedTransactions.length&&o.push(this._signedTransactions.get(s))}}this._transactions.clear(),this._nodeAccountIds.locked=!1,this._nodeAccountIds.setList(n),this._nodeAccountIds.locked=!0,this._signedTransactions.setList(o)}setBatchKey(t){return this._requireNotFrozen(),this._batchKey=t,this}get batchKey(){return this._batchKey}get signableNodeBodyBytesList(){return this._requireFrozen(),this._signedTransactions.list.map(t=>{if(!t.bodyBytes)throw new Error("Missing bodyBytes in signed transaction.");const s=l.proto.TransactionBody.decode(t.bodyBytes);if(!s.nodeAccountID)throw new Error("Missing nodeAccountID in transaction body.");const i=_._fromProtobuf(s.nodeAccountID);if(!s.transactionID)throw new Error("Missing transactionID in transaction body.");const e=n._fromProtobuf(s.transactionID);return new I(i,e,t.bodyBytes)})}_buildSignedTransactions(){this._signedTransactions.locked||this._signedTransactions.setList(this._nodeAccountIds.list.map(t=>this._makeSignedTransaction(t)))}_buildIncompleteTransactions(){0==this._nodeAccountIds.length?this._transactions.setList([this._makeSignedTransaction(null)]):this._transactions.setList(this._nodeAccountIds.list.map(t=>this._makeSignedTransaction(t)))}freeze(){return this.freezeWith(null)}_freezeWithAccountId(t){null==this._operatorAccountId&&(this._operatorAccountId=t)}freezeWith(t){if(this._signOnDemand=null!=t&&t.signOnDemand,this._operator=null!=t?t._operator:null,this._freezeWithAccountId(null!=t?t.operatorAccountId:null),this._maxTransactionFee=null==this._maxTransactionFee?null!=t&&null!=t.defaultMaxTransactionFee?t.defaultMaxTransactionFee:this._defaultMaxTransactionFee:this._maxTransactionFee,this._regenerateTransactionId=null!=t&&null==this._regenerateTransactionId?t.defaultRegenerateTransactionId:this._regenerateTransactionId,this.batchKey?this._nodeAccountIds.setList([S]):this._setNodeAccountIds(t),this._setTransactionId(),null!=t)for(const s of this._transactionIds.list)null!=s.accountId&&s.accountId.validateChecksum(t);return this._buildNewTransactionIdList(),this._signOnDemand||this._buildSignedTransactions(),this}async signWithSigner(t){return await t.signTransaction(this),this}async freezeWithSigner(t){return await t.populateTransaction(this),this.freeze(),this}toBytes(){return this._requireNotSignOnDemand(),this._isFrozen()?(this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),this._buildAllTransactions()):this._buildIncompleteTransactions(),l.proto.TransactionList.encode({transactionList:this._transactions.list}).finish()}async toBytesAsync(){return this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),l.proto.TransactionList.encode({transactionList:this._transactions.list}).finish()}async getTransactionHash(){return this._requireFrozen(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),this._transactions.setLocked(),this._signedTransactions.setLocked(),d(this._transactions.get(0).signedTransactionBytes)}async getTransactionHashPerNode(){return this._requireFrozen(),this._transactionIds.setLocked(),this._nodeAccountIds.setLocked(),await this._buildAllTransactionsAsync(),await i._fromTransaction(this)}isFrozen(){return this._signedTransactions.length>0}_getTransactionId(){const t=this.transactionId;if(null==t)throw new Error("transaction must have been frozen before getting the transaction ID, try calling `freeze`");return t}_validateChecksums(t){}async _beforeExecute(t){this.transactionNodeIds=Object.values(t.network).map(t=>t.toString()),this._logger&&this._logger.info(`Network used: ${t._network.networkName}`),this._isFrozen()||this.freezeWith(t),this._applyMaxNodesPerTransactionLimit(t),t.isAutoValidateChecksumsEnabled()&&this._validateChecksums(t),null!=this._operator&&null!=this._operator||(this._operator=null!=t?t._operator:null),null!=this._operatorAccountId&&null!=this._operatorAccountId||(this._operatorAccountId=null!=t&&null!=t._operator?t._operator.accountId:null),null!=this._operator&&await this.signWith(this._operator.publicKey,this._operator.transactionSigner)}async _makeRequestAsync(){const t=this._transactionIds.index*this._nodeAccountIds.length+this._nodeAccountIds.index;return this._signOnDemand||this._isThrottled?await this._buildTransactionAsync():(this._buildTransaction(t),this._transactions.get(t))}async _signTransaction(){const t=this._makeSignedTransaction(this._nodeAccountIds.next),s=t.bodyBytes;for(let n=0;n<this._publicKeys.length;n++){const i=this._publicKeys[n],e=this._transactionSigners[n];if(null==e)continue;const o=await e(s);null==t.sigMap&&(t.sigMap={}),null==t.sigMap.sigPair&&(t.sigMap.sigPair=[]),t.sigMap.sigPair.push(i._toProtobufSignature(o))}return t}_buildNewTransactionIdList(){if(this._transactionIds.locked||null==this._operatorAccountId)return;const t=n.withValidStart(this._operatorAccountId,m.generate());this._transactionIds.set(this._transactionIds.index,t)}_buildAllTransactions(){for(let t=0;t<this._signedTransactions.length;t++)this._buildTransaction(t)}async _buildAllTransactionsAsync(){if(this._signOnDemand){if(this._buildSignedTransactions(),!this._transactions.locked)for(let t=0;t<this._signedTransactions.length;t++)this._transactions.push(await this._buildTransactionAsync())}else this._buildAllTransactions()}_buildTransaction(t){if(this._transactions.length<t)for(let s=this._transactions.length;s<t;s++)this._transactions.push(null);null!=this._transactions.list[t]&&this._transactions.set(t,{signedTransactionBytes:l.proto.SignedTransaction.encode(this._signedTransactions.get(t)).finish()}),this._transactions.setIfAbsent(t,()=>({signedTransactionBytes:l.proto.SignedTransaction.encode(this._signedTransactions.get(t)).finish()}))}async _buildTransactionAsync(){return{signedTransactionBytes:l.proto.SignedTransaction.encode(await this._signTransaction()).finish()}}_shouldRetry(t,s){const{nodeTransactionPrecheckCode:n}=s,i=c._fromCode(null!=n?n:l.proto.ResponseCodeEnum.OK);switch(this._logger&&(this._logger.debug(`[${this._getLogId()}] received status ${i.toString()}`),this._logger.info(`SDK Transaction Status Response: ${i.toString()}`)),i){case c.Busy:case c.Unknown:case c.PlatformTransactionNotCreated:case c.PlatformNotActive:return[i,a.Retry];case c.Ok:return[i,a.Finished];case c.TransactionExpired:return this._transactionIds.locked||null!=this._regenerateTransactionId&&!this._regenerateTransactionId?[i,a.Error]:(this._buildNewTransactionIdList(),[i,a.Retry]);default:return[i,a.Error]}}_mapStatusError(t,s,n){const{nodeTransactionPrecheckCode:i}=s,e=c._fromCode(null!=i?i:l.proto.ResponseCodeEnum.OK);return this._logger&&this._logger.info(`Transaction Error Info: ${e.toString()}, ${this.transactionId.toString()}`),new g({nodeId:n,status:e,transactionId:this._getTransactionId(),contractFunctionResult:null})}async _mapResponse(t,n,i){const e=await d(i.signedTransactionBytes),o=this._getTransactionId();return this._transactionIds.advance(),this._logger&&this._logger.info(`Transaction Info: ${JSON.stringify(new s({nodeId:n,transactionHash:e,transactionId:o,logger:this._logger}).toJSON())}`),new s({nodeId:n,transactionHash:e,transactionId:o,transaction:this,logger:this._logger})}_makeSignedTransaction(t){const s=this._makeTransactionBody(t);this._logger&&this._logger.info(`Transaction Body: ${JSON.stringify(s)}`);return{sigMap:{sigPair:[]},bodyBytes:l.proto.TransactionBody.encode(s).finish()}}isBatchedAndNotBatchTransaction(){return null!=this.batchKey&&"atomicBatch"!=this._getTransactionDataCase()}_makeTransactionBody(t){return{[this._getTransactionDataCase()]:this._makeTransactionData(),transactionFee:null!=this._maxTransactionFee?this._maxTransactionFee.toTinybars():null,memo:this._transactionMemo,transactionID:null!=this._transactionIds.current?this._transactionIds.current._toProtobuf():null,nodeAccountID:null!=t?t._toProtobuf():null,transactionValidDuration:{seconds:h.fromNumber(this._transactionValidDuration)},maxCustomFees:null!=this._customFeeLimits?this._customFeeLimits.map(t=>t._toProtobuf()):null,batchKey:this.batchKey?._toProtobufKey()}}_getTransactionDataCase(){throw new Error("not implemented")}_getScheduledTransactionBody(){return{memo:this.transactionMemo,transactionFee:null==this._maxTransactionFee?this._defaultMaxTransactionFee.toTinybars():this._maxTransactionFee.toTinybars(),maxCustomFees:null!=this._customFeeLimits?this._customFeeLimits.map(t=>t._toProtobuf()):null,[this._getTransactionDataCase()]:this._makeTransactionData()}}_makeTransactionData(){throw new Error("not implemented")}_isFrozen(){return this._signOnDemand||this._signedTransactions.length>0}_requireNotFrozen(){if(this._isFrozen())throw new Error("transaction is immutable; it has at least one signature or has been explicitly frozen")}_requireNotSignOnDemand(){if(this._signOnDemand)throw new Error("Please use `toBytesAsync()` if `signOnDemand` is enabled")}_requireFrozen(){if(!this._isFrozen())throw new Error("transaction must have been frozen before calculating the hash will be stable, try calling `freeze`")}_requireOneNodeAccountId(){if(1!=this._nodeAccountIds.length)throw"transaction did not have exactly one node ID set"}_requestToBytes(t){return l.proto.Transaction.encode(t).finish()}_responseToBytes(t){return l.proto.TransactionResponse.encode(t).finish()}_removeSignaturesFromTransaction(t,s){const n=[];return t.sigMap&&t.sigMap.sigPair?(t.sigMap.sigPair=t.sigMap.sigPair.filter(t=>{const i=this._shouldRemoveSignature(t,s),e=t.ed25519??t.ECDSASecp256k1;return i&&e&&n.push(e),!i}),n):[]}_shouldRemoveSignature=(t,s)=>u(t?.pubKeyPrefix||new Uint8Array)===s;_collectSignaturesByPublicKey(){const t=new Map,s={};for(const n of this._signedTransactions.list){if(!n.sigMap||!n.sigMap.sigPair)return new Map;for(const i of n.sigMap.sigPair){const n=i.ed25519??i.ECDSASecp256k1;if(!n||!i.pubKeyPrefix)return new Map;const e=u(i.pubKeyPrefix);let o=s[e];o||(o=f.fromString(e),s[e]=o),t.has(o)||t.set(o,[]);const r=t.get(o);r&&r.push(n)}}return t}}const B=[];export{P as CHUNK_SIZE,w as DEFAULT_AUTO_RENEW_PERIOD,A as DEFAULT_RECORD_THRESHOLD,B as SCHEDULE_CREATE_TRANSACTION,k as TRANSACTION_REGISTRY,L as default};
|
|
2
2
|
//# sourceMappingURL=Transaction.js.map
|