@aeternity/aepp-sdk 9.0.1 → 11.0.0

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 (284) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/index.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/index.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
package/src/tx/tx.js CHANGED
@@ -22,34 +22,42 @@
22
22
  * @example import { Transaction } from '@aeternity/aepp-sdk'
23
23
  */
24
24
 
25
- import * as R from 'ramda'
26
-
27
25
  import ChainNode from '../chain/node'
28
26
  import Tx from './'
29
-
30
27
  import { buildTx, calculateFee, unpackTx } from './builder'
31
28
  import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL } from './builder/schema'
32
- import { buildContractId } from './builder/helpers'
29
+ import { buildContractId, encode } from './builder/helpers'
33
30
  import { TxObject } from './tx-object'
31
+ import {
32
+ ArgumentError,
33
+ UnsupportedABIversionError,
34
+ UnsupportedVMversionError,
35
+ UnsupportedProtocolError,
36
+ UnknownTxError
37
+ } from '../utils/errors'
34
38
 
35
39
  async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
36
40
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
37
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.spend, { senderId, ...R.head(arguments), payload })
41
+ const { fee, ttl, nonce } = await this.prepareTxParams(
42
+ TX_TYPE.spend, { senderId, ...arguments[0], payload }
43
+ )
38
44
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
39
45
  const { tx } = this.nativeMode
40
46
  ? {
41
- tx: TxObject({
42
- params: R.merge(R.head(arguments), {
43
- recipientId,
44
- senderId,
45
- nonce,
46
- ttl,
47
- payload
48
- }),
49
- type: TX_TYPE.spend
50
- }).encodedTx
51
- }
52
- : await this.api.postSpend(R.merge(R.head(arguments), {
47
+ tx: TxObject({
48
+ params: {
49
+ ...arguments[0],
50
+ recipientId,
51
+ senderId,
52
+ nonce,
53
+ ttl,
54
+ payload
55
+ },
56
+ type: TX_TYPE.spend
57
+ }).encodedTx
58
+ }
59
+ : await this.api.postSpend({
60
+ ...arguments[0],
53
61
  amount: parseInt(amount),
54
62
  recipientId,
55
63
  senderId,
@@ -57,160 +65,197 @@ async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
57
65
  ttl,
58
66
  fee: parseInt(fee),
59
67
  payload
60
- }))
68
+ })
61
69
 
62
70
  return tx
63
71
  }
64
72
 
65
73
  async function namePreclaimTx ({ accountId, commitmentId }) {
66
74
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
67
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.namePreClaim, { senderId: accountId, ...R.head(arguments) })
75
+ const { fee, ttl, nonce } = await this.prepareTxParams(
76
+ TX_TYPE.namePreClaim, { senderId: accountId, ...arguments[0] }
77
+ )
68
78
 
69
79
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
70
80
  const { tx } = this.nativeMode
71
81
  ? {
72
- tx: TxObject({
73
- params: R.merge(R.head(arguments), { nonce, ttl, fee }),
74
- type: TX_TYPE.namePreClaim
75
- }).encodedTx
76
- }
77
- : await this.api.postNamePreclaim(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
82
+ tx: TxObject({
83
+ params: { ...arguments[0], nonce, ttl, fee },
84
+ type: TX_TYPE.namePreClaim
85
+ }).encodedTx
86
+ }
87
+ : await this.api.postNamePreclaim({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
78
88
 
79
89
  return tx
80
90
  }
81
91
 
82
92
  async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
83
93
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
84
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameClaim, { senderId: accountId, ...R.head(arguments), vsn })
94
+ const { fee, ttl, nonce } = await this.prepareTxParams(
95
+ TX_TYPE.nameClaim, { senderId: accountId, ...arguments[0], vsn }
96
+ )
85
97
 
86
98
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
87
99
  const { tx } = this.nativeMode
88
100
  ? {
89
- tx: TxObject({
90
- params: R.merge(R.head(arguments), { nonce, ttl, fee, vsn }),
91
- type: TX_TYPE.nameClaim
92
- }).encodedTx
93
- }
94
- : await this.api.postNameClaim(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
101
+ tx: TxObject({
102
+ params: { ...arguments[0], nonce, ttl, fee, vsn },
103
+ type: TX_TYPE.nameClaim
104
+ }).encodedTx
105
+ }
106
+ : await this.api.postNameClaim({
107
+ ...arguments[0], nonce, ttl, fee: parseInt(fee), name: encode(name, 'nm')
108
+ })
95
109
 
96
110
  return tx
97
111
  }
98
112
 
99
113
  async function nameTransferTx ({ accountId, nameId, recipientId }) {
100
114
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
101
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameTransfer, { senderId: accountId, ...R.head(arguments) })
115
+ const { fee, ttl, nonce } = await this.prepareTxParams(
116
+ TX_TYPE.nameTransfer, { senderId: accountId, ...arguments[0] }
117
+ )
102
118
 
103
119
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
104
120
  const { tx } = this.nativeMode
105
121
  ? {
106
- tx: TxObject({
107
- params: R.merge(R.head(arguments), { recipientId, nonce, ttl, fee }),
108
- type: TX_TYPE.nameTransfer
109
- }).encodedTx
110
- }
111
- : await this.api.postNameTransfer(R.merge(R.head(arguments), { recipientId, nonce, ttl, fee: parseInt(fee) }))
122
+ tx: TxObject({
123
+ params: { ...arguments[0], recipientId, nonce, ttl, fee },
124
+ type: TX_TYPE.nameTransfer
125
+ }).encodedTx
126
+ }
127
+ : await this.api.postNameTransfer({
128
+ ...arguments[0], recipientId, nonce, ttl, fee: parseInt(fee)
129
+ })
112
130
 
113
131
  return tx
114
132
  }
115
133
 
116
134
  async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }) {
117
135
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
118
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameUpdate, { senderId: accountId, ...R.head(arguments) })
136
+ const { fee, ttl, nonce } = await this.prepareTxParams(
137
+ TX_TYPE.nameUpdate, { senderId: accountId, ...arguments[0] }
138
+ )
119
139
 
120
140
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
121
141
  const { tx } = this.nativeMode
122
142
  ? {
123
- tx: TxObject({
124
- params: R.merge(R.head(arguments), { nonce, ttl, fee }),
125
- type: TX_TYPE.nameUpdate
126
- }).encodedTx
127
- }
128
- : await this.api.postNameUpdate(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
143
+ tx: TxObject({
144
+ params: { ...arguments[0], nonce, ttl, fee },
145
+ type: TX_TYPE.nameUpdate
146
+ }).encodedTx
147
+ }
148
+ : await this.api.postNameUpdate({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
129
149
 
130
150
  return tx
131
151
  }
132
152
 
133
153
  async function nameRevokeTx ({ accountId, nameId }) {
134
154
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
135
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameRevoke, { senderId: accountId, ...R.head(arguments) })
155
+ const { fee, ttl, nonce } = await this.prepareTxParams(
156
+ TX_TYPE.nameRevoke, { senderId: accountId, ...arguments[0] }
157
+ )
136
158
 
137
159
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
138
160
  const { tx } = this.nativeMode
139
161
  ? {
140
- tx: TxObject({
141
- params: R.merge(R.head(arguments), { nonce, ttl, fee }),
142
- type: TX_TYPE.nameRevoke
143
- }).encodedTx
144
- }
145
- : await this.api.postNameRevoke(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
162
+ tx: TxObject({
163
+ params: { ...arguments[0], nonce, ttl, fee },
164
+ type: TX_TYPE.nameRevoke
165
+ }).encodedTx
166
+ }
167
+ : await this.api.postNameRevoke({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
146
168
 
147
169
  return tx
148
170
  }
149
171
 
150
- async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
172
+ async function contractCreateTx ({
173
+ ownerId, code, vmVersion, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
174
+ }) {
151
175
  // Get VM_ABI version
152
- const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
176
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
153
177
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
154
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCreate, { senderId: ownerId, ...R.head(arguments), ctVersion, gasPrice })
178
+ const { fee, ttl, nonce } = await this.prepareTxParams(
179
+ TX_TYPE.contractCreate, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
180
+ )
155
181
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
156
182
  return this.nativeMode
157
183
  ? {
158
- tx: TxObject({
159
- params: R.merge(R.head(arguments), { nonce, ttl, fee, ctVersion, gasPrice }),
160
- type: TX_TYPE.contractCreate
161
- }).encodedTx,
162
- contractId: buildContractId(ownerId, nonce)
163
- }
164
- : this.api.postContractCreate(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee), gas: parseInt(gas), gasPrice, vmVersion: ctVersion.vmVersion, abiVersion: ctVersion.abiVersion }))
184
+ tx: TxObject({
185
+ params: { ...arguments[0], nonce, ttl, fee, ctVersion, gasPrice },
186
+ type: TX_TYPE.contractCreate
187
+ }).encodedTx,
188
+ contractId: buildContractId(ownerId, nonce)
189
+ }
190
+ : this.api.postContractCreate({
191
+ ...arguments[0],
192
+ nonce,
193
+ ttl,
194
+ fee: parseInt(fee),
195
+ gas: parseInt(gas),
196
+ gasPrice,
197
+ vmVersion: ctVersion.vmVersion,
198
+ abiVersion: ctVersion.abiVersion
199
+ })
165
200
  }
166
201
 
167
- async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
168
- const ctVersion = this.getVmVersion(TX_TYPE.contractCall, R.head(arguments))
202
+ async function contractCallTx ({
203
+ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
204
+ }) {
205
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCall, arguments[0])
169
206
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
170
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCall, { senderId: callerId, ...R.head(arguments), gasPrice, abiVersion: ctVersion.abiVersion })
207
+ const { fee, ttl, nonce } = await this.prepareTxParams(
208
+ TX_TYPE.contractCall,
209
+ { senderId: callerId, ...arguments[0], gasPrice, abiVersion: ctVersion.abiVersion }
210
+ )
171
211
 
172
212
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
173
213
  const { tx } = this.nativeMode
174
214
  ? {
175
- tx: TxObject({
176
- params: R.merge(R.head(arguments), { nonce, ttl, fee, abiVersion: ctVersion.abiVersion, gasPrice }),
177
- type: TX_TYPE.contractCall
178
- }).encodedTx
179
- }
180
- : await this.api.postContractCall(R.merge(R.head(arguments), {
215
+ tx: TxObject({
216
+ params: { ...arguments[0], nonce, ttl, fee, abiVersion: ctVersion.abiVersion, gasPrice },
217
+ type: TX_TYPE.contractCall
218
+ }).encodedTx
219
+ }
220
+ : await this.api.postContractCall({
221
+ ...arguments[0],
181
222
  nonce,
182
223
  ttl,
183
224
  fee: parseInt(fee),
184
225
  gas: parseInt(gas),
185
226
  gasPrice,
186
227
  abiVersion: ctVersion.abiVersion
187
- }))
228
+ })
188
229
 
189
230
  return tx
190
231
  }
191
232
 
192
- async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, queryFee, oracleTtl, abiVersion = ABI_VERSIONS.NO_ABI }) {
193
- // const { abiVersion: abi } = this.getVmVersion(TX_TYPE.oracleRegister, R.head(arguments))
233
+ async function oracleRegisterTx ({
234
+ accountId, queryFormat, responseFormat, queryFee, oracleTtl, abiVersion = ABI_VERSIONS.NO_ABI
235
+ }) {
236
+ // const { abiVersion: abi } = this.getVmVersion(TX_TYPE.oracleRegister, arguments[0])
194
237
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
195
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleRegister, { senderId: accountId, ...R.head(arguments), abiVersion })
238
+ const { fee, ttl, nonce } = await this.prepareTxParams(
239
+ TX_TYPE.oracleRegister, { senderId: accountId, ...arguments[0], abiVersion }
240
+ )
196
241
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
197
242
  const { tx } = this.nativeMode
198
243
  ? {
199
- tx: TxObject({
200
- params: {
201
- accountId,
202
- queryFee,
203
- abiVersion,
204
- fee,
205
- oracleTtl,
206
- nonce,
207
- ttl,
208
- queryFormat,
209
- responseFormat
210
- },
211
- type: TX_TYPE.oracleRegister
212
- }).encodedTx
213
- }
244
+ tx: TxObject({
245
+ params: {
246
+ accountId,
247
+ queryFee,
248
+ abiVersion,
249
+ fee,
250
+ oracleTtl,
251
+ nonce,
252
+ ttl,
253
+ queryFormat,
254
+ responseFormat
255
+ },
256
+ type: TX_TYPE.oracleRegister
257
+ }).encodedTx
258
+ }
214
259
  : await this.api.postOracleRegister({
215
260
  accountId,
216
261
  queryFee,
@@ -228,16 +273,18 @@ async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, query
228
273
 
229
274
  async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
230
275
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
231
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleExtend, { senderId: callerId, ...R.head(arguments) })
276
+ const { fee, ttl, nonce } = await this.prepareTxParams(
277
+ TX_TYPE.oracleExtend, { senderId: callerId, ...arguments[0] }
278
+ )
232
279
 
233
280
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
234
281
  const { tx } = this.nativeMode
235
282
  ? {
236
- tx: TxObject({
237
- params: { oracleId, fee, oracleTtl, nonce, ttl },
238
- type: TX_TYPE.oracleExtend
239
- }).encodedTx
240
- }
283
+ tx: TxObject({
284
+ params: { oracleId, fee, oracleTtl, nonce, ttl },
285
+ type: TX_TYPE.oracleExtend
286
+ }).encodedTx
287
+ }
241
288
  : await this.api.postOracleExtend({ oracleId, fee: parseInt(fee), oracleTtl, nonce, ttl })
242
289
 
243
290
  return tx
@@ -245,16 +292,18 @@ async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
245
292
 
246
293
  async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, queryFee, senderId }) {
247
294
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
248
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleQuery, { senderId, ...R.head(arguments) })
295
+ const { fee, ttl, nonce } = await this.prepareTxParams(
296
+ TX_TYPE.oracleQuery, { senderId, ...arguments[0] }
297
+ )
249
298
 
250
299
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
251
300
  const { tx } = this.nativeMode
252
301
  ? {
253
- tx: TxObject({
254
- params: { oracleId, responseTtl, query, queryTtl, fee, queryFee, ttl, nonce, senderId },
255
- type: TX_TYPE.oracleQuery
256
- }).encodedTx
257
- }
302
+ tx: TxObject({
303
+ params: { oracleId, responseTtl, query, queryTtl, fee, queryFee, ttl, nonce, senderId },
304
+ type: TX_TYPE.oracleQuery
305
+ }).encodedTx
306
+ }
258
307
  : await this.api.postOracleQuery({
259
308
  oracleId,
260
309
  responseTtl,
@@ -272,27 +321,34 @@ async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, quer
272
321
 
273
322
  async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, response }) {
274
323
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
275
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleResponse, { senderId: callerId, ...R.head(arguments) })
324
+ const { fee, ttl, nonce } = await this.prepareTxParams(
325
+ TX_TYPE.oracleResponse, { senderId: callerId, ...arguments[0] }
326
+ )
276
327
 
277
328
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
278
329
  const { tx } = this.nativeMode
279
330
  ? {
280
- tx: TxObject({
281
- params: { oracleId, responseTtl, queryId, response, fee, ttl, nonce },
282
- type: TX_TYPE.oracleResponse
283
- }).encodedTx
284
- }
285
- : await this.api.postOracleRespond({ oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce })
331
+ tx: TxObject({
332
+ params: { oracleId, responseTtl, queryId, response, fee, ttl, nonce },
333
+ type: TX_TYPE.oracleResponse
334
+ }).encodedTx
335
+ }
336
+ : await this.api.postOracleRespond({
337
+ oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce
338
+ })
286
339
  return tx
287
340
  }
288
341
 
289
342
  async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
290
343
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
291
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelCloseSolo, { senderId: fromId, ...R.head(arguments), payload })
344
+ const { fee, ttl, nonce } = await this.prepareTxParams(
345
+ TX_TYPE.channelCloseSolo, { senderId: fromId, ...arguments[0], payload }
346
+ )
292
347
 
293
348
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
294
349
  const { tx } = this.nativeMode
295
- ? buildTx(R.merge(R.head(arguments), {
350
+ ? buildTx({
351
+ ...arguments[0],
296
352
  channelId,
297
353
  fromId,
298
354
  payload,
@@ -300,8 +356,9 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
300
356
  ttl,
301
357
  fee,
302
358
  nonce
303
- }), TX_TYPE.channelCloseSolo)
304
- : await this.api.postChannelCloseSolo(R.merge(R.head(arguments), {
359
+ }, TX_TYPE.channelCloseSolo)
360
+ : await this.api.postChannelCloseSolo({
361
+ ...arguments[0],
305
362
  channelId,
306
363
  fromId,
307
364
  payload,
@@ -309,18 +366,21 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
309
366
  ttl,
310
367
  fee: parseInt(fee),
311
368
  nonce
312
- }))
369
+ })
313
370
 
314
371
  return tx
315
372
  }
316
373
 
317
374
  async function channelSlashTx ({ channelId, fromId, payload, poi }) {
318
375
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
319
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSlash, { senderId: fromId, ...R.head(arguments), payload })
376
+ const { fee, ttl, nonce } = await this.prepareTxParams(
377
+ TX_TYPE.channelSlash, { senderId: fromId, ...arguments[0], payload }
378
+ )
320
379
 
321
380
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
322
381
  const { tx } = this.nativeMode
323
- ? buildTx(R.merge(R.head(arguments), {
382
+ ? buildTx({
383
+ ...arguments[0],
324
384
  channelId,
325
385
  fromId,
326
386
  payload,
@@ -328,8 +388,9 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
328
388
  ttl,
329
389
  fee,
330
390
  nonce
331
- }), TX_TYPE.channelSlash)
332
- : await this.api.postChannelSlash(R.merge(R.head(arguments), {
391
+ }, TX_TYPE.channelSlash)
392
+ : await this.api.postChannelSlash({
393
+ ...arguments[0],
333
394
  channelId,
334
395
  fromId,
335
396
  payload,
@@ -337,18 +398,21 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
337
398
  ttl,
338
399
  fee: parseInt(fee),
339
400
  nonce
340
- }))
401
+ })
341
402
 
342
403
  return tx
343
404
  }
344
405
 
345
406
  async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, responderAmountFinal }) {
346
407
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
347
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSettle, { senderId: fromId, ...R.head(arguments) })
408
+ const { fee, ttl, nonce } = await this.prepareTxParams(
409
+ TX_TYPE.channelSettle, { senderId: fromId, ...arguments[0] }
410
+ )
348
411
 
349
412
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
350
413
  const { tx } = this.nativeMode
351
- ? buildTx(R.merge(R.head(arguments), {
414
+ ? buildTx({
415
+ ...arguments[0],
352
416
  channelId,
353
417
  fromId,
354
418
  initiatorAmountFinal,
@@ -356,8 +420,9 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
356
420
  ttl,
357
421
  fee,
358
422
  nonce
359
- }), TX_TYPE.channelSettle)
360
- : await this.api.postChannelSettle(R.merge(R.head(arguments), {
423
+ }, TX_TYPE.channelSettle)
424
+ : await this.api.postChannelSettle({
425
+ ...arguments[0],
361
426
  channelId,
362
427
  fromId,
363
428
  initiatorAmountFinal: parseInt(initiatorAmountFinal),
@@ -365,46 +430,54 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
365
430
  ttl,
366
431
  fee: parseInt(fee),
367
432
  nonce
368
- }))
433
+ })
369
434
 
370
435
  return tx
371
436
  }
372
437
 
373
438
  async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
374
439
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
375
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...R.head(arguments), payload })
440
+ const { fee, ttl, nonce } = await this.prepareTxParams(
441
+ TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...arguments[0], payload }
442
+ )
376
443
 
377
444
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
378
445
  const { tx } = this.nativeMode
379
- ? buildTx(R.merge(R.head(arguments), {
446
+ ? buildTx({
447
+ ...arguments[0],
380
448
  channelId,
381
449
  fromId,
382
450
  payload,
383
451
  ttl,
384
452
  fee,
385
453
  nonce
386
- }), TX_TYPE.channelSnapshotSolo)
387
- : await this.api.postChannelSnapshotSolo(R.merge(R.head(arguments), {
454
+ }, TX_TYPE.channelSnapshotSolo)
455
+ : await this.api.postChannelSnapshotSolo({
456
+ ...arguments[0],
388
457
  channelId,
389
458
  fromId,
390
459
  payload,
391
460
  ttl,
392
461
  fee: parseInt(fee),
393
462
  nonce
394
- }))
463
+ })
395
464
 
396
465
  return tx
397
466
  }
398
467
 
399
- async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData }) {
468
+ async function gaAttachTx ({
469
+ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData
470
+ }) {
400
471
  // Get VM_ABI version
401
- const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
472
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
402
473
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
403
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.gaAttach, { senderId: ownerId, ...R.head(arguments), ctVersion, gasPrice })
474
+ const { fee, ttl, nonce } = await this.prepareTxParams(
475
+ TX_TYPE.gaAttach, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
476
+ )
404
477
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
405
478
  return {
406
479
  tx: TxObject({
407
- params: R.merge(R.head(arguments), { nonce, ttl, fee, ctVersion, gasPrice }),
480
+ params: { ...arguments[0], nonce, ttl, fee, ctVersion, gasPrice },
408
481
  type: TX_TYPE.gaAttach
409
482
  }).encodedTx,
410
483
  contractId: buildContractId(ownerId, nonce)
@@ -429,18 +502,20 @@ async function payingForTx ({ tx, payerId, ...args }) {
429
502
  function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
430
503
  const { consensusProtocolVersion } = this.getNodeInfo()
431
504
  const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
432
- if (!supportedProtocol) throw new Error('Not supported consensus protocol version')
505
+ if (!supportedProtocol) throw new UnsupportedProtocolError('Not supported consensus protocol version')
433
506
  const protocolForTX = supportedProtocol[txType]
434
- if (!protocolForTX) throw new Error('Not supported tx type')
507
+ if (!protocolForTX) throw new UnknownTxError('Not supported tx type')
435
508
 
436
- const ctVersion = {
437
- abiVersion: abiVersion || protocolForTX.abiVersion[0],
438
- vmVersion: vmVersion || protocolForTX.vmVersion[0]
509
+ abiVersion = abiVersion || protocolForTX.abiVersion[0]
510
+ vmVersion = vmVersion || protocolForTX.vmVersion[0]
511
+ if (!protocolForTX.vmVersion.includes(vmVersion)) {
512
+ throw new UnsupportedVMversionError(`VM VERSION ${vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
513
+ }
514
+ if (!protocolForTX.abiVersion.includes(abiVersion)) {
515
+ throw new UnsupportedABIversionError(`ABI VERSION ${abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
439
516
  }
440
- if (protocolForTX.vmVersion.length && !R.contains(ctVersion.vmVersion, protocolForTX.vmVersion)) throw new Error(`VM VERSION ${ctVersion.vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
441
- if (protocolForTX.abiVersion.length && !R.contains(ctVersion.abiVersion, protocolForTX.abiVersion)) throw new Error(`ABI VERSION ${ctVersion.abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
442
517
 
443
- return ctVersion
518
+ return { vmVersion, abiVersion }
444
519
  }
445
520
 
446
521
  /**
@@ -452,7 +527,7 @@ function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
452
527
  */
453
528
  async function calculateTtl (ttl = TX_TTL, relative = true) {
454
529
  if (ttl === 0) return 0
455
- if (ttl < 0) throw new Error('ttl must be greater than 0')
530
+ if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl)
456
531
 
457
532
  if (relative) {
458
533
  const { height } = await this.api.getCurrentKeyBlock()
@@ -470,7 +545,8 @@ async function calculateTtl (ttl = TX_TTL, relative = true) {
470
545
  */
471
546
  async function getAccountNonce (accountId, nonce) {
472
547
  if (nonce) return nonce
473
- const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId).catch(() => ({ nonce: 0 }))
548
+ const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId)
549
+ .catch(() => ({ nonce: 0 }))
474
550
  return accountNonce + 1
475
551
  }
476
552
 
@@ -481,16 +557,19 @@ async function getAccountNonce (accountId, nonce) {
481
557
  * @param {Object} params Object which contains all tx data
482
558
  * @return {Object} { ttl, nonce, fee } Object with account nonce, absolute ttl and transaction fee
483
559
  */
484
- async function prepareTxParams (txType, { senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn }) {
485
- const account = await this.getAccount(senderId).catch(e => ({ nonce: 0 }))
486
- // Is GA account
487
- if (account.contractId) {
488
- n = 0
489
- } else {
490
- n = n || (account.nonce + 1)
491
- }
560
+ async function prepareTxParams (
561
+ txType,
562
+ { senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn, strategy }
563
+ ) {
564
+ n = n || (
565
+ await this.api.getAccountNextNonce(senderId, { strategy }).catch(e => ({ nextNonce: 1 }))
566
+ ).nextNonce
492
567
  const ttl = await calculateTtl.call(this, t, !absoluteTtl)
493
- const fee = calculateFee(f, txType, { showWarning: this.showWarning, gas, params: R.merge(R.last(arguments), { nonce: n, ttl }), vsn })
568
+ const fee = calculateFee(
569
+ f,
570
+ txType,
571
+ { showWarning: this.showWarning, gas, params: { ...arguments[1], nonce: n, ttl }, vsn }
572
+ )
494
573
  return { fee, ttl, nonce: n }
495
574
  }
496
575