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

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 (396) 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 +23 -94
  5. package/v0/protocol/SubstrateCryptoClient.js.map +1 -1
  6. package/v0/protocol/SubstrateDelegateProtocol.js +297 -542
  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 +333 -672
  11. package/v0/protocol/SubstrateProtocol.js.map +1 -1
  12. package/v0/protocol/SubstrateProtocolOptions.js +25 -93
  13. package/v0/protocol/SubstrateProtocolOptions.js.map +1 -1
  14. package/v0/protocol/astar/AstarAddress.js +7 -27
  15. package/v0/protocol/astar/AstarAddress.js.map +1 -1
  16. package/v0/protocol/common/SubstrateAccountController.js +400 -687
  17. package/v0/protocol/common/SubstrateAccountController.js.map +1 -1
  18. package/v0/protocol/common/SubstrateTransactionController.d.ts +0 -1
  19. package/v0/protocol/common/SubstrateTransactionController.js +185 -346
  20. package/v0/protocol/common/SubstrateTransactionController.js.map +1 -1
  21. package/v0/protocol/common/blockexplorer/SubstrateBlockExplorerClient.js +52 -100
  22. package/v0/protocol/common/blockexplorer/SubstrateBlockExplorerClient.js.map +1 -1
  23. package/v0/protocol/common/data/account/SubstrateAccountInfo.js +27 -29
  24. package/v0/protocol/common/data/account/SubstrateAccountInfo.js.map +1 -1
  25. package/v0/protocol/common/data/account/SubstrateAddress.d.ts +0 -1
  26. package/v0/protocol/common/data/account/SubstrateAddress.js +43 -46
  27. package/v0/protocol/common/data/account/SubstrateAddress.js.map +1 -1
  28. package/v0/protocol/common/data/account/SubstrateRegistration.js +50 -56
  29. package/v0/protocol/common/data/account/SubstrateRegistration.js.map +1 -1
  30. package/v0/protocol/common/data/metadata/Metadata.js +24 -25
  31. package/v0/protocol/common/data/metadata/Metadata.js.map +1 -1
  32. package/v0/protocol/common/data/metadata/MetadataVersioned.js +2 -5
  33. package/v0/protocol/common/data/metadata/MetadataVersioned.js.map +1 -1
  34. package/v0/protocol/common/data/metadata/decorator/MetadataDecorator.js +18 -20
  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 +0 -1
  37. package/v0/protocol/common/data/metadata/decorator/storage/SubstrateStorageEntry.js +89 -237
  38. package/v0/protocol/common/data/metadata/decorator/storage/SubstrateStorageEntry.js.map +1 -1
  39. package/v0/protocol/common/data/metadata/v11/MetadataV11.js +43 -63
  40. package/v0/protocol/common/data/metadata/v11/MetadataV11.js.map +1 -1
  41. package/v0/protocol/common/data/metadata/v11/module/MetadataV11Call.js +30 -51
  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 +20 -38
  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 +16 -34
  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 +18 -36
  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 +29 -51
  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 +17 -35
  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 +23 -41
  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 +72 -114
  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 +41 -61
  58. package/v0/protocol/common/data/metadata/v12/MetadataV12.js.map +1 -1
  59. package/v0/protocol/common/data/metadata/v12/module/MetadataV12Module.js +14 -32
  60. package/v0/protocol/common/data/metadata/v12/module/MetadataV12Module.js.map +1 -1
  61. package/v0/protocol/common/data/metadata/v13/MetadataV13.js +41 -61
  62. package/v0/protocol/common/data/metadata/v13/MetadataV13.js.map +1 -1
  63. package/v0/protocol/common/data/metadata/v13/module/MetadataV13Module.js +31 -53
  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 +17 -35
  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 +23 -41
  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 +83 -130
  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 +53 -74
  72. package/v0/protocol/common/data/metadata/v14/MetadataV14.js.map +1 -1
  73. package/v0/protocol/common/data/metadata/v14/MetadataV14Component.js +7 -25
  74. package/v0/protocol/common/data/metadata/v14/MetadataV14Component.js.map +1 -1
  75. package/v0/protocol/common/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js +17 -35
  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 +16 -34
  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 +8 -28
  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 +19 -37
  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 +8 -28
  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 +8 -28
  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 +30 -48
  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 +16 -34
  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 +23 -41
  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 +49 -90
  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 +20 -41
  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 +17 -35
  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 +20 -38
  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 +22 -40
  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 +16 -34
  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 +21 -39
  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 +106 -150
  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 +2 -3
  110. package/v0/protocol/common/data/scale/SCALEDecoder.js +69 -74
  111. package/v0/protocol/common/data/scale/SCALEDecoder.js.map +1 -1
  112. package/v0/protocol/common/data/scale/type/SCALEAccountId.d.ts +0 -1
  113. package/v0/protocol/common/data/scale/type/SCALEAccountId.js +25 -44
  114. package/v0/protocol/common/data/scale/type/SCALEAccountId.js.map +1 -1
  115. package/v0/protocol/common/data/scale/type/SCALEArray.js +27 -45
  116. package/v0/protocol/common/data/scale/type/SCALEArray.js.map +1 -1
  117. package/v0/protocol/common/data/scale/type/SCALEBoolean.js +18 -36
  118. package/v0/protocol/common/data/scale/type/SCALEBoolean.js.map +1 -1
  119. package/v0/protocol/common/data/scale/type/SCALEBytes.d.ts +0 -1
  120. package/v0/protocol/common/data/scale/type/SCALEBytes.js +23 -42
  121. package/v0/protocol/common/data/scale/type/SCALEBytes.js.map +1 -1
  122. package/v0/protocol/common/data/scale/type/SCALEClass.js +8 -28
  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 +54 -73
  126. package/v0/protocol/common/data/scale/type/SCALECompactInt.js.map +1 -1
  127. package/v0/protocol/common/data/scale/type/SCALEData.d.ts +0 -1
  128. package/v0/protocol/common/data/scale/type/SCALEData.js +33 -51
  129. package/v0/protocol/common/data/scale/type/SCALEData.js.map +1 -1
  130. package/v0/protocol/common/data/scale/type/SCALEEnum.js +21 -39
  131. package/v0/protocol/common/data/scale/type/SCALEEnum.js.map +1 -1
  132. package/v0/protocol/common/data/scale/type/SCALEEra.js +46 -68
  133. package/v0/protocol/common/data/scale/type/SCALEEra.js.map +1 -1
  134. package/v0/protocol/common/data/scale/type/SCALEHash.d.ts +0 -1
  135. package/v0/protocol/common/data/scale/type/SCALEHash.js +29 -53
  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 +46 -65
  139. package/v0/protocol/common/data/scale/type/SCALEInt.js.map +1 -1
  140. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.d.ts +1 -2
  141. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.js +40 -59
  142. package/v0/protocol/common/data/scale/type/SCALEMultiAddress.js.map +1 -1
  143. package/v0/protocol/common/data/scale/type/SCALEOptional.js +27 -47
  144. package/v0/protocol/common/data/scale/type/SCALEOptional.js.map +1 -1
  145. package/v0/protocol/common/data/scale/type/SCALEString.js +25 -44
  146. package/v0/protocol/common/data/scale/type/SCALEString.js.map +1 -1
  147. package/v0/protocol/common/data/scale/type/SCALETuple.js +22 -40
  148. package/v0/protocol/common/data/scale/type/SCALETuple.js.map +1 -1
  149. package/v0/protocol/common/data/scale/type/SCALEType.js +6 -9
  150. package/v0/protocol/common/data/scale/type/SCALEType.js.map +1 -1
  151. package/v0/protocol/common/data/staking/SubstrateActiveEraInfo.js +11 -12
  152. package/v0/protocol/common/data/staking/SubstrateActiveEraInfo.js.map +1 -1
  153. package/v0/protocol/common/data/staking/SubstrateEraElectionStatus.js +14 -15
  154. package/v0/protocol/common/data/staking/SubstrateEraElectionStatus.js.map +1 -1
  155. package/v0/protocol/common/data/staking/SubstrateEraRewardPoints.js +13 -16
  156. package/v0/protocol/common/data/staking/SubstrateEraRewardPoints.js.map +1 -1
  157. package/v0/protocol/common/data/staking/SubstrateExposure.js +14 -17
  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 +12 -13
  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 +13 -14
  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 +16 -19
  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 +9 -10
  174. package/v0/protocol/common/data/staking/SubstrateValidatorPrefs.js.map +1 -1
  175. package/v0/protocol/common/data/transaction/SubstrateSignature.d.ts +0 -1
  176. package/v0/protocol/common/data/transaction/SubstrateSignature.js +30 -53
  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 +53 -73
  180. package/v0/protocol/common/data/transaction/SubstrateTransaction.js.map +1 -1
  181. package/v0/protocol/common/data/transaction/SubstrateTransactionPayload.js +44 -76
  182. package/v0/protocol/common/data/transaction/SubstrateTransactionPayload.js.map +1 -1
  183. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethod.js +40 -76
  184. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethod.js.map +1 -1
  185. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethodArgs.js +360 -631
  186. package/v0/protocol/common/data/transaction/method/SubstrateTransactionMethodArgs.js.map +1 -1
  187. package/v0/protocol/common/node/SubstrateNodeClient.js +226 -533
  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 +1 -2
  193. package/v0/protocol/compat/SubstrateCompatAddress.js +17 -30
  194. package/v0/protocol/compat/SubstrateCompatAddress.js.map +1 -1
  195. package/v0/protocol/compat/SubstrateCompatSignature.d.ts +0 -1
  196. package/v0/protocol/compat/SubstrateCompatSignature.js +4 -5
  197. package/v0/protocol/compat/SubstrateCompatSignature.js.map +1 -1
  198. package/v0/protocol/kusama/KusamaAddress.js +7 -27
  199. package/v0/protocol/kusama/KusamaAddress.js.map +1 -1
  200. package/v0/protocol/moonbeam/MoonbeamAddress.d.ts +0 -1
  201. package/v0/protocol/moonbeam/MoonbeamAddress.js +45 -36
  202. package/v0/protocol/moonbeam/MoonbeamAddress.js.map +1 -1
  203. package/v0/protocol/moonbeam/MoonbeamSignature.d.ts +0 -1
  204. package/v0/protocol/moonbeam/MoonbeamSignature.js +16 -35
  205. package/v0/protocol/moonbeam/MoonbeamSignature.js.map +1 -1
  206. package/v0/protocol/polkadot/PolkadotAddress.js +7 -27
  207. package/v0/protocol/polkadot/PolkadotAddress.js.map +1 -1
  208. package/v0/serializer/validators/transaction-validator.js +30 -83
  209. package/v0/serializer/validators/transaction-validator.js.map +1 -1
  210. package/v0/serializer/validators/validators.js +54 -133
  211. package/v0/serializer/validators/validators.js.map +1 -1
  212. package/v0/utils/sr25519.js +26 -74
  213. package/v0/utils/sr25519.js.map +1 -1
  214. package/v1/block-explorer/subscan/SubscanBlockExplorer.js +12 -61
  215. package/v1/block-explorer/subscan/SubscanBlockExplorer.js.map +1 -1
  216. package/v1/block-explorer/subscan/SubscanBlockExplorerClient.js +55 -103
  217. package/v1/block-explorer/subscan/SubscanBlockExplorerClient.js.map +1 -1
  218. package/v1/controller/account/SubstrateCommonAccountController.js +65 -132
  219. package/v1/controller/account/SubstrateCommonAccountController.js.map +1 -1
  220. package/v1/controller/transaction/SubstrateCommonTransactionController.js +194 -356
  221. package/v1/controller/transaction/SubstrateCommonTransactionController.js.map +1 -1
  222. package/v1/crypto/SubstrateCryptoClient.js +23 -94
  223. package/v1/crypto/SubstrateCryptoClient.js.map +1 -1
  224. package/v1/data/account/SubstrateAccountInfo.js +27 -29
  225. package/v1/data/account/SubstrateAccountInfo.js.map +1 -1
  226. package/v1/data/account/SubstrateRegistration.js +50 -56
  227. package/v1/data/account/SubstrateRegistration.js.map +1 -1
  228. package/v1/data/account/address/SubstrateAddress.d.ts +1 -2
  229. package/v1/data/account/address/SubstrateAddress.js +2 -3
  230. package/v1/data/account/address/SubstrateAddress.js.map +1 -1
  231. package/v1/data/account/address/SubstrateAddressFactory.d.ts +2 -3
  232. package/v1/data/account/address/SubstrateAddressFactory.js +16 -23
  233. package/v1/data/account/address/SubstrateAddressFactory.js.map +1 -1
  234. package/v1/data/account/address/SubstrateEthAddress.d.ts +0 -1
  235. package/v1/data/account/address/SubstrateEthAddress.js +48 -39
  236. package/v1/data/account/address/SubstrateEthAddress.js.map +1 -1
  237. package/v1/data/account/address/SubstrateSS58Address.d.ts +0 -1
  238. package/v1/data/account/address/SubstrateSS58Address.js +47 -50
  239. package/v1/data/account/address/SubstrateSS58Address.js.map +1 -1
  240. package/v1/data/metadata/Metadata.js +24 -25
  241. package/v1/data/metadata/Metadata.js.map +1 -1
  242. package/v1/data/metadata/MetadataVersioned.js +2 -5
  243. package/v1/data/metadata/MetadataVersioned.js.map +1 -1
  244. package/v1/data/metadata/decorator/MetadataDecorator.js +18 -20
  245. package/v1/data/metadata/decorator/MetadataDecorator.js.map +1 -1
  246. package/v1/data/metadata/decorator/constant/SubstrateConstant.d.ts +0 -1
  247. package/v1/data/metadata/decorator/storage/SubstrateStorageEntry.js +89 -237
  248. package/v1/data/metadata/decorator/storage/SubstrateStorageEntry.js.map +1 -1
  249. package/v1/data/metadata/v11/MetadataV11.js +43 -63
  250. package/v1/data/metadata/v11/MetadataV11.js.map +1 -1
  251. package/v1/data/metadata/v11/module/MetadataV11Call.js +30 -51
  252. package/v1/data/metadata/v11/module/MetadataV11Call.js.map +1 -1
  253. package/v1/data/metadata/v11/module/MetadataV11Constant.js +20 -38
  254. package/v1/data/metadata/v11/module/MetadataV11Constant.js.map +1 -1
  255. package/v1/data/metadata/v11/module/MetadataV11Error.js +16 -34
  256. package/v1/data/metadata/v11/module/MetadataV11Error.js.map +1 -1
  257. package/v1/data/metadata/v11/module/MetadataV11Event.js +18 -36
  258. package/v1/data/metadata/v11/module/MetadataV11Event.js.map +1 -1
  259. package/v1/data/metadata/v11/module/MetadataV11Module.js +29 -51
  260. package/v1/data/metadata/v11/module/MetadataV11Module.js.map +1 -1
  261. package/v1/data/metadata/v11/module/storage/MetadataV11Storage.js +17 -35
  262. package/v1/data/metadata/v11/module/storage/MetadataV11Storage.js.map +1 -1
  263. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntry.js +23 -41
  264. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntry.js.map +1 -1
  265. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js +72 -114
  266. package/v1/data/metadata/v11/module/storage/MetadataV11StorageEntryType.js.map +1 -1
  267. package/v1/data/metadata/v12/MetadataV12.js +41 -61
  268. package/v1/data/metadata/v12/MetadataV12.js.map +1 -1
  269. package/v1/data/metadata/v12/module/MetadataV12Module.js +14 -32
  270. package/v1/data/metadata/v12/module/MetadataV12Module.js.map +1 -1
  271. package/v1/data/metadata/v13/MetadataV13.js +41 -61
  272. package/v1/data/metadata/v13/MetadataV13.js.map +1 -1
  273. package/v1/data/metadata/v13/module/MetadataV13Module.js +31 -53
  274. package/v1/data/metadata/v13/module/MetadataV13Module.js.map +1 -1
  275. package/v1/data/metadata/v13/module/storage/MetadataV13Storage.js +17 -35
  276. package/v1/data/metadata/v13/module/storage/MetadataV13Storage.js.map +1 -1
  277. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntry.js +23 -41
  278. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntry.js.map +1 -1
  279. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js +83 -130
  280. package/v1/data/metadata/v13/module/storage/MetadataV13StorageEntryType.js.map +1 -1
  281. package/v1/data/metadata/v14/MetadataV14.js +53 -74
  282. package/v1/data/metadata/v14/MetadataV14.js.map +1 -1
  283. package/v1/data/metadata/v14/MetadataV14Component.js +7 -25
  284. package/v1/data/metadata/v14/MetadataV14Component.js.map +1 -1
  285. package/v1/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js +17 -35
  286. package/v1/data/metadata/v14/extrinsic/MetadataV14Extrinsic.js.map +1 -1
  287. package/v1/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js +16 -34
  288. package/v1/data/metadata/v14/extrinsic/MetadataV14SignedExtension.js.map +1 -1
  289. package/v1/data/metadata/v14/pallet/MetadataV14Call.js +8 -28
  290. package/v1/data/metadata/v14/pallet/MetadataV14Call.js.map +1 -1
  291. package/v1/data/metadata/v14/pallet/MetadataV14Constant.js +19 -37
  292. package/v1/data/metadata/v14/pallet/MetadataV14Constant.js.map +1 -1
  293. package/v1/data/metadata/v14/pallet/MetadataV14Error.js +8 -28
  294. package/v1/data/metadata/v14/pallet/MetadataV14Error.js.map +1 -1
  295. package/v1/data/metadata/v14/pallet/MetadataV14Event.js +8 -28
  296. package/v1/data/metadata/v14/pallet/MetadataV14Event.js.map +1 -1
  297. package/v1/data/metadata/v14/pallet/MetadataV14Pallet.js +30 -48
  298. package/v1/data/metadata/v14/pallet/MetadataV14Pallet.js.map +1 -1
  299. package/v1/data/metadata/v14/pallet/storage/MetadataV14Storage.js +16 -34
  300. package/v1/data/metadata/v14/pallet/storage/MetadataV14Storage.js.map +1 -1
  301. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js +23 -41
  302. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntry.js.map +1 -1
  303. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js +49 -90
  304. package/v1/data/metadata/v14/pallet/storage/MetadataV14StorageEntryType.js.map +1 -1
  305. package/v1/data/metadata/v14/registry/MetadataV14PortableRegistry.js +20 -41
  306. package/v1/data/metadata/v14/registry/MetadataV14PortableRegistry.js.map +1 -1
  307. package/v1/data/metadata/v14/registry/MetadataV14PortableType.js +17 -35
  308. package/v1/data/metadata/v14/registry/MetadataV14PortableType.js.map +1 -1
  309. package/v1/data/metadata/v14/registry/si/MetadataV14SiField.js +20 -38
  310. package/v1/data/metadata/v14/registry/si/MetadataV14SiField.js.map +1 -1
  311. package/v1/data/metadata/v14/registry/si/MetadataV14SiType.js +22 -40
  312. package/v1/data/metadata/v14/registry/si/MetadataV14SiType.js.map +1 -1
  313. package/v1/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js +16 -34
  314. package/v1/data/metadata/v14/registry/si/MetadataV14SiTypeParameter.js.map +1 -1
  315. package/v1/data/metadata/v14/registry/si/MetadataV14SiVariant.js +21 -39
  316. package/v1/data/metadata/v14/registry/si/MetadataV14SiVariant.js.map +1 -1
  317. package/v1/data/metadata/v14/registry/si/MetadataV14TypeDef.js +106 -150
  318. package/v1/data/metadata/v14/registry/si/MetadataV14TypeDef.js.map +1 -1
  319. package/v1/data/scale/SCALEDecoder.d.ts +2 -3
  320. package/v1/data/scale/SCALEDecoder.js +69 -80
  321. package/v1/data/scale/SCALEDecoder.js.map +1 -1
  322. package/v1/data/scale/type/SCALEAccountId.d.ts +0 -1
  323. package/v1/data/scale/type/SCALEAccountId.js +27 -46
  324. package/v1/data/scale/type/SCALEAccountId.js.map +1 -1
  325. package/v1/data/scale/type/SCALEArray.js +27 -45
  326. package/v1/data/scale/type/SCALEArray.js.map +1 -1
  327. package/v1/data/scale/type/SCALEBoolean.js +18 -36
  328. package/v1/data/scale/type/SCALEBoolean.js.map +1 -1
  329. package/v1/data/scale/type/SCALEBytes.d.ts +0 -1
  330. package/v1/data/scale/type/SCALEBytes.js +23 -42
  331. package/v1/data/scale/type/SCALEBytes.js.map +1 -1
  332. package/v1/data/scale/type/SCALEClass.js +8 -28
  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 +54 -73
  336. package/v1/data/scale/type/SCALECompactInt.js.map +1 -1
  337. package/v1/data/scale/type/SCALEData.d.ts +0 -1
  338. package/v1/data/scale/type/SCALEData.js +33 -51
  339. package/v1/data/scale/type/SCALEData.js.map +1 -1
  340. package/v1/data/scale/type/SCALEEnum.js +21 -39
  341. package/v1/data/scale/type/SCALEEnum.js.map +1 -1
  342. package/v1/data/scale/type/SCALEEra.js +46 -68
  343. package/v1/data/scale/type/SCALEEra.js.map +1 -1
  344. package/v1/data/scale/type/SCALEHash.d.ts +0 -1
  345. package/v1/data/scale/type/SCALEHash.js +29 -53
  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 +46 -65
  349. package/v1/data/scale/type/SCALEInt.js.map +1 -1
  350. package/v1/data/scale/type/SCALEMultiAddress.d.ts +1 -2
  351. package/v1/data/scale/type/SCALEMultiAddress.js +40 -59
  352. package/v1/data/scale/type/SCALEMultiAddress.js.map +1 -1
  353. package/v1/data/scale/type/SCALEOptional.js +27 -47
  354. package/v1/data/scale/type/SCALEOptional.js.map +1 -1
  355. package/v1/data/scale/type/SCALEString.js +25 -44
  356. package/v1/data/scale/type/SCALEString.js.map +1 -1
  357. package/v1/data/scale/type/SCALETuple.js +22 -40
  358. package/v1/data/scale/type/SCALETuple.js.map +1 -1
  359. package/v1/data/scale/type/SCALEType.js +6 -9
  360. package/v1/data/scale/type/SCALEType.js.map +1 -1
  361. package/v1/data/transaction/SubstrateSignature.d.ts +0 -1
  362. package/v1/data/transaction/SubstrateSignature.js +36 -61
  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 +66 -87
  366. package/v1/data/transaction/SubstrateTransaction.js.map +1 -1
  367. package/v1/data/transaction/SubstrateTransactionPayload.js +81 -114
  368. package/v1/data/transaction/SubstrateTransactionPayload.js.map +1 -1
  369. package/v1/data/transaction/method/SubstrateTransactionMethod.js +40 -76
  370. package/v1/data/transaction/method/SubstrateTransactionMethod.js.map +1 -1
  371. package/v1/data/transaction/method/SubstrateTransactionMethodArgs.js +35 -65
  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 +159 -357
  377. package/v1/node/SubstrateCommonNodeClient.js.map +1 -1
  378. package/v1/protocol/SubstrateProtocol.d.ts +2 -4
  379. package/v1/protocol/SubstrateProtocol.js +182 -410
  380. package/v1/protocol/SubstrateProtocol.js.map +1 -1
  381. package/v1/protocol/SubstrateStakingProtocol.js +15 -82
  382. package/v1/protocol/SubstrateStakingProtocol.js.map +1 -1
  383. package/v1/serializer/v3/schemas/converter/transaction-converter.js +8 -20
  384. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  385. package/v1/serializer/v3/validators/transaction-validator.js +15 -63
  386. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  387. package/v1/serializer/v3/validators/validators.js +48 -129
  388. package/v1/serializer/v3/validators/validators.js.map +1 -1
  389. package/v1/types/configuration.d.ts +6 -6
  390. package/v1/types/crypto.d.ts +1 -1
  391. package/v1/utils/keys.js +4 -5
  392. package/v1/utils/keys.js.map +1 -1
  393. package/v1/utils/protocol.js +14 -15
  394. package/v1/utils/protocol.js.map +1 -1
  395. package/v1/utils/signature.js +3 -4
  396. package/v1/utils/signature.js.map +1 -1
@@ -1,81 +1,40 @@
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
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.SubstrateNodeClient = void 0;
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); }
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)) {
79
38
  this.network = network;
80
39
  this.baseURL = baseURL;
81
40
  this.storageEntries = storageEntries;
@@ -86,475 +45,209 @@ var SubstrateNodeClient = /** @class */ (function () {
86
45
  this.lastFees = new Map();
87
46
  this.initApiPromise = null;
88
47
  }
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) {
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) {
132
66
  this.lastFees.set(type, fee);
133
- };
134
- SubstrateNodeClient.prototype.getSavedLastFee = function (type, defaultValue) {
135
- if (defaultValue === void 0) { defaultValue = 'null'; }
136
- var fee = this.lastFees.get(type) || null;
67
+ }
68
+ getSavedLastFee(type, defaultValue = 'null') {
69
+ let fee = this.lastFees.get(type) || null;
137
70
  if (!fee && defaultValue === 'largest') {
138
- var savedFees = Array.from(this.lastFees.values());
139
- fee = savedFees.length > 0 ? bignumber_1.default.max.apply(bignumber_1.default, savedFees) : null;
71
+ const savedFees = Array.from(this.lastFees.values());
72
+ fee = savedFees.length > 0 ? bignumber_1.default.max(...savedFees) : null;
140
73
  }
141
74
  return fee;
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)];
339
- }
340
- });
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 })];
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];
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;
382
147
  }
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
- });
404
- });
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*/];
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');
491
192
  }
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();
492
199
  });
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)];
200
+ this.initApiPromise = initApiPromise.catch((error) => {
201
+ console.warn(error);
202
+ this.initApiPromise = initApiPromise; // retry once
554
203
  });
204
+ }
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 });
555
219
  });
556
- };
557
- return SubstrateNodeClient;
558
- }());
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
+ }
559
252
  exports.SubstrateNodeClient = SubstrateNodeClient;
560
253
  //# sourceMappingURL=SubstrateNodeClient.js.map