@pezkuwi/api-contract 16.5.5 → 16.5.8

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 (373) hide show
  1. package/Abi/index.d.ts +31 -0
  2. package/Abi/index.js +359 -0
  3. package/Abi/toLatestCompatible.d.ts +15 -0
  4. package/Abi/toLatestCompatible.js +30 -0
  5. package/Abi/toV1.d.ts +3 -0
  6. package/Abi/toV1.js +21 -0
  7. package/Abi/toV2.d.ts +3 -0
  8. package/Abi/toV2.js +27 -0
  9. package/Abi/toV3.d.ts +3 -0
  10. package/Abi/toV3.js +10 -0
  11. package/Abi/toV4.d.ts +3 -0
  12. package/Abi/toV4.js +10 -0
  13. package/LICENSE +201 -0
  14. package/README.md +1 -1
  15. package/augment.d.ts +1 -0
  16. package/augment.js +1 -0
  17. package/base/Base.d.ts +13 -0
  18. package/base/Base.js +40 -0
  19. package/base/Blueprint.d.ts +24 -0
  20. package/base/Blueprint.js +51 -0
  21. package/base/Code.d.ts +22 -0
  22. package/base/Code.js +74 -0
  23. package/base/Contract.d.ts +25 -0
  24. package/base/Contract.js +127 -0
  25. package/base/index.d.ts +3 -0
  26. package/base/index.js +3 -0
  27. package/base/mock.d.ts +3 -0
  28. package/base/mock.js +38 -0
  29. package/base/types.d.ts +25 -0
  30. package/base/types.js +1 -0
  31. package/base/util.d.ts +16 -0
  32. package/base/util.js +33 -0
  33. package/build/Abi/index.js +359 -0
  34. package/build/Abi/toLatestCompatible.js +30 -0
  35. package/build/Abi/toV1.js +21 -0
  36. package/build/Abi/toV2.js +27 -0
  37. package/build/Abi/toV3.js +10 -0
  38. package/build/Abi/toV4.js +10 -0
  39. package/build/LICENSE +201 -0
  40. package/build/README.md +3 -0
  41. package/build/augment.js +1 -0
  42. package/build/base/Base.js +40 -0
  43. package/build/base/Blueprint.js +51 -0
  44. package/build/base/Code.js +74 -0
  45. package/build/base/Contract.js +127 -0
  46. package/build/base/index.js +3 -0
  47. package/build/base/mock.js +38 -0
  48. package/build/base/types.js +1 -0
  49. package/build/base/util.d.ts +1 -1
  50. package/build/base/util.js +33 -0
  51. package/build/bundle-pezkuwi-api-contract.js +1238 -0
  52. package/build/bundle.js +4 -0
  53. package/build/cjs/Abi/index.d.ts +31 -0
  54. package/build/cjs/Abi/index.js +363 -0
  55. package/build/cjs/Abi/toLatestCompatible.d.ts +15 -0
  56. package/build/cjs/Abi/toLatestCompatible.js +36 -0
  57. package/build/cjs/Abi/toV1.d.ts +3 -0
  58. package/build/cjs/Abi/toV1.js +24 -0
  59. package/build/cjs/Abi/toV2.d.ts +3 -0
  60. package/build/cjs/Abi/toV2.js +30 -0
  61. package/build/cjs/Abi/toV3.d.ts +3 -0
  62. package/build/cjs/Abi/toV3.js +13 -0
  63. package/build/cjs/Abi/toV4.d.ts +3 -0
  64. package/build/cjs/Abi/toV4.js +13 -0
  65. package/build/cjs/augment.d.ts +1 -0
  66. package/build/cjs/augment.js +3 -0
  67. package/build/cjs/base/Base.d.ts +13 -0
  68. package/build/cjs/base/Base.js +44 -0
  69. package/build/cjs/base/Blueprint.d.ts +24 -0
  70. package/build/cjs/base/Blueprint.js +57 -0
  71. package/build/cjs/base/Code.d.ts +22 -0
  72. package/build/cjs/base/Code.js +80 -0
  73. package/build/cjs/base/Contract.d.ts +25 -0
  74. package/build/cjs/base/Contract.js +133 -0
  75. package/build/cjs/base/index.d.ts +3 -0
  76. package/build/cjs/base/index.js +14 -0
  77. package/build/cjs/base/mock.d.ts +3 -0
  78. package/build/cjs/base/mock.js +41 -0
  79. package/build/cjs/base/types.d.ts +25 -0
  80. package/build/cjs/base/types.js +2 -0
  81. package/build/cjs/base/util.d.ts +16 -0
  82. package/build/cjs/base/util.js +42 -0
  83. package/build/cjs/bundle.d.ts +4 -0
  84. package/build/cjs/bundle.js +10 -0
  85. package/build/cjs/index.d.ts +2 -0
  86. package/build/cjs/index.js +5 -0
  87. package/build/cjs/package.json +3 -0
  88. package/build/cjs/packageDetect.d.ts +1 -0
  89. package/build/cjs/packageDetect.js +7 -0
  90. package/build/cjs/packageInfo.d.ts +6 -0
  91. package/build/cjs/packageInfo.js +4 -0
  92. package/build/cjs/promise/index.d.ts +13 -0
  93. package/build/cjs/promise/index.js +23 -0
  94. package/build/cjs/promise/types.d.ts +3 -0
  95. package/build/cjs/promise/types.js +2 -0
  96. package/build/cjs/rx/index.d.ts +13 -0
  97. package/build/cjs/rx/index.js +23 -0
  98. package/build/cjs/rx/types.d.ts +3 -0
  99. package/build/cjs/rx/types.js +2 -0
  100. package/build/cjs/types.d.ts +79 -0
  101. package/build/cjs/types.js +2 -0
  102. package/build/cjs/util.d.ts +5 -0
  103. package/build/cjs/util.js +13 -0
  104. package/build/index.js +2 -0
  105. package/build/package.json +408 -0
  106. package/build/packageDetect.js +5 -0
  107. package/build/packageInfo.js +1 -0
  108. package/build/promise/index.js +17 -0
  109. package/build/promise/types.js +1 -0
  110. package/build/rx/index.js +17 -0
  111. package/build/rx/types.js +1 -0
  112. package/build/types.js +1 -0
  113. package/build/util.js +10 -0
  114. package/build-deno/Abi/index.ts +475 -0
  115. package/build-deno/Abi/toLatestCompatible.ts +47 -0
  116. package/build-deno/Abi/toV1.ts +33 -0
  117. package/build-deno/Abi/toV2.ts +56 -0
  118. package/build-deno/Abi/toV3.ts +16 -0
  119. package/build-deno/Abi/toV4.ts +19 -0
  120. package/build-deno/README.md +3 -0
  121. package/build-deno/augment.ts +2 -0
  122. package/build-deno/base/Base.ts +50 -0
  123. package/build-deno/base/Blueprint.ts +88 -0
  124. package/build-deno/base/Code.ts +140 -0
  125. package/build-deno/base/Contract.ts +194 -0
  126. package/build-deno/base/index.ts +4 -0
  127. package/build-deno/base/mock.ts +46 -0
  128. package/build-deno/base/types.ts +38 -0
  129. package/build-deno/base/util.ts +54 -0
  130. package/build-deno/bundle.ts +6 -0
  131. package/build-deno/checkTypes.manual.ts +42 -0
  132. package/build-deno/index.ts +4 -0
  133. package/build-deno/mod.ts +2 -0
  134. package/build-deno/packageDetect.ts +9 -0
  135. package/build-deno/packageInfo.ts +3 -0
  136. package/build-deno/promise/index.ts +28 -0
  137. package/build-deno/promise/types.ts +5 -0
  138. package/build-deno/rx/index.ts +28 -0
  139. package/build-deno/rx/types.ts +5 -0
  140. package/build-deno/test/contracts/index.ts +18 -0
  141. package/build-deno/test/contracts/ink/index.ts +11 -0
  142. package/build-deno/test/contracts/ink/v0/accumulator.wasm +0 -0
  143. package/build-deno/test/contracts/ink/v0/adder.wasm +0 -0
  144. package/build-deno/test/contracts/ink/v0/delegator.wasm +0 -0
  145. package/build-deno/test/contracts/ink/v0/dns.wasm +0 -0
  146. package/build-deno/test/contracts/ink/v0/erc20.wasm +0 -0
  147. package/build-deno/test/contracts/ink/v0/erc721.wasm +0 -0
  148. package/build-deno/test/contracts/ink/v0/flipper.wasm +0 -0
  149. package/build-deno/test/contracts/ink/v0/incrementer.wasm +0 -0
  150. package/build-deno/test/contracts/ink/v0/index.ts +9 -0
  151. package/build-deno/test/contracts/ink/v0/multisig_plain.wasm +0 -0
  152. package/build-deno/test/contracts/ink/v0/subber.wasm +0 -0
  153. package/build-deno/test/contracts/ink/v0/trait-flipper.wasm +0 -0
  154. package/build-deno/test/contracts/ink/v1/index.ts +3 -0
  155. package/build-deno/test/contracts/ink/v2/index.ts +3 -0
  156. package/build-deno/test/contracts/ink/v3/index.ts +3 -0
  157. package/build-deno/test/contracts/ink/v4/erc20.wasm +0 -0
  158. package/build-deno/test/contracts/ink/v4/flipper.wasm +0 -0
  159. package/build-deno/test/contracts/ink/v4/index.ts +5 -0
  160. package/build-deno/test/contracts/ink/v5/erc20.wasm +0 -0
  161. package/build-deno/test/contracts/ink/v5/flipper.wasm +0 -0
  162. package/build-deno/test/contracts/ink/v5/index.ts +6 -0
  163. package/build-deno/test/contracts/ink/v6/erc20.polkavm +0 -0
  164. package/build-deno/test/contracts/ink/v6/index.ts +3 -0
  165. package/build-deno/test/contracts/solang/index.ts +5 -0
  166. package/build-deno/test/contracts/solang/v0/index.ts +2 -0
  167. package/build-deno/test/contracts/solang/v0/ints256.sol +13 -0
  168. package/build-deno/test/contracts/solang/v0/ints256.wasm +0 -0
  169. package/build-deno/test/contracts/user/index.ts +7 -0
  170. package/build-deno/test/contracts/user/v0/assetTransfer.wasm +0 -0
  171. package/build-deno/test/contracts/user/v0/enumExample.wasm +0 -0
  172. package/build-deno/test/contracts/user/v0/index.ts +5 -0
  173. package/build-deno/test/contracts/user/v3/index.ts +2 -0
  174. package/build-deno/test/contracts/user/v4/index.ts +2 -0
  175. package/build-deno/test/contracts/util.ts +12 -0
  176. package/build-deno/types.ts +95 -0
  177. package/build-deno/util.ts +18 -0
  178. package/build-tsc/Abi/index.d.ts +31 -0
  179. package/build-tsc/Abi/toLatestCompatible.d.ts +15 -0
  180. package/build-tsc/Abi/toV1.d.ts +3 -0
  181. package/build-tsc/Abi/toV2.d.ts +3 -0
  182. package/build-tsc/Abi/toV3.d.ts +3 -0
  183. package/build-tsc/Abi/toV4.d.ts +3 -0
  184. package/build-tsc/augment.d.ts +1 -0
  185. package/build-tsc/base/Base.d.ts +13 -0
  186. package/build-tsc/base/Blueprint.d.ts +24 -0
  187. package/build-tsc/base/Code.d.ts +22 -0
  188. package/build-tsc/base/Contract.d.ts +25 -0
  189. package/build-tsc/base/index.d.ts +3 -0
  190. package/build-tsc/base/mock.d.ts +3 -0
  191. package/build-tsc/base/types.d.ts +25 -0
  192. package/build-tsc/base/util.d.ts +16 -0
  193. package/build-tsc/bundle.d.ts +4 -0
  194. package/build-tsc/index.d.ts +2 -0
  195. package/build-tsc/packageDetect.d.ts +1 -0
  196. package/build-tsc/packageInfo.d.ts +6 -0
  197. package/build-tsc/promise/index.d.ts +13 -0
  198. package/build-tsc/promise/types.d.ts +3 -0
  199. package/build-tsc/rx/index.d.ts +13 -0
  200. package/build-tsc/rx/types.d.ts +3 -0
  201. package/build-tsc/types.d.ts +79 -0
  202. package/build-tsc/util.d.ts +5 -0
  203. package/build-tsc-cjs/Abi/index.js +363 -0
  204. package/build-tsc-cjs/Abi/toLatestCompatible.js +36 -0
  205. package/build-tsc-cjs/Abi/toV1.js +24 -0
  206. package/build-tsc-cjs/Abi/toV2.js +30 -0
  207. package/build-tsc-cjs/Abi/toV3.js +13 -0
  208. package/build-tsc-cjs/Abi/toV4.js +13 -0
  209. package/build-tsc-cjs/augment.js +3 -0
  210. package/build-tsc-cjs/base/Base.js +44 -0
  211. package/build-tsc-cjs/base/Blueprint.js +57 -0
  212. package/build-tsc-cjs/base/Code.js +80 -0
  213. package/build-tsc-cjs/base/Contract.js +133 -0
  214. package/build-tsc-cjs/base/index.js +14 -0
  215. package/build-tsc-cjs/base/mock.js +41 -0
  216. package/build-tsc-cjs/base/types.js +2 -0
  217. package/build-tsc-cjs/base/util.js +42 -0
  218. package/build-tsc-cjs/bundle.js +10 -0
  219. package/build-tsc-cjs/index.js +5 -0
  220. package/build-tsc-cjs/packageDetect.js +7 -0
  221. package/build-tsc-cjs/packageInfo.js +4 -0
  222. package/build-tsc-cjs/promise/index.js +23 -0
  223. package/build-tsc-cjs/promise/types.js +2 -0
  224. package/build-tsc-cjs/rx/index.js +23 -0
  225. package/build-tsc-cjs/rx/types.js +2 -0
  226. package/build-tsc-cjs/types.js +2 -0
  227. package/build-tsc-cjs/util.js +13 -0
  228. package/build-tsc-esm/Abi/index.js +359 -0
  229. package/build-tsc-esm/Abi/toLatestCompatible.js +30 -0
  230. package/build-tsc-esm/Abi/toV1.js +21 -0
  231. package/build-tsc-esm/Abi/toV2.js +27 -0
  232. package/build-tsc-esm/Abi/toV3.js +10 -0
  233. package/build-tsc-esm/Abi/toV4.js +10 -0
  234. package/build-tsc-esm/augment.js +1 -0
  235. package/build-tsc-esm/base/Base.js +40 -0
  236. package/build-tsc-esm/base/Blueprint.js +51 -0
  237. package/build-tsc-esm/base/Code.js +74 -0
  238. package/build-tsc-esm/base/Contract.js +127 -0
  239. package/build-tsc-esm/base/index.js +3 -0
  240. package/build-tsc-esm/base/mock.js +38 -0
  241. package/build-tsc-esm/base/types.js +1 -0
  242. package/build-tsc-esm/base/util.js +33 -0
  243. package/build-tsc-esm/bundle.js +4 -0
  244. package/build-tsc-esm/index.js +2 -0
  245. package/build-tsc-esm/packageDetect.js +5 -0
  246. package/build-tsc-esm/packageInfo.js +1 -0
  247. package/build-tsc-esm/promise/index.js +17 -0
  248. package/build-tsc-esm/promise/types.js +1 -0
  249. package/build-tsc-esm/rx/index.js +17 -0
  250. package/build-tsc-esm/rx/types.js +1 -0
  251. package/build-tsc-esm/types.js +1 -0
  252. package/build-tsc-esm/util.js +10 -0
  253. package/bundle-pezkuwi-api-contract.js +1238 -0
  254. package/bundle.d.ts +4 -0
  255. package/bundle.js +4 -0
  256. package/cjs/Abi/index.d.ts +31 -0
  257. package/cjs/Abi/index.js +363 -0
  258. package/cjs/Abi/toLatestCompatible.d.ts +15 -0
  259. package/cjs/Abi/toLatestCompatible.js +36 -0
  260. package/cjs/Abi/toV1.d.ts +3 -0
  261. package/cjs/Abi/toV1.js +24 -0
  262. package/cjs/Abi/toV2.d.ts +3 -0
  263. package/cjs/Abi/toV2.js +30 -0
  264. package/cjs/Abi/toV3.d.ts +3 -0
  265. package/cjs/Abi/toV3.js +13 -0
  266. package/cjs/Abi/toV4.d.ts +3 -0
  267. package/cjs/Abi/toV4.js +13 -0
  268. package/cjs/augment.d.ts +1 -0
  269. package/cjs/augment.js +3 -0
  270. package/cjs/base/Base.d.ts +13 -0
  271. package/cjs/base/Base.js +44 -0
  272. package/cjs/base/Blueprint.d.ts +24 -0
  273. package/cjs/base/Blueprint.js +57 -0
  274. package/cjs/base/Code.d.ts +22 -0
  275. package/cjs/base/Code.js +80 -0
  276. package/cjs/base/Contract.d.ts +25 -0
  277. package/cjs/base/Contract.js +133 -0
  278. package/cjs/base/index.d.ts +3 -0
  279. package/cjs/base/index.js +14 -0
  280. package/cjs/base/mock.d.ts +3 -0
  281. package/cjs/base/mock.js +41 -0
  282. package/cjs/base/types.d.ts +25 -0
  283. package/cjs/base/types.js +2 -0
  284. package/cjs/base/util.d.ts +16 -0
  285. package/cjs/base/util.js +42 -0
  286. package/cjs/bundle.d.ts +4 -0
  287. package/cjs/bundle.js +10 -0
  288. package/cjs/index.d.ts +2 -0
  289. package/cjs/index.js +5 -0
  290. package/cjs/package.json +3 -0
  291. package/cjs/packageDetect.d.ts +1 -0
  292. package/cjs/packageDetect.js +7 -0
  293. package/cjs/packageInfo.d.ts +6 -0
  294. package/cjs/packageInfo.js +4 -0
  295. package/cjs/promise/index.d.ts +13 -0
  296. package/cjs/promise/index.js +23 -0
  297. package/cjs/promise/types.d.ts +3 -0
  298. package/cjs/promise/types.js +2 -0
  299. package/cjs/rx/index.d.ts +13 -0
  300. package/cjs/rx/index.js +23 -0
  301. package/cjs/rx/types.d.ts +3 -0
  302. package/cjs/rx/types.js +2 -0
  303. package/cjs/types.d.ts +79 -0
  304. package/cjs/types.js +2 -0
  305. package/cjs/util.d.ts +5 -0
  306. package/cjs/util.js +13 -0
  307. package/index.d.ts +2 -0
  308. package/index.js +2 -0
  309. package/package.json +384 -15
  310. package/packageDetect.d.ts +1 -0
  311. package/packageDetect.js +5 -0
  312. package/packageInfo.d.ts +6 -0
  313. package/packageInfo.js +1 -0
  314. package/promise/index.d.ts +13 -0
  315. package/promise/index.js +17 -0
  316. package/promise/types.d.ts +3 -0
  317. package/promise/types.js +1 -0
  318. package/rx/index.d.ts +13 -0
  319. package/rx/index.js +17 -0
  320. package/rx/types.d.ts +3 -0
  321. package/rx/types.js +1 -0
  322. package/src/Abi/Abi.spec.ts +2 -2
  323. package/src/Abi/index.ts +1 -1
  324. package/src/Abi/toLatestCompatible.spec.ts +1 -1
  325. package/src/Abi/toLatestCompatible.ts +1 -1
  326. package/src/Abi/toV1.ts +1 -1
  327. package/src/Abi/toV2.ts +1 -1
  328. package/src/Abi/toV3.ts +1 -1
  329. package/src/Abi/toV4.ts +1 -1
  330. package/src/augment.ts +1 -1
  331. package/src/base/Base.ts +1 -1
  332. package/src/base/Blueprint.ts +1 -1
  333. package/src/base/Code.spec.ts +1 -1
  334. package/src/base/Code.ts +1 -1
  335. package/src/base/Contract.ts +1 -1
  336. package/src/base/index.ts +1 -1
  337. package/src/base/mock.ts +1 -1
  338. package/src/base/types.ts +1 -1
  339. package/src/base/util.ts +1 -1
  340. package/src/bundle.ts +1 -1
  341. package/src/checkTypes.manual.ts +4 -4
  342. package/src/index.ts +1 -1
  343. package/src/mod.ts +1 -1
  344. package/src/packageDetect.ts +2 -2
  345. package/src/packageInfo.ts +3 -3
  346. package/src/promise/index.ts +1 -1
  347. package/src/promise/types.ts +1 -1
  348. package/src/rx/index.ts +1 -1
  349. package/src/rx/types.ts +1 -1
  350. package/src/test/contracts/index.ts +1 -1
  351. package/src/test/contracts/ink/index.ts +1 -1
  352. package/src/test/contracts/ink/v0/index.ts +1 -1
  353. package/src/test/contracts/ink/v1/index.ts +1 -1
  354. package/src/test/contracts/ink/v2/index.ts +1 -1
  355. package/src/test/contracts/ink/v3/index.ts +1 -1
  356. package/src/test/contracts/ink/v4/index.ts +1 -1
  357. package/src/test/contracts/ink/v5/index.ts +1 -1
  358. package/src/test/contracts/ink/v6/index.ts +1 -1
  359. package/src/test/contracts/solang/index.ts +1 -1
  360. package/src/test/contracts/solang/v0/index.ts +1 -1
  361. package/src/test/contracts/user/index.ts +1 -1
  362. package/src/test/contracts/user/v0/index.ts +1 -1
  363. package/src/test/contracts/user/v3/index.ts +1 -1
  364. package/src/test/contracts/user/v4/index.ts +1 -1
  365. package/src/test/contracts/util.ts +1 -1
  366. package/src/types.ts +1 -1
  367. package/src/util.ts +1 -1
  368. package/tsconfig.build.tsbuildinfo +1 -1
  369. package/tsconfig.spec.tsbuildinfo +1 -0
  370. package/types.d.ts +79 -0
  371. package/types.js +1 -0
  372. package/util.d.ts +5 -0
  373. package/util.js +10 -0
@@ -0,0 +1,25 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
3
+ import type { ApiTypes, ObsInnerType } from '@pezkuwi/api/types';
4
+ import type { AccountId } from '@pezkuwi/types/interfaces';
5
+ import type { AbiMessage, BlueprintOptions, ContractCallOutcome, ContractOptions } from '../types.js';
6
+ export interface MessageMeta {
7
+ readonly meta: AbiMessage;
8
+ }
9
+ export interface BlueprintDeploy<ApiType extends ApiTypes> extends MessageMeta {
10
+ (options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
11
+ }
12
+ export interface ContractQuery<ApiType extends ApiTypes> extends MessageMeta {
13
+ (origin: AccountId | string | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome>;
14
+ }
15
+ export interface ContractTx<ApiType extends ApiTypes> extends MessageMeta {
16
+ (options: ContractOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
17
+ }
18
+ export type ContractGeneric<O, T> = (messageOrId: AbiMessage | string | number, options: O, ...params: unknown[]) => T;
19
+ export type ContractCallResult<ApiType extends ApiTypes, T> = ApiType extends 'rxjs' ? Observable<T> : Promise<ObsInnerType<Observable<T>>>;
20
+ export interface ContractCallSend<ApiType extends ApiTypes> {
21
+ send(account: string | AccountId | Uint8Array): ContractCallResult<ApiType, ContractCallOutcome>;
22
+ }
23
+ export type MapConstructorExec<ApiType extends ApiTypes> = Record<string, BlueprintDeploy<ApiType>>;
24
+ export type MapMessageTx<ApiType extends ApiTypes> = Record<string, ContractTx<ApiType>>;
25
+ export type MapMessageQuery<ApiType extends ApiTypes> = Record<string, ContractQuery<ApiType>>;
package/base/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/base/util.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { SubmittableResult } from '@pezkuwi/api';
2
+ import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
3
+ import type { ApiTypes } from '@pezkuwi/api/types';
4
+ import type { WeightV1, WeightV2 } from '@pezkuwi/types/interfaces';
5
+ import type { BN } from '@pezkuwi/util';
6
+ import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll } from '../types.js';
7
+ import type { BlueprintDeploy, ContractGeneric } from './types.js';
8
+ export declare const EMPTY_SALT: Uint8Array;
9
+ export declare function withMeta<T extends {
10
+ meta: AbiMessage;
11
+ }>(meta: AbiMessage, creator: Omit<T, 'meta'>): T;
12
+ export declare function createBluePrintTx<ApiType extends ApiTypes, R extends SubmittableResult>(meta: AbiMessage, fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType>;
13
+ export declare function createBluePrintWithId<T>(fn: (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: unknown[]) => T): ContractGeneric<BlueprintOptions, T>;
14
+ export declare function encodeSalt(salt?: Uint8Array | string | null): Uint8Array;
15
+ export declare function convertWeight(weight: WeightV1 | WeightV2 | bigint | string | number | BN): WeightAll;
16
+ export declare function isWeightV2(weight: WeightV1 | WeightV2 | bigint | string | number | BN): weight is WeightV2;
package/base/util.js ADDED
@@ -0,0 +1,33 @@
1
+ import { Bytes } from '@pezkuwi/types';
2
+ import { bnToBn, compactAddLength, u8aToU8a } from '@pezkuwi/util';
3
+ import { randomAsU8a } from '@pezkuwi/util-crypto';
4
+ export const EMPTY_SALT = new Uint8Array();
5
+ export function withMeta(meta, creator) {
6
+ creator.meta = meta;
7
+ return creator;
8
+ }
9
+ export function createBluePrintTx(meta, fn) {
10
+ return withMeta(meta, (options, ...params) => fn(options, params));
11
+ }
12
+ export function createBluePrintWithId(fn) {
13
+ return (constructorOrId, options, ...params) => fn(constructorOrId, options, params);
14
+ }
15
+ export function encodeSalt(salt = randomAsU8a()) {
16
+ return salt instanceof Bytes
17
+ ? salt
18
+ : salt?.length
19
+ ? compactAddLength(u8aToU8a(salt))
20
+ : EMPTY_SALT;
21
+ }
22
+ export function convertWeight(weight) {
23
+ const [refTime, proofSize] = isWeightV2(weight)
24
+ ? [weight.refTime.toBn(), weight.proofSize.toBn()]
25
+ : [bnToBn(weight), undefined];
26
+ return {
27
+ v1Weight: refTime,
28
+ v2Weight: { proofSize, refTime }
29
+ };
30
+ }
31
+ export function isWeightV2(weight) {
32
+ return !!weight.proofSize;
33
+ }
@@ -0,0 +1,359 @@
1
+ import { Option, TypeRegistry } from '@pezkuwi/types';
2
+ import { TypeDefInfo } from '@pezkuwi/types-create';
3
+ import { assertReturn, compactAddLength, compactStripLength, isBn, isNumber, isObject, isString, isUndefined, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@pezkuwi/util';
4
+ import { convertVersions, enumVersions } from './toLatestCompatible.js';
5
+ const l = logger('Abi');
6
+ const PRIMITIVE_ALWAYS = ['AccountId', 'AccountId20', 'AccountIndex', 'Address', 'Balance'];
7
+ function findMessage(list, messageOrId) {
8
+ const message = isNumber(messageOrId)
9
+ ? list[messageOrId]
10
+ : isString(messageOrId)
11
+ ? list.find(({ identifier }) => [identifier, stringCamelCase(identifier)].includes(messageOrId.toString()))
12
+ : messageOrId;
13
+ return assertReturn(message, () => `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`);
14
+ }
15
+ function getMetadata(registry, json) {
16
+ // this is for V1, V2, V3
17
+ const vx = enumVersions.find((v) => isObject(json[v]));
18
+ // this was added in V4
19
+ const jsonVersion = json.version;
20
+ if (!vx && jsonVersion && !enumVersions.find((v) => v === `V${jsonVersion}`)) {
21
+ throw new Error(`Unable to handle version ${jsonVersion}`);
22
+ }
23
+ const metadata = registry.createType('ContractMetadata', vx
24
+ ? { [vx]: json[vx] }
25
+ : jsonVersion
26
+ ? { [`V${jsonVersion}`]: json }
27
+ : { V0: json });
28
+ const converter = convertVersions.find(([v]) => metadata[`is${v}`]);
29
+ if (!converter) {
30
+ throw new Error(`Unable to convert ABI with version ${metadata.type} to a supported version`);
31
+ }
32
+ const upgradedMetadata = converter[1](registry, metadata[`as${converter[0]}`]);
33
+ return upgradedMetadata;
34
+ }
35
+ function isRevive(json) {
36
+ const source = json['source'];
37
+ const version = json['version'];
38
+ const hasContractBinary = typeof source === 'object' &&
39
+ source !== null &&
40
+ 'contract_binary' in source;
41
+ const hasVersion = typeof version === 'number' && version >= 6;
42
+ return hasContractBinary || hasVersion;
43
+ }
44
+ function parseJson(json, chainProperties) {
45
+ const registry = new TypeRegistry();
46
+ const revive = isRevive(json);
47
+ const typeName = revive ? 'ContractReviveProjectInfo' : 'ContractProjectInfo';
48
+ const info = registry.createType(typeName, json);
49
+ const metadata = getMetadata(registry, json);
50
+ const lookup = registry.createType('PortableRegistry', { types: metadata.types }, true);
51
+ // attach the lookup to the registry - now the types are known
52
+ registry.setLookup(lookup);
53
+ if (chainProperties) {
54
+ registry.setChainProperties(chainProperties);
55
+ }
56
+ // warm-up the actual type, pre-use
57
+ lookup.types.forEach(({ id }) => lookup.getTypeDef(id));
58
+ return [json, registry, metadata, info, revive];
59
+ }
60
+ /**
61
+ * @internal
62
+ * Determines if the given input value is a ContractTypeSpec
63
+ */
64
+ function isTypeSpec(value) {
65
+ return !!value && value instanceof Map && !isUndefined(value.type) && !isUndefined(value.displayName);
66
+ }
67
+ /**
68
+ * @internal
69
+ * Determines if the given input value is an Option
70
+ */
71
+ function isOption(value) {
72
+ return !!value && value instanceof Option;
73
+ }
74
+ export class Abi {
75
+ events;
76
+ constructors;
77
+ info;
78
+ json;
79
+ messages;
80
+ metadata;
81
+ registry;
82
+ environment = new Map();
83
+ isRevive;
84
+ constructor(abiJson, chainProperties) {
85
+ [this.json, this.registry, this.metadata, this.info, this.isRevive] = parseJson(isString(abiJson)
86
+ ? JSON.parse(abiJson)
87
+ : abiJson, chainProperties);
88
+ this.constructors = this.metadata.spec.constructors.map((spec, index) => this.#createMessage(spec, index, {
89
+ isConstructor: true,
90
+ isDefault: spec.default.isTrue,
91
+ isPayable: spec.payable.isTrue,
92
+ returnType: spec.returnType.isSome
93
+ ? this.registry.lookup.getTypeDef(spec.returnType.unwrap().type)
94
+ : null
95
+ }));
96
+ this.events = this.metadata.spec.events.map((_, index) => this.#createEvent(index));
97
+ this.messages = this.metadata.spec.messages.map((spec, index) => this.#createMessage(spec, index, {
98
+ isDefault: spec.default.isTrue,
99
+ isMutating: spec.mutates.isTrue,
100
+ isPayable: spec.payable.isTrue,
101
+ returnType: spec.returnType.isSome
102
+ ? this.registry.lookup.getTypeDef(spec.returnType.unwrap().type)
103
+ : null
104
+ }));
105
+ // NOTE See the rationale for having Option<...> values in the actual
106
+ // ContractEnvironmentV4 structure definition in interfaces/contractsAbi
107
+ // (Due to conversions, the fields may not exist)
108
+ for (const [key, opt] of this.metadata.spec.environment.entries()) {
109
+ if (isOption(opt)) {
110
+ if (opt.isSome) {
111
+ const value = opt.unwrap();
112
+ if (isBn(value)) {
113
+ this.environment.set(key, value);
114
+ }
115
+ else if (isTypeSpec(value)) {
116
+ this.environment.set(key, this.registry.lookup.getTypeDef(value.type));
117
+ }
118
+ else {
119
+ throw new Error(`Invalid environment definition for ${key}:: Expected either Number or ContractTypeSpec`);
120
+ }
121
+ }
122
+ }
123
+ else {
124
+ throw new Error(`Expected Option<*> definition for ${key} in ContractEnvironment`);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Warning: Unstable API, bound to change
130
+ */
131
+ decodeEvent(record) {
132
+ switch (this.metadata.version.toString()) {
133
+ // earlier version are hoisted to v4
134
+ case '4':
135
+ return this.#decodeEventV4(record);
136
+ case '5':
137
+ return this.#decodeEventV5(record);
138
+ // Latest
139
+ default:
140
+ return this.#decodeEventV6(record);
141
+ }
142
+ }
143
+ #decodeEventV6 = (record) => {
144
+ const topics = record.event.data[2];
145
+ // Try to match by signature topic (first topic)
146
+ const signatureTopic = topics[0];
147
+ const data = record.event.data[1];
148
+ if (signatureTopic) {
149
+ const event = this.events.find((e) => e.signatureTopic !== undefined && e.signatureTopic !== null && e.signatureTopic === signatureTopic.toHex());
150
+ // Early return if event found by signature topic
151
+ if (event) {
152
+ return event.fromU8a(data);
153
+ }
154
+ }
155
+ // If no event returned yet, it might be anonymous
156
+ const amountOfTopics = topics.length;
157
+ const potentialEvents = this.events.filter((e) => {
158
+ // event can't have a signature topic
159
+ if (e.signatureTopic !== null && e.signatureTopic !== undefined) {
160
+ return false;
161
+ }
162
+ // event should have same amount of indexed fields as emitted topics
163
+ const amountIndexed = e.args.filter((a) => a.indexed).length;
164
+ if (amountIndexed !== amountOfTopics) {
165
+ return false;
166
+ }
167
+ // If all conditions met, it's a potential event
168
+ return true;
169
+ });
170
+ if (potentialEvents.length === 1) {
171
+ return potentialEvents[0].fromU8a(data);
172
+ }
173
+ throw new Error('Unable to determine event');
174
+ };
175
+ #decodeEventV5 = (record) => {
176
+ // Find event by first topic, which potentially is the signature_topic
177
+ const signatureTopic = record.topics[0];
178
+ const data = record.event.data[1];
179
+ if (signatureTopic) {
180
+ const event = this.events.find((e) => e.signatureTopic !== undefined && e.signatureTopic !== null && e.signatureTopic === signatureTopic.toHex());
181
+ // Early return if event found by signature topic
182
+ if (event) {
183
+ return event.fromU8a(data);
184
+ }
185
+ }
186
+ // If no event returned yet, it might be anonymous
187
+ const amountOfTopics = record.topics.length;
188
+ const potentialEvents = this.events.filter((e) => {
189
+ // event can't have a signature topic
190
+ if (e.signatureTopic !== null && e.signatureTopic !== undefined) {
191
+ return false;
192
+ }
193
+ // event should have same amount of indexed fields as emitted topics
194
+ const amountIndexed = e.args.filter((a) => a.indexed).length;
195
+ if (amountIndexed !== amountOfTopics) {
196
+ return false;
197
+ }
198
+ // If all conditions met, it's a potential event
199
+ return true;
200
+ });
201
+ if (potentialEvents.length === 1) {
202
+ return potentialEvents[0].fromU8a(data);
203
+ }
204
+ throw new Error('Unable to determine event');
205
+ };
206
+ #decodeEventV4 = (record) => {
207
+ const data = record.event.data[1];
208
+ const index = data[0];
209
+ const event = this.events[index];
210
+ if (!event) {
211
+ throw new Error(`Unable to find event with index ${index}`);
212
+ }
213
+ return event.fromU8a(data.subarray(1));
214
+ };
215
+ /**
216
+ * Warning: Unstable API, bound to change
217
+ */
218
+ decodeConstructor(data) {
219
+ return this.#decodeMessage('message', this.constructors, data);
220
+ }
221
+ /**
222
+ * Warning: Unstable API, bound to change
223
+ */
224
+ decodeMessage(data) {
225
+ return this.#decodeMessage('message', this.messages, data);
226
+ }
227
+ findConstructor(constructorOrId) {
228
+ return findMessage(this.constructors, constructorOrId);
229
+ }
230
+ findMessage(messageOrId) {
231
+ return findMessage(this.messages, messageOrId);
232
+ }
233
+ #createArgs = (args, spec) => {
234
+ return args.map(({ label, type }, index) => {
235
+ try {
236
+ if (!isObject(type)) {
237
+ throw new Error('Invalid type definition found');
238
+ }
239
+ const displayName = type.displayName.length
240
+ ? type.displayName[type.displayName.length - 1].toString()
241
+ : undefined;
242
+ const camelName = stringCamelCase(label);
243
+ if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) {
244
+ return {
245
+ name: camelName,
246
+ type: {
247
+ info: TypeDefInfo.Plain,
248
+ type: displayName
249
+ }
250
+ };
251
+ }
252
+ const typeDef = this.registry.lookup.getTypeDef(type.type);
253
+ return {
254
+ name: camelName,
255
+ type: displayName && !typeDef.type.startsWith(displayName)
256
+ ? { displayName, ...typeDef }
257
+ : typeDef
258
+ };
259
+ }
260
+ catch (error) {
261
+ l.error(`Error expanding argument ${index} in ${stringify(spec)}`);
262
+ throw error;
263
+ }
264
+ });
265
+ };
266
+ #createMessageParams = (args, spec) => {
267
+ return this.#createArgs(args, spec);
268
+ };
269
+ #createEventParams = (args, spec) => {
270
+ const params = this.#createArgs(args, spec);
271
+ return params.map((p, index) => ({ ...p, indexed: args[index].indexed.toPrimitive() }));
272
+ };
273
+ #createEvent = (index) => {
274
+ // TODO TypeScript would narrow this type to the correct version,
275
+ // but version is `Text` so I need to call `toString()` here,
276
+ // which breaks the type inference.
277
+ switch (this.metadata.version.toString()) {
278
+ case '4':
279
+ return this.#createEventV4(this.metadata.spec.events[index], index);
280
+ default:
281
+ return this.#createEventV5(this.metadata.spec.events[index], index);
282
+ }
283
+ };
284
+ #createEventV5 = (spec, index) => {
285
+ const args = this.#createEventParams(spec.args, spec);
286
+ const event = {
287
+ args,
288
+ docs: spec.docs.map((d) => d.toString()),
289
+ fromU8a: (data) => ({
290
+ args: this.#decodeArgs(args, data),
291
+ event
292
+ }),
293
+ identifier: [spec.module_path, spec.label].join('::'),
294
+ index,
295
+ signatureTopic: spec.signature_topic.isSome ? spec.signature_topic.unwrap().toHex() : null
296
+ };
297
+ return event;
298
+ };
299
+ #createEventV4 = (spec, index) => {
300
+ const args = this.#createEventParams(spec.args, spec);
301
+ const event = {
302
+ args,
303
+ docs: spec.docs.map((d) => d.toString()),
304
+ fromU8a: (data) => ({
305
+ args: this.#decodeArgs(args, data),
306
+ event
307
+ }),
308
+ identifier: spec.label.toString(),
309
+ index
310
+ };
311
+ return event;
312
+ };
313
+ #createMessage = (spec, index, add = {}) => {
314
+ const args = this.#createMessageParams(spec.args, spec);
315
+ const identifier = spec.label.toString();
316
+ const message = {
317
+ ...add,
318
+ args,
319
+ docs: spec.docs.map((d) => d.toString()),
320
+ fromU8a: (data) => ({
321
+ args: this.#decodeArgs(args, data),
322
+ message
323
+ }),
324
+ identifier,
325
+ index,
326
+ isDefault: spec.default.isTrue,
327
+ method: stringCamelCase(identifier),
328
+ path: identifier.split('::').map((s) => stringCamelCase(s)),
329
+ selector: spec.selector,
330
+ toU8a: (params) => this.#encodeMessageArgs(spec, args, params)
331
+ };
332
+ return message;
333
+ };
334
+ #decodeArgs = (args, data) => {
335
+ // for decoding we expect the input to be just the arg data, no selectors
336
+ // no length added (this allows use with events as well)
337
+ let offset = 0;
338
+ return args.map(({ type: { lookupName, type } }) => {
339
+ const value = this.registry.createType(lookupName || type, data.subarray(offset));
340
+ offset += value.encodedLength;
341
+ return value;
342
+ });
343
+ };
344
+ #decodeMessage = (type, list, data) => {
345
+ const [, trimmed] = compactStripLength(data);
346
+ const selector = trimmed.subarray(0, 4);
347
+ const message = list.find((m) => m.selector.eq(selector));
348
+ if (!message) {
349
+ throw new Error(`Unable to find ${type} with selector ${u8aToHex(selector)}`);
350
+ }
351
+ return message.fromU8a(trimmed.subarray(4));
352
+ };
353
+ #encodeMessageArgs = ({ label, selector }, args, data) => {
354
+ if (data.length !== args.length) {
355
+ throw new Error(`Expected ${args.length} arguments to contract message '${label.toString()}', found ${data.length}`);
356
+ }
357
+ return compactAddLength(u8aConcat(this.registry.createType('ContractSelector', selector).toU8a(), ...args.map(({ type: { lookupName, type } }, index) => this.registry.createType(lookupName || type, data[index]).toU8a())));
358
+ };
359
+ }
@@ -0,0 +1,30 @@
1
+ import { v0ToV1 } from './toV1.js';
2
+ import { v1ToV2 } from './toV2.js';
3
+ import { v2ToV3 } from './toV3.js';
4
+ import { v3ToV4 } from './toV4.js';
5
+ export const enumVersions = ['V6', 'V5', 'V4', 'V3', 'V2', 'V1'];
6
+ function createConverter(next, step) {
7
+ return (registry, input) => next(registry, step(registry, input));
8
+ }
9
+ export function v6ToLatestCompatible(_registry, v6) {
10
+ return v6;
11
+ }
12
+ export function v5ToLatestCompatible(_registry, v5) {
13
+ return v5;
14
+ }
15
+ export function v4ToLatestCompatible(_registry, v4) {
16
+ return v4;
17
+ }
18
+ export const v3ToLatestCompatible = /*#__PURE__*/ createConverter(v4ToLatestCompatible, v3ToV4);
19
+ export const v2ToLatestCompatible = /*#__PURE__*/ createConverter(v3ToLatestCompatible, v2ToV3);
20
+ export const v1ToLatestCompatible = /*#__PURE__*/ createConverter(v2ToLatestCompatible, v1ToV2);
21
+ export const v0ToLatestCompatible = /*#__PURE__*/ createConverter(v1ToLatestCompatible, v0ToV1);
22
+ export const convertVersions = [
23
+ ['V6', v6ToLatestCompatible],
24
+ ['V5', v5ToLatestCompatible],
25
+ ['V4', v4ToLatestCompatible],
26
+ ['V3', v3ToLatestCompatible],
27
+ ['V2', v2ToLatestCompatible],
28
+ ['V1', v1ToLatestCompatible],
29
+ ['V0', v0ToLatestCompatible]
30
+ ];
@@ -0,0 +1,21 @@
1
+ import { convertSiV0toV1 } from '@pezkuwi/types';
2
+ import { objectSpread } from '@pezkuwi/util';
3
+ function v0ToV1Names(all) {
4
+ return all.map((e) => objectSpread({}, e, {
5
+ name: Array.isArray(e.name)
6
+ ? e.name
7
+ : [e.name]
8
+ }));
9
+ }
10
+ export function v0ToV1(registry, v0) {
11
+ if (!v0.metadataVersion.length) {
12
+ throw new Error('Invalid format for V0 (detected) contract metadata');
13
+ }
14
+ return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
15
+ spec: objectSpread({}, v0.spec, {
16
+ constructors: v0ToV1Names(v0.spec.constructors),
17
+ messages: v0ToV1Names(v0.spec.messages)
18
+ }),
19
+ types: convertSiV0toV1(registry, v0.types)
20
+ }));
21
+ }
@@ -0,0 +1,27 @@
1
+ import { objectSpread } from '@pezkuwi/util';
2
+ const ARG_TYPES = {
3
+ ContractConstructorSpec: 'ContractMessageParamSpecV2',
4
+ ContractEventSpec: 'ContractEventParamSpecV2',
5
+ ContractMessageSpec: 'ContractMessageParamSpecV2'
6
+ };
7
+ function v1ToV2Label(entry) {
8
+ return objectSpread({}, entry, {
9
+ label: Array.isArray(entry.name)
10
+ ? entry.name.join('::')
11
+ : entry.name
12
+ });
13
+ }
14
+ function v1ToV2Labels(registry, outType, all) {
15
+ return all.map((e) => registry.createType(`${outType}V2`, objectSpread(v1ToV2Label(e), {
16
+ args: e.args.map((a) => registry.createType(ARG_TYPES[outType], v1ToV2Label(a)))
17
+ })));
18
+ }
19
+ export function v1ToV2(registry, v1) {
20
+ return registry.createType('ContractMetadataV2', objectSpread({}, v1, {
21
+ spec: objectSpread({}, v1.spec, {
22
+ constructors: v1ToV2Labels(registry, 'ContractConstructorSpec', v1.spec.constructors),
23
+ events: v1ToV2Labels(registry, 'ContractEventSpec', v1.spec.events),
24
+ messages: v1ToV2Labels(registry, 'ContractMessageSpec', v1.spec.messages)
25
+ })
26
+ }));
27
+ }
@@ -0,0 +1,10 @@
1
+ import { objectSpread } from '@pezkuwi/util';
2
+ export function v2ToV3(registry, v2) {
3
+ return registry.createType('ContractMetadataV3', objectSpread({}, v2, {
4
+ spec: objectSpread({}, v2.spec, {
5
+ constructors: v2.spec.constructors.map((c) =>
6
+ // V3 introduces the payable flag on constructors, for <V3, it is always true
7
+ registry.createType('ContractConstructorSpecV3', objectSpread({}, c, { payable: true })))
8
+ })
9
+ }));
10
+ }
@@ -0,0 +1,10 @@
1
+ import { objectSpread } from '@pezkuwi/util';
2
+ export function v3ToV4(registry, v3) {
3
+ return registry.createType('ContractMetadataV4', objectSpread({}, v3, {
4
+ spec: objectSpread({}, v3.spec, {
5
+ constructors: v3.spec.constructors.map((c) => registry.createType('ContractConstructorSpecV4', objectSpread({}, c))),
6
+ messages: v3.spec.messages.map((m) => registry.createType('ContractMessageSpecV3', objectSpread({}, m)))
7
+ }),
8
+ version: registry.createType('Text', '4')
9
+ }));
10
+ }