@hiero-ledger/sdk 2.80.0 → 2.81.0-beta.1

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.
Files changed (182) hide show
  1. package/README.md +34 -7
  2. package/dist/umd.js +2213 -318
  3. package/dist/umd.js.map +1 -0
  4. package/dist/umd.min.js +6 -5
  5. package/dist/umd.min.js.map +1 -0
  6. package/lib/Executable.cjs +7 -4
  7. package/lib/Executable.js +1 -1
  8. package/lib/Executable.js.map +1 -1
  9. package/lib/PublicKey.cjs +45 -26
  10. package/lib/PublicKey.d.ts +12 -0
  11. package/lib/PublicKey.js +1 -1
  12. package/lib/PublicKey.js.map +1 -1
  13. package/lib/RequestType.cjs +19 -1
  14. package/lib/RequestType.d.ts +2 -0
  15. package/lib/RequestType.js +1 -1
  16. package/lib/RequestType.js.map +1 -1
  17. package/lib/Status.cjs +203 -252
  18. package/lib/Status.d.ts +8 -6
  19. package/lib/Status.js +1 -1
  20. package/lib/Status.js.map +1 -1
  21. package/lib/Transfer.cjs +25 -2
  22. package/lib/Transfer.d.ts +4 -0
  23. package/lib/Transfer.js +1 -1
  24. package/lib/Transfer.js.map +1 -1
  25. package/lib/account/AccountCreateTransaction.cjs +38 -0
  26. package/lib/account/AccountCreateTransaction.d.ts +21 -0
  27. package/lib/account/AccountCreateTransaction.js +1 -1
  28. package/lib/account/AccountCreateTransaction.js.map +1 -1
  29. package/lib/account/AccountUpdateTransaction.cjs +74 -1
  30. package/lib/account/AccountUpdateTransaction.d.ts +43 -0
  31. package/lib/account/AccountUpdateTransaction.js +1 -1
  32. package/lib/account/AccountUpdateTransaction.js.map +1 -1
  33. package/lib/account/TransferTransaction.cjs +57 -9
  34. package/lib/account/TransferTransaction.d.ts +31 -1
  35. package/lib/account/TransferTransaction.js +1 -1
  36. package/lib/account/TransferTransaction.js.map +1 -1
  37. package/lib/browser.js +1 -1
  38. package/lib/client/Client.cjs +38 -0
  39. package/lib/client/Client.d.ts +30 -0
  40. package/lib/client/Client.js +1 -1
  41. package/lib/client/Client.js.map +1 -1
  42. package/lib/client/addressbooks/mainnet.cjs +1 -1
  43. package/lib/client/addressbooks/mainnet.d.ts +1 -1
  44. package/lib/client/addressbooks/mainnet.js +1 -1
  45. package/lib/client/addressbooks/mainnet.js.map +1 -1
  46. package/lib/client/addressbooks/previewnet.cjs +1 -1
  47. package/lib/client/addressbooks/previewnet.d.ts +1 -1
  48. package/lib/client/addressbooks/previewnet.js +1 -1
  49. package/lib/client/addressbooks/previewnet.js.map +1 -1
  50. package/lib/client/addressbooks/testnet.cjs +1 -1
  51. package/lib/client/addressbooks/testnet.d.ts +1 -1
  52. package/lib/client/addressbooks/testnet.js +1 -1
  53. package/lib/client/addressbooks/testnet.js.map +1 -1
  54. package/lib/contract/ContractCreateTransaction.cjs +37 -1
  55. package/lib/contract/ContractCreateTransaction.d.ts +21 -0
  56. package/lib/contract/ContractCreateTransaction.js +1 -1
  57. package/lib/contract/ContractCreateTransaction.js.map +1 -1
  58. package/lib/contract/ContractUpdateTransaction.cjs +74 -1
  59. package/lib/contract/ContractUpdateTransaction.d.ts +43 -0
  60. package/lib/contract/ContractUpdateTransaction.js +1 -1
  61. package/lib/contract/ContractUpdateTransaction.js.map +1 -1
  62. package/lib/exports.cjs +103 -0
  63. package/lib/exports.d.ts +13 -0
  64. package/lib/exports.js +1 -1
  65. package/lib/exports.js.map +1 -1
  66. package/lib/hooks/EvmHook.cjs +84 -0
  67. package/lib/hooks/EvmHook.d.ts +51 -0
  68. package/lib/hooks/EvmHook.js +2 -0
  69. package/lib/hooks/EvmHook.js.map +1 -0
  70. package/lib/hooks/EvmHookCall.cjs +103 -0
  71. package/lib/hooks/EvmHookCall.d.ts +69 -0
  72. package/lib/hooks/EvmHookCall.js +2 -0
  73. package/lib/hooks/EvmHookCall.js.map +1 -0
  74. package/lib/hooks/EvmHookMappingEntry.cjs +135 -0
  75. package/lib/hooks/EvmHookMappingEntry.d.ts +84 -0
  76. package/lib/hooks/EvmHookMappingEntry.js +2 -0
  77. package/lib/hooks/EvmHookMappingEntry.js.map +1 -0
  78. package/lib/hooks/EvmHookStorageUpdate.cjs +238 -0
  79. package/lib/hooks/EvmHookStorageUpdate.d.ts +144 -0
  80. package/lib/hooks/EvmHookStorageUpdate.js +2 -0
  81. package/lib/hooks/EvmHookStorageUpdate.js.map +1 -0
  82. package/lib/hooks/FungibleHookCall.cjs +67 -0
  83. package/lib/hooks/FungibleHookCall.d.ts +50 -0
  84. package/lib/hooks/FungibleHookCall.js +2 -0
  85. package/lib/hooks/FungibleHookCall.js.map +1 -0
  86. package/lib/hooks/FungibleHookType.cjs +11 -0
  87. package/lib/hooks/FungibleHookType.d.ts +5 -0
  88. package/lib/hooks/FungibleHookType.js +2 -0
  89. package/lib/hooks/FungibleHookType.js.map +1 -0
  90. package/lib/hooks/HookCall.cjs +99 -0
  91. package/lib/hooks/HookCall.d.ts +64 -0
  92. package/lib/hooks/HookCall.js +2 -0
  93. package/lib/hooks/HookCall.js.map +1 -0
  94. package/lib/hooks/HookCreationDetails.cjs +149 -0
  95. package/lib/hooks/HookCreationDetails.d.ts +91 -0
  96. package/lib/hooks/HookCreationDetails.js +2 -0
  97. package/lib/hooks/HookCreationDetails.js.map +1 -0
  98. package/lib/hooks/HookEntityId.cjs +67 -0
  99. package/lib/hooks/HookEntityId.d.ts +41 -0
  100. package/lib/hooks/HookEntityId.js +2 -0
  101. package/lib/hooks/HookEntityId.js.map +1 -0
  102. package/lib/hooks/HookExtensionPoint.cjs +31 -0
  103. package/lib/hooks/HookExtensionPoint.d.ts +16 -0
  104. package/lib/hooks/HookExtensionPoint.js +2 -0
  105. package/lib/hooks/HookExtensionPoint.js.map +1 -0
  106. package/lib/hooks/HookId.cjs +101 -0
  107. package/lib/hooks/HookId.d.ts +63 -0
  108. package/lib/hooks/HookId.js +2 -0
  109. package/lib/hooks/HookId.js.map +1 -0
  110. package/lib/hooks/HookStoreTransaction.cjs +157 -0
  111. package/lib/hooks/HookStoreTransaction.d.ts +77 -0
  112. package/lib/hooks/HookStoreTransaction.js +2 -0
  113. package/lib/hooks/HookStoreTransaction.js.map +1 -0
  114. package/lib/hooks/NftHookCall.cjs +67 -0
  115. package/lib/hooks/NftHookCall.d.ts +50 -0
  116. package/lib/hooks/NftHookCall.js +2 -0
  117. package/lib/hooks/NftHookCall.js.map +1 -0
  118. package/lib/hooks/NftHookType.cjs +13 -0
  119. package/lib/hooks/NftHookType.d.ts +7 -0
  120. package/lib/hooks/NftHookType.js +2 -0
  121. package/lib/hooks/NftHookType.js.map +1 -0
  122. package/lib/index.js +1 -1
  123. package/lib/native.js +1 -1
  124. package/lib/token/AbstractTokenTransferTransaction.cjs +17 -5
  125. package/lib/token/AbstractTokenTransferTransaction.d.ts +13 -2
  126. package/lib/token/AbstractTokenTransferTransaction.js +1 -1
  127. package/lib/token/AbstractTokenTransferTransaction.js.map +1 -1
  128. package/lib/token/TokenAirdropTransaction.cjs +1 -1
  129. package/lib/token/TokenAirdropTransaction.js +1 -1
  130. package/lib/token/TokenAirdropTransaction.js.map +1 -1
  131. package/lib/token/TokenNftTransfer.cjs +51 -2
  132. package/lib/token/TokenNftTransfer.d.ts +7 -0
  133. package/lib/token/TokenNftTransfer.js +1 -1
  134. package/lib/token/TokenNftTransfer.js.map +1 -1
  135. package/lib/token/TokenTransfer.cjs +26 -2
  136. package/lib/token/TokenTransfer.d.ts +4 -0
  137. package/lib/token/TokenTransfer.js +1 -1
  138. package/lib/token/TokenTransfer.js.map +1 -1
  139. package/lib/transaction/Transaction.cjs +2 -1
  140. package/lib/transaction/Transaction.js +1 -1
  141. package/lib/transaction/Transaction.js.map +1 -1
  142. package/lib/transaction/TransactionResponse.cjs +82 -9
  143. package/lib/transaction/TransactionResponse.d.ts +33 -2
  144. package/lib/transaction/TransactionResponse.js +1 -1
  145. package/lib/transaction/TransactionResponse.js.map +1 -1
  146. package/lib/version.js +1 -1
  147. package/package.json +15 -13
  148. package/src/Executable.js +10 -7
  149. package/src/PublicKey.js +53 -36
  150. package/src/RequestType.js +18 -0
  151. package/src/Status.js +201 -252
  152. package/src/Transfer.js +33 -1
  153. package/src/account/AccountCreateTransaction.js +39 -0
  154. package/src/account/AccountUpdateTransaction.js +78 -0
  155. package/src/account/TransferTransaction.js +84 -8
  156. package/src/client/Client.js +38 -0
  157. package/src/client/addressbooks/mainnet.js +1 -1
  158. package/src/client/addressbooks/previewnet.js +1 -1
  159. package/src/client/addressbooks/testnet.js +1 -1
  160. package/src/contract/ContractCreateTransaction.js +37 -0
  161. package/src/contract/ContractUpdateTransaction.js +80 -0
  162. package/src/exports.js +17 -0
  163. package/src/hooks/EvmHook.js +83 -0
  164. package/src/hooks/EvmHookCall.js +100 -0
  165. package/src/hooks/EvmHookMappingEntry.js +140 -0
  166. package/src/hooks/EvmHookStorageUpdate.js +257 -0
  167. package/src/hooks/FungibleHookCall.js +65 -0
  168. package/src/hooks/FungibleHookType.js +6 -0
  169. package/src/hooks/HookCall.js +97 -0
  170. package/src/hooks/HookCreationDetails.js +155 -0
  171. package/src/hooks/HookEntityId.js +67 -0
  172. package/src/hooks/HookExtensionPoint.js +25 -0
  173. package/src/hooks/HookId.js +102 -0
  174. package/src/hooks/HookStoreTransaction.js +185 -0
  175. package/src/hooks/NftHookCall.js +64 -0
  176. package/src/hooks/NftHookType.js +8 -0
  177. package/src/token/AbstractTokenTransferTransaction.js +16 -1
  178. package/src/token/TokenAirdropTransaction.js +1 -0
  179. package/src/token/TokenNftTransfer.js +68 -1
  180. package/src/token/TokenTransfer.js +34 -1
  181. package/src/transaction/Transaction.js +3 -0
  182. package/src/transaction/TransactionResponse.js +98 -13
@@ -27,6 +27,8 @@ export default class TokenNftTransfer {
27
27
  * @param {AccountId | string} props.receiverAccountId
28
28
  * @param {Long | number} props.serialNumber
29
29
  * @param {boolean} props.isApproved
30
+ * @param {NftHookCall} [props.senderHookCall]
31
+ * @param {NftHookCall} [props.receiverHookCall]
30
32
  */
31
33
  constructor(props: {
32
34
  tokenId: TokenId | string;
@@ -34,6 +36,8 @@ export default class TokenNftTransfer {
34
36
  receiverAccountId: AccountId | string;
35
37
  serialNumber: Long | number;
36
38
  isApproved: boolean;
39
+ senderHookCall?: NftHookCall | undefined;
40
+ receiverHookCall?: NftHookCall | undefined;
37
41
  });
38
42
  /**
39
43
  * The Token ID that sends or receives cryptocurrency.
@@ -48,6 +52,8 @@ export default class TokenNftTransfer {
48
52
  */
49
53
  receiverAccountId: AccountId;
50
54
  serialNumber: Long;
55
+ senderHookCall: NftHookCall | undefined;
56
+ receiverHookCall: NftHookCall | undefined;
51
57
  isApproved: boolean;
52
58
  /**
53
59
  * @internal
@@ -68,3 +74,4 @@ export type BigNumber = import("bignumber.js").default;
68
74
  import TokenId from "./TokenId.js";
69
75
  import AccountId from "../account/AccountId.js";
70
76
  import Long from "long";
77
+ import NftHookCall from "../hooks/NftHookCall.js";
@@ -1,2 +1,2 @@
1
- import r from"long";import o from"../account/AccountId.js";import e from"./TokenId.js";class t{constructor(t){this.tokenId=t.tokenId instanceof e?t.tokenId:e.fromString(t.tokenId),this.senderAccountId=t.senderAccountId instanceof o?t.senderAccountId:o.fromString(t.senderAccountId),this.receiverAccountId=t.receiverAccountId instanceof o?t.receiverAccountId:o.fromString(t.receiverAccountId),this.serialNumber=r.fromValue(t.serialNumber),this.isApproved=t.isApproved}static _fromProtobuf(n){const c=[];for(const s of n){const n=e._fromProtobuf(s.token);for(const e of null!=s.nftTransfers?s.nftTransfers:[])c.push(new t({tokenId:n,senderAccountId:o._fromProtobuf(e.senderAccountID),receiverAccountId:o._fromProtobuf(e.receiverAccountID),serialNumber:null!=e.serialNumber?e.serialNumber:r.ZERO,isApproved:1==e.isApproval}))}return c}_toProtobuf(){return{senderAccountID:this.senderAccountId._toProtobuf(),receiverAccountID:this.receiverAccountId._toProtobuf(),serialNumber:this.serialNumber,isApproval:this.isApproved}}}export{t as default};
1
+ import o from"long";import e from"../account/AccountId.js";import r from"./TokenId.js";import t from"../hooks/NftHookCall.js";import n from"../hooks/NftHookType.js";class c{constructor(t){this.tokenId=t.tokenId instanceof r?t.tokenId:r.fromString(t.tokenId),this.senderAccountId=t.senderAccountId instanceof e?t.senderAccountId:e.fromString(t.senderAccountId),this.receiverAccountId=t.receiverAccountId instanceof e?t.receiverAccountId:e.fromString(t.receiverAccountId),this.serialNumber=o.fromValue(t.serialNumber),this.senderHookCall=t.senderHookCall,this.receiverHookCall=t.receiverHookCall,this.isApproved=t.isApproved}static _fromProtobuf(l){const s=[];for(const i of l){const l=r._fromProtobuf(i.token);for(const r of null!=i.nftTransfers?i.nftTransfers:[]){let i,u;null!=r.preTxSenderAllowanceHook?i=t._fromProtobufWithType(r.preTxSenderAllowanceHook,n.PRE_HOOK_SENDER):null!=r.prePostTxSenderAllowanceHook&&(i=t._fromProtobufWithType(r.prePostTxSenderAllowanceHook,n.PRE_POST_HOOK_SENDER)),null!=r.preTxReceiverAllowanceHook?u=t._fromProtobufWithType(r.preTxReceiverAllowanceHook,n.PRE_HOOK_RECEIVER):null!=r.prePostTxReceiverAllowanceHook&&(u=t._fromProtobufWithType(r.prePostTxReceiverAllowanceHook,n.PRE_POST_HOOK_RECEIVER)),s.push(new c({tokenId:l,senderAccountId:e._fromProtobuf(r.senderAccountID),receiverAccountId:e._fromProtobuf(r.receiverAccountID),serialNumber:null!=r.serialNumber?r.serialNumber:o.ZERO,isApproved:1==r.isApproval,senderHookCall:i,receiverHookCall:u}))}}return s}_toProtobuf(){const o={senderAccountID:this.senderAccountId._toProtobuf(),receiverAccountID:this.receiverAccountId._toProtobuf(),serialNumber:this.serialNumber,isApproval:this.isApproved};if(null!=this.senderHookCall)switch(this.senderHookCall.type){case n.PRE_HOOK_SENDER:o.preTxSenderAllowanceHook=this.senderHookCall._toProtobuf();break;case n.PRE_POST_HOOK_SENDER:o.prePostTxSenderAllowanceHook=this.senderHookCall._toProtobuf()}if(null!=this.receiverHookCall)switch(this.receiverHookCall.type){case n.PRE_HOOK_RECEIVER:o.preTxReceiverAllowanceHook=this.receiverHookCall._toProtobuf();break;case n.PRE_POST_HOOK_RECEIVER:o.prePostTxReceiverAllowanceHook=this.receiverHookCall._toProtobuf()}return o}}export{c as default};
2
2
  //# sourceMappingURL=TokenNftTransfer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TokenNftTransfer.js","sources":["../../src/token/TokenNftTransfer.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(\"@hiero-ledger/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hiero-ledger/proto\").proto.INftTransfer} HieroProto.proto.INftTransfer\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * An account, and the amount that it sends or receives during a cryptocurrency tokentransfer.\n */\nexport default class TokenNftTransfer {\n /**\n * @internal\n * @param {object} props\n * @param {TokenId | string} props.tokenId\n * @param {AccountId | string} props.senderAccountId\n * @param {AccountId | string} props.receiverAccountId\n * @param {Long | number} props.serialNumber\n * @param {boolean} props.isApproved\n */\n constructor(props) {\n /**\n * The Token ID that sends or receives cryptocurrency.\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 this.senderAccountId =\n props.senderAccountId instanceof AccountId\n ? props.senderAccountId\n : AccountId.fromString(props.senderAccountId);\n\n /**\n * The Account ID that sends or receives cryptocurrency.\n */\n this.receiverAccountId =\n props.receiverAccountId instanceof AccountId\n ? props.receiverAccountId\n : AccountId.fromString(props.receiverAccountId);\n\n this.serialNumber = Long.fromValue(props.serialNumber);\n this.isApproved = props.isApproved;\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITokenTransferList[]} tokenTransfers\n * @returns {TokenNftTransfer[]}\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 for (const transfer of tokenTransfer.nftTransfers != null\n ? tokenTransfer.nftTransfers\n : []) {\n transfers.push(\n new TokenNftTransfer({\n tokenId,\n senderAccountId: AccountId._fromProtobuf(\n /** @type {HieroProto.proto.IAccountID} */ (\n transfer.senderAccountID\n ),\n ),\n receiverAccountId: AccountId._fromProtobuf(\n /** @type {HieroProto.proto.IAccountID} */ (\n transfer.receiverAccountID\n ),\n ),\n serialNumber:\n transfer.serialNumber != null\n ? transfer.serialNumber\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.INftTransfer}\n */\n _toProtobuf() {\n return {\n senderAccountID: this.senderAccountId._toProtobuf(),\n receiverAccountID: this.receiverAccountId._toProtobuf(),\n serialNumber: this.serialNumber,\n isApproval: this.isApproved,\n };\n }\n}\n"],"names":["TokenNftTransfer","constructor","props","this","tokenId","TokenId","fromString","senderAccountId","AccountId","receiverAccountId","serialNumber","Long","fromValue","isApproved","_fromProtobuf","tokenTransfers","transfers","tokenTransfer","transfer","nftTransfers","push","ZERO","isApproval","_toProtobuf","senderAccountID","receiverAccountID"],"mappings":"uFAsBe,MAAMA,EAUjB,WAAAC,CAAYC,GAIRC,KAAKC,QACDF,EAAME,mBAAmBC,EACnBH,EAAME,QACNC,EAAQC,WAAWJ,EAAME,SAKnCD,KAAKI,gBACDL,EAAMK,2BAA2BC,EAC3BN,EAAMK,gBACNC,EAAUF,WAAWJ,EAAMK,iBAKrCJ,KAAKM,kBACDP,EAAMO,6BAA6BD,EAC7BN,EAAMO,kBACND,EAAUF,WAAWJ,EAAMO,mBAErCN,KAAKO,aAAeC,EAAKC,UAAUV,EAAMQ,cACzCP,KAAKU,WAAaX,EAAMW,UAChC,CAOI,oBAAOC,CAAcC,GACjB,MAAMC,EAAY,GAElB,IAAK,MAAMC,KAAiBF,EAAgB,CACxC,MAAMX,EAAUC,EAAQS,cACsBG,EAAmB,OAEjE,IAAK,MAAMC,KAA0C,MAA9BD,EAAcE,aAC/BF,EAAcE,aACd,GACFH,EAAUI,KACN,IAAIpB,EAAiB,CACjBI,UACAG,gBAAiBC,EAAUM,cAEnBI,EAChC,iBAEwBT,kBAAmBD,EAAUM,cAErBI,EAChC,mBAEwBR,aAC6B,MAAzBQ,EAASR,aACHQ,EAASR,aACTC,EAAKU,KACfR,WAAmC,GAAvBK,EAASI,aAI7C,CAEQ,OAAON,CACf,CAMI,WAAAO,GACI,MAAO,CACHC,gBAAiBrB,KAAKI,gBAAgBgB,cACtCE,kBAAmBtB,KAAKM,kBAAkBc,cAC1Cb,aAAcP,KAAKO,aACnBY,WAAYnB,KAAKU,WAE7B"}
1
+ {"version":3,"file":"TokenNftTransfer.js","sources":["../../src/token/TokenNftTransfer.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 NftHookCall from \"../hooks/NftHookCall.js\";\nimport NftHookType from \"../hooks/NftHookType.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hiero-ledger/proto\").proto.INftTransfer} HieroProto.proto.INftTransfer\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITokenID} HieroProto.proto.ITokenID\n */\n\n/**\n * @typedef {import(\"bignumber.js\").default} BigNumber\n */\n\n/**\n * An account, and the amount that it sends or receives during a cryptocurrency tokentransfer.\n */\nexport default class TokenNftTransfer {\n /**\n * @internal\n * @param {object} props\n * @param {TokenId | string} props.tokenId\n * @param {AccountId | string} props.senderAccountId\n * @param {AccountId | string} props.receiverAccountId\n * @param {Long | number} props.serialNumber\n * @param {boolean} props.isApproved\n * @param {NftHookCall} [props.senderHookCall]\n * @param {NftHookCall} [props.receiverHookCall]\n */\n constructor(props) {\n /**\n * The Token ID that sends or receives cryptocurrency.\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 this.senderAccountId =\n props.senderAccountId instanceof AccountId\n ? props.senderAccountId\n : AccountId.fromString(props.senderAccountId);\n\n /**\n * The Account ID that sends or receives cryptocurrency.\n */\n this.receiverAccountId =\n props.receiverAccountId instanceof AccountId\n ? props.receiverAccountId\n : AccountId.fromString(props.receiverAccountId);\n\n this.serialNumber = Long.fromValue(props.serialNumber);\n this.senderHookCall = props.senderHookCall;\n this.receiverHookCall = props.receiverHookCall;\n this.isApproved = props.isApproved;\n }\n\n /**\n * @internal\n * @param {HieroProto.proto.ITokenTransferList[]} tokenTransfers\n * @returns {TokenNftTransfer[]}\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 for (const transfer of tokenTransfer.nftTransfers != null\n ? tokenTransfer.nftTransfers\n : []) {\n // Determine sender hook type\n let senderHookCall;\n if (transfer.preTxSenderAllowanceHook != null) {\n senderHookCall = NftHookCall._fromProtobufWithType(\n transfer.preTxSenderAllowanceHook,\n NftHookType.PRE_HOOK_SENDER,\n );\n } else if (transfer.prePostTxSenderAllowanceHook != null) {\n senderHookCall = NftHookCall._fromProtobufWithType(\n transfer.prePostTxSenderAllowanceHook,\n NftHookType.PRE_POST_HOOK_SENDER,\n );\n }\n\n // Determine receiver hook type\n let receiverHookCall;\n if (transfer.preTxReceiverAllowanceHook != null) {\n receiverHookCall = NftHookCall._fromProtobufWithType(\n transfer.preTxReceiverAllowanceHook,\n NftHookType.PRE_HOOK_RECEIVER,\n );\n } else if (transfer.prePostTxReceiverAllowanceHook != null) {\n receiverHookCall = NftHookCall._fromProtobufWithType(\n transfer.prePostTxReceiverAllowanceHook,\n NftHookType.PRE_POST_HOOK_RECEIVER,\n );\n }\n\n transfers.push(\n new TokenNftTransfer({\n tokenId,\n senderAccountId: AccountId._fromProtobuf(\n /** @type {HieroProto.proto.IAccountID} */ (\n transfer.senderAccountID\n ),\n ),\n receiverAccountId: AccountId._fromProtobuf(\n /** @type {HieroProto.proto.IAccountID} */ (\n transfer.receiverAccountID\n ),\n ),\n serialNumber:\n transfer.serialNumber != null\n ? transfer.serialNumber\n : Long.ZERO,\n isApproved: transfer.isApproval == true,\n senderHookCall: senderHookCall,\n receiverHookCall: receiverHookCall,\n }),\n );\n }\n }\n\n return transfers;\n }\n\n /**\n * @internal\n * @returns {HieroProto.proto.INftTransfer}\n */\n _toProtobuf() {\n /** @type {HieroProto.proto.INftTransfer} */\n const result = {\n senderAccountID: this.senderAccountId._toProtobuf(),\n receiverAccountID: this.receiverAccountId._toProtobuf(),\n serialNumber: this.serialNumber,\n isApproval: this.isApproved,\n };\n\n // Handle sender hook\n if (this.senderHookCall != null) {\n switch (this.senderHookCall.type) {\n case NftHookType.PRE_HOOK_SENDER:\n result.preTxSenderAllowanceHook =\n this.senderHookCall._toProtobuf();\n break;\n case NftHookType.PRE_POST_HOOK_SENDER:\n result.prePostTxSenderAllowanceHook =\n this.senderHookCall._toProtobuf();\n break;\n }\n }\n\n // Handle receiver hook\n if (this.receiverHookCall != null) {\n switch (this.receiverHookCall.type) {\n case NftHookType.PRE_HOOK_RECEIVER:\n result.preTxReceiverAllowanceHook =\n this.receiverHookCall._toProtobuf();\n break;\n case NftHookType.PRE_POST_HOOK_RECEIVER:\n result.prePostTxReceiverAllowanceHook =\n this.receiverHookCall._toProtobuf();\n break;\n }\n }\n\n return result;\n }\n}\n"],"names":["TokenNftTransfer","constructor","props","this","tokenId","TokenId","fromString","senderAccountId","AccountId","receiverAccountId","serialNumber","Long","fromValue","senderHookCall","receiverHookCall","isApproved","_fromProtobuf","tokenTransfers","transfers","tokenTransfer","transfer","nftTransfers","preTxSenderAllowanceHook","NftHookCall","_fromProtobufWithType","NftHookType","PRE_HOOK_SENDER","prePostTxSenderAllowanceHook","PRE_POST_HOOK_SENDER","preTxReceiverAllowanceHook","PRE_HOOK_RECEIVER","prePostTxReceiverAllowanceHook","PRE_POST_HOOK_RECEIVER","push","ZERO","isApproval","_toProtobuf","result","senderAccountID","receiverAccountID","type"],"mappings":"qKAwBe,MAAMA,EAYjB,WAAAC,CAAYC,GAIRC,KAAKC,QACDF,EAAME,mBAAmBC,EACnBH,EAAME,QACNC,EAAQC,WAAWJ,EAAME,SAKnCD,KAAKI,gBACDL,EAAMK,2BAA2BC,EAC3BN,EAAMK,gBACNC,EAAUF,WAAWJ,EAAMK,iBAKrCJ,KAAKM,kBACDP,EAAMO,6BAA6BD,EAC7BN,EAAMO,kBACND,EAAUF,WAAWJ,EAAMO,mBAErCN,KAAKO,aAAeC,EAAKC,UAAUV,EAAMQ,cACzCP,KAAKU,eAAiBX,EAAMW,eAC5BV,KAAKW,iBAAmBZ,EAAMY,iBAC9BX,KAAKY,WAAab,EAAMa,UAChC,CAOI,oBAAOC,CAAcC,GACjB,MAAMC,EAAY,GAElB,IAAK,MAAMC,KAAiBF,EAAgB,CACxC,MAAMb,EAAUC,EAAQW,cACsBG,EAAmB,OAEjE,IAAK,MAAMC,KAA0C,MAA9BD,EAAcE,aAC/BF,EAAcE,aACd,GAAI,CAEN,IAAIR,EAcAC,EAbqC,MAArCM,EAASE,yBACTT,EAAiBU,EAAYC,sBACzBJ,EAASE,yBACTG,EAAYC,iBAEgC,MAAzCN,EAASO,+BAChBd,EAAiBU,EAAYC,sBACzBJ,EAASO,6BACTF,EAAYG,uBAMuB,MAAvCR,EAASS,2BACTf,EAAmBS,EAAYC,sBAC3BJ,EAASS,2BACTJ,EAAYK,mBAEkC,MAA3CV,EAASW,iCAChBjB,EAAmBS,EAAYC,sBAC3BJ,EAASW,+BACTN,EAAYO,yBAIpBd,EAAUe,KACN,IAAIjC,EAAiB,CACjBI,UACAG,gBAAiBC,EAAUQ,cAEnBI,EAChC,iBAEwBX,kBAAmBD,EAAUQ,cAErBI,EAChC,mBAEwBV,aAC6B,MAAzBU,EAASV,aACHU,EAASV,aACTC,EAAKuB,KACfnB,WAAmC,GAAvBK,EAASe,WACrBtB,eAAgBA,EAChBC,iBAAkBA,IAG1C,CACA,CAEQ,OAAOI,CACf,CAMI,WAAAkB,GAEI,MAAMC,EAAS,CACXC,gBAAiBnC,KAAKI,gBAAgB6B,cACtCG,kBAAmBpC,KAAKM,kBAAkB2B,cAC1C1B,aAAcP,KAAKO,aACnByB,WAAYhC,KAAKY,YAIrB,GAA2B,MAAvBZ,KAAKU,eACL,OAAQV,KAAKU,eAAe2B,MACxB,KAAKf,EAAYC,gBACbW,EAAOf,yBACHnB,KAAKU,eAAeuB,cACxB,MACJ,KAAKX,EAAYG,qBACbS,EAAOV,6BACHxB,KAAKU,eAAeuB,cAMpC,GAA6B,MAAzBjC,KAAKW,iBACL,OAAQX,KAAKW,iBAAiB0B,MAC1B,KAAKf,EAAYK,kBACbO,EAAOR,2BACH1B,KAAKW,iBAAiBsB,cAC1B,MACJ,KAAKX,EAAYO,uBACbK,EAAON,+BACH5B,KAAKW,iBAAiBsB,cAKtC,OAAOC,CACf"}
@@ -8,6 +8,8 @@ var _long = _interopRequireDefault(require("long"));
8
8
  var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
9
9
  var _TokenId = _interopRequireDefault(require("./TokenId.cjs"));
10
10
  var _util = require("../util.cjs");
11
+ var _FungibleHookCall = _interopRequireDefault(require("../hooks/FungibleHookCall.cjs"));
12
+ var _FungibleHookType = _interopRequireDefault(require("../hooks/FungibleHookType.cjs"));
11
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
14
  // SPDX-License-Identifier: Apache-2.0
13
15
 
@@ -44,6 +46,7 @@ class TokenTransfer {
44
46
  * @param {number | null} props.expectedDecimals
45
47
  * @param {Long | number | BigNumber | bigint} props.amount
46
48
  * @param {boolean} props.isApproved
49
+ * @param {FungibleHookCall} [props.hookCall]
47
50
  */
48
51
  constructor(props) {
49
52
  /**
@@ -62,6 +65,7 @@ class TokenTransfer {
62
65
  this.expectedDecimals = props.expectedDecimals;
63
66
  this.amount = (0, _util.convertAmountToLong)(props.amount);
64
67
  this.isApproved = props.isApproved;
68
+ this.hookCall = props.hookCall || null;
65
69
  }
66
70
 
67
71
  /**
@@ -75,13 +79,21 @@ class TokenTransfer {
75
79
  const tokenId = _TokenId.default._fromProtobuf(/** @type {HieroProto.proto.ITokenID} */tokenTransfer.token);
76
80
  const expectedDecimals = tokenTransfer.expectedDecimals != null ? Object.hasOwn(tokenTransfer.expectedDecimals, "value") ? tokenTransfer.expectedDecimals.value : null : null;
77
81
  for (const transfer of tokenTransfer.transfers != null ? tokenTransfer.transfers : []) {
82
+ // Determine which hook type is present, if any
83
+ let hookCall = null;
84
+ if (transfer.preTxAllowanceHook != null) {
85
+ hookCall = _FungibleHookCall.default._fromProtobufWithType(transfer.preTxAllowanceHook, _FungibleHookType.default.PRE_TX_ALLOWANCE_HOOK);
86
+ } else if (transfer.prePostTxAllowanceHook != null) {
87
+ hookCall = _FungibleHookCall.default._fromProtobufWithType(transfer.prePostTxAllowanceHook, _FungibleHookType.default.PRE_POST_TX_ALLOWANCE_HOOK);
88
+ }
78
89
  transfers.push(new TokenTransfer({
79
90
  tokenId,
80
91
  accountId: _AccountId.default._fromProtobuf(/** @type {HieroProto.proto.IAccountID} */
81
92
  transfer.accountID),
82
93
  expectedDecimals: expectedDecimals || null,
83
94
  amount: transfer.amount != null ? transfer.amount : _long.default.ZERO,
84
- isApproved: transfer.isApproval == true
95
+ isApproved: transfer.isApproval == true,
96
+ hookCall: hookCall ?? undefined
85
97
  }));
86
98
  }
87
99
  }
@@ -93,11 +105,23 @@ class TokenTransfer {
93
105
  * @returns {HieroProto.proto.IAccountAmount}
94
106
  */
95
107
  _toProtobuf() {
96
- return {
108
+ /** @type {HieroProto.proto.IAccountAmount} */
109
+ const result = {
97
110
  accountID: this.accountId._toProtobuf(),
98
111
  amount: this.amount,
99
112
  isApproval: this.isApproved
100
113
  };
114
+ if (this.hookCall != null) {
115
+ switch (this.hookCall.type) {
116
+ case _FungibleHookType.default.PRE_TX_ALLOWANCE_HOOK:
117
+ result.preTxAllowanceHook = this.hookCall._toProtobuf();
118
+ break;
119
+ case _FungibleHookType.default.PRE_POST_TX_ALLOWANCE_HOOK:
120
+ result.prePostTxAllowanceHook = this.hookCall._toProtobuf();
121
+ break;
122
+ }
123
+ }
124
+ return result;
101
125
  }
102
126
 
103
127
  /**
@@ -34,6 +34,7 @@ export default class TokenTransfer {
34
34
  * @param {number | null} props.expectedDecimals
35
35
  * @param {Long | number | BigNumber | bigint} props.amount
36
36
  * @param {boolean} props.isApproved
37
+ * @param {FungibleHookCall} [props.hookCall]
37
38
  */
38
39
  constructor(props: {
39
40
  tokenId: TokenId | string;
@@ -41,6 +42,7 @@ export default class TokenTransfer {
41
42
  expectedDecimals: number | null;
42
43
  amount: Long | number | BigNumber | bigint;
43
44
  isApproved: boolean;
45
+ hookCall?: FungibleHookCall | undefined;
44
46
  });
45
47
  /**
46
48
  * The Token ID that sends or receives cryptocurrency.
@@ -57,6 +59,7 @@ export default class TokenTransfer {
57
59
  expectedDecimals: number | null;
58
60
  amount: Long;
59
61
  isApproved: boolean;
62
+ hookCall: FungibleHookCall | null;
60
63
  /**
61
64
  * @internal
62
65
  * @returns {HieroProto.proto.IAccountAmount}
@@ -90,3 +93,4 @@ export type TokenTransferJSON = {
90
93
  import TokenId from "./TokenId.js";
91
94
  import AccountId from "../account/AccountId.js";
92
95
  import Long from "long";
96
+ import FungibleHookCall from "../hooks/FungibleHookCall.js";
@@ -1,2 +1,2 @@
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};
1
+ import o from"long";import t from"../account/AccountId.js";import e from"./TokenId.js";import{convertAmountToLong as n}from"../util.js";import l from"../hooks/FungibleHookCall.js";import r from"../hooks/FungibleHookType.js";class s{constructor(o){this.tokenId=o.tokenId instanceof e?o.tokenId:e.fromString(o.tokenId),this.accountId=o.accountId instanceof t?o.accountId:t.fromString(o.accountId),this.expectedDecimals=o.expectedDecimals,this.amount=n(o.amount),this.isApproved=o.isApproved,this.hookCall=o.hookCall||null}static _fromProtobuf(n){const c=[];for(const i of n){const n=e._fromProtobuf(i.token),a=null!=i.expectedDecimals&&Object.hasOwn(i.expectedDecimals,"value")?i.expectedDecimals.value:null;for(const e of null!=i.transfers?i.transfers:[]){let i=null;null!=e.preTxAllowanceHook?i=l._fromProtobufWithType(e.preTxAllowanceHook,r.PRE_TX_ALLOWANCE_HOOK):null!=e.prePostTxAllowanceHook&&(i=l._fromProtobufWithType(e.prePostTxAllowanceHook,r.PRE_POST_TX_ALLOWANCE_HOOK)),c.push(new s({tokenId:n,accountId:t._fromProtobuf(e.accountID),expectedDecimals:a||null,amount:null!=e.amount?e.amount:o.ZERO,isApproved:1==e.isApproval,hookCall:i??void 0}))}}return c}_toProtobuf(){const o={accountID:this.accountId._toProtobuf(),amount:this.amount,isApproval:this.isApproved};if(null!=this.hookCall)switch(this.hookCall.type){case r.PRE_TX_ALLOWANCE_HOOK:o.preTxAllowanceHook=this.hookCall._toProtobuf();break;case r.PRE_POST_TX_ALLOWANCE_HOOK:o.prePostTxAllowanceHook=this.hookCall._toProtobuf()}return o}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{s 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\";\nimport { convertAmountToLong } from \"../util.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hiero-ledger/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"}
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\";\nimport FungibleHookCall from \"../hooks/FungibleHookCall.js\";\nimport FungibleHookType from \"../hooks/FungibleHookType.js\";\n\n/**\n * @namespace proto\n * @typedef {import(\"@hiero-ledger/proto\").proto.ITokenTransferList} HieroProto.proto.ITokenTransferList\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountAmount} HieroProto.proto.IAccountAmount\n * @typedef {import(\"@hiero-ledger/proto\").proto.IAccountID} HieroProto.proto.IAccountID\n * @typedef {import(\"@hiero-ledger/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 * @param {FungibleHookCall} [props.hookCall]\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 this.hookCall = props.hookCall || null;\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 // Determine which hook type is present, if any\n let hookCall = null;\n if (transfer.preTxAllowanceHook != null) {\n hookCall = FungibleHookCall._fromProtobufWithType(\n transfer.preTxAllowanceHook,\n FungibleHookType.PRE_TX_ALLOWANCE_HOOK,\n );\n } else if (transfer.prePostTxAllowanceHook != null) {\n hookCall = FungibleHookCall._fromProtobufWithType(\n transfer.prePostTxAllowanceHook,\n FungibleHookType.PRE_POST_TX_ALLOWANCE_HOOK,\n );\n }\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 hookCall: hookCall ?? undefined,\n }),\n );\n }\n }\n\n return transfers;\n }\n\n /**\n * @internal\n * @returns {HieroProto.proto.IAccountAmount}\n */\n _toProtobuf() {\n /** @type {HieroProto.proto.IAccountAmount} */\n const result = {\n accountID: this.accountId._toProtobuf(),\n amount: this.amount,\n isApproval: this.isApproved,\n };\n\n if (this.hookCall != null) {\n switch (this.hookCall.type) {\n case FungibleHookType.PRE_TX_ALLOWANCE_HOOK:\n result.preTxAllowanceHook = this.hookCall._toProtobuf();\n break;\n case FungibleHookType.PRE_POST_TX_ALLOWANCE_HOOK:\n result.prePostTxAllowanceHook = this.hookCall._toProtobuf();\n break;\n }\n }\n\n return result;\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","hookCall","_fromProtobuf","tokenTransfers","transfers","tokenTransfer","Object","hasOwn","value","transfer","preTxAllowanceHook","FungibleHookCall","_fromProtobufWithType","FungibleHookType","PRE_TX_ALLOWANCE_HOOK","prePostTxAllowanceHook","PRE_POST_TX_ALLOWANCE_HOOK","push","Long","ZERO","isApproval","undefined","_toProtobuf","result","accountID","type","toJSON","toString","JSON","stringify"],"mappings":"gOAiCe,MAAMA,EAWjB,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,WACxBT,KAAKU,SAAWX,EAAMW,UAAY,IAC1C,CAOI,oBAAOC,CAAcC,GACjB,MAAMC,EAAY,GAElB,IAAK,MAAMC,KAAiBF,EAAgB,CACxC,MAAMX,EAAUC,EAAQS,cACsBG,EAAmB,OAE3DR,EACgC,MAAlCQ,EAAcR,kBACRS,OAAOC,OAAOF,EAAcR,iBAAkB,SAC1CQ,EAAcR,iBAAiBW,MAEnC,KAEV,IAAK,MAAMC,KAAuC,MAA3BJ,EAAcD,UAC/BC,EAAcD,UACd,GAAI,CAEN,IAAIH,EAAW,KACoB,MAA/BQ,EAASC,mBACTT,EAAWU,EAAiBC,sBACxBH,EAASC,mBACTG,EAAiBC,uBAEqB,MAAnCL,EAASM,yBAChBd,EAAWU,EAAiBC,sBACxBH,EAASM,uBACTF,EAAiBG,6BAIzBZ,EAAUa,KACN,IAAI7B,EAAc,CACdI,UACAG,UAAWC,EAAUM,cAEbO,EAChC,WAEwBZ,iBAAkBA,GAAoB,KACtCC,OACuB,MAAnBW,EAASX,OACHW,EAASX,OACToB,EAAKC,KACfnB,WAAmC,GAAvBS,EAASW,WACrBnB,SAAUA,QAAYoB,IAG9C,CACA,CAEQ,OAAOjB,CACf,CAMI,WAAAkB,GAEI,MAAMC,EAAS,CACXC,UAAWjC,KAAKI,UAAU2B,cAC1BxB,OAAQP,KAAKO,OACbsB,WAAY7B,KAAKS,YAGrB,GAAqB,MAAjBT,KAAKU,SACL,OAAQV,KAAKU,SAASwB,MAClB,KAAKZ,EAAiBC,sBAClBS,EAAOb,mBAAqBnB,KAAKU,SAASqB,cAC1C,MACJ,KAAKT,EAAiBG,2BAClBO,EAAOR,uBAAyBxB,KAAKU,SAASqB,cAK1D,OAAOC,CACf,CAKI,MAAAG,GACI,MAAO,CACHlC,QAASD,KAAKC,QAAQmC,WACtBhC,UAAWJ,KAAKI,UAAUgC,WAC1B9B,iBAAkBN,KAAKM,iBACvBC,OAAQP,KAAKO,OAAO6B,WACpB3B,WAAYT,KAAKS,WAE7B,CAKI,QAAA2B,GACI,OAAOC,KAAKC,UAAUtC,KAAKmC,SACnC"}
@@ -1752,7 +1752,8 @@ class Transaction extends _Executable.default {
1752
1752
  transactionHash,
1753
1753
  transactionId,
1754
1754
  transaction: this,
1755
- logger: this._logger
1755
+ logger: this._logger,
1756
+ transactionNodeAccountIds: !this._nodeAccountIds.isEmpty ? this._nodeAccountIds.list : undefined
1756
1757
  });
1757
1758
  }
1758
1759
 
@@ -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 d}from"../cryptography/sha384.js";import{encode as u}from"../encoding/hex.js";import*as l from"@hiero-ledger/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:case c.InvalidNodeAccount: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};
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"@hiero-ledger/proto";import _ from"../PrecheckStatusError.js";import g 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 g(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=g._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=g._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 g(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(g.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=g._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=g._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:case c.InvalidNodeAccount: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 _({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,transactionNodeAccountIds:this._nodeAccountIds.isEmpty?void 0:this._nodeAccountIds.list})}_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