@airgap/substrate 0.13.45-beta.3 → 0.13.45-beta.4

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 (395) hide show
  1. package/package.json +5 -5
  2. package/v0/index.js +12 -12
  3. package/v0/index.js.map +1 -1
  4. package/v0/protocol/SubstrateCryptoClient.js +94 -23
  5. package/v0/protocol/SubstrateCryptoClient.js.map +1 -1
  6. package/v0/protocol/SubstrateDelegateProtocol.js +542 -297
  7. package/v0/protocol/SubstrateDelegateProtocol.js.map +1 -1
  8. package/v0/protocol/SubstrateNetwork.js +1 -1
  9. package/v0/protocol/SubstrateNetwork.js.map +1 -1
  10. package/v0/protocol/SubstrateProtocol.js +672 -333
  11. package/v0/protocol/SubstrateProtocol.js.map +1 -1
  12. package/v0/protocol/SubstrateProtocolOptions.js +93 -25
  13. package/v0/protocol/SubstrateProtocolOptions.js.map +1 -1
  14. package/v0/protocol/astar/AstarAddress.js +27 -7
  15. package/v0/protocol/astar/AstarAddress.js.map +1 -1
  16. package/v0/protocol/common/SubstrateAccountController.js +687 -400
  17. package/v0/protocol/common/SubstrateAccountController.js.map +1 -1
  18. package/v0/protocol/common/SubstrateTransactionController.d.ts +1 -0
  19. package/v0/protocol/common/SubstrateTransactionController.js +346 -185
  20. package/v0/protocol/common/SubstrateTransactionController.js.map +1 -1
  21. package/v0/protocol/common/blockexplorer/SubstrateBlockExplorerClient.js +100 -52
  22. package/v0/protocol/common/blockexplorer/SubstrateBlockExplorerClient.js.map +1 -1
  23. package/v0/protocol/common/data/account/SubstrateAccountInfo.js +29 -27
  24. package/v0/protocol/common/data/account/SubstrateAccountInfo.js.map +1 -1
  25. package/v0/protocol/common/data/account/SubstrateAddress.d.ts +1 -0
  26. package/v0/protocol/common/data/account/SubstrateAddress.js +46 -43
  27. package/v0/protocol/common/data/account/SubstrateAddress.js.map +1 -1
  28. package/v0/protocol/common/data/account/SubstrateRegistration.js +56 -50
  29. package/v0/protocol/common/data/account/SubstrateRegistration.js.map +1 -1
  30. package/v0/protocol/common/data/metadata/Metadata.js +25 -24
  31. package/v0/protocol/common/data/metadata/Metadata.js.map +1 -1
  32. package/v0/protocol/common/data/metadata/MetadataVersioned.js +5 -2
  33. package/v0/protocol/common/data/metadata/MetadataVersioned.js.map +1 -1
  34. package/v0/protocol/common/data/metadata/decorator/MetadataDecorator.js +20 -18
  35. package/v0/protocol/common/data/metadata/decorator/MetadataDecorator.js.map +1 -1
  36. package/v0/protocol/common/data/metadata/decorator/constant/SubstrateConstant.d.ts +1 -0
  37. package/v0/protocol/common/data/metadata/decorator/storage/SubstrateStorageEntry.js +237 -89
  38. package/v0/protocol/common/data/metadata/decorator/storage/SubstrateStorageEntry.js.map +1 -1
  39. package/v0/protocol/common/data/metadata/v11/MetadataV11.js +63 -43
  40. package/v0/protocol/common/data/metadata/v11/MetadataV11.js.map +1 -1
  41. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Call.js +51 -30
  42. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Call.js.map +1 -1
  43. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Constant.js +38 -20
  44. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Constant.js.map +1 -1
  45. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Error.js +34 -16
  46. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Error.js.map +1 -1
  47. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Event.js +36 -18
  48. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Event.js.map +1 -1
  49. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Module.js +51 -29
  50. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Module.js.map +1 -1
  51. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11Storage.js +35 -17
  52. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11Storage.js.map +1 -1
  53. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11StorageEntry.js +41 -23
  54. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11StorageEntry.js.map +1 -1
  55. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js +114 -72
  56. package/v0/protocol/common/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js.map +1 -1
  57. package/v0/protocol/common/data/metadata/v12/MetadataV12.js +61 -41
  58. package/v0/protocol/common/data/metadata/v12/MetadataV12.js.map +1 -1
  59. package/v0/protocol/common/data/metadata/v12/module/MetadataV12Module.js +32 -14
  60. package/v0/protocol/common/data/metadata/v12/module/MetadataV12Module.js.map +1 -1
  61. package/v0/protocol/common/data/metadata/v13/MetadataV13.js +61 -41
  62. package/v0/protocol/common/data/metadata/v13/MetadataV13.js.map +1 -1
  63. package/v0/protocol/common/data/metadata/v13/module/MetadataV13Module.js +53 -31
  64. package/v0/protocol/common/data/metadata/v13/module/MetadataV13Module.js.map +1 -1
  65. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13Storage.js +35 -17
  66. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13Storage.js.map +1 -1
  67. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13StorageEntry.js +41 -23
  68. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13StorageEntry.js.map +1 -1
  69. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js +130 -83
  70. package/v0/protocol/common/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js.map +1 -1
  71. package/v0/protocol/common/data/metadata/v14/MetadataV14.js +74 -53
  72. package/v0/protocol/common/data/metadata/v14/MetadataV14.js.map +1 -1
  73. package/v0/protocol/common/data/metadata/v14/MetadataV14Component.js +25 -7
  74. package/v0/protocol/common/data/metadata/v14/MetadataV14Component.js.map +1 -1
  75. package/v0/protocol/common/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js +35 -17
  76. package/v0/protocol/common/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js.map +1 -1
  77. package/v0/protocol/common/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js +34 -16
  78. package/v0/protocol/common/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js.map +1 -1
  79. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Call.js +28 -8
  80. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Call.js.map +1 -1
  81. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Constant.js +37 -19
  82. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Constant.js.map +1 -1
  83. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Error.js +28 -8
  84. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Error.js.map +1 -1
  85. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Event.js +28 -8
  86. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Event.js.map +1 -1
  87. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Pallet.js +48 -30
  88. package/v0/protocol/common/data/metadata/v14/pallet/MetadataV14Pallet.js.map +1 -1
  89. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14Storage.js +34 -16
  90. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14Storage.js.map +1 -1
  91. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js +41 -23
  92. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js.map +1 -1
  93. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js +90 -49
  94. package/v0/protocol/common/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js.map +1 -1
  95. package/v0/protocol/common/data/metadata/v14/registry/MetadataV14PortableRegistry.js +41 -20
  96. package/v0/protocol/common/data/metadata/v14/registry/MetadataV14PortableRegistry.js.map +1 -1
  97. package/v0/protocol/common/data/metadata/v14/registry/MetadataV14PortableType.js +35 -17
  98. package/v0/protocol/common/data/metadata/v14/registry/MetadataV14PortableType.js.map +1 -1
  99. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiField.js +38 -20
  100. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiField.js.map +1 -1
  101. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiType.js +40 -22
  102. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiType.js.map +1 -1
  103. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js +34 -16
  104. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js.map +1 -1
  105. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiVariant.js +39 -21
  106. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14SiVariant.js.map +1 -1
  107. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14TypeDef.js +150 -106
  108. package/v0/protocol/common/data/metadata/v14/registry/si/MetadataV14TypeDef.js.map +1 -1
  109. package/v0/protocol/common/data/scale/SCALEDecoder.d.ts +3 -2
  110. package/v0/protocol/common/data/scale/SCALEDecoder.js +74 -69
  111. package/v0/protocol/common/data/scale/SCALEDecoder.js.map +1 -1
  112. package/v0/protocol/common/data/scale/type/SCALEAccountId.d.ts +1 -0
  113. package/v0/protocol/common/data/scale/type/SCALEAccountId.js +44 -25
  114. package/v0/protocol/common/data/scale/type/SCALEAccountId.js.map +1 -1
  115. package/v0/protocol/common/data/scale/type/SCALEArray.js +45 -27
  116. package/v0/protocol/common/data/scale/type/SCALEArray.js.map +1 -1
  117. package/v0/protocol/common/data/scale/type/SCALEBoolean.js +36 -18
  118. package/v0/protocol/common/data/scale/type/SCALEBoolean.js.map +1 -1
  119. package/v0/protocol/common/data/scale/type/SCALEBytes.d.ts +1 -0
  120. package/v0/protocol/common/data/scale/type/SCALEBytes.js +42 -23
  121. package/v0/protocol/common/data/scale/type/SCALEBytes.js.map +1 -1
  122. package/v0/protocol/common/data/scale/type/SCALEClass.js +28 -8
  123. package/v0/protocol/common/data/scale/type/SCALEClass.js.map +1 -1
  124. package/v0/protocol/common/data/scale/type/SCALECompactInt.d.ts +1 -1
  125. package/v0/protocol/common/data/scale/type/SCALECompactInt.js +73 -54
  126. package/v0/protocol/common/data/scale/type/SCALECompactInt.js.map +1 -1
  127. package/v0/protocol/common/data/scale/type/SCALEData.d.ts +1 -0
  128. package/v0/protocol/common/data/scale/type/SCALEData.js +51 -33
  129. package/v0/protocol/common/data/scale/type/SCALEData.js.map +1 -1
  130. package/v0/protocol/common/data/scale/type/SCALEEnum.js +39 -21
  131. package/v0/protocol/common/data/scale/type/SCALEEnum.js.map +1 -1
  132. package/v0/protocol/common/data/scale/type/SCALEEra.js +68 -46
  133. package/v0/protocol/common/data/scale/type/SCALEEra.js.map +1 -1
  134. package/v0/protocol/common/data/scale/type/SCALEHash.d.ts +1 -0
  135. package/v0/protocol/common/data/scale/type/SCALEHash.js +53 -29
  136. package/v0/protocol/common/data/scale/type/SCALEHash.js.map +1 -1
  137. package/v0/protocol/common/data/scale/type/SCALEInt.d.ts +1 -1
  138. package/v0/protocol/common/data/scale/type/SCALEInt.js +65 -46
  139. package/v0/protocol/common/data/scale/type/SCALEInt.js.map +1 -1
  140. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.d.ts +2 -1
  141. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.js +59 -40
  142. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.js.map +1 -1
  143. package/v0/protocol/common/data/scale/type/SCALEOptional.js +47 -27
  144. package/v0/protocol/common/data/scale/type/SCALEOptional.js.map +1 -1
  145. package/v0/protocol/common/data/scale/type/SCALEString.js +44 -25
  146. package/v0/protocol/common/data/scale/type/SCALEString.js.map +1 -1
  147. package/v0/protocol/common/data/scale/type/SCALETuple.js +40 -22
  148. package/v0/protocol/common/data/scale/type/SCALETuple.js.map +1 -1
  149. package/v0/protocol/common/data/scale/type/SCALEType.js +9 -6
  150. package/v0/protocol/common/data/scale/type/SCALEType.js.map +1 -1
  151. package/v0/protocol/common/data/staking/SubstrateActiveEraInfo.js +12 -11
  152. package/v0/protocol/common/data/staking/SubstrateActiveEraInfo.js.map +1 -1
  153. package/v0/protocol/common/data/staking/SubstrateEraElectionStatus.js +15 -14
  154. package/v0/protocol/common/data/staking/SubstrateEraElectionStatus.js.map +1 -1
  155. package/v0/protocol/common/data/staking/SubstrateEraRewardPoints.js +16 -13
  156. package/v0/protocol/common/data/staking/SubstrateEraRewardPoints.js.map +1 -1
  157. package/v0/protocol/common/data/staking/SubstrateExposure.js +17 -14
  158. package/v0/protocol/common/data/staking/SubstrateExposure.js.map +1 -1
  159. package/v0/protocol/common/data/staking/SubstrateNominationStatus.js +1 -1
  160. package/v0/protocol/common/data/staking/SubstrateNominationStatus.js.map +1 -1
  161. package/v0/protocol/common/data/staking/SubstrateNominations.js +13 -12
  162. package/v0/protocol/common/data/staking/SubstrateNominations.js.map +1 -1
  163. package/v0/protocol/common/data/staking/SubstrateNominatorDetails.d.ts +1 -1
  164. package/v0/protocol/common/data/staking/SubstratePayee.js +1 -1
  165. package/v0/protocol/common/data/staking/SubstratePayee.js.map +1 -1
  166. package/v0/protocol/common/data/staking/SubstrateSlashingSpans.js +14 -13
  167. package/v0/protocol/common/data/staking/SubstrateSlashingSpans.js.map +1 -1
  168. package/v0/protocol/common/data/staking/SubstrateStakingActionType.js +1 -1
  169. package/v0/protocol/common/data/staking/SubstrateStakingActionType.js.map +1 -1
  170. package/v0/protocol/common/data/staking/SubstrateStakingLedger.js +19 -16
  171. package/v0/protocol/common/data/staking/SubstrateStakingLedger.js.map +1 -1
  172. package/v0/protocol/common/data/staking/SubstrateValidatorDetails.d.ts +1 -1
  173. package/v0/protocol/common/data/staking/SubstrateValidatorPrefs.js +10 -9
  174. package/v0/protocol/common/data/staking/SubstrateValidatorPrefs.js.map +1 -1
  175. package/v0/protocol/common/data/transaction/SubstrateSignature.d.ts +1 -0
  176. package/v0/protocol/common/data/transaction/SubstrateSignature.js +53 -30
  177. package/v0/protocol/common/data/transaction/SubstrateSignature.js.map +1 -1
  178. package/v0/protocol/common/data/transaction/SubstrateTransaction.d.ts +1 -1
  179. package/v0/protocol/common/data/transaction/SubstrateTransaction.js +73 -53
  180. package/v0/protocol/common/data/transaction/SubstrateTransaction.js.map +1 -1
  181. package/v0/protocol/common/data/transaction/SubstrateTransactionPayload.js +76 -44
  182. package/v0/protocol/common/data/transaction/SubstrateTransactionPayload.js.map +1 -1
  183. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethod.js +76 -40
  184. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethod.js.map +1 -1
  185. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethodArgs.js +631 -360
  186. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethodArgs.js.map +1 -1
  187. package/v0/protocol/common/node/SubstrateNodeClient.js +533 -226
  188. package/v0/protocol/common/node/SubstrateNodeClient.js.map +1 -1
  189. package/v0/protocol/common/node/supported.d.ts +9 -9
  190. package/v0/protocol/common/node/supported.js +1 -1
  191. package/v0/protocol/common/node/supported.js.map +1 -1
  192. package/v0/protocol/compat/SubstrateCompatAddress.d.ts +2 -1
  193. package/v0/protocol/compat/SubstrateCompatAddress.js +30 -17
  194. package/v0/protocol/compat/SubstrateCompatAddress.js.map +1 -1
  195. package/v0/protocol/compat/SubstrateCompatSignature.d.ts +1 -0
  196. package/v0/protocol/compat/SubstrateCompatSignature.js +5 -4
  197. package/v0/protocol/compat/SubstrateCompatSignature.js.map +1 -1
  198. package/v0/protocol/kusama/KusamaAddress.js +27 -7
  199. package/v0/protocol/kusama/KusamaAddress.js.map +1 -1
  200. package/v0/protocol/moonbeam/MoonbeamAddress.d.ts +1 -0
  201. package/v0/protocol/moonbeam/MoonbeamAddress.js +36 -45
  202. package/v0/protocol/moonbeam/MoonbeamAddress.js.map +1 -1
  203. package/v0/protocol/moonbeam/MoonbeamSignature.d.ts +1 -0
  204. package/v0/protocol/moonbeam/MoonbeamSignature.js +35 -16
  205. package/v0/protocol/moonbeam/MoonbeamSignature.js.map +1 -1
  206. package/v0/protocol/polkadot/PolkadotAddress.js +27 -7
  207. package/v0/protocol/polkadot/PolkadotAddress.js.map +1 -1
  208. package/v0/serializer/validators/transaction-validator.js +83 -30
  209. package/v0/serializer/validators/transaction-validator.js.map +1 -1
  210. package/v0/serializer/validators/validators.js +133 -54
  211. package/v0/serializer/validators/validators.js.map +1 -1
  212. package/v0/utils/sr25519.js +74 -26
  213. package/v0/utils/sr25519.js.map +1 -1
  214. package/v1/block-explorer/subscan/SubscanBlockExplorer.js +61 -12
  215. package/v1/block-explorer/subscan/SubscanBlockExplorer.js.map +1 -1
  216. package/v1/block-explorer/subscan/SubscanBlockExplorerClient.js +103 -55
  217. package/v1/block-explorer/subscan/SubscanBlockExplorerClient.js.map +1 -1
  218. package/v1/controller/account/SubstrateCommonAccountController.js +132 -65
  219. package/v1/controller/account/SubstrateCommonAccountController.js.map +1 -1
  220. package/v1/controller/transaction/SubstrateCommonTransactionController.js +356 -194
  221. package/v1/controller/transaction/SubstrateCommonTransactionController.js.map +1 -1
  222. package/v1/crypto/SubstrateCryptoClient.js +94 -23
  223. package/v1/crypto/SubstrateCryptoClient.js.map +1 -1
  224. package/v1/data/account/SubstrateAccountInfo.js +29 -27
  225. package/v1/data/account/SubstrateAccountInfo.js.map +1 -1
  226. package/v1/data/account/SubstrateRegistration.js +56 -50
  227. package/v1/data/account/SubstrateRegistration.js.map +1 -1
  228. package/v1/data/account/address/SubstrateAddress.d.ts +2 -1
  229. package/v1/data/account/address/SubstrateAddress.js +3 -2
  230. package/v1/data/account/address/SubstrateAddress.js.map +1 -1
  231. package/v1/data/account/address/SubstrateAddressFactory.d.ts +3 -2
  232. package/v1/data/account/address/SubstrateAddressFactory.js +23 -16
  233. package/v1/data/account/address/SubstrateAddressFactory.js.map +1 -1
  234. package/v1/data/account/address/SubstrateEthAddress.d.ts +1 -0
  235. package/v1/data/account/address/SubstrateEthAddress.js +39 -48
  236. package/v1/data/account/address/SubstrateEthAddress.js.map +1 -1
  237. package/v1/data/account/address/SubstrateSS58Address.d.ts +1 -0
  238. package/v1/data/account/address/SubstrateSS58Address.js +50 -47
  239. package/v1/data/account/address/SubstrateSS58Address.js.map +1 -1
  240. package/v1/data/metadata/Metadata.js +25 -24
  241. package/v1/data/metadata/Metadata.js.map +1 -1
  242. package/v1/data/metadata/MetadataVersioned.js +5 -2
  243. package/v1/data/metadata/MetadataVersioned.js.map +1 -1
  244. package/v1/data/metadata/decorator/MetadataDecorator.js +20 -18
  245. package/v1/data/metadata/decorator/MetadataDecorator.js.map +1 -1
  246. package/v1/data/metadata/decorator/constant/SubstrateConstant.d.ts +1 -0
  247. package/v1/data/metadata/decorator/storage/SubstrateStorageEntry.js +237 -89
  248. package/v1/data/metadata/decorator/storage/SubstrateStorageEntry.js.map +1 -1
  249. package/v1/data/metadata/v11/MetadataV11.js +63 -43
  250. package/v1/data/metadata/v11/MetadataV11.js.map +1 -1
  251. package/v1/data/metadata/v11/module/MetadataV11Call.js +51 -30
  252. package/v1/data/metadata/v11/module/MetadataV11Call.js.map +1 -1
  253. package/v1/data/metadata/v11/module/MetadataV11Constant.js +38 -20
  254. package/v1/data/metadata/v11/module/MetadataV11Constant.js.map +1 -1
  255. package/v1/data/metadata/v11/module/MetadataV11Error.js +34 -16
  256. package/v1/data/metadata/v11/module/MetadataV11Error.js.map +1 -1
  257. package/v1/data/metadata/v11/module/MetadataV11Event.js +36 -18
  258. package/v1/data/metadata/v11/module/MetadataV11Event.js.map +1 -1
  259. package/v1/data/metadata/v11/module/MetadataV11Module.js +51 -29
  260. package/v1/data/metadata/v11/module/MetadataV11Module.js.map +1 -1
  261. package/v1/data/metadata/v11/module/storage/MetadataV11Storage.js +35 -17
  262. package/v1/data/metadata/v11/module/storage/MetadataV11Storage.js.map +1 -1
  263. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntry.js +41 -23
  264. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntry.js.map +1 -1
  265. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js +114 -72
  266. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js.map +1 -1
  267. package/v1/data/metadata/v12/MetadataV12.js +61 -41
  268. package/v1/data/metadata/v12/MetadataV12.js.map +1 -1
  269. package/v1/data/metadata/v12/module/MetadataV12Module.js +32 -14
  270. package/v1/data/metadata/v12/module/MetadataV12Module.js.map +1 -1
  271. package/v1/data/metadata/v13/MetadataV13.js +61 -41
  272. package/v1/data/metadata/v13/MetadataV13.js.map +1 -1
  273. package/v1/data/metadata/v13/module/MetadataV13Module.js +53 -31
  274. package/v1/data/metadata/v13/module/MetadataV13Module.js.map +1 -1
  275. package/v1/data/metadata/v13/module/storage/MetadataV13Storage.js +35 -17
  276. package/v1/data/metadata/v13/module/storage/MetadataV13Storage.js.map +1 -1
  277. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntry.js +41 -23
  278. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntry.js.map +1 -1
  279. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js +130 -83
  280. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js.map +1 -1
  281. package/v1/data/metadata/v14/MetadataV14.js +74 -53
  282. package/v1/data/metadata/v14/MetadataV14.js.map +1 -1
  283. package/v1/data/metadata/v14/MetadataV14Component.js +25 -7
  284. package/v1/data/metadata/v14/MetadataV14Component.js.map +1 -1
  285. package/v1/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js +35 -17
  286. package/v1/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js.map +1 -1
  287. package/v1/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js +34 -16
  288. package/v1/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js.map +1 -1
  289. package/v1/data/metadata/v14/pallet/MetadataV14Call.js +28 -8
  290. package/v1/data/metadata/v14/pallet/MetadataV14Call.js.map +1 -1
  291. package/v1/data/metadata/v14/pallet/MetadataV14Constant.js +37 -19
  292. package/v1/data/metadata/v14/pallet/MetadataV14Constant.js.map +1 -1
  293. package/v1/data/metadata/v14/pallet/MetadataV14Error.js +28 -8
  294. package/v1/data/metadata/v14/pallet/MetadataV14Error.js.map +1 -1
  295. package/v1/data/metadata/v14/pallet/MetadataV14Event.js +28 -8
  296. package/v1/data/metadata/v14/pallet/MetadataV14Event.js.map +1 -1
  297. package/v1/data/metadata/v14/pallet/MetadataV14Pallet.js +48 -30
  298. package/v1/data/metadata/v14/pallet/MetadataV14Pallet.js.map +1 -1
  299. package/v1/data/metadata/v14/pallet/storage/MetadataV14Storage.js +34 -16
  300. package/v1/data/metadata/v14/pallet/storage/MetadataV14Storage.js.map +1 -1
  301. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js +41 -23
  302. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js.map +1 -1
  303. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js +90 -49
  304. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js.map +1 -1
  305. package/v1/data/metadata/v14/registry/MetadataV14PortableRegistry.js +41 -20
  306. package/v1/data/metadata/v14/registry/MetadataV14PortableRegistry.js.map +1 -1
  307. package/v1/data/metadata/v14/registry/MetadataV14PortableType.js +35 -17
  308. package/v1/data/metadata/v14/registry/MetadataV14PortableType.js.map +1 -1
  309. package/v1/data/metadata/v14/registry/si/MetadataV14SiField.js +38 -20
  310. package/v1/data/metadata/v14/registry/si/MetadataV14SiField.js.map +1 -1
  311. package/v1/data/metadata/v14/registry/si/MetadataV14SiType.js +40 -22
  312. package/v1/data/metadata/v14/registry/si/MetadataV14SiType.js.map +1 -1
  313. package/v1/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js +34 -16
  314. package/v1/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js.map +1 -1
  315. package/v1/data/metadata/v14/registry/si/MetadataV14SiVariant.js +39 -21
  316. package/v1/data/metadata/v14/registry/si/MetadataV14SiVariant.js.map +1 -1
  317. package/v1/data/metadata/v14/registry/si/MetadataV14TypeDef.js +150 -106
  318. package/v1/data/metadata/v14/registry/si/MetadataV14TypeDef.js.map +1 -1
  319. package/v1/data/scale/SCALEDecoder.d.ts +3 -2
  320. package/v1/data/scale/SCALEDecoder.js +80 -69
  321. package/v1/data/scale/SCALEDecoder.js.map +1 -1
  322. package/v1/data/scale/type/SCALEAccountId.d.ts +1 -0
  323. package/v1/data/scale/type/SCALEAccountId.js +46 -27
  324. package/v1/data/scale/type/SCALEAccountId.js.map +1 -1
  325. package/v1/data/scale/type/SCALEArray.js +45 -27
  326. package/v1/data/scale/type/SCALEArray.js.map +1 -1
  327. package/v1/data/scale/type/SCALEBoolean.js +36 -18
  328. package/v1/data/scale/type/SCALEBoolean.js.map +1 -1
  329. package/v1/data/scale/type/SCALEBytes.d.ts +1 -0
  330. package/v1/data/scale/type/SCALEBytes.js +42 -23
  331. package/v1/data/scale/type/SCALEBytes.js.map +1 -1
  332. package/v1/data/scale/type/SCALEClass.js +28 -8
  333. package/v1/data/scale/type/SCALEClass.js.map +1 -1
  334. package/v1/data/scale/type/SCALECompactInt.d.ts +1 -1
  335. package/v1/data/scale/type/SCALECompactInt.js +73 -54
  336. package/v1/data/scale/type/SCALECompactInt.js.map +1 -1
  337. package/v1/data/scale/type/SCALEData.d.ts +1 -0
  338. package/v1/data/scale/type/SCALEData.js +51 -33
  339. package/v1/data/scale/type/SCALEData.js.map +1 -1
  340. package/v1/data/scale/type/SCALEEnum.js +39 -21
  341. package/v1/data/scale/type/SCALEEnum.js.map +1 -1
  342. package/v1/data/scale/type/SCALEEra.js +68 -46
  343. package/v1/data/scale/type/SCALEEra.js.map +1 -1
  344. package/v1/data/scale/type/SCALEHash.d.ts +1 -0
  345. package/v1/data/scale/type/SCALEHash.js +53 -29
  346. package/v1/data/scale/type/SCALEHash.js.map +1 -1
  347. package/v1/data/scale/type/SCALEInt.d.ts +1 -1
  348. package/v1/data/scale/type/SCALEInt.js +65 -46
  349. package/v1/data/scale/type/SCALEInt.js.map +1 -1
  350. package/v1/data/scale/type/SCALEMultiAddress.d.ts +2 -1
  351. package/v1/data/scale/type/SCALEMultiAddress.js +59 -40
  352. package/v1/data/scale/type/SCALEMultiAddress.js.map +1 -1
  353. package/v1/data/scale/type/SCALEOptional.js +47 -27
  354. package/v1/data/scale/type/SCALEOptional.js.map +1 -1
  355. package/v1/data/scale/type/SCALEString.js +44 -25
  356. package/v1/data/scale/type/SCALEString.js.map +1 -1
  357. package/v1/data/scale/type/SCALETuple.js +40 -22
  358. package/v1/data/scale/type/SCALETuple.js.map +1 -1
  359. package/v1/data/scale/type/SCALEType.js +9 -6
  360. package/v1/data/scale/type/SCALEType.js.map +1 -1
  361. package/v1/data/transaction/SubstrateSignature.d.ts +1 -0
  362. package/v1/data/transaction/SubstrateSignature.js +61 -36
  363. package/v1/data/transaction/SubstrateSignature.js.map +1 -1
  364. package/v1/data/transaction/SubstrateTransaction.d.ts +2 -2
  365. package/v1/data/transaction/SubstrateTransaction.js +87 -66
  366. package/v1/data/transaction/SubstrateTransaction.js.map +1 -1
  367. package/v1/data/transaction/SubstrateTransactionPayload.js +114 -81
  368. package/v1/data/transaction/SubstrateTransactionPayload.js.map +1 -1
  369. package/v1/data/transaction/method/SubstrateTransactionMethod.js +76 -40
  370. package/v1/data/transaction/method/SubstrateTransactionMethod.js.map +1 -1
  371. package/v1/data/transaction/method/SubstrateTransactionMethodArgs.js +65 -35
  372. package/v1/data/transaction/method/SubstrateTransactionMethodArgs.js.map +1 -1
  373. package/v1/index.js +38 -38
  374. package/v1/index.js.map +1 -1
  375. package/v1/node/SubstrateCommonNodeClient.d.ts +12 -12
  376. package/v1/node/SubstrateCommonNodeClient.js +357 -159
  377. package/v1/node/SubstrateCommonNodeClient.js.map +1 -1
  378. package/v1/protocol/SubstrateProtocol.js +388 -182
  379. package/v1/protocol/SubstrateProtocol.js.map +1 -1
  380. package/v1/protocol/SubstrateStakingProtocol.js +82 -15
  381. package/v1/protocol/SubstrateStakingProtocol.js.map +1 -1
  382. package/v1/serializer/v3/schemas/converter/transaction-converter.js +20 -8
  383. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  384. package/v1/serializer/v3/validators/transaction-validator.js +63 -15
  385. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  386. package/v1/serializer/v3/validators/validators.js +129 -48
  387. package/v1/serializer/v3/validators/validators.js.map +1 -1
  388. package/v1/types/configuration.d.ts +6 -6
  389. package/v1/types/crypto.d.ts +1 -1
  390. package/v1/utils/keys.js +5 -4
  391. package/v1/utils/keys.js.map +1 -1
  392. package/v1/utils/protocol.js +15 -14
  393. package/v1/utils/protocol.js.map +1 -1
  394. package/v1/utils/signature.js +4 -3
  395. package/v1/utils/signature.js.map +1 -1
@@ -1,40 +1,81 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
40
  };
5
41
  Object.defineProperty(exports, "__esModule", { value: true });
6
42
  exports.SubstrateNodeClient = void 0;
7
- const RPCBody_1 = require("@airgap/coinlib-core/data/RPCBody");
8
- const axios_0_19_0_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0"));
9
- const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
10
- const cache_1 = require("@airgap/coinlib-core/utils/cache");
11
- const errors_1 = require("@airgap/coinlib-core/errors");
12
- const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
13
- const hex_1 = require("@airgap/coinlib-core/utils/hex");
14
- const SubstrateAccountInfo_1 = require("../data/account/SubstrateAccountInfo");
15
- const SubstrateRegistration_1 = require("../data/account/SubstrateRegistration");
16
- const Metadata_1 = require("../data/metadata/Metadata");
17
- const SCALEAccountId_1 = require("../data/scale/type/SCALEAccountId");
18
- const SCALEArray_1 = require("../data/scale/type/SCALEArray");
19
- const SCALECompactInt_1 = require("../data/scale/type/SCALECompactInt");
20
- const SCALEData_1 = require("../data/scale/type/SCALEData");
21
- const SCALEEnum_1 = require("../data/scale/type/SCALEEnum");
22
- const SCALEInt_1 = require("../data/scale/type/SCALEInt");
23
- const SCALETuple_1 = require("../data/scale/type/SCALETuple");
24
- const SubstrateActiveEraInfo_1 = require("../data/staking/SubstrateActiveEraInfo");
25
- const SubstrateEraElectionStatus_1 = require("../data/staking/SubstrateEraElectionStatus");
26
- const SubstrateEraRewardPoints_1 = require("../data/staking/SubstrateEraRewardPoints");
27
- const SubstrateExposure_1 = require("../data/staking/SubstrateExposure");
28
- const SubstrateNominations_1 = require("../data/staking/SubstrateNominations");
29
- const SubstratePayee_1 = require("../data/staking/SubstratePayee");
30
- const SubstrateSlashingSpans_1 = require("../data/staking/SubstrateSlashingSpans");
31
- const SubstrateStakingLedger_1 = require("../data/staking/SubstrateStakingLedger");
32
- const SubstrateValidatorPrefs_1 = require("../data/staking/SubstrateValidatorPrefs");
33
- const supported_1 = require("./supported");
34
- const CACHE_DEFAULT_EXPIRATION_TIME = 3000; // 3s
35
- const MAX_RETRIES = 3;
36
- class SubstrateNodeClient {
37
- constructor(network, baseURL, storageEntries = supported_1.supportedStorageEntries, calls = supported_1.supportedCalls, constants = supported_1.supportedConstants, callEndpoints = supported_1.supportedCallEndpoints, cache = new cache_1.Cache(CACHE_DEFAULT_EXPIRATION_TIME)) {
43
+ var RPCBody_1 = require("@airgap/coinlib-core/data/RPCBody");
44
+ var axios_0_19_0_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0"));
45
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
46
+ var cache_1 = require("@airgap/coinlib-core/utils/cache");
47
+ var errors_1 = require("@airgap/coinlib-core/errors");
48
+ var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
49
+ var hex_1 = require("@airgap/coinlib-core/utils/hex");
50
+ var SubstrateAccountInfo_1 = require("../data/account/SubstrateAccountInfo");
51
+ var SubstrateRegistration_1 = require("../data/account/SubstrateRegistration");
52
+ var Metadata_1 = require("../data/metadata/Metadata");
53
+ var SCALEAccountId_1 = require("../data/scale/type/SCALEAccountId");
54
+ var SCALEArray_1 = require("../data/scale/type/SCALEArray");
55
+ var SCALECompactInt_1 = require("../data/scale/type/SCALECompactInt");
56
+ var SCALEData_1 = require("../data/scale/type/SCALEData");
57
+ var SCALEEnum_1 = require("../data/scale/type/SCALEEnum");
58
+ var SCALEInt_1 = require("../data/scale/type/SCALEInt");
59
+ var SCALETuple_1 = require("../data/scale/type/SCALETuple");
60
+ var SubstrateActiveEraInfo_1 = require("../data/staking/SubstrateActiveEraInfo");
61
+ var SubstrateEraElectionStatus_1 = require("../data/staking/SubstrateEraElectionStatus");
62
+ var SubstrateEraRewardPoints_1 = require("../data/staking/SubstrateEraRewardPoints");
63
+ var SubstrateExposure_1 = require("../data/staking/SubstrateExposure");
64
+ var SubstrateNominations_1 = require("../data/staking/SubstrateNominations");
65
+ var SubstratePayee_1 = require("../data/staking/SubstratePayee");
66
+ var SubstrateSlashingSpans_1 = require("../data/staking/SubstrateSlashingSpans");
67
+ var SubstrateStakingLedger_1 = require("../data/staking/SubstrateStakingLedger");
68
+ var SubstrateValidatorPrefs_1 = require("../data/staking/SubstrateValidatorPrefs");
69
+ var supported_1 = require("./supported");
70
+ var CACHE_DEFAULT_EXPIRATION_TIME = 3000; // 3s
71
+ var MAX_RETRIES = 3;
72
+ var SubstrateNodeClient = /** @class */ (function () {
73
+ function SubstrateNodeClient(network, baseURL, storageEntries, calls, constants, callEndpoints, cache) {
74
+ if (storageEntries === void 0) { storageEntries = supported_1.supportedStorageEntries; }
75
+ if (calls === void 0) { calls = supported_1.supportedCalls; }
76
+ if (constants === void 0) { constants = supported_1.supportedConstants; }
77
+ if (callEndpoints === void 0) { callEndpoints = supported_1.supportedCallEndpoints; }
78
+ if (cache === void 0) { cache = new cache_1.Cache(CACHE_DEFAULT_EXPIRATION_TIME); }
38
79
  this.network = network;
39
80
  this.baseURL = baseURL;
40
81
  this.storageEntries = storageEntries;
@@ -45,209 +86,475 @@ class SubstrateNodeClient {
45
86
  this.lastFees = new Map();
46
87
  this.initApiPromise = null;
47
88
  }
48
- async getAccountInfo(address) {
49
- return this.fromStorage('System', 'Account', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SubstrateAccountInfo_1.SubstrateAccountInfo.decode(this.network, this.runtimeVersion, item) : null);
50
- }
51
- async getExistentialDeposit() {
52
- return this.getConstant('Balances', 'ExistentialDeposit').then((constant) => SCALEInt_1.SCALEInt.decode(constant).decoded.value);
53
- }
54
- async getTransactionMetadata(type) {
55
- const [methodName, callName] = this.callEndpoints.get(type) || [null, null];
56
- let call = null;
57
- if (methodName && callName) {
58
- call = await this.getCall(methodName, callName);
59
- }
60
- return call ? call : Promise.reject('Could not find requested transaction.');
61
- }
62
- async getTransferFeeEstimate(transaction) {
63
- return this.send('payment', 'queryInfo', [(0, hex_1.bytesToHex)(transaction)]).then((result) => (result ? new bignumber_1.default(result.partialFee) : null));
64
- }
65
- saveLastFee(type, fee) {
89
+ SubstrateNodeClient.prototype.getAccountInfo = function (address) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var _this = this;
92
+ return __generator(this, function (_a) {
93
+ return [2 /*return*/, this.fromStorage('System', 'Account', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
94
+ return item ? SubstrateAccountInfo_1.SubstrateAccountInfo.decode(_this.network, _this.runtimeVersion, item) : null;
95
+ })];
96
+ });
97
+ });
98
+ };
99
+ SubstrateNodeClient.prototype.getExistentialDeposit = function () {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ return __generator(this, function (_a) {
102
+ return [2 /*return*/, this.getConstant('Balances', 'ExistentialDeposit').then(function (constant) { return SCALEInt_1.SCALEInt.decode(constant).decoded.value; })];
103
+ });
104
+ });
105
+ };
106
+ SubstrateNodeClient.prototype.getTransactionMetadata = function (type) {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var _a, methodName, callName, call;
109
+ return __generator(this, function (_b) {
110
+ switch (_b.label) {
111
+ case 0:
112
+ _a = this.callEndpoints.get(type) || [null, null], methodName = _a[0], callName = _a[1];
113
+ call = null;
114
+ if (!(methodName && callName)) return [3 /*break*/, 2];
115
+ return [4 /*yield*/, this.getCall(methodName, callName)];
116
+ case 1:
117
+ call = _b.sent();
118
+ _b.label = 2;
119
+ case 2: return [2 /*return*/, call ? call : Promise.reject('Could not find requested transaction.')];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ SubstrateNodeClient.prototype.getTransferFeeEstimate = function (transaction) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ return [2 /*return*/, this.send('payment', 'queryInfo', [(0, hex_1.bytesToHex)(transaction)]).then(function (result) { return (result ? new bignumber_1.default(result.partialFee) : null); })];
128
+ });
129
+ });
130
+ };
131
+ SubstrateNodeClient.prototype.saveLastFee = function (type, fee) {
66
132
  this.lastFees.set(type, fee);
67
- }
68
- getSavedLastFee(type, defaultValue = 'null') {
69
- let fee = this.lastFees.get(type) || null;
133
+ };
134
+ SubstrateNodeClient.prototype.getSavedLastFee = function (type, defaultValue) {
135
+ if (defaultValue === void 0) { defaultValue = 'null'; }
136
+ var fee = this.lastFees.get(type) || null;
70
137
  if (!fee && defaultValue === 'largest') {
71
- const savedFees = Array.from(this.lastFees.values());
72
- fee = savedFees.length > 0 ? bignumber_1.default.max(...savedFees) : null;
138
+ var savedFees = Array.from(this.lastFees.values());
139
+ fee = savedFees.length > 0 ? bignumber_1.default.max.apply(bignumber_1.default, savedFees) : null;
73
140
  }
74
141
  return fee;
75
- }
76
- async getFirstBlockHash() {
77
- return this.getBlockHash(0);
78
- }
79
- async getLastBlockHash() {
80
- return this.getBlockHash();
81
- }
82
- async getCurrentHeight() {
83
- return this.send('chain', 'getBlock').then((result) => new bignumber_1.default((0, hex_1.stripHexPrefix)(result.block.header.number), 16));
84
- }
85
- async getCurrentEraIndex() {
86
- return this.fromStorage('Staking', 'CurrentEra').then((item) => (item ? SCALEInt_1.SCALEInt.decode(item).decoded.value : null));
87
- }
88
- async getRuntimeVersion() {
89
- return this.send('state', 'getRuntimeVersion').catch(() => null);
90
- }
91
- async getBonded(address) {
92
- return this.fromStorage('Staking', 'Bonded', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SCALEAccountId_1.SCALEAccountId.decode(this.network, item).decoded.address : null);
93
- }
94
- async getNominations(address) {
95
- return this.fromStorage('Staking', 'Nominators', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SubstrateNominations_1.SubstrateNominations.decode(this.network, this.runtimeVersion, item) : null);
96
- }
97
- async getRewardPoints(eraIndex) {
98
- return this.fromStorage('Staking', 'ErasRewardPoints', SCALEInt_1.SCALEInt.from(eraIndex, 32)).then((item) => item ? SubstrateEraRewardPoints_1.SubstrateEraRewardPoints.decode(this.network, this.runtimeVersion, item) : null);
99
- }
100
- async getValidatorReward(eraIndex) {
101
- return this.fromStorage('Staking', 'ErasValidatorReward', SCALEInt_1.SCALEInt.from(eraIndex, 32)).then((item) => item ? SCALEInt_1.SCALEInt.decode(item).decoded.value : null);
102
- }
103
- async getStakersClipped(eraIndex, validator) {
104
- return this.fromStorage('Staking', 'ErasStakersClipped', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(validator, this.network)).then((item) => (item ? SubstrateExposure_1.SubstrateExposure.decode(this.network, this.runtimeVersion, item) : null));
105
- }
106
- async getRewardDestination(address) {
107
- return this.fromStorage('Staking', 'Payee', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SCALEEnum_1.SCALEEnum.decode(item, (hex) => SubstratePayee_1.SubstratePayee[SubstratePayee_1.SubstratePayee[hex]]).decoded.value : null);
108
- }
109
- async getStakingLedger(address) {
110
- return this.fromStorage('Staking', 'Ledger', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SubstrateStakingLedger_1.SubstrateStakingLedger.decode(this.network, this.runtimeVersion, item) : null);
111
- }
112
- async getValidators() {
113
- return this.fromStorage('Session', 'Validators').then((items) => items
114
- ? SCALEArray_1.SCALEArray.decode(this.network, this.runtimeVersion, items, (network, _, hex) => SCALEAccountId_1.SCALEAccountId.decode(network, hex)).decoded.elements.map((encoded) => encoded.address)
115
- : null);
116
- }
117
- async getValidatorExposure(eraIndex, address) {
118
- return this.fromStorage('Staking', 'ErasStakers', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => (item ? SubstrateExposure_1.SubstrateExposure.decode(this.network, this.runtimeVersion, item) : null));
119
- }
120
- async getElectionStatus() {
121
- return this.fromStorage('Staking', 'EraElectionStatus').then((item) => item ? SubstrateEraElectionStatus_1.SubstrateEraElectionStatus.decode(this.network, this.runtimeVersion, item) : null);
122
- }
123
- async getIdentityOf(address) {
124
- return this.fromStorage('Identity', 'IdentityOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SubstrateRegistration_1.SubstrateRegistration.decode(this.network, this.runtimeVersion, item) : null);
125
- }
126
- async getSuperOf(address) {
127
- return this.fromStorage('Identity', 'SuperOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item
128
- ? SCALETuple_1.SCALETuple.decode(this.network, this.runtimeVersion, item, (network, _, hex) => SCALEAccountId_1.SCALEAccountId.decode(network, hex), (_network, _runtimeVersion, hex) => SCALEData_1.SCALEData.decode(hex)).decoded
129
- : null);
130
- }
131
- async getSubsOf(address) {
132
- return this.fromStorage('Identity', 'SubsOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item
133
- ? SCALETuple_1.SCALETuple.decode(this.network, this.runtimeVersion, item, (_network, _runtimeVersion, hex) => SCALECompactInt_1.SCALECompactInt.decode(hex), (network, _, hex) => SCALEArray_1.SCALEArray.decode(network, _, hex, (innerNetwork, _, innerHex) => SCALEAccountId_1.SCALEAccountId.decode(innerNetwork, innerHex))).decoded
134
- : null);
135
- }
136
- async getValidatorPrefs(eraIndex, address) {
137
- return this.fromStorage('Staking', 'ErasValidatorPrefs', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => (item ? SubstrateValidatorPrefs_1.SubstrateValidatorPrefs.decode(this.network, this.runtimeVersion, item) : null));
138
- }
139
- async getExpectedEraDuration() {
140
- const constants = await Promise.all([
141
- this.getConstant('Babe', 'ExpectedBlockTime'),
142
- this.getConstant('Babe', 'EpochDuration'),
143
- this.getConstant('Staking', 'SessionsPerEra')
144
- ]).then((constants) => constants.map((constant) => (constant ? SCALEInt_1.SCALEInt.decode(constant).decoded.value : null)));
145
- if (constants.some((constant) => constant === null)) {
146
- return null;
147
- }
148
- const expectedBlockTime = constants[0];
149
- const epochDuration = constants[1];
150
- const sessionsPerEra = constants[2];
151
- return expectedBlockTime.multipliedBy(epochDuration).multipliedBy(sessionsPerEra);
152
- }
153
- async getActiveEraInfo() {
154
- return this.fromStorage('Staking', 'ActiveEra').then((item) => item ? SubstrateActiveEraInfo_1.SubstrateActiveEraInfo.decode(this.network, this.runtimeVersion, item) : null);
155
- }
156
- async getSlashingSpan(address) {
157
- return this.fromStorage('Staking', 'SlashingSpans', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then((item) => item ? SubstrateSlashingSpans_1.SubstrateSlashingSpans.decode(this.network, this.runtimeVersion, item) : null);
158
- }
159
- async submitTransaction(encoded) {
160
- return this.send('author', 'submitExtrinsic', [encoded], { allowCache: false });
161
- }
162
- async getBlockHash(blockNumber) {
163
- return this.send('chain', 'getBlockHash', blockNumber !== undefined ? [(0, hex_1.toHexString)(blockNumber)] : []);
164
- }
165
- async fromStorage(moduleName, entryName, ...args) {
166
- await this.initApi();
167
- const storageEntry = this.metadata?.storageEntry(moduleName, entryName);
168
- if (!storageEntry) {
169
- console.warn(`Could not find requested item: ${moduleName} ${entryName}`);
170
- return null;
171
- }
172
- const hash = await storageEntry.hash(...args);
173
- const result = await this.send('state', 'getStorage', [hash]);
174
- return result;
175
- }
176
- async getCall(moduleName, callName) {
177
- await this.initApi();
178
- const call = this.metadata?.call(moduleName, callName);
179
- return call ? call : Promise.reject(`Could not find requested item: ${moduleName} ${callName}`);
180
- }
181
- async getConstant(moduleName, constantName) {
182
- await this.initApi();
183
- const constant = this.metadata?.constant(moduleName, constantName);
184
- return constant ? constant.value.toString('hex') : Promise.reject(`Could not find requested item: ${moduleName} ${constantName}`);
185
- }
186
- async initApi() {
187
- if (!this.initApiPromise) {
188
- const initApiPromise = new Promise(async (resolve, reject) => {
189
- const [metadataEncoded, runtimeVersion] = await Promise.all([this.send('state', 'getMetadata'), this.getRuntimeVersion()]);
190
- if (!runtimeVersion) {
191
- reject('Could not fetch runtime version from the node');
142
+ };
143
+ SubstrateNodeClient.prototype.getFirstBlockHash = function () {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ return __generator(this, function (_a) {
146
+ return [2 /*return*/, this.getBlockHash(0)];
147
+ });
148
+ });
149
+ };
150
+ SubstrateNodeClient.prototype.getLastBlockHash = function () {
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ return __generator(this, function (_a) {
153
+ return [2 /*return*/, this.getBlockHash()];
154
+ });
155
+ });
156
+ };
157
+ SubstrateNodeClient.prototype.getCurrentHeight = function () {
158
+ return __awaiter(this, void 0, void 0, function () {
159
+ return __generator(this, function (_a) {
160
+ return [2 /*return*/, this.send('chain', 'getBlock').then(function (result) { return new bignumber_1.default((0, hex_1.stripHexPrefix)(result.block.header.number), 16); })];
161
+ });
162
+ });
163
+ };
164
+ SubstrateNodeClient.prototype.getCurrentEraIndex = function () {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ return __generator(this, function (_a) {
167
+ return [2 /*return*/, this.fromStorage('Staking', 'CurrentEra').then(function (item) { return (item ? SCALEInt_1.SCALEInt.decode(item).decoded.value : null); })];
168
+ });
169
+ });
170
+ };
171
+ SubstrateNodeClient.prototype.getRuntimeVersion = function () {
172
+ return __awaiter(this, void 0, void 0, function () {
173
+ return __generator(this, function (_a) {
174
+ return [2 /*return*/, this.send('state', 'getRuntimeVersion').catch(function () { return null; })];
175
+ });
176
+ });
177
+ };
178
+ SubstrateNodeClient.prototype.getBonded = function (address) {
179
+ return __awaiter(this, void 0, void 0, function () {
180
+ var _this = this;
181
+ return __generator(this, function (_a) {
182
+ return [2 /*return*/, this.fromStorage('Staking', 'Bonded', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
183
+ return item ? SCALEAccountId_1.SCALEAccountId.decode(_this.network, item).decoded.address : null;
184
+ })];
185
+ });
186
+ });
187
+ };
188
+ SubstrateNodeClient.prototype.getNominations = function (address) {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var _this = this;
191
+ return __generator(this, function (_a) {
192
+ return [2 /*return*/, this.fromStorage('Staking', 'Nominators', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
193
+ return item ? SubstrateNominations_1.SubstrateNominations.decode(_this.network, _this.runtimeVersion, item) : null;
194
+ })];
195
+ });
196
+ });
197
+ };
198
+ SubstrateNodeClient.prototype.getRewardPoints = function (eraIndex) {
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var _this = this;
201
+ return __generator(this, function (_a) {
202
+ return [2 /*return*/, this.fromStorage('Staking', 'ErasRewardPoints', SCALEInt_1.SCALEInt.from(eraIndex, 32)).then(function (item) {
203
+ return item ? SubstrateEraRewardPoints_1.SubstrateEraRewardPoints.decode(_this.network, _this.runtimeVersion, item) : null;
204
+ })];
205
+ });
206
+ });
207
+ };
208
+ SubstrateNodeClient.prototype.getValidatorReward = function (eraIndex) {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ return __generator(this, function (_a) {
211
+ return [2 /*return*/, this.fromStorage('Staking', 'ErasValidatorReward', SCALEInt_1.SCALEInt.from(eraIndex, 32)).then(function (item) {
212
+ return item ? SCALEInt_1.SCALEInt.decode(item).decoded.value : null;
213
+ })];
214
+ });
215
+ });
216
+ };
217
+ SubstrateNodeClient.prototype.getStakersClipped = function (eraIndex, validator) {
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ var _this = this;
220
+ return __generator(this, function (_a) {
221
+ return [2 /*return*/, this.fromStorage('Staking', 'ErasStakersClipped', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(validator, this.network)).then(function (item) { return (item ? SubstrateExposure_1.SubstrateExposure.decode(_this.network, _this.runtimeVersion, item) : null); })];
222
+ });
223
+ });
224
+ };
225
+ SubstrateNodeClient.prototype.getRewardDestination = function (address) {
226
+ return __awaiter(this, void 0, void 0, function () {
227
+ return __generator(this, function (_a) {
228
+ return [2 /*return*/, this.fromStorage('Staking', 'Payee', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
229
+ return item ? SCALEEnum_1.SCALEEnum.decode(item, function (hex) { return SubstratePayee_1.SubstratePayee[SubstratePayee_1.SubstratePayee[hex]]; }).decoded.value : null;
230
+ })];
231
+ });
232
+ });
233
+ };
234
+ SubstrateNodeClient.prototype.getStakingLedger = function (address) {
235
+ return __awaiter(this, void 0, void 0, function () {
236
+ var _this = this;
237
+ return __generator(this, function (_a) {
238
+ return [2 /*return*/, this.fromStorage('Staking', 'Ledger', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
239
+ return item ? SubstrateStakingLedger_1.SubstrateStakingLedger.decode(_this.network, _this.runtimeVersion, item) : null;
240
+ })];
241
+ });
242
+ });
243
+ };
244
+ SubstrateNodeClient.prototype.getValidators = function () {
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var _this = this;
247
+ return __generator(this, function (_a) {
248
+ return [2 /*return*/, this.fromStorage('Session', 'Validators').then(function (items) {
249
+ return items
250
+ ? SCALEArray_1.SCALEArray.decode(_this.network, _this.runtimeVersion, items, function (network, _, hex) {
251
+ return SCALEAccountId_1.SCALEAccountId.decode(network, hex);
252
+ }).decoded.elements.map(function (encoded) { return encoded.address; })
253
+ : null;
254
+ })];
255
+ });
256
+ });
257
+ };
258
+ SubstrateNodeClient.prototype.getValidatorExposure = function (eraIndex, address) {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var _this = this;
261
+ return __generator(this, function (_a) {
262
+ return [2 /*return*/, this.fromStorage('Staking', 'ErasStakers', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) { return (item ? SubstrateExposure_1.SubstrateExposure.decode(_this.network, _this.runtimeVersion, item) : null); })];
263
+ });
264
+ });
265
+ };
266
+ SubstrateNodeClient.prototype.getElectionStatus = function () {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var _this = this;
269
+ return __generator(this, function (_a) {
270
+ return [2 /*return*/, this.fromStorage('Staking', 'EraElectionStatus').then(function (item) {
271
+ return item ? SubstrateEraElectionStatus_1.SubstrateEraElectionStatus.decode(_this.network, _this.runtimeVersion, item) : null;
272
+ })];
273
+ });
274
+ });
275
+ };
276
+ SubstrateNodeClient.prototype.getIdentityOf = function (address) {
277
+ return __awaiter(this, void 0, void 0, function () {
278
+ var _this = this;
279
+ return __generator(this, function (_a) {
280
+ return [2 /*return*/, this.fromStorage('Identity', 'IdentityOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
281
+ return item ? SubstrateRegistration_1.SubstrateRegistration.decode(_this.network, _this.runtimeVersion, item) : null;
282
+ })];
283
+ });
284
+ });
285
+ };
286
+ SubstrateNodeClient.prototype.getSuperOf = function (address) {
287
+ return __awaiter(this, void 0, void 0, function () {
288
+ var _this = this;
289
+ return __generator(this, function (_a) {
290
+ return [2 /*return*/, this.fromStorage('Identity', 'SuperOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
291
+ return item
292
+ ? SCALETuple_1.SCALETuple.decode(_this.network, _this.runtimeVersion, item, function (network, _, hex) { return SCALEAccountId_1.SCALEAccountId.decode(network, hex); }, function (_network, _runtimeVersion, hex) { return SCALEData_1.SCALEData.decode(hex); }).decoded
293
+ : null;
294
+ })];
295
+ });
296
+ });
297
+ };
298
+ SubstrateNodeClient.prototype.getSubsOf = function (address) {
299
+ return __awaiter(this, void 0, void 0, function () {
300
+ var _this = this;
301
+ return __generator(this, function (_a) {
302
+ return [2 /*return*/, this.fromStorage('Identity', 'SubsOf', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
303
+ return item
304
+ ? SCALETuple_1.SCALETuple.decode(_this.network, _this.runtimeVersion, item, function (_network, _runtimeVersion, hex) { return SCALECompactInt_1.SCALECompactInt.decode(hex); }, function (network, _, hex) {
305
+ return SCALEArray_1.SCALEArray.decode(network, _, hex, function (innerNetwork, _, innerHex) { return SCALEAccountId_1.SCALEAccountId.decode(innerNetwork, innerHex); });
306
+ }).decoded
307
+ : null;
308
+ })];
309
+ });
310
+ });
311
+ };
312
+ SubstrateNodeClient.prototype.getValidatorPrefs = function (eraIndex, address) {
313
+ return __awaiter(this, void 0, void 0, function () {
314
+ var _this = this;
315
+ return __generator(this, function (_a) {
316
+ return [2 /*return*/, this.fromStorage('Staking', 'ErasValidatorPrefs', SCALEInt_1.SCALEInt.from(eraIndex, 32), SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) { return (item ? SubstrateValidatorPrefs_1.SubstrateValidatorPrefs.decode(_this.network, _this.runtimeVersion, item) : null); })];
317
+ });
318
+ });
319
+ };
320
+ SubstrateNodeClient.prototype.getExpectedEraDuration = function () {
321
+ return __awaiter(this, void 0, void 0, function () {
322
+ var constants, expectedBlockTime, epochDuration, sessionsPerEra;
323
+ return __generator(this, function (_a) {
324
+ switch (_a.label) {
325
+ case 0: return [4 /*yield*/, Promise.all([
326
+ this.getConstant('Babe', 'ExpectedBlockTime'),
327
+ this.getConstant('Babe', 'EpochDuration'),
328
+ this.getConstant('Staking', 'SessionsPerEra')
329
+ ]).then(function (constants) { return constants.map(function (constant) { return (constant ? SCALEInt_1.SCALEInt.decode(constant).decoded.value : null); }); })];
330
+ case 1:
331
+ constants = _a.sent();
332
+ if (constants.some(function (constant) { return constant === null; })) {
333
+ return [2 /*return*/, null];
334
+ }
335
+ expectedBlockTime = constants[0];
336
+ epochDuration = constants[1];
337
+ sessionsPerEra = constants[2];
338
+ return [2 /*return*/, expectedBlockTime.multipliedBy(epochDuration).multipliedBy(sessionsPerEra)];
192
339
  }
193
- this.metadata = Metadata_1.Metadata.decode(this.network, runtimeVersion?.specVersion, metadataEncoded).decorate(this.storageEntries, this.calls, this.constants);
194
- this.runtimeVersion = runtimeVersion?.specVersion;
195
- resolve();
196
- }).then(async () => {
197
- this.initApiPromise = Promise.resolve();
198
- await this.initCache();
199
340
  });
200
- this.initApiPromise = initApiPromise.catch((error) => {
201
- console.warn(error);
202
- this.initApiPromise = initApiPromise; // retry once
341
+ });
342
+ };
343
+ SubstrateNodeClient.prototype.getActiveEraInfo = function () {
344
+ return __awaiter(this, void 0, void 0, function () {
345
+ var _this = this;
346
+ return __generator(this, function (_a) {
347
+ return [2 /*return*/, this.fromStorage('Staking', 'ActiveEra').then(function (item) {
348
+ return item ? SubstrateActiveEraInfo_1.SubstrateActiveEraInfo.decode(_this.network, _this.runtimeVersion, item) : null;
349
+ })];
350
+ });
351
+ });
352
+ };
353
+ SubstrateNodeClient.prototype.getSlashingSpan = function (address) {
354
+ return __awaiter(this, void 0, void 0, function () {
355
+ var _this = this;
356
+ return __generator(this, function (_a) {
357
+ return [2 /*return*/, this.fromStorage('Staking', 'SlashingSpans', SCALEAccountId_1.SCALEAccountId.from(address, this.network)).then(function (item) {
358
+ return item ? SubstrateSlashingSpans_1.SubstrateSlashingSpans.decode(_this.network, _this.runtimeVersion, item) : null;
359
+ })];
360
+ });
361
+ });
362
+ };
363
+ SubstrateNodeClient.prototype.submitTransaction = function (encoded) {
364
+ return __awaiter(this, void 0, void 0, function () {
365
+ return __generator(this, function (_a) {
366
+ return [2 /*return*/, this.send('author', 'submitExtrinsic', [encoded], { allowCache: false })];
203
367
  });
368
+ });
369
+ };
370
+ SubstrateNodeClient.prototype.getBlockHash = function (blockNumber) {
371
+ return __awaiter(this, void 0, void 0, function () {
372
+ return __generator(this, function (_a) {
373
+ return [2 /*return*/, this.send('chain', 'getBlockHash', blockNumber !== undefined ? [(0, hex_1.toHexString)(blockNumber)] : [])];
374
+ });
375
+ });
376
+ };
377
+ SubstrateNodeClient.prototype.fromStorage = function (moduleName, entryName) {
378
+ var _a;
379
+ var args = [];
380
+ for (var _i = 2; _i < arguments.length; _i++) {
381
+ args[_i - 2] = arguments[_i];
204
382
  }
205
- return this.initApiPromise;
206
- }
207
- async initCache() {
208
- const blockTime = await this.getConstant('Babe', 'ExpectedBlockTime')
209
- .then((constant) => SCALEInt_1.SCALEInt.decode(constant).decoded.toNumber())
210
- .catch(() => 6000);
211
- this.cache.expirationTime = Math.floor(blockTime / 3);
212
- }
213
- async send(module, method, params = [], config = { allowCache: true }) {
214
- const endpoint = `${module}_${method}`;
215
- const key = `${endpoint}$${params.join('')}`;
216
- return this.cache.get(key).catch(() => {
217
- const promise = this.sendRepeat(endpoint, params);
218
- return this.cache.save(key, promise, { cacheValue: config.allowCache });
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ var storageEntry, hash, result;
385
+ return __generator(this, function (_b) {
386
+ switch (_b.label) {
387
+ case 0: return [4 /*yield*/, this.initApi()];
388
+ case 1:
389
+ _b.sent();
390
+ storageEntry = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.storageEntry(moduleName, entryName);
391
+ if (!storageEntry) {
392
+ console.warn("Could not find requested item: ".concat(moduleName, " ").concat(entryName));
393
+ return [2 /*return*/, null];
394
+ }
395
+ return [4 /*yield*/, storageEntry.hash.apply(storageEntry, args)];
396
+ case 2:
397
+ hash = _b.sent();
398
+ return [4 /*yield*/, this.send('state', 'getStorage', [hash])];
399
+ case 3:
400
+ result = _b.sent();
401
+ return [2 /*return*/, result];
402
+ }
403
+ });
219
404
  });
220
- }
221
- async sendRepeat(endpoint, params, attempts = 0) {
222
- const handleResponse = (response) => {
223
- const data = response.data;
224
- if (data.error) {
225
- throw data.error;
226
- }
227
- return data.result;
228
- };
229
- const handleAxiosError = async (error) => {
230
- if (error.response?.status === 500 && attempts < MAX_RETRIES) {
231
- return await this.sendRepeat(endpoint, params, attempts + 1);
232
- }
233
- else {
234
- throw new errors_1.NetworkError(coinlib_error_1.Domain.SUBSTRATE, error);
235
- }
236
- };
237
- const handleError = async (error) => {
238
- if (typeof error === 'string') {
239
- throw new errors_1.NetworkError(coinlib_error_1.Domain.SUBSTRATE, {}, error);
240
- }
241
- else {
242
- const axiosError = error;
243
- return await handleAxiosError(axiosError);
244
- }
245
- };
246
- return axios_0_19_0_1.default
247
- .post(this.baseURL, new RPCBody_1.RPCBody(endpoint, params.map(hex_1.addHexPrefix)))
248
- .then(handleResponse)
249
- .catch(handleError);
250
- }
251
- }
405
+ };
406
+ SubstrateNodeClient.prototype.getCall = function (moduleName, callName) {
407
+ var _a;
408
+ return __awaiter(this, void 0, void 0, function () {
409
+ var call;
410
+ return __generator(this, function (_b) {
411
+ switch (_b.label) {
412
+ case 0: return [4 /*yield*/, this.initApi()];
413
+ case 1:
414
+ _b.sent();
415
+ call = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.call(moduleName, callName);
416
+ return [2 /*return*/, call ? call : Promise.reject("Could not find requested item: ".concat(moduleName, " ").concat(callName))];
417
+ }
418
+ });
419
+ });
420
+ };
421
+ SubstrateNodeClient.prototype.getConstant = function (moduleName, constantName) {
422
+ var _a;
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ var constant;
425
+ return __generator(this, function (_b) {
426
+ switch (_b.label) {
427
+ case 0: return [4 /*yield*/, this.initApi()];
428
+ case 1:
429
+ _b.sent();
430
+ constant = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.constant(moduleName, constantName);
431
+ return [2 /*return*/, constant ? constant.value.toString('hex') : Promise.reject("Could not find requested item: ".concat(moduleName, " ").concat(constantName))];
432
+ }
433
+ });
434
+ });
435
+ };
436
+ SubstrateNodeClient.prototype.initApi = function () {
437
+ return __awaiter(this, void 0, void 0, function () {
438
+ var initApiPromise_1;
439
+ var _this = this;
440
+ return __generator(this, function (_a) {
441
+ if (!this.initApiPromise) {
442
+ initApiPromise_1 = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
443
+ var _a, metadataEncoded, runtimeVersion;
444
+ return __generator(this, function (_b) {
445
+ switch (_b.label) {
446
+ case 0: return [4 /*yield*/, Promise.all([this.send('state', 'getMetadata'), this.getRuntimeVersion()])];
447
+ case 1:
448
+ _a = _b.sent(), metadataEncoded = _a[0], runtimeVersion = _a[1];
449
+ if (!runtimeVersion) {
450
+ reject('Could not fetch runtime version from the node');
451
+ }
452
+ this.metadata = Metadata_1.Metadata.decode(this.network, runtimeVersion === null || runtimeVersion === void 0 ? void 0 : runtimeVersion.specVersion, metadataEncoded).decorate(this.storageEntries, this.calls, this.constants);
453
+ this.runtimeVersion = runtimeVersion === null || runtimeVersion === void 0 ? void 0 : runtimeVersion.specVersion;
454
+ resolve();
455
+ return [2 /*return*/];
456
+ }
457
+ });
458
+ }); }).then(function () { return __awaiter(_this, void 0, void 0, function () {
459
+ return __generator(this, function (_a) {
460
+ switch (_a.label) {
461
+ case 0:
462
+ this.initApiPromise = Promise.resolve();
463
+ return [4 /*yield*/, this.initCache()];
464
+ case 1:
465
+ _a.sent();
466
+ return [2 /*return*/];
467
+ }
468
+ });
469
+ }); });
470
+ this.initApiPromise = initApiPromise_1.catch(function (error) {
471
+ console.warn(error);
472
+ _this.initApiPromise = initApiPromise_1; // retry once
473
+ });
474
+ }
475
+ return [2 /*return*/, this.initApiPromise];
476
+ });
477
+ });
478
+ };
479
+ SubstrateNodeClient.prototype.initCache = function () {
480
+ return __awaiter(this, void 0, void 0, function () {
481
+ var blockTime;
482
+ return __generator(this, function (_a) {
483
+ switch (_a.label) {
484
+ case 0: return [4 /*yield*/, this.getConstant('Babe', 'ExpectedBlockTime')
485
+ .then(function (constant) { return SCALEInt_1.SCALEInt.decode(constant).decoded.toNumber(); })
486
+ .catch(function () { return 6000; })];
487
+ case 1:
488
+ blockTime = _a.sent();
489
+ this.cache.expirationTime = Math.floor(blockTime / 3);
490
+ return [2 /*return*/];
491
+ }
492
+ });
493
+ });
494
+ };
495
+ SubstrateNodeClient.prototype.send = function (module, method, params, config) {
496
+ if (params === void 0) { params = []; }
497
+ if (config === void 0) { config = { allowCache: true }; }
498
+ return __awaiter(this, void 0, void 0, function () {
499
+ var endpoint, key;
500
+ var _this = this;
501
+ return __generator(this, function (_a) {
502
+ endpoint = "".concat(module, "_").concat(method);
503
+ key = "".concat(endpoint, "$").concat(params.join(''));
504
+ return [2 /*return*/, this.cache.get(key).catch(function () {
505
+ var promise = _this.sendRepeat(endpoint, params);
506
+ return _this.cache.save(key, promise, { cacheValue: config.allowCache });
507
+ })];
508
+ });
509
+ });
510
+ };
511
+ SubstrateNodeClient.prototype.sendRepeat = function (endpoint, params, attempts) {
512
+ if (attempts === void 0) { attempts = 0; }
513
+ return __awaiter(this, void 0, void 0, function () {
514
+ var handleResponse, handleAxiosError, handleError;
515
+ var _this = this;
516
+ return __generator(this, function (_a) {
517
+ handleResponse = function (response) {
518
+ var data = response.data;
519
+ if (data.error) {
520
+ throw data.error;
521
+ }
522
+ return data.result;
523
+ };
524
+ handleAxiosError = function (error) { return __awaiter(_this, void 0, void 0, function () {
525
+ var _a;
526
+ return __generator(this, function (_b) {
527
+ switch (_b.label) {
528
+ case 0:
529
+ if (!(((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 500 && attempts < MAX_RETRIES)) return [3 /*break*/, 2];
530
+ return [4 /*yield*/, this.sendRepeat(endpoint, params, attempts + 1)];
531
+ case 1: return [2 /*return*/, _b.sent()];
532
+ case 2: throw new errors_1.NetworkError(coinlib_error_1.Domain.SUBSTRATE, error);
533
+ }
534
+ });
535
+ }); };
536
+ handleError = function (error) { return __awaiter(_this, void 0, void 0, function () {
537
+ var axiosError;
538
+ return __generator(this, function (_a) {
539
+ switch (_a.label) {
540
+ case 0:
541
+ if (!(typeof error === 'string')) return [3 /*break*/, 1];
542
+ throw new errors_1.NetworkError(coinlib_error_1.Domain.SUBSTRATE, {}, error);
543
+ case 1:
544
+ axiosError = error;
545
+ return [4 /*yield*/, handleAxiosError(axiosError)];
546
+ case 2: return [2 /*return*/, _a.sent()];
547
+ }
548
+ });
549
+ }); };
550
+ return [2 /*return*/, axios_0_19_0_1.default
551
+ .post(this.baseURL, new RPCBody_1.RPCBody(endpoint, params.map(hex_1.addHexPrefix)))
552
+ .then(handleResponse)
553
+ .catch(handleError)];
554
+ });
555
+ });
556
+ };
557
+ return SubstrateNodeClient;
558
+ }());
252
559
  exports.SubstrateNodeClient = SubstrateNodeClient;
253
560
  //# sourceMappingURL=SubstrateNodeClient.js.map