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