@hiero-ledger/sdk 2.71.1 → 2.72.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 +12 -2
- package/dist/umd.min.js +1 -1
- package/lib/contract/ContractExecuteTransaction.cjs +5 -1
- package/lib/contract/ContractExecuteTransaction.js +1 -1
- package/lib/contract/ContractExecuteTransaction.js.map +1 -1
- package/lib/transaction/Transaction.cjs +1 -0
- package/lib/transaction/Transaction.js +1 -1
- package/lib/transaction/Transaction.js.map +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/contract/ContractExecuteTransaction.js +5 -1
- package/src/transaction/Transaction.js +6 -0
|
@@ -159,7 +159,11 @@ class ContractExecuteTransaction extends _Transaction.default {
|
|
|
159
159
|
*/
|
|
160
160
|
setGas(gas) {
|
|
161
161
|
this._requireNotFrozen();
|
|
162
|
-
|
|
162
|
+
const gasLong = gas instanceof _long.default ? gas : _long.default.fromValue(gas);
|
|
163
|
+
if (gasLong.lt(0)) {
|
|
164
|
+
throw new Error("Gas must be greater than 0");
|
|
165
|
+
}
|
|
166
|
+
this._gas = gasLong;
|
|
163
167
|
return this;
|
|
164
168
|
}
|
|
165
169
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"../Hbar.js";import
|
|
1
|
+
import t from"../Hbar.js";import r,{TRANSACTION_REGISTRY as n}from"../transaction/Transaction.js";import a from"./ContractId.js";import o from"./ContractFunctionParameters.js";import s from"long";import e from"../HbarUnit.js";class i extends r{constructor(t={}){super(),this._contractId=null,this._gas=null,this._amount=null,this._functionParameters=null,null!=t.contractId&&this.setContractId(t.contractId),null!=t.gas&&this.setGas(t.gas),null!=t.amount&&this.setPayableAmount(t.amount),null!=t.functionParameters?this.setFunctionParameters(t.functionParameters):null!=t.function&&this.setFunction(t.function.name,t.function.parameters)}static _fromProtobuf(n,o,s,e,u){const c=u[0].contractCall;return r._fromProtobufTransactions(new i({contractId:null!=c.contractID?a._fromProtobuf(c.contractID):void 0,gas:null!=c.gas?c.gas:void 0,amount:null!=c.amount?t.fromTinybars(c.amount):void 0,functionParameters:null!=c.functionParameters?c.functionParameters:void 0}),n,o,s,e,u)}get contractId(){return this._contractId}setContractId(t){return this._requireNotFrozen(),this._contractId="string"==typeof t?a.fromString(t):t.clone(),this}get gas(){return this._gas}setGas(t){this._requireNotFrozen();const r=t instanceof s?t:s.fromValue(t);if(r.lt(0))throw new Error("Gas must be greater than 0");return this._gas=r,this}get payableAmount(){return this._amount}setPayableAmount(r,n=e.Hbar){return this._requireNotFrozen(),this._amount=r instanceof t?r:t.from(r,n),this}get functionParameters(){return this._functionParameters}setFunctionParameters(t){return this._requireNotFrozen(),this._functionParameters=t,this}setFunction(t,r){return this._requireNotFrozen(),this._functionParameters=null!=r?r._build(t):(new o)._build(t),this}_validateChecksums(t){null!=this._contractId&&this._contractId.validateChecksum(t)}_execute(t,r){return t.smartContract.contractCallMethod(r)}_getTransactionDataCase(){return"contractCall"}_makeTransactionData(){return{contractID:null!=this._contractId?this._contractId._toProtobuf():null,gas:this._gas,amount:null!=this._amount?this._amount.toTinybars():null,functionParameters:this._functionParameters}}_getLogId(){return`ContractExecuteTransaction:${this._transactionIds.current.validStart.toString()}`}}n.set("contractCall",i._fromProtobuf);export{i as default};
|
|
2
2
|
//# sourceMappingURL=ContractExecuteTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractExecuteTransaction.js","sources":["../../src/contract/ContractExecuteTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Hbar from \"../Hbar.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport ContractId from \"./ContractId.js\";\nimport ContractFunctionParameters from \"./ContractFunctionParameters.js\";\nimport Long from \"long\";\nimport HbarUnit from \"../HbarUnit.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.IContractCallTransactionBody} HieroProto.proto.IContractCallTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.IContractID} HieroProto.proto.IContractID\n * @typedef {import(\"@hashgraph/proto\").proto.IFileID} HieroProto.proto.IFileID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\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 */\n\n/**\n * @typedef {object} FunctionParameters\n * @property {string} name\n * @property {ContractFunctionParameters} parameters\n */\n\n/**\n * Call a function of a given smart contract, providing function parameter\n * inputs as needed.\n * <p>\n * Resource (\"gas\") charges SHALL include all relevant fees incurred by\n * the contract execution, including any storage required.<br/>\n * The total transaction fee SHALL incorporate all of the \"gas\" actually\n * consumed as well as the standard fees for transaction handling,\n * data transfers, signature verification, etc...\n */\nexport default class ContractExecuteTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {ContractId | string} [props.contractId]\n * @param {number | Long} [props.gas]\n * @param {number | string | Long | BigNumber | Hbar} [props.amount]\n * @param {Uint8Array} [props.functionParameters]\n * @param {FunctionParameters} [props.function]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?ContractId}\n */\n this._contractId = null;\n\n /**\n * @private\n * @type {?Long}\n */\n this._gas = null;\n\n /**\n * @private\n * @type {?Hbar}\n */\n this._amount = null;\n\n /**\n * @private\n * @type {?Uint8Array}\n */\n this._functionParameters = null;\n\n if (props.contractId != null) {\n this.setContractId(props.contractId);\n }\n\n if (props.gas != null) {\n this.setGas(props.gas);\n }\n\n if (props.amount != null) {\n this.setPayableAmount(props.amount);\n }\n\n if (props.functionParameters != null) {\n this.setFunctionParameters(props.functionParameters);\n } else if (props.function != null) {\n this.setFunction(props.function.name, props.function.parameters);\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 {ContractExecuteTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const call =\n /** @type {HieroProto.proto.IContractCallTransactionBody} */ (\n body.contractCall\n );\n\n return Transaction._fromProtobufTransactions(\n new ContractExecuteTransaction({\n contractId:\n call.contractID != null\n ? ContractId._fromProtobuf(\n /** @type {HieroProto.proto.IContractID} */ (\n call.contractID\n ),\n )\n : undefined,\n gas: call.gas != null ? call.gas : undefined,\n amount:\n call.amount != null\n ? Hbar.fromTinybars(call.amount)\n : undefined,\n functionParameters:\n call.functionParameters != null\n ? call.functionParameters\n : undefined,\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {?ContractId}\n */\n get contractId() {\n return this._contractId;\n }\n\n /**\n * Sets the contract ID which is being executed in this transaction.\n *\n * @param {ContractId | string} contractId\n * @returns {ContractExecuteTransaction}\n */\n setContractId(contractId) {\n this._requireNotFrozen();\n this._contractId =\n typeof contractId === \"string\"\n ? ContractId.fromString(contractId)\n : contractId.clone();\n\n return this;\n }\n\n /**\n * @returns {?Long}\n */\n get gas() {\n return this._gas;\n }\n\n /**\n * Sets the amount of gas to use for the call.\n *\n * @param {number | Long} gas\n * @returns {ContractExecuteTransaction}\n */\n setGas(gas) {\n this._requireNotFrozen();\n this._gas = gas instanceof Long ? gas : Long.fromValue(gas);\n\n return this;\n }\n\n /**\n * @returns {?Hbar}\n */\n get payableAmount() {\n return this._amount;\n }\n\n /**\n * Sets the number of hbars to be sent with this function call.\n *\n * @param {number | string | Long | BigNumber | Hbar} amount\n * @param {HbarUnit} unit\n * @returns {ContractExecuteTransaction}\n */\n setPayableAmount(amount, unit = HbarUnit.Hbar) {\n this._requireNotFrozen();\n this._amount =\n amount instanceof Hbar ? amount : Hbar.from(amount, unit);\n\n return this;\n }\n\n /**\n * @returns {?Uint8Array}\n */\n get functionParameters() {\n return this._functionParameters;\n }\n\n /**\n * @param {Uint8Array} functionParameters\n * @returns {this}\n */\n setFunctionParameters(functionParameters) {\n this._requireNotFrozen();\n this._functionParameters = functionParameters;\n\n return this;\n }\n\n /**\n * @param {string} name\n * @param {ContractFunctionParameters} [functionParameters]\n * @returns {this}\n */\n setFunction(name, functionParameters) {\n this._requireNotFrozen();\n this._functionParameters =\n functionParameters != null\n ? functionParameters._build(name)\n : new ContractFunctionParameters()._build(name);\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._contractId != null) {\n this._contractId.validateChecksum(client);\n }\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.smartContract.contractCallMethod(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"contractCall\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.IContractCallTransactionBody}\n */\n _makeTransactionData() {\n return {\n contractID:\n this._contractId != null\n ? this._contractId._toProtobuf()\n : null,\n gas: this._gas,\n amount: this._amount != null ? this._amount.toTinybars() : null,\n functionParameters: this._functionParameters,\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 `ContractExecuteTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"contractCall\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n ContractExecuteTransaction._fromProtobuf,\n);\n"],"names":["ContractExecuteTransaction","Transaction","constructor","props","super","this","_contractId","_gas","_amount","_functionParameters","contractId","setContractId","gas","setGas","amount","setPayableAmount","functionParameters","setFunctionParameters","function","setFunction","name","parameters","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","call","_fromProtobufTransactions","contractID","ContractId","undefined","Hbar","fromTinybars","_requireNotFrozen","fromString","clone","Long","fromValue","payableAmount","unit","HbarUnit","from","_build","ContractFunctionParameters","_validateChecksums","client","validateChecksum","_execute","channel","request","smartContract","contractCallMethod","_getTransactionDataCase","_makeTransactionData","_toProtobuf","toTinybars","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"kOAgDe,MAAMA,UAAmCC,EASpD,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,YAAc,KAMnBD,KAAKE,KAAO,KAMZF,KAAKG,QAAU,KAMfH,KAAKI,oBAAsB,KAEH,MAApBN,EAAMO,YACNL,KAAKM,cAAcR,EAAMO,YAGZ,MAAbP,EAAMS,KACNP,KAAKQ,OAAOV,EAAMS,KAGF,MAAhBT,EAAMW,QACNT,KAAKU,iBAAiBZ,EAAMW,QAGA,MAA5BX,EAAMa,mBACNX,KAAKY,sBAAsBd,EAAMa,oBACR,MAAlBb,EAAMe,UACbb,KAAKc,YAAYhB,EAAMe,SAASE,KAAMjB,EAAMe,SAASG,WAEjE,CAWI,oBAAOC,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,aAEL,OAAO1B,EAAY4B,0BACf,IAAI7B,EAA2B,CAC3BU,WACuB,MAAnBkB,EAAKE,WACCC,EAAWT,cAEHM,EAClC,iBAE0BI,EACVpB,IAAiB,MAAZgB,EAAKhB,IAAcgB,EAAKhB,SAAMoB,EACnClB,OACmB,MAAfc,EAAKd,OACCmB,EAAKC,aAAaN,EAAKd,aACvBkB,EACVhB,mBAC+B,MAA3BY,EAAKZ,mBACCY,EAAKZ,wBACLgB,IAEdT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,cAAIjB,GACA,OAAOL,KAAKC,WACpB,CAQI,aAAAK,CAAcD,GAOV,OANAL,KAAK8B,oBACL9B,KAAKC,YACqB,iBAAfI,EACDqB,EAAWK,WAAW1B,GACtBA,EAAW2B,QAEdhC,IACf,CAKI,OAAIO,GACA,OAAOP,KAAKE,IACpB,CAQI,MAAAM,CAAOD,GAIH,OAHAP,KAAK8B,oBACL9B,KAAKE,KAAOK,aAAe0B,EAAO1B,EAAM0B,EAAKC,UAAU3B,GAEhDP,IACf,CAKI,iBAAImC,GACA,OAAOnC,KAAKG,OACpB,CASI,gBAAAO,CAAiBD,EAAQ2B,EAAOC,EAAST,MAKrC,OAJA5B,KAAK8B,oBACL9B,KAAKG,QACDM,aAAkBmB,EAAOnB,EAASmB,EAAKU,KAAK7B,EAAQ2B,GAEjDpC,IACf,CAKI,sBAAIW,GACA,OAAOX,KAAKI,mBACpB,CAMI,qBAAAQ,CAAsBD,GAIlB,OAHAX,KAAK8B,oBACL9B,KAAKI,oBAAsBO,EAEpBX,IACf,CAOI,WAAAc,CAAYC,EAAMJ,GAOd,OANAX,KAAK8B,oBACL9B,KAAKI,oBACqB,MAAtBO,EACMA,EAAmB4B,OAAOxB,IAC1B,IAAIyB,GAA6BD,OAAOxB,GAE3Cf,IACf,CAKI,kBAAAyC,CAAmBC,GACS,MAApB1C,KAAKC,aACLD,KAAKC,YAAY0C,iBAAiBD,EAE9C,CASI,QAAAE,CAASC,EAASC,GACd,OAAOD,EAAQE,cAAcC,mBAAmBF,EACxD,CAOI,uBAAAG,GACI,MAAO,cACf,CAOI,oBAAAC,GACI,MAAO,CACHzB,WACwB,MAApBzB,KAAKC,YACCD,KAAKC,YAAYkD,cACjB,KACV5C,IAAKP,KAAKE,KACVO,OAAwB,MAAhBT,KAAKG,QAAkBH,KAAKG,QAAQiD,aAAe,KAC3DzC,mBAAoBX,KAAKI,oBAErC,CAKI,SAAAiD,GAII,MAAO,8BAFHrD,KAAKsD,gBAAgBC,QACxB,WAC8CC,YACvD,EAGAC,EAAqBC,IACjB,eAEA/D,EAA2BsB"}
|
|
1
|
+
{"version":3,"file":"ContractExecuteTransaction.js","sources":["../../src/contract/ContractExecuteTransaction.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Hbar from \"../Hbar.js\";\nimport Transaction, {\n TRANSACTION_REGISTRY,\n} from \"../transaction/Transaction.js\";\nimport ContractId from \"./ContractId.js\";\nimport ContractFunctionParameters from \"./ContractFunctionParameters.js\";\nimport Long from \"long\";\nimport HbarUnit from \"../HbarUnit.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.IContractCallTransactionBody} HieroProto.proto.IContractCallTransactionBody\n * @typedef {import(\"@hashgraph/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hashgraph/proto\").proto.IContractID} HieroProto.proto.IContractID\n * @typedef {import(\"@hashgraph/proto\").proto.IFileID} HieroProto.proto.IFileID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\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 */\n\n/**\n * @typedef {object} FunctionParameters\n * @property {string} name\n * @property {ContractFunctionParameters} parameters\n */\n\n/**\n * Call a function of a given smart contract, providing function parameter\n * inputs as needed.\n * <p>\n * Resource (\"gas\") charges SHALL include all relevant fees incurred by\n * the contract execution, including any storage required.<br/>\n * The total transaction fee SHALL incorporate all of the \"gas\" actually\n * consumed as well as the standard fees for transaction handling,\n * data transfers, signature verification, etc...\n */\nexport default class ContractExecuteTransaction extends Transaction {\n /**\n * @param {object} [props]\n * @param {ContractId | string} [props.contractId]\n * @param {number | Long} [props.gas]\n * @param {number | string | Long | BigNumber | Hbar} [props.amount]\n * @param {Uint8Array} [props.functionParameters]\n * @param {FunctionParameters} [props.function]\n */\n constructor(props = {}) {\n super();\n\n /**\n * @private\n * @type {?ContractId}\n */\n this._contractId = null;\n\n /**\n * @private\n * @type {?Long}\n */\n this._gas = null;\n\n /**\n * @private\n * @type {?Hbar}\n */\n this._amount = null;\n\n /**\n * @private\n * @type {?Uint8Array}\n */\n this._functionParameters = null;\n\n if (props.contractId != null) {\n this.setContractId(props.contractId);\n }\n\n if (props.gas != null) {\n this.setGas(props.gas);\n }\n\n if (props.amount != null) {\n this.setPayableAmount(props.amount);\n }\n\n if (props.functionParameters != null) {\n this.setFunctionParameters(props.functionParameters);\n } else if (props.function != null) {\n this.setFunction(props.function.name, props.function.parameters);\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 {ContractExecuteTransaction}\n */\n static _fromProtobuf(\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n ) {\n const body = bodies[0];\n const call =\n /** @type {HieroProto.proto.IContractCallTransactionBody} */ (\n body.contractCall\n );\n\n return Transaction._fromProtobufTransactions(\n new ContractExecuteTransaction({\n contractId:\n call.contractID != null\n ? ContractId._fromProtobuf(\n /** @type {HieroProto.proto.IContractID} */ (\n call.contractID\n ),\n )\n : undefined,\n gas: call.gas != null ? call.gas : undefined,\n amount:\n call.amount != null\n ? Hbar.fromTinybars(call.amount)\n : undefined,\n functionParameters:\n call.functionParameters != null\n ? call.functionParameters\n : undefined,\n }),\n transactions,\n signedTransactions,\n transactionIds,\n nodeIds,\n bodies,\n );\n }\n\n /**\n * @returns {?ContractId}\n */\n get contractId() {\n return this._contractId;\n }\n\n /**\n * Sets the contract ID which is being executed in this transaction.\n *\n * @param {ContractId | string} contractId\n * @returns {ContractExecuteTransaction}\n */\n setContractId(contractId) {\n this._requireNotFrozen();\n this._contractId =\n typeof contractId === \"string\"\n ? ContractId.fromString(contractId)\n : contractId.clone();\n\n return this;\n }\n\n /**\n * @returns {?Long}\n */\n get gas() {\n return this._gas;\n }\n\n /**\n * Sets the amount of gas to use for the call.\n *\n * @param {number | Long} gas\n * @returns {ContractExecuteTransaction}\n */\n setGas(gas) {\n this._requireNotFrozen();\n const gasLong = gas instanceof Long ? gas : Long.fromValue(gas);\n if (gasLong.lt(0)) {\n throw new Error(\"Gas must be greater than 0\");\n }\n this._gas = gasLong;\n\n return this;\n }\n\n /**\n * @returns {?Hbar}\n */\n get payableAmount() {\n return this._amount;\n }\n\n /**\n * Sets the number of hbars to be sent with this function call.\n *\n * @param {number | string | Long | BigNumber | Hbar} amount\n * @param {HbarUnit} unit\n * @returns {ContractExecuteTransaction}\n */\n setPayableAmount(amount, unit = HbarUnit.Hbar) {\n this._requireNotFrozen();\n this._amount =\n amount instanceof Hbar ? amount : Hbar.from(amount, unit);\n\n return this;\n }\n\n /**\n * @returns {?Uint8Array}\n */\n get functionParameters() {\n return this._functionParameters;\n }\n\n /**\n * @param {Uint8Array} functionParameters\n * @returns {this}\n */\n setFunctionParameters(functionParameters) {\n this._requireNotFrozen();\n this._functionParameters = functionParameters;\n\n return this;\n }\n\n /**\n * @param {string} name\n * @param {ContractFunctionParameters} [functionParameters]\n * @returns {this}\n */\n setFunction(name, functionParameters) {\n this._requireNotFrozen();\n this._functionParameters =\n functionParameters != null\n ? functionParameters._build(name)\n : new ContractFunctionParameters()._build(name);\n\n return this;\n }\n\n /**\n * @param {Client} client\n */\n _validateChecksums(client) {\n if (this._contractId != null) {\n this._contractId.validateChecksum(client);\n }\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.smartContract.contractCallMethod(request);\n }\n\n /**\n * @override\n * @protected\n * @returns {NonNullable<HieroProto.proto.TransactionBody[\"data\"]>}\n */\n _getTransactionDataCase() {\n return \"contractCall\";\n }\n\n /**\n * @override\n * @protected\n * @returns {HieroProto.proto.IContractCallTransactionBody}\n */\n _makeTransactionData() {\n return {\n contractID:\n this._contractId != null\n ? this._contractId._toProtobuf()\n : null,\n gas: this._gas,\n amount: this._amount != null ? this._amount.toTinybars() : null,\n functionParameters: this._functionParameters,\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 `ContractExecuteTransaction:${timestamp.toString()}`;\n }\n}\n\nTRANSACTION_REGISTRY.set(\n \"contractCall\",\n // eslint-disable-next-line @typescript-eslint/unbound-method\n ContractExecuteTransaction._fromProtobuf,\n);\n"],"names":["ContractExecuteTransaction","Transaction","constructor","props","super","this","_contractId","_gas","_amount","_functionParameters","contractId","setContractId","gas","setGas","amount","setPayableAmount","functionParameters","setFunctionParameters","function","setFunction","name","parameters","_fromProtobuf","transactions","signedTransactions","transactionIds","nodeIds","bodies","call","_fromProtobufTransactions","contractID","ContractId","undefined","Hbar","fromTinybars","_requireNotFrozen","fromString","clone","gasLong","Long","fromValue","lt","Error","payableAmount","unit","HbarUnit","from","_build","ContractFunctionParameters","_validateChecksums","client","validateChecksum","_execute","channel","request","smartContract","contractCallMethod","_getTransactionDataCase","_makeTransactionData","_toProtobuf","toTinybars","_getLogId","_transactionIds","current","toString","TRANSACTION_REGISTRY","set"],"mappings":"kOAgDe,MAAMA,UAAmCC,EASpD,WAAAC,CAAYC,EAAQ,IAChBC,QAMAC,KAAKC,YAAc,KAMnBD,KAAKE,KAAO,KAMZF,KAAKG,QAAU,KAMfH,KAAKI,oBAAsB,KAEH,MAApBN,EAAMO,YACNL,KAAKM,cAAcR,EAAMO,YAGZ,MAAbP,EAAMS,KACNP,KAAKQ,OAAOV,EAAMS,KAGF,MAAhBT,EAAMW,QACNT,KAAKU,iBAAiBZ,EAAMW,QAGA,MAA5BX,EAAMa,mBACNX,KAAKY,sBAAsBd,EAAMa,oBACR,MAAlBb,EAAMe,UACbb,KAAKc,YAAYhB,EAAMe,SAASE,KAAMjB,EAAMe,SAASG,WAEjE,CAWI,oBAAOC,CACHC,EACAC,EACAC,EACAC,EACAC,GAEA,MACMC,EADOD,EAAO,GAIf,aAEL,OAAO1B,EAAY4B,0BACf,IAAI7B,EAA2B,CAC3BU,WACuB,MAAnBkB,EAAKE,WACCC,EAAWT,cAEHM,EAClC,iBAE0BI,EACVpB,IAAiB,MAAZgB,EAAKhB,IAAcgB,EAAKhB,SAAMoB,EACnClB,OACmB,MAAfc,EAAKd,OACCmB,EAAKC,aAAaN,EAAKd,aACvBkB,EACVhB,mBAC+B,MAA3BY,EAAKZ,mBACCY,EAAKZ,wBACLgB,IAEdT,EACAC,EACAC,EACAC,EACAC,EAEZ,CAKI,cAAIjB,GACA,OAAOL,KAAKC,WACpB,CAQI,aAAAK,CAAcD,GAOV,OANAL,KAAK8B,oBACL9B,KAAKC,YACqB,iBAAfI,EACDqB,EAAWK,WAAW1B,GACtBA,EAAW2B,QAEdhC,IACf,CAKI,OAAIO,GACA,OAAOP,KAAKE,IACpB,CAQI,MAAAM,CAAOD,GACHP,KAAK8B,oBACL,MAAMG,EAAU1B,aAAe2B,EAAO3B,EAAM2B,EAAKC,UAAU5B,GAC3D,GAAI0B,EAAQG,GAAG,GACX,MAAM,IAAIC,MAAM,8BAIpB,OAFArC,KAAKE,KAAO+B,EAELjC,IACf,CAKI,iBAAIsC,GACA,OAAOtC,KAAKG,OACpB,CASI,gBAAAO,CAAiBD,EAAQ8B,EAAOC,EAASZ,MAKrC,OAJA5B,KAAK8B,oBACL9B,KAAKG,QACDM,aAAkBmB,EAAOnB,EAASmB,EAAKa,KAAKhC,EAAQ8B,GAEjDvC,IACf,CAKI,sBAAIW,GACA,OAAOX,KAAKI,mBACpB,CAMI,qBAAAQ,CAAsBD,GAIlB,OAHAX,KAAK8B,oBACL9B,KAAKI,oBAAsBO,EAEpBX,IACf,CAOI,WAAAc,CAAYC,EAAMJ,GAOd,OANAX,KAAK8B,oBACL9B,KAAKI,oBACqB,MAAtBO,EACMA,EAAmB+B,OAAO3B,IAC1B,IAAI4B,GAA6BD,OAAO3B,GAE3Cf,IACf,CAKI,kBAAA4C,CAAmBC,GACS,MAApB7C,KAAKC,aACLD,KAAKC,YAAY6C,iBAAiBD,EAE9C,CASI,QAAAE,CAASC,EAASC,GACd,OAAOD,EAAQE,cAAcC,mBAAmBF,EACxD,CAOI,uBAAAG,GACI,MAAO,cACf,CAOI,oBAAAC,GACI,MAAO,CACH5B,WACwB,MAApBzB,KAAKC,YACCD,KAAKC,YAAYqD,cACjB,KACV/C,IAAKP,KAAKE,KACVO,OAAwB,MAAhBT,KAAKG,QAAkBH,KAAKG,QAAQoD,aAAe,KAC3D5C,mBAAoBX,KAAKI,oBAErC,CAKI,SAAAoD,GAII,MAAO,8BAFHxD,KAAKyD,gBAAgBC,QACxB,WAC8CC,YACvD,EAGAC,EAAqBC,IACjB,eAEAlE,EAA2BsB"}
|
|
@@ -1777,6 +1777,7 @@ class Transaction extends _Executable.default {
|
|
|
1777
1777
|
return {
|
|
1778
1778
|
memo: this.transactionMemo,
|
|
1779
1779
|
transactionFee: this._maxTransactionFee == null ? this._defaultMaxTransactionFee.toTinybars() : this._maxTransactionFee.toTinybars(),
|
|
1780
|
+
maxCustomFees: this._customFeeLimits != null ? this._customFeeLimits.map(maxCustomFee => maxCustomFee._toProtobuf()) : null,
|
|
1780
1781
|
[this._getTransactionDataCase()]: this._makeTransactionData()
|
|
1781
1782
|
};
|
|
1782
1783
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"../Hbar.js";import n from"./TransactionResponse.js";import s 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,B=new Map;class P 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 n=[],i=[],e=[],o=[],r=[],a=[],c=l.proto.TransactionList.decode(t).transactionList;if(0===c.length){const n=l.proto.Transaction.decode(t);0!==n.signedTransactionBytes.length?c.push(n):c.push({signedTransactionBytes:l.proto.SignedTransaction.encode({sigMap:n.sigMap,bodyBytes:n.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 n=l.proto.TransactionBody.decode(t.bodyBytes);if(null!=n.transactionID){const t=s._fromProtobuf(n.transactionID);o.includes(t.toString())||(i.push(t),o.push(t.toString()))}if(null!=n.nodeAccountID){const t=_._fromProtobuf(n.nodeAccountID);r.includes(t.toString())||(e.push(t),r.push(t.toString()))}if(null==n.data)throw new Error("(BUG) body.data was not set in the protobuf");a.push(n)}if(t.signedTransactionBytes&&0!=t.signedTransactionBytes.length){const c=l.proto.SignedTransaction.decode(t.signedTransactionBytes);n.push(c);const h=l.proto.TransactionBody.decode(c.bodyBytes);if(null!=h.transactionID){const t=s._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=B.get(h.data);if(null==u)throw new Error(`(BUG) Transaction.fromBytes() not implemented for type ${h.data}`);return u(c,n,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,n){return this._requireNotFrozen(),this.setBatchKey(n),await this.signWithOperator(t)}static _fromProtobufTransactions(n,s,i,e,o,r){const a=r[0];for(let t=0;t<e.length;t++)for(let n=0;n<o.length-1;n++)if(!y(r[t*o.length+n],r[t*o.length+n+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);n._transactions.setList(s),n._signedTransactions.setList(i),n._transactionIds.setList(e),n._nodeAccountIds.setList(o),n._transactionValidDuration=null!=a.transactionValidDuration&&null!=a.transactionValidDuration.seconds?h.fromValue(a.transactionValidDuration.seconds).toInt():120,n._maxTransactionFee=null!=a.transactionFee&&a.transactionFee>new h(0,0,!0)?t.fromTinybars(a.transactionFee):null,n._customFeeLimits=null!=a.maxCustomFees?a.maxCustomFees?.map((t=>T._fromProtobuf(t))):[],n._batchKey=null!=a.batchKey?b._fromProtobufKey(a?.batchKey):null,n._transactionMemo=null!=a.memo?a.memo:"";for(let t=0;t<o.length;t++){const e=i[t]||s[t];if(null!=e.sigMap&&null!=e.sigMap.sigPair)for(const t of e.sigMap.sigPair)n._signerPublicKeys.add(d(t.pubKeyPrefix)),n._publicKeys.push(f.fromBytes(t.pubKeyPrefix)),n._transactionSigners.push(null)}return n}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(n){return this._requireNotFrozen(),this._maxTransactionFee=n instanceof t?n:new t(n),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 n=0;n<this.getRequiredChunks();n++)this._transactionIds.index=n,t.push(this.bodySize);return this._transactionIds.index=0,t}sign(t){return this.signWith(t.publicKey,(n=>Promise.resolve(t.sign(n))))}async signWith(t,n){this._signOnDemand||this._requireFrozen();const s=t.toBytesRaw(),i=d(s);if(this._signerPublicKeys.has(i))return this;if(this._transactions.clear(),this._signerPublicKeys.add(i),this._publicKeys.push(t),this._transactionSigners.push(n),this._signOnDemand)return this;this._transactionIds.setLocked(),this._nodeAccountIds.setLocked();for(const s of this._signedTransactions.list){const i=s.bodyBytes,e=await n(i);null==s.sigMap&&(s.sigMap={}),null==s.sigMap.sigPair&&(s.sigMap.sigPair=[]),s.sigMap.sigPair.push(t._toProtobufSignature(e))}return this}signWithOperator(t){const n=t._operator;if(null==n)throw new Error("`client` must have an operator to sign with the operator");return this._isFrozen()||this.freezeWith(t),this.signWith(n.publicKey,n.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 n=s.generate(t.operatorAccountId);this._transactionIds.clear(),this._signedTransactions.clear(),this._transactionIds.setList([n]),this._isThrottled=!0}addSignature(t,n){if(!(n instanceof e))return this._addSignatureLegacy(t,n);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=s._fromProtobuf(i),a=_._fromProtobuf(o),c=n.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,n){const s=n instanceof Uint8Array,i=Array.isArray(n);if(this.getRequiredChunks()>1)throw new Error("Add signature is not supported for chunked transactions");if(s&&1!==this._signedTransactions.length)throw new Error("Signature array must match the number of transactions");if(i&&n.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=s?[n]:n;for(let n=0;n<this._signedTransactions.length;n++){const s=this._signedTransactions.get(n);null==s.sigMap&&(s.sigMap={}),null==s.sigMap.sigPair&&(s.sigMap.sigPair=[]),s.sigMap.sigPair.push(t._toProtobufSignature(r[n]))}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 n=t.toBytesRaw(),s=d(n);if(!this._signerPublicKeys.has(s))throw new Error("The public key has not signed this transaction");const i=[];for(const t of this._signedTransactions.list){const n=this._removeSignaturesFromTransaction(t,s);i.push(...n)}return this._signerPublicKeys.delete(s),this._publicKeys=this._publicKeys.filter((n=>!n.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 n=l.proto.TransactionBody.decode(t.bodyBytes);if(!n.nodeAccountID)throw new Error("Missing nodeAccountID in transaction body.");const i=_._fromProtobuf(n.nodeAccountID);if(!n.transactionID)throw new Error("Missing transactionID in transaction body.");const e=s._fromProtobuf(n.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 n of this._transactionIds.list)null!=n.accountId&&n.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),n=t.bodyBytes;for(let s=0;s<this._publicKeys.length;s++){const i=this._publicKeys[s],e=this._transactionSigners[s];if(null==e)continue;const o=await e(n);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=s.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 n=this._transactions.length;n<t;n++)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,n){const{nodeTransactionPrecheckCode:s}=n,i=c._fromCode(null!=s?s: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,n,s){const{nodeTransactionPrecheckCode:i}=n,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:s,status:e,transactionId:this._getTransactionId(),contractFunctionResult:null})}async _mapResponse(t,s,i){const e=await u(i.signedTransactionBytes),o=this._getTransactionId();return this._transactionIds.advance(),this._logger&&this._logger.info(`Transaction Info: ${JSON.stringify(new n({nodeId:s,transactionHash:e,transactionId:o,logger:this._logger}).toJSON())}`),new n({nodeId:s,transactionHash:e,transactionId:o,transaction:this,logger:this._logger})}_makeSignedTransaction(t){const n=this._makeTransactionBody(t);this._logger&&this._logger.info(`Transaction Body: ${JSON.stringify(n)}`);return{sigMap:{sigPair:[]},bodyBytes:l.proto.TransactionBody.encode(n).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(),[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,n){const s=[];return t.sigMap&&t.sigMap.sigPair?(t.sigMap.sigPair=t.sigMap.sigPair.filter((t=>{const i=this._shouldRemoveSignature(t,n),e=t.ed25519??t.ECDSASecp256k1;return i&&e&&s.push(e),!i})),s):[]}_shouldRemoveSignature=(t,n)=>d(t?.pubKeyPrefix||new Uint8Array)===n;_collectSignaturesByPublicKey(){const t=new Map,n={};for(const s of this._signedTransactions.list){if(!s.sigMap||!s.sigMap.sigPair)return new Map;for(const i of s.sigMap.sigPair){const s=i.ed25519??i.ECDSASecp256k1;if(!s||!i.pubKeyPrefix)return new Map;const e=d(i.pubKeyPrefix);let o=n[e];o||(o=f.fromString(e),n[e]=o),t.has(o)||t.set(o,[]);const r=t.get(o);r&&r.push(s)}}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,B as TRANSACTION_REGISTRY,P 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 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};
|
|
2
2
|
//# sourceMappingURL=Transaction.js.map
|