@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/bin/aesophia_cli +0 -0
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +4206 -1127
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/AeSdkBase.d.ts +3 -3
  9. package/es/AeSdkBase.mjs +4 -0
  10. package/es/AeSdkBase.mjs.map +1 -1
  11. package/es/AeSdkMethods.d.ts +3 -4
  12. package/es/AeSdkMethods.mjs.map +1 -1
  13. package/es/Node.d.ts +4 -3
  14. package/es/Node.mjs +1 -1
  15. package/es/Node.mjs.map +1 -1
  16. package/es/account/Base.d.ts +2 -2
  17. package/es/account/Base.mjs.map +1 -1
  18. package/es/account/Generalized.mjs +5 -3
  19. package/es/account/Generalized.mjs.map +1 -1
  20. package/es/account/Ledger.mjs +2 -1
  21. package/es/account/Ledger.mjs.map +1 -1
  22. package/es/account/Memory.mjs +2 -1
  23. package/es/account/Memory.mjs.map +1 -1
  24. package/es/aens.d.ts +1 -1
  25. package/es/aens.mjs +5 -1
  26. package/es/aens.mjs.map +1 -1
  27. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  28. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -4
  29. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  30. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +1 -1
  31. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  32. package/es/chain.d.ts +9 -1
  33. package/es/chain.mjs +4 -1
  34. package/es/chain.mjs.map +1 -1
  35. package/es/channel/Base.d.ts +6 -1
  36. package/es/channel/Base.mjs +9 -6
  37. package/es/channel/Base.mjs.map +1 -1
  38. package/es/channel/Contract.d.ts +8 -7
  39. package/es/channel/Contract.mjs +1 -1
  40. package/es/channel/Contract.mjs.map +1 -1
  41. package/es/channel/Spend.d.ts +3 -1
  42. package/es/channel/Spend.mjs +4 -2
  43. package/es/channel/Spend.mjs.map +1 -1
  44. package/es/channel/handlers.mjs +11 -9
  45. package/es/channel/handlers.mjs.map +1 -1
  46. package/es/channel/internal.mjs +3 -1
  47. package/es/channel/internal.mjs.map +1 -1
  48. package/es/contract/Contract.d.ts +21 -46
  49. package/es/contract/Contract.mjs +69 -52
  50. package/es/contract/Contract.mjs.map +1 -1
  51. package/es/contract/compiler/Base.d.ts +81 -0
  52. package/es/contract/compiler/Base.mjs +5 -0
  53. package/es/contract/compiler/Base.mjs.map +1 -0
  54. package/es/contract/compiler/Cli.d.ts +23 -0
  55. package/es/contract/compiler/Cli.mjs +155 -0
  56. package/es/contract/compiler/Cli.mjs.map +1 -0
  57. package/es/contract/compiler/Http.d.ts +32 -0
  58. package/es/contract/{CompilerHttp.mjs → compiler/Http.mjs} +64 -9
  59. package/es/contract/compiler/Http.mjs.map +1 -0
  60. package/es/contract/compiler/HttpNode.d.ts +17 -0
  61. package/es/contract/compiler/HttpNode.mjs +26 -0
  62. package/es/contract/compiler/HttpNode.mjs.map +1 -0
  63. package/es/contract/compiler/getFileSystem.d.ts +6 -0
  64. package/es/contract/compiler/getFileSystem.mjs +40 -0
  65. package/es/contract/compiler/getFileSystem.mjs.map +1 -0
  66. package/es/contract/ga.d.ts +5 -4
  67. package/es/contract/ga.mjs +11 -2
  68. package/es/contract/ga.mjs.map +1 -1
  69. package/es/index-browser.d.ts +39 -0
  70. package/es/index-browser.mjs +55 -0
  71. package/es/index-browser.mjs.map +1 -0
  72. package/es/index.d.ts +4 -38
  73. package/es/index.mjs +4 -53
  74. package/es/index.mjs.map +1 -1
  75. package/es/oracle.mjs +1 -1
  76. package/es/oracle.mjs.map +1 -1
  77. package/es/spend.mjs +1 -3
  78. package/es/spend.mjs.map +1 -1
  79. package/es/tx/builder/constants.d.ts +28 -1
  80. package/es/tx/builder/constants.mjs +32 -3
  81. package/es/tx/builder/constants.mjs.map +1 -1
  82. package/es/tx/builder/field-types/abi-version.d.ts +10 -0
  83. package/es/tx/builder/field-types/abi-version.mjs +20 -0
  84. package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
  85. package/es/tx/builder/field-types/address.d.ts +5 -6
  86. package/es/tx/builder/field-types/address.mjs +17 -8
  87. package/es/tx/builder/field-types/address.mjs.map +1 -1
  88. package/es/tx/builder/field-types/array.d.ts +7 -0
  89. package/es/tx/builder/field-types/array.mjs +11 -0
  90. package/es/tx/builder/field-types/array.mjs.map +1 -0
  91. package/es/tx/builder/field-types/boolean.d.ts +6 -0
  92. package/es/tx/builder/field-types/boolean.mjs +13 -0
  93. package/es/tx/builder/field-types/boolean.mjs.map +1 -0
  94. package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
  95. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  96. package/es/tx/builder/field-types/ct-version.d.ts +30 -0
  97. package/es/tx/builder/field-types/ct-version.mjs +48 -0
  98. package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
  99. package/es/tx/builder/field-types/deposit.d.ts +1 -1
  100. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  101. package/es/tx/builder/field-types/encoded.d.ts +6 -0
  102. package/es/tx/builder/field-types/encoded.mjs +21 -0
  103. package/es/tx/builder/field-types/encoded.mjs.map +1 -0
  104. package/es/tx/builder/field-types/entry.d.ts +11 -0
  105. package/es/tx/builder/field-types/entry.mjs +31 -0
  106. package/es/tx/builder/field-types/entry.mjs.map +1 -0
  107. package/es/tx/builder/field-types/enumeration.d.ts +5 -3
  108. package/es/tx/builder/field-types/enumeration.mjs +11 -2
  109. package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
  110. package/es/tx/builder/field-types/fee.d.ts +10 -7
  111. package/es/tx/builder/field-types/fee.mjs +24 -20
  112. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  113. package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
  114. package/es/tx/builder/field-types/gas-limit.mjs +9 -6
  115. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  116. package/es/tx/builder/field-types/gas-price.d.ts +1 -1
  117. package/es/tx/builder/field-types/index.d.ts +66 -28
  118. package/es/tx/builder/field-types/index.mjs +30 -12
  119. package/es/tx/builder/field-types/index.mjs.map +1 -1
  120. package/es/tx/builder/field-types/mptree.d.ts +37 -0
  121. package/es/tx/builder/field-types/mptree.mjs +268 -0
  122. package/es/tx/builder/field-types/mptree.mjs.map +1 -0
  123. package/es/tx/builder/field-types/name-fee.d.ts +1 -2
  124. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  125. package/es/tx/builder/field-types/name-id.mjs +2 -1
  126. package/es/tx/builder/field-types/name-id.mjs.map +1 -1
  127. package/es/tx/builder/field-types/pointers.mjs +2 -2
  128. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  129. package/es/tx/builder/field-types/raw.d.ts +6 -0
  130. package/es/tx/builder/field-types/raw.mjs +13 -0
  131. package/es/tx/builder/field-types/raw.mjs.map +1 -0
  132. package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  133. package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
  134. package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
  135. package/es/tx/builder/field-types/string.d.ts +6 -0
  136. package/es/tx/builder/field-types/string.mjs +10 -0
  137. package/es/tx/builder/field-types/string.mjs.map +1 -0
  138. package/es/tx/builder/field-types/u-int.d.ts +1 -2
  139. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  140. package/es/tx/builder/index.d.ts +11 -29
  141. package/es/tx/builder/index.mjs +50 -211
  142. package/es/tx/builder/index.mjs.map +1 -1
  143. package/es/tx/builder/schema.d.ts +2111 -571
  144. package/es/tx/builder/schema.mjs +57 -125
  145. package/es/tx/builder/schema.mjs.map +1 -1
  146. package/es/tx/index.d.ts +5 -20
  147. package/es/tx/index.mjs +31 -88
  148. package/es/tx/index.mjs.map +1 -1
  149. package/es/tx/validator.d.ts +3 -5
  150. package/es/tx/validator.mjs +82 -95
  151. package/es/tx/validator.mjs.map +1 -1
  152. package/es/utils/bytes.mjs +1 -1
  153. package/es/utils/bytes.mjs.map +1 -1
  154. package/es/utils/errors.d.ts +3 -8
  155. package/es/utils/errors.mjs +1 -11
  156. package/es/utils/errors.mjs.map +1 -1
  157. package/es/utils/other.d.ts +1 -1
  158. package/package.json +35 -27
  159. package/src/AeSdkBase.ts +6 -3
  160. package/src/AeSdkMethods.ts +3 -4
  161. package/src/Node.ts +6 -3
  162. package/src/account/Base.ts +2 -2
  163. package/src/account/Generalized.ts +2 -2
  164. package/src/account/Ledger.ts +1 -1
  165. package/src/account/Memory.ts +1 -1
  166. package/src/aens.ts +3 -2
  167. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -7
  168. package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
  169. package/src/chain.ts +5 -3
  170. package/src/channel/Base.ts +13 -5
  171. package/src/channel/Contract.ts +11 -10
  172. package/src/channel/Spend.ts +7 -2
  173. package/src/channel/handlers.ts +10 -9
  174. package/src/channel/internal.ts +1 -1
  175. package/src/contract/Contract.ts +69 -79
  176. package/src/contract/compiler/Base.ts +94 -0
  177. package/src/contract/compiler/Cli.ts +134 -0
  178. package/src/contract/compiler/Http.ts +124 -0
  179. package/src/contract/compiler/HttpNode.ts +26 -0
  180. package/src/contract/compiler/getFileSystem.ts +42 -0
  181. package/src/contract/ga.ts +9 -6
  182. package/src/index-browser.ts +58 -0
  183. package/src/index.ts +4 -56
  184. package/src/oracle.ts +1 -1
  185. package/src/spend.ts +1 -1
  186. package/src/tx/builder/constants.ts +32 -3
  187. package/src/tx/builder/field-types/abi-version.ts +21 -0
  188. package/src/tx/builder/field-types/address.ts +23 -13
  189. package/src/tx/builder/field-types/array.ts +19 -0
  190. package/src/tx/builder/field-types/boolean.ts +9 -0
  191. package/src/tx/builder/field-types/coin-amount.ts +2 -1
  192. package/src/tx/builder/field-types/ct-version.ts +50 -0
  193. package/src/tx/builder/field-types/deposit.ts +1 -1
  194. package/src/tx/builder/field-types/encoded.ts +27 -0
  195. package/src/tx/builder/field-types/entry.ts +31 -0
  196. package/src/tx/builder/field-types/enumeration.ts +15 -4
  197. package/src/tx/builder/field-types/fee.ts +38 -18
  198. package/src/tx/builder/field-types/gas-limit.ts +12 -7
  199. package/src/tx/builder/field-types/index.ts +46 -17
  200. package/src/tx/builder/field-types/mptree.ts +242 -0
  201. package/src/tx/builder/field-types/name-fee.ts +1 -2
  202. package/src/tx/builder/field-types/name-id.ts +1 -1
  203. package/src/tx/builder/field-types/pointers.ts +2 -2
  204. package/src/tx/builder/field-types/raw.ts +9 -0
  205. package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
  206. package/src/tx/builder/field-types/string.ts +11 -0
  207. package/src/tx/builder/field-types/u-int.ts +1 -3
  208. package/src/tx/builder/index.ts +63 -247
  209. package/src/tx/builder/schema.ts +273 -323
  210. package/src/tx/index.ts +37 -104
  211. package/src/tx/validator.ts +72 -95
  212. package/src/utils/bytes.ts +1 -1
  213. package/src/utils/errors.ts +4 -13
  214. package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
  215. package/types-legacy/ts4.2/AeSdkMethods.d.ts +3 -4
  216. package/types-legacy/ts4.2/Node.d.ts +3 -3
  217. package/types-legacy/ts4.2/account/Base.d.ts +2 -2
  218. package/types-legacy/ts4.2/aens.d.ts +1 -1
  219. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  220. package/types-legacy/ts4.2/chain.d.ts +9 -1
  221. package/types-legacy/ts4.2/channel/Base.d.ts +6 -1
  222. package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
  223. package/types-legacy/ts4.2/channel/Spend.d.ts +3 -1
  224. package/types-legacy/ts4.2/contract/Contract.d.ts +21 -46
  225. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
  226. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
  227. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
  228. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
  229. package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
  230. package/types-legacy/ts4.2/contract/ga.d.ts +5 -4
  231. package/types-legacy/ts4.2/index-browser.d.ts +39 -0
  232. package/types-legacy/ts4.2/index.d.ts +4 -38
  233. package/types-legacy/ts4.2/tx/builder/constants.d.ts +28 -1
  234. package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
  235. package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
  236. package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
  237. package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
  238. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
  239. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
  240. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
  241. package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
  242. package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
  243. package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
  244. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +10 -7
  245. package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +5 -2
  246. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +1 -1
  247. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +72 -28
  248. package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
  249. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -2
  250. package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
  251. package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  252. package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
  253. package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
  254. package/types-legacy/ts4.2/tx/builder/index.d.ts +11 -29
  255. package/types-legacy/ts4.2/tx/builder/schema.d.ts +2380 -668
  256. package/types-legacy/ts4.2/tx/index.d.ts +5 -20
  257. package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
  258. package/types-legacy/ts4.2/utils/errors.d.ts +3 -8
  259. package/types-legacy/ts4.2/utils/other.d.ts +1 -1
  260. package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
  261. package/types-legacy/ts4.5/AeSdkMethods.d.ts +3 -4
  262. package/types-legacy/ts4.5/Node.d.ts +3 -3
  263. package/types-legacy/ts4.5/account/Base.d.ts +2 -2
  264. package/types-legacy/ts4.5/aens.d.ts +1 -1
  265. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  266. package/types-legacy/ts4.5/chain.d.ts +9 -1
  267. package/types-legacy/ts4.5/channel/Base.d.ts +6 -1
  268. package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
  269. package/types-legacy/ts4.5/channel/Spend.d.ts +3 -1
  270. package/types-legacy/ts4.5/contract/Contract.d.ts +21 -46
  271. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
  272. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
  273. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
  274. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
  275. package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
  276. package/types-legacy/ts4.5/contract/ga.d.ts +5 -4
  277. package/types-legacy/ts4.5/index-browser.d.ts +39 -0
  278. package/types-legacy/ts4.5/index.d.ts +4 -38
  279. package/types-legacy/ts4.5/tx/builder/constants.d.ts +28 -1
  280. package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
  281. package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
  282. package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
  283. package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
  284. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
  285. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
  286. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
  287. package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
  288. package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
  289. package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
  290. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +10 -7
  291. package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +5 -2
  292. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +1 -1
  293. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +72 -28
  294. package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
  295. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -2
  296. package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
  297. package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  298. package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
  299. package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
  300. package/types-legacy/ts4.5/tx/builder/index.d.ts +11 -29
  301. package/types-legacy/ts4.5/tx/builder/schema.d.ts +2380 -668
  302. package/types-legacy/ts4.5/tx/index.d.ts +5 -20
  303. package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
  304. package/types-legacy/ts4.5/utils/errors.d.ts +3 -8
  305. package/types-legacy/ts4.5/utils/other.d.ts +1 -1
  306. package/es/contract/CompilerHttp.d.ts +0 -18
  307. package/es/contract/CompilerHttp.mjs.map +0 -1
  308. package/es/tx/builder/field-types/addresses.d.ts +0 -6
  309. package/es/tx/builder/field-types/addresses.mjs +0 -13
  310. package/es/tx/builder/field-types/addresses.mjs.map +0 -1
  311. package/es/utils/mptree.d.ts +0 -26
  312. package/es/utils/mptree.mjs +0 -143
  313. package/es/utils/mptree.mjs.map +0 -1
  314. package/src/contract/CompilerHttp.ts +0 -67
  315. package/src/tx/builder/field-types/addresses.ts +0 -18
  316. package/src/utils/mptree.ts +0 -145
  317. package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
  318. package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
  319. package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
  320. package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
  321. package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
  322. package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
package/src/chain.ts CHANGED
@@ -353,7 +353,7 @@ export async function getMicroBlockHeader(
353
353
  interface TxDryRunArguments {
354
354
  tx: Encoded.Transaction;
355
355
  accountAddress: Encoded.AccountAddress;
356
- top?: number;
356
+ top?: number | Encoded.KeyBlockHash | Encoded.MicroBlockHash;
357
357
  txEvents?: any;
358
358
  resolve: Function;
359
359
  reject: Function;
@@ -367,8 +367,10 @@ async function txDryRunHandler(key: string, onNode: Node): Promise<void> {
367
367
 
368
368
  let dryRunRes;
369
369
  try {
370
+ const top = typeof rs[0].top === 'number'
371
+ ? (await getKeyBlock(rs[0].top, { onNode })).hash : rs[0].top;
370
372
  dryRunRes = await onNode.protectedDryRunTxs({
371
- top: rs[0].top,
373
+ top,
372
374
  txEvents: rs[0].txEvents,
373
375
  txs: rs.map((req) => ({ tx: req.tx })),
374
376
  accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))
@@ -406,7 +408,7 @@ export async function txDryRun(
406
408
  {
407
409
  top, txEvents, combine, onNode,
408
410
  }:
409
- { top?: number; txEvents?: boolean; combine?: boolean; onNode: Node },
411
+ { top?: TxDryRunArguments['top']; txEvents?: boolean; combine?: boolean; onNode: Node },
410
412
  ): Promise<{
411
413
  txEvents?: TransformNodeType<DryRunResults['txEvents']>;
412
414
  } & TransformNodeType<DryRunResult>> {
@@ -210,7 +210,12 @@ export default class Channel {
210
210
  /**
211
211
  * Get current state
212
212
  */
213
- async state(): Promise<ChannelState> {
213
+ async state(): Promise<{
214
+ calls: Encoded.CallStateTree;
215
+ halfSignedTx: Encoded.Transaction | '';
216
+ signedTx: Encoded.Transaction;
217
+ trees: Encoded.StateTrees;
218
+ }> {
214
219
  return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
215
220
  }
216
221
 
@@ -224,14 +229,14 @@ export default class Channel {
224
229
  if (this._state == null) {
225
230
  return null;
226
231
  }
227
- const { txType, tx } = unpackTx(this._state, Tag.SignedTx).tx.encodedTx;
228
- switch (txType) {
232
+ const { tag, round } = unpackTx(this._state, Tag.SignedTx).encodedTx;
233
+ switch (tag) {
229
234
  case Tag.ChannelCreateTx:
230
235
  return 1;
231
236
  case Tag.ChannelOffChainTx:
232
237
  case Tag.ChannelWithdrawTx:
233
238
  case Tag.ChannelDepositTx:
234
- return tx.round;
239
+ return round;
235
240
  default:
236
241
  return null;
237
242
  }
@@ -321,7 +326,10 @@ export default class Channel {
321
326
 
322
327
  return Channel.initialize({
323
328
  ...options,
324
- reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),
329
+ reconnectTx: await sign(
330
+ 'reconnect',
331
+ buildTx({ ...txParams, tag: Tag.ChannelClientReconnectTx }),
332
+ ),
325
333
  });
326
334
  }
327
335
  }
@@ -16,7 +16,9 @@
16
16
  */
17
17
  import BigNumber from 'bignumber.js';
18
18
  import { snakeToPascal } from '../utils/string';
19
- import { MIN_GAS_PRICE, Tag } from '../tx/builder/constants';
19
+ import {
20
+ MIN_GAS_PRICE, Tag, AbiVersion, VmVersion,
21
+ } from '../tx/builder/constants';
20
22
  import {
21
23
  signAndNotify,
22
24
  awaitingCompletion,
@@ -46,7 +48,7 @@ function snakeToPascalObjKeys<Type>(obj: object): Type {
46
48
  interface CallContractOptions {
47
49
  amount?: number | BigNumber;
48
50
  callData?: Encoded.ContractBytearray;
49
- abiVersion?: number;
51
+ abiVersion?: AbiVersion;
50
52
  contract?: Encoded.ContractAddress;
51
53
  returnValue?: any;
52
54
  gasUsed?: number | BigNumber;
@@ -58,13 +60,13 @@ interface CallContractOptions {
58
60
  }
59
61
 
60
62
  interface Contract {
61
- abiVersion: number;
63
+ abiVersion: AbiVersion;
62
64
  active: boolean;
63
65
  deposit: number | BigNumber;
64
66
  id: string;
65
67
  ownerId: string;
66
68
  referrerIds: string[];
67
- vmVersion: number;
69
+ vmVersion: VmVersion;
68
70
  }
69
71
 
70
72
  export default class ChannelContract extends ChannelSpend {
@@ -113,8 +115,8 @@ export default class ChannelContract extends ChannelSpend {
113
115
  code: Encoded.ContractBytearray;
114
116
  callData: Encoded.ContractBytearray;
115
117
  deposit: number | BigNumber;
116
- vmVersion: number;
117
- abiVersion: number;
118
+ vmVersion: VmVersion;
119
+ abiVersion: AbiVersion;
118
120
  },
119
121
  sign: SignTx,
120
122
  ): Promise<{
@@ -150,8 +152,7 @@ export default class ChannelContract extends ChannelSpend {
150
152
  state2: ChannelState,
151
153
  ): ChannelFsm => (
152
154
  awaitingCompletion(this, message2, state2, () => {
153
- const { round } = unpackTx(message2.params.data.state, Tag.SignedTx)
154
- .tx.encodedTx.tx;
155
+ const { round } = unpackTx(message2.params.data.state, Tag.SignedTx).encodedTx;
155
156
  const addressKey = this._options.role === 'initiator'
156
157
  ? 'initiatorId' : 'responderId';
157
158
  const owner = this._options[addressKey];
@@ -294,7 +295,7 @@ export default class ChannelContract extends ChannelSpend {
294
295
  amount: number;
295
296
  callData: Encoded.ContractBytearray;
296
297
  contract: Encoded.ContractAddress;
297
- abiVersion: number;
298
+ abiVersion: AbiVersion;
298
299
  gasLimit?: number;
299
300
  gasPrice?: number;
300
301
  },
@@ -390,7 +391,7 @@ export default class ChannelContract extends ChannelSpend {
390
391
  amount: number;
391
392
  callData: Encoded.ContractBytearray;
392
393
  contract: Encoded.ContractAddress;
393
- abiVersion: number;
394
+ abiVersion: AbiVersion;
394
395
  },
395
396
  ): Promise<CallContractOptions> {
396
397
  return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
@@ -25,6 +25,8 @@ import { ChannelConnectionError } from '../utils/errors';
25
25
  import {
26
26
  awaitingCompletion, channelOpen, handleUnexpectedMessage, signAndNotify,
27
27
  } from './handlers';
28
+ import { unpackTx } from '../tx/builder';
29
+ import { Tag } from '../tx/builder/constants';
28
30
 
29
31
  export default class ChannelSpend extends Channel {
30
32
  /**
@@ -133,8 +135,11 @@ export default class ChannelSpend extends Channel {
133
135
  accounts: Encoded.AccountAddress[];
134
136
  contracts?: Encoded.ContractAddress[];
135
137
  },
136
- ): Promise<Encoded.Poi> {
137
- return (await call(this, 'channels.get.poi', { accounts, contracts })).poi;
138
+ ): Promise<ReturnType<typeof unpackTx<Tag.TreesPoi>>> {
139
+ return unpackTx(
140
+ (await call(this, 'channels.get.poi', { accounts, contracts })).poi,
141
+ Tag.TreesPoi,
142
+ );
138
143
  }
139
144
 
140
145
  /**
@@ -21,7 +21,6 @@ import {
21
21
  ChannelState,
22
22
  changeStatus,
23
23
  changeState,
24
- call,
25
24
  notify,
26
25
  emit,
27
26
  disconnect,
@@ -31,7 +30,7 @@ import {
31
30
  ChannelStatus,
32
31
  } from './internal';
33
32
  import { unpackTx, buildTx } from '../tx/builder';
34
- import { encode, Encoded, Encoding } from '../utils/encoder';
33
+ import { decode, Encoded } from '../utils/encoder';
35
34
  import {
36
35
  IllegalArgumentError,
37
36
  InsufficientBalanceError,
@@ -46,14 +45,16 @@ export async function appendSignature(
46
45
  tx: Encoded.Transaction,
47
46
  signFn: SignTx,
48
47
  ): Promise<Encoded.Transaction | number | null> {
49
- const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx).tx;
50
- const result = await signFn(encode(encodedTx.rlpEncoded, Encoding.Transaction));
48
+ const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx);
49
+ const payloadTx = buildTx(encodedTx);
50
+ const result = await signFn(payloadTx);
51
51
  if (typeof result === 'string') {
52
- const { tx: signedTx } = unpackTx(result, Tag.SignedTx);
52
+ const { signatures: signatures2 } = unpackTx(result, Tag.SignedTx);
53
53
  return buildTx({
54
- signatures: signatures.concat(signedTx.signatures),
55
- encodedTx: signedTx.encodedTx.rlpEncoded,
56
- }, Tag.SignedTx).tx;
54
+ tag: Tag.SignedTx,
55
+ signatures: signatures.concat(signatures2),
56
+ encodedTx: decode(payloadTx),
57
+ });
57
58
  }
58
59
  return result;
59
60
  }
@@ -164,7 +165,7 @@ export async function awaitingReconnection(
164
165
  if (message.method === 'channels.info') {
165
166
  if (message.params.data.event === 'fsm_up') {
166
167
  channel._fsmId = message.params.data.fsm_id;
167
- changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx);
168
+ changeState(channel, (await channel.state()).signedTx);
168
169
  return { handler: channelOpen };
169
170
  }
170
171
  }
@@ -317,7 +317,7 @@ export async function initialize(
317
317
  changeStatus(channel, 'connected');
318
318
  if (channelOptions.reconnectTx != null) {
319
319
  enterState(channel, { handler: openHandler });
320
- const signedTx = (await call(channel, 'channels.get.offchain_state', {})).signed_tx;
320
+ const { signedTx } = await channel.state();
321
321
  changeState(channel, signedTx);
322
322
  }
323
323
  ping(channel);
@@ -26,8 +26,8 @@ import { Encoder as Calldata } from '@aeternity/aepp-calldata';
26
26
  import { DRY_RUN_ACCOUNT } from '../tx/builder/schema';
27
27
  import { Tag, AensName } from '../tx/builder/constants';
28
28
  import { buildContractIdByContractTx, unpackTx } from '../tx/builder';
29
- import { _buildTx } from '../tx';
30
- import { send } from '../spend';
29
+ import { _buildTx, BuildTxOptions } from '../tx';
30
+ import { send, SendOptions } from '../spend';
31
31
  import { decode, Encoded } from '../utils/encoder';
32
32
  import {
33
33
  MissingContractDefError,
@@ -49,40 +49,19 @@ import {
49
49
  NoWalletConnectedError,
50
50
  } from '../utils/errors';
51
51
  import { hash as calcHash } from '../utils/crypto';
52
- import { Aci as BaseAci } from '../apis/compiler';
53
52
  import {
54
53
  ContractCallObject as NodeContractCallObject, ContractCallReturnType, Event as NodeEvent,
55
54
  } from '../apis/node';
56
- import CompilerHttp from './CompilerHttp';
55
+ import CompilerBase, { Aci } from './compiler/Base';
57
56
  import Node, { TransformNodeType } from '../Node';
58
57
  import {
59
- getAccount, getContract, getContractByteCode, getKeyBlock, resolveName, txDryRun,
58
+ getAccount, getContract, getContractByteCode, resolveName, txDryRun,
60
59
  } from '../chain';
61
60
  import AccountBase from '../account/Base';
62
61
  import { concatBuffers } from '../utils/other';
63
62
  import { isNameValid, produceNameId } from '../tx/builder/helpers';
64
63
 
65
- interface FunctionACI {
66
- arguments: any[];
67
- name: string;
68
- payable: boolean;
69
- returns: string;
70
- stateful: boolean;
71
- }
72
-
73
- interface Aci extends BaseAci {
74
- encodedAci: {
75
- contract: {
76
- name: string;
77
- event: any;
78
- kind: string;
79
- state: any;
80
- type_defs: any[];
81
- functions: FunctionACI[];
82
- };
83
- };
84
- externalEncodedAci: any[];
85
- }
64
+ type FunctionAci = Aci['encodedAci']['contract']['functions'][0];
86
65
 
87
66
  interface Event extends NodeEvent {
88
67
  address: Encoded.ContractAddress;
@@ -217,9 +196,10 @@ class Contract<M extends ContractMethodsBase> {
217
196
  async $compile(): Promise<Encoded.ContractBytearray> {
218
197
  if (this.$options.bytecode != null) return this.$options.bytecode;
219
198
  if (this.$options.sourceCode == null) throw new IllegalArgumentError('Can\'t compile without source code');
220
- this.$options.bytecode = (await this.$options.onCompiler.compileContract({
221
- code: this.$options.sourceCode, options: { fileSystem: this.$options.fileSystem },
222
- })).bytecode as Encoded.ContractBytearray;
199
+ if (this.$options.onCompiler == null) throw new IllegalArgumentError('Can\'t compile without compiler');
200
+ this.$options.bytecode = (await this.$options.onCompiler
201
+ .compileBySourceCode(this.$options.sourceCode, this.$options.fileSystem)
202
+ ).bytecode;
223
203
  return this.$options.bytecode;
224
204
  }
225
205
 
@@ -247,10 +227,9 @@ class Contract<M extends ContractMethodsBase> {
247
227
 
248
228
  protected async _sendAndProcess(
249
229
  tx: Encoded.Transaction,
250
- options: any,
230
+ options: SendOptions,
251
231
  ): Promise<SendAndProcessReturnType> {
252
- options = { ...this.$options, ...options };
253
- const txData = await send(tx, options);
232
+ const txData = await send(tx, { ...this.$options, ...options });
254
233
  const result = {
255
234
  hash: txData.hash,
256
235
  tx: unpackTx<Tag.ContractCallTx | Tag.ContractCreateTx>(txData.rawTx),
@@ -285,18 +264,22 @@ class Contract<M extends ContractMethodsBase> {
285
264
  */
286
265
  async $deploy(
287
266
  params: MethodParameters<M, 'init'>,
288
- options?: Parameters<Contract<M>['$call']>[2] & Parameters<Contract<M>['_sendAndProcess']>[1],
267
+ options?: Parameters<Contract<M>['$call']>[2]
268
+ & Partial<BuildTxOptions<Tag.ContractCreateTx, 'ownerId' | 'code' | 'callData'>>,
289
269
  ): Promise<Omit<SendAndProcessReturnType, 'hash'> & {
290
270
  transaction?: Encoded.TxHash;
291
271
  owner?: Encoded.AccountAddress;
292
272
  address?: Encoded.ContractAddress;
273
+ decodedEvents?: ReturnType<Contract<M>['$decodeEvents']>;
293
274
  }> {
294
- const opt = { ...this.$options, ...options };
275
+ const { callStatic, ...opt } = { ...this.$options, ...options };
295
276
  if (this.$options.bytecode == null) await this.$compile();
296
- if (opt.callStatic === true) return this.$call('init', params, opt);
277
+ if (callStatic === true) return this.$call('init', params, { ...opt, callStatic });
297
278
  if (this.$options.address != null) throw new DuplicateContractError();
298
279
 
280
+ if (opt.onAccount == null) throw new IllegalArgumentError('Can\'t deploy without account');
299
281
  const ownerId = opt.onAccount.address;
282
+ if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t deploy without bytecode');
300
283
  const tx = await _buildTx(Tag.ContractCreateTx, {
301
284
  ...opt,
302
285
  gasLimit: opt.gasLimit ?? await this._estimateGas('init', params, opt),
@@ -305,9 +288,12 @@ class Contract<M extends ContractMethodsBase> {
305
288
  ownerId,
306
289
  });
307
290
  this.$options.address = buildContractIdByContractTx(tx);
308
- const { hash, ...other } = await this._sendAndProcess(tx, opt);
291
+ const { hash, ...other } = await this._sendAndProcess(tx, { ...opt, onAccount: opt.onAccount });
309
292
  return {
310
293
  ...other,
294
+ ...other.result?.log != null && {
295
+ decodedEvents: this.$decodeEvents(other.result.log, opt),
296
+ },
311
297
  owner: ownerId,
312
298
  transaction: hash,
313
299
  address: this.$options.address,
@@ -319,7 +305,7 @@ class Contract<M extends ContractMethodsBase> {
319
305
  * @param name - Function name
320
306
  * @returns function ACI
321
307
  */
322
- protected _getFunctionACI(name: string): Partial<FunctionACI> {
308
+ protected _getFunctionACI(name: string): Partial<FunctionAci> {
323
309
  const fn = this._aci.encodedAci.contract.functions.find(
324
310
  (f: { name: string }) => f.name === name,
325
311
  );
@@ -340,25 +326,32 @@ class Contract<M extends ContractMethodsBase> {
340
326
  async $call<Fn extends MethodNames<M>>(
341
327
  fn: Fn,
342
328
  params: MethodParameters<M, Fn>,
343
- options: object = {},
329
+ options: Partial<BuildTxOptions<Tag.ContractCallTx, 'callerId' | 'contractId' | 'callData'>>
330
+ & Parameters<Contract<M>['$decodeEvents']>[1]
331
+ & Omit<Parameters<Contract<M>['_sendAndProcess']>[1], 'onAccount' | 'onNode'>
332
+ & Omit<Parameters<typeof txDryRun>[2], 'onNode'>
333
+ & { onAccount?: AccountBase; onNode?: Node; callStatic?: boolean } = {},
344
334
  ): Promise<{
345
335
  decodedResult?: any;
346
336
  decodedEvents?: ReturnType<Contract<M>['$decodeEvents']>;
347
337
  } & SendAndProcessReturnType> {
348
- const opt = { ...this.$options, ...options };
338
+ const { callStatic, top, ...opt } = { ...this.$options, ...options };
349
339
  const fnACI = this._getFunctionACI(fn);
350
340
  const contractId = this.$options.address;
351
341
  const { onNode } = opt;
352
342
 
353
343
  if (fn == null) throw new MissingFunctionNameError();
354
- if (fn === 'init' && opt.callStatic === false) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
355
- if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(opt.amount, fn);
344
+ if (fn === 'init' && callStatic !== true) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
345
+ if (fn !== 'init' && opt.amount != null && opt.amount > 0 && fnACI.payable === false) {
346
+ throw new NotPayableFunctionError(opt.amount, fn);
347
+ }
356
348
 
357
349
  let callerId;
358
350
  try {
351
+ if (opt.onAccount == null) throw new InternalError('Use fallback account');
359
352
  callerId = opt.onAccount.address;
360
353
  } catch (error) {
361
- const useFallbackAccount = opt.callStatic === true && (
354
+ const useFallbackAccount = callStatic === true && (
362
355
  (error instanceof TypeError && error.message === 'Account should be an address (ak-prefixed string), or instance of AccountBase, got undefined instead')
363
356
  || (error instanceof NoWalletConnectedError)
364
357
  );
@@ -368,14 +361,12 @@ class Contract<M extends ContractMethodsBase> {
368
361
  const callData = this._calldata.encode(this._name, fn, params);
369
362
 
370
363
  let res: any;
371
- if (opt.callStatic === true) {
372
- if (typeof opt.top === 'number') {
373
- opt.top = (await getKeyBlock(opt.top, { onNode })).hash;
364
+ if (callStatic === true) {
365
+ if (opt.nonce == null && top != null) {
366
+ const topKey = typeof top === 'number' ? 'height' : 'hash';
367
+ opt.nonce = (await getAccount(callerId, { [topKey]: top, onNode })).nonce + 1;
374
368
  }
375
369
  const txOpt = { ...opt, onNode, callData };
376
- if (opt.nonce == null && opt.top != null) {
377
- opt.nonce = (await getAccount(callerId, { hash: opt.top, onNode })).nonce + 1;
378
- }
379
370
  let tx;
380
371
  if (fn === 'init') {
381
372
  if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t dry-run "init" without bytecode');
@@ -388,7 +379,7 @@ class Contract<M extends ContractMethodsBase> {
388
379
  tx = await _buildTx(Tag.ContractCallTx, { ...txOpt, callerId, contractId });
389
380
  }
390
381
 
391
- const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, opt);
382
+ const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, { ...opt, top });
392
383
  if (callObj == null) throw new UnexpectedTsError();
393
384
  this._handleCallError({
394
385
  returnType: callObj.returnType as ContractCallReturnType,
@@ -396,6 +387,7 @@ class Contract<M extends ContractMethodsBase> {
396
387
  }, tx);
397
388
  res = { ...dryRunOther, tx: unpackTx(tx), result: callObj };
398
389
  } else {
390
+ if (top != null) throw new IllegalArgumentError('Can\'t handle `top` option in on-chain contract call');
399
391
  if (contractId == null) throw new MissingContractAddressError('Can\'t call contract without address');
400
392
  const tx = await _buildTx(Tag.ContractCallTx, {
401
393
  ...opt,
@@ -404,9 +396,10 @@ class Contract<M extends ContractMethodsBase> {
404
396
  contractId,
405
397
  callData,
406
398
  });
407
- res = await this._sendAndProcess(tx, opt);
399
+ if (opt.onAccount == null) throw new IllegalArgumentError('Can\'t call contract on chain without account');
400
+ res = await this._sendAndProcess(tx, { ...opt, onAccount: opt.onAccount });
408
401
  }
409
- if (opt.callStatic === true || res.txData.blockHeight != null) {
402
+ if (callStatic === true || res.txData.blockHeight != null) {
410
403
  res.decodedResult = fnACI.returns != null && fnACI.returns !== 'unit' && fn !== 'init'
411
404
  && this._calldata.decode(this._name, fn, res.result.returnValue);
412
405
  res.decodedEvents = this.$decodeEvents(res.result.log, opt);
@@ -489,10 +482,11 @@ class Contract<M extends ContractMethodsBase> {
489
482
  {
490
483
  onCompiler,
491
484
  onNode,
492
- sourceCode,
493
485
  bytecode,
494
486
  aci,
495
487
  address,
488
+ sourceCodePath,
489
+ sourceCode,
496
490
  fileSystem,
497
491
  validateBytecode,
498
492
  ...otherOptions
@@ -502,9 +496,14 @@ class Contract<M extends ContractMethodsBase> {
502
496
  address?: Encoded.ContractAddress | AensName;
503
497
  },
504
498
  ): Promise<ContractWithMethods<M>> {
505
- if (aci == null && sourceCode != null) {
506
- // TODO: should be fixed when the compiledAci interface gets updated
507
- aci = await onCompiler.generateACI({ code: sourceCode, options: { fileSystem } }) as Aci;
499
+ if (aci == null && onCompiler != null) {
500
+ let res;
501
+ if (sourceCodePath != null) res = await onCompiler.compile(sourceCodePath);
502
+ if (sourceCode != null) res = await onCompiler.compileBySourceCode(sourceCode, fileSystem);
503
+ if (res != null) {
504
+ aci = res.aci;
505
+ bytecode ??= res.bytecode;
506
+ }
508
507
  }
509
508
  if (aci == null) throw new MissingContractDefError();
510
509
 
@@ -525,14 +524,15 @@ class Contract<M extends ContractMethodsBase> {
525
524
  if (contract.active == null) throw new InactiveContractError(address);
526
525
  }
527
526
 
528
- if (validateBytecode != null) {
527
+ if (validateBytecode === true) {
529
528
  if (address == null) throw new MissingContractAddressError('Can\'t validate bytecode without contract address');
530
529
  const onChanBytecode = (await getContractByteCode(address, { onNode })).bytecode;
531
- const isValid: boolean = sourceCode != null
532
- ? await onCompiler.validateByteCode(
533
- { bytecode: onChanBytecode, source: sourceCode, options: { fileSystem } },
534
- ).then(() => true, () => false)
535
- : bytecode === onChanBytecode;
530
+ let isValid = false;
531
+ if (bytecode != null) isValid = bytecode === onChanBytecode;
532
+ else if (sourceCode != null) {
533
+ if (onCompiler == null) throw new IllegalArgumentError('Can\'t validate bytecode without compiler');
534
+ isValid = await onCompiler.validateBySourceCode(onChanBytecode, sourceCode, fileSystem);
535
+ }
536
536
  if (!isValid) throw new BytecodeMismatchError(sourceCode != null ? 'source code' : 'bytecode');
537
537
  }
538
538
 
@@ -547,32 +547,22 @@ class Contract<M extends ContractMethodsBase> {
547
547
 
548
548
  _calldata: Calldata;
549
549
 
550
- $options: {
551
- sourceCode?: string;
552
- bytecode?: Encoded.ContractBytearray;
553
- address?: Encoded.ContractAddress;
554
- onCompiler: CompilerHttp;
555
- onNode: Node;
556
- omitUnknown?: boolean;
557
- contractAddressToName?: { [key: Encoded.ContractAddress]: string };
558
- [key: string]: any;
559
- };
550
+ $options: Omit<ConstructorParameters<typeof Contract>[0], 'aci'>;
560
551
 
561
552
  constructor({ aci, ...otherOptions }: {
562
- onAccount?: AccountBase;
563
- onCompiler: CompilerHttp;
553
+ onCompiler?: CompilerBase;
564
554
  onNode: Node;
565
- sourceCode?: string;
566
555
  bytecode?: Encoded.ContractBytearray;
567
556
  aci: Aci;
568
557
  address?: Encoded.ContractAddress;
569
- fileSystem?: Record<string, string>;
570
- [key: string]: any;
571
- }) {
558
+ sourceCodePath?: Parameters<CompilerBase['compile']>[0];
559
+ sourceCode?: Parameters<CompilerBase['compileBySourceCode']>[0];
560
+ fileSystem?: Parameters<CompilerBase['compileBySourceCode']>[1];
561
+ } & Parameters<Contract<M>['$deploy']>[1]) {
572
562
  this._aci = aci;
573
563
  this._name = aci.encodedAci.contract.name;
574
564
  this._calldata = new Calldata([aci.encodedAci, ...aci.externalEncodedAci]);
575
- this.$options = { callStatic: false, ...otherOptions };
565
+ this.$options = otherOptions;
576
566
 
577
567
  /**
578
568
  * Generate proto function based on contract function using Contract ACI schema
@@ -591,7 +581,7 @@ class Contract<M extends ContractMethodsBase> {
591
581
  Object.assign(
592
582
  this,
593
583
  Object.fromEntries(this._aci.encodedAci.contract.functions
594
- .map(({ name, arguments: aciArgs, stateful }: FunctionACI) => {
584
+ .map(({ name, arguments: aciArgs, stateful }: FunctionAci) => {
595
585
  const callStatic = name !== 'init' && !stateful;
596
586
  return [
597
587
  name,
@@ -0,0 +1,94 @@
1
+ import { Encoded } from '../../utils/encoder';
2
+ import { Aci as BaseAci } from '../../apis/compiler';
3
+
4
+ interface FunctionAci {
5
+ arguments: any[];
6
+ name: string;
7
+ payable: boolean;
8
+ returns: string;
9
+ stateful: boolean;
10
+ }
11
+
12
+ export interface Aci extends BaseAci {
13
+ encodedAci: {
14
+ contract: {
15
+ name: string;
16
+ event: any;
17
+ kind: string;
18
+ state: any;
19
+ type_defs: any[];
20
+ functions: FunctionAci[];
21
+ };
22
+ };
23
+ externalEncodedAci: any[];
24
+ }
25
+
26
+ /**
27
+ * A base class for all compiler implementations
28
+ */
29
+ export default abstract class CompilerBase {
30
+ /**
31
+ * Compile contract by contract's path
32
+ * Available only in Node.js
33
+ * @param path - Path to contract source code
34
+ * @returns ACI and bytecode
35
+ */
36
+ abstract compile(path: string): Promise<{
37
+ bytecode: Encoded.ContractBytearray;
38
+ aci: Aci;
39
+ }>;
40
+
41
+ /**
42
+ * Compile contract by contract's source code
43
+ * @param sourceCode - Contract source code as string
44
+ * @param fileSystem - A map of contract filename to the corresponding contract source code to
45
+ * include into the main contract
46
+ * @example
47
+ * ```js
48
+ * {
49
+ * 'library.aes': 'namespace TestLib =\n function sum(x: int, y: int) : int = x + y'
50
+ * }
51
+ * ```
52
+ * @returns ACI and bytecode
53
+ */
54
+ abstract compileBySourceCode(
55
+ sourceCode: string,
56
+ fileSystem?: Record<string, string>,
57
+ ): Promise<{
58
+ bytecode: Encoded.ContractBytearray;
59
+ aci: Aci;
60
+ }>;
61
+
62
+ /**
63
+ * Verify that a contract bytecode is the result of compiling the given source code
64
+ * Available only in Node.js
65
+ * @param bytecode - Contract bytecode to verify
66
+ * @param path - Path to contract source code
67
+ * @returns ACI and bytecode
68
+ */
69
+ abstract validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean>;
70
+
71
+ /**
72
+ * Verify that a contract bytecode is the result of compiling the given source code
73
+ * @param bytecode - Contract bytecode to verify
74
+ * @param sourceCode - Contract source code as string
75
+ * @param fileSystem - A map of contract filename to the corresponding contract source code to
76
+ * include into the main contract
77
+ * @example
78
+ * ```js
79
+ * {
80
+ * 'library.aes': 'namespace TestLib =\n function sum(x: int, y: int) : int = x + y'
81
+ * }
82
+ * ```
83
+ */
84
+ abstract validateBySourceCode(
85
+ bytecode: Encoded.ContractBytearray,
86
+ sourceCode: string,
87
+ fileSystem?: Record<string, string>,
88
+ ): Promise<boolean>;
89
+
90
+ /**
91
+ * @returns Compiler version
92
+ */
93
+ abstract version(): Promise<string>;
94
+ }