@aeternity/aepp-sdk 9.0.1 → 10.0.0-beta.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 (137) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  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 +1 -1
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/account/base.js +30 -122
  9. package/es/account/base.js.map +1 -1
  10. package/es/account/memory.js +17 -19
  11. package/es/account/memory.js.map +1 -1
  12. package/es/account/multiple.js +73 -164
  13. package/es/account/multiple.js.map +1 -1
  14. package/es/ae/aens.js +164 -599
  15. package/es/ae/aens.js.map +1 -1
  16. package/es/ae/contract.js +82 -759
  17. package/es/ae/contract.js.map +1 -1
  18. package/es/ae/index.js +78 -315
  19. package/es/ae/index.js.map +1 -1
  20. package/es/ae/oracle.js +130 -498
  21. package/es/ae/oracle.js.map +1 -1
  22. package/es/chain/index.js +1 -1
  23. package/es/chain/index.js.map +1 -1
  24. package/es/chain/node.js +288 -1008
  25. package/es/chain/node.js.map +1 -1
  26. package/es/channel/handlers.js +597 -1086
  27. package/es/channel/handlers.js.map +1 -1
  28. package/es/channel/index.js +203 -451
  29. package/es/channel/index.js.map +1 -1
  30. package/es/channel/internal.js +129 -301
  31. package/es/channel/internal.js.map +1 -1
  32. package/es/contract/aci/index.js +319 -480
  33. package/es/contract/aci/index.js.map +1 -1
  34. package/es/contract/aci/transformation.js +35 -711
  35. package/es/contract/aci/transformation.js.map +1 -1
  36. package/es/contract/compiler.js +129 -203
  37. package/es/contract/compiler.js.map +1 -1
  38. package/es/contract/ga/helpers.js +16 -114
  39. package/es/contract/ga/helpers.js.map +1 -1
  40. package/es/contract/ga/index.js +101 -242
  41. package/es/contract/ga/index.js.map +1 -1
  42. package/es/contract/index.js +1 -1
  43. package/es/contract/index.js.map +1 -1
  44. package/es/index.js +1 -2
  45. package/es/index.js.map +1 -1
  46. package/es/node-pool/index.js +54 -73
  47. package/es/node-pool/index.js.map +1 -1
  48. package/es/node.js +56 -157
  49. package/es/node.js.map +1 -1
  50. package/es/other.d.ts +1 -1
  51. package/es/tx/builder/helpers.js +38 -75
  52. package/es/tx/builder/helpers.js.map +1 -1
  53. package/es/tx/builder/index.js +196 -294
  54. package/es/tx/builder/index.js.map +1 -1
  55. package/es/tx/builder/schema.js +577 -459
  56. package/es/tx/builder/schema.js.map +1 -1
  57. package/es/tx/index.js +1 -1
  58. package/es/tx/index.js.map +1 -1
  59. package/es/tx/tx-object.js +105 -132
  60. package/es/tx/tx-object.js.map +1 -1
  61. package/es/tx/tx.js +808 -1628
  62. package/es/tx/tx.js.map +1 -1
  63. package/es/tx/validator.js +132 -268
  64. package/es/tx/validator.js.map +1 -1
  65. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  67. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  69. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  71. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  72. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  73. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  75. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  77. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +353 -600
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  79. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  80. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  81. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  83. package/es/utils/amount-formatter.js +41 -61
  84. package/es/utils/amount-formatter.js.map +1 -1
  85. package/es/utils/async-init.js +28 -64
  86. package/es/utils/async-init.js.map +1 -1
  87. package/es/utils/bignumber.js +3 -11
  88. package/es/utils/bignumber.js.map +1 -1
  89. package/es/utils/bytes.js +5 -9
  90. package/es/utils/bytes.js.map +1 -1
  91. package/es/utils/crypto.js +47 -62
  92. package/es/utils/crypto.js.map +1 -1
  93. package/es/utils/hd-wallet.js +45 -81
  94. package/es/utils/hd-wallet.js.map +1 -1
  95. package/es/utils/json-big.js +16 -49
  96. package/es/utils/json-big.js.map +1 -1
  97. package/es/utils/keystore.js +81 -246
  98. package/es/utils/keystore.js.map +1 -1
  99. package/es/utils/mptree.js +88 -134
  100. package/es/utils/mptree.js.map +1 -1
  101. package/es/utils/other.js +10 -60
  102. package/es/utils/other.js.map +1 -1
  103. package/es/utils/semver-satisfies.js +9 -28
  104. package/es/utils/semver-satisfies.js.map +1 -1
  105. package/es/utils/string.js +4 -13
  106. package/es/utils/string.js.map +1 -1
  107. package/es/utils/swagger.js +85 -224
  108. package/es/utils/swagger.js.map +1 -1
  109. package/package.json +44 -40
  110. package/src/account/multiple.js +18 -19
  111. package/src/ae/aens.js +25 -21
  112. package/src/ae/contract.js +32 -163
  113. package/src/ae/index.js +3 -3
  114. package/src/ae/oracle.js +18 -14
  115. package/src/chain/node.js +2 -4
  116. package/src/channel/handlers.js +0 -1
  117. package/src/channel/index.js +4 -5
  118. package/src/contract/aci/index.js +221 -102
  119. package/src/contract/aci/transformation.js +30 -422
  120. package/src/contract/compiler.js +45 -4
  121. package/src/contract/ga/helpers.js +1 -8
  122. package/src/contract/ga/index.js +13 -11
  123. package/src/index.js +0 -2
  124. package/src/node-pool/index.js +21 -12
  125. package/src/node.js +22 -26
  126. package/src/tx/builder/index.js +2 -1
  127. package/src/tx/builder/schema.js +2 -1
  128. package/src/tx/tx.js +147 -143
  129. package/src/tx/validator.js +9 -7
  130. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  131. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
  132. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  133. package/src/utils/bignumber.ts +2 -1
  134. package/src/utils/other.ts +1 -1
  135. package/src/utils/semver-satisfies.ts +1 -1
  136. package/src/utils/swagger.js +14 -7
  137. package/src/contract/aci/helpers.js +0 -140
package/src/tx/tx.js CHANGED
@@ -22,11 +22,8 @@
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
29
  import { buildContractId } from './builder/helpers'
@@ -34,22 +31,24 @@ 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(TX_TYPE.spend, { senderId, ...arguments[0], payload })
38
35
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
39
36
  const { tx } = this.nativeMode
40
37
  ? {
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), {
38
+ tx: TxObject({
39
+ params: {
40
+ ...arguments[0],
41
+ recipientId,
42
+ senderId,
43
+ nonce,
44
+ ttl,
45
+ payload
46
+ },
47
+ type: TX_TYPE.spend
48
+ }).encodedTx
49
+ }
50
+ : await this.api.postSpend({
51
+ ...arguments[0],
53
52
  amount: parseInt(amount),
54
53
  recipientId,
55
54
  senderId,
@@ -57,160 +56,161 @@ async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
57
56
  ttl,
58
57
  fee: parseInt(fee),
59
58
  payload
60
- }))
59
+ })
61
60
 
62
61
  return tx
63
62
  }
64
63
 
65
64
  async function namePreclaimTx ({ accountId, commitmentId }) {
66
65
  // 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) })
66
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.namePreClaim, { senderId: accountId, ...arguments[0] })
68
67
 
69
68
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
70
69
  const { tx } = this.nativeMode
71
70
  ? {
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) }))
71
+ tx: TxObject({
72
+ params: { ...arguments[0], nonce, ttl, fee },
73
+ type: TX_TYPE.namePreClaim
74
+ }).encodedTx
75
+ }
76
+ : await this.api.postNamePreclaim({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
78
77
 
79
78
  return tx
80
79
  }
81
80
 
82
81
  async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
83
82
  // 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 })
83
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameClaim, { senderId: accountId, ...arguments[0], vsn })
85
84
 
86
85
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
87
86
  const { tx } = this.nativeMode
88
87
  ? {
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) }))
88
+ tx: TxObject({
89
+ params: { ...arguments[0], nonce, ttl, fee, vsn },
90
+ type: TX_TYPE.nameClaim
91
+ }).encodedTx
92
+ }
93
+ : await this.api.postNameClaim({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
95
94
 
96
95
  return tx
97
96
  }
98
97
 
99
98
  async function nameTransferTx ({ accountId, nameId, recipientId }) {
100
99
  // 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) })
100
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameTransfer, { senderId: accountId, ...arguments[0] })
102
101
 
103
102
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
104
103
  const { tx } = this.nativeMode
105
104
  ? {
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) }))
105
+ tx: TxObject({
106
+ params: { ...arguments[0], recipientId, nonce, ttl, fee },
107
+ type: TX_TYPE.nameTransfer
108
+ }).encodedTx
109
+ }
110
+ : await this.api.postNameTransfer({ ...arguments[0], recipientId, nonce, ttl, fee: parseInt(fee) })
112
111
 
113
112
  return tx
114
113
  }
115
114
 
116
115
  async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }) {
117
116
  // 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) })
117
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameUpdate, { senderId: accountId, ...arguments[0] })
119
118
 
120
119
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
121
120
  const { tx } = this.nativeMode
122
121
  ? {
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) }))
122
+ tx: TxObject({
123
+ params: { ...arguments[0], nonce, ttl, fee },
124
+ type: TX_TYPE.nameUpdate
125
+ }).encodedTx
126
+ }
127
+ : await this.api.postNameUpdate({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
129
128
 
130
129
  return tx
131
130
  }
132
131
 
133
132
  async function nameRevokeTx ({ accountId, nameId }) {
134
133
  // 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) })
134
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameRevoke, { senderId: accountId, ...arguments[0] })
136
135
 
137
136
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
138
137
  const { tx } = this.nativeMode
139
138
  ? {
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) }))
139
+ tx: TxObject({
140
+ params: { ...arguments[0], nonce, ttl, fee },
141
+ type: TX_TYPE.nameRevoke
142
+ }).encodedTx
143
+ }
144
+ : await this.api.postNameRevoke({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
146
145
 
147
146
  return tx
148
147
  }
149
148
 
150
149
  async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
151
150
  // Get VM_ABI version
152
- const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
151
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
153
152
  // 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 })
153
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCreate, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice })
155
154
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
156
155
  return this.nativeMode
157
156
  ? {
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 }))
157
+ tx: TxObject({
158
+ params: { ...arguments[0], nonce, ttl, fee, ctVersion, gasPrice },
159
+ type: TX_TYPE.contractCreate
160
+ }).encodedTx,
161
+ contractId: buildContractId(ownerId, nonce)
162
+ }
163
+ : this.api.postContractCreate({ ...arguments[0], nonce, ttl, fee: parseInt(fee), gas: parseInt(gas), gasPrice, vmVersion: ctVersion.vmVersion, abiVersion: ctVersion.abiVersion })
165
164
  }
166
165
 
167
166
  async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
168
- const ctVersion = this.getVmVersion(TX_TYPE.contractCall, R.head(arguments))
167
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCall, arguments[0])
169
168
  // 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 })
169
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCall, { senderId: callerId, ...arguments[0], gasPrice, abiVersion: ctVersion.abiVersion })
171
170
 
172
171
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
173
172
  const { tx } = this.nativeMode
174
173
  ? {
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), {
174
+ tx: TxObject({
175
+ params: { ...arguments[0], nonce, ttl, fee, abiVersion: ctVersion.abiVersion, gasPrice },
176
+ type: TX_TYPE.contractCall
177
+ }).encodedTx
178
+ }
179
+ : await this.api.postContractCall({
180
+ ...arguments[0],
181
181
  nonce,
182
182
  ttl,
183
183
  fee: parseInt(fee),
184
184
  gas: parseInt(gas),
185
185
  gasPrice,
186
186
  abiVersion: ctVersion.abiVersion
187
- }))
187
+ })
188
188
 
189
189
  return tx
190
190
  }
191
191
 
192
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))
193
+ // const { abiVersion: abi } = this.getVmVersion(TX_TYPE.oracleRegister, arguments[0])
194
194
  // 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 })
195
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleRegister, { senderId: accountId, ...arguments[0], abiVersion })
196
196
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
197
197
  const { tx } = this.nativeMode
198
198
  ? {
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
- }
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
+ }
214
214
  : await this.api.postOracleRegister({
215
215
  accountId,
216
216
  queryFee,
@@ -228,16 +228,16 @@ async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, query
228
228
 
229
229
  async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
230
230
  // 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) })
231
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleExtend, { senderId: callerId, ...arguments[0] })
232
232
 
233
233
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
234
234
  const { tx } = this.nativeMode
235
235
  ? {
236
- tx: TxObject({
237
- params: { oracleId, fee, oracleTtl, nonce, ttl },
238
- type: TX_TYPE.oracleExtend
239
- }).encodedTx
240
- }
236
+ tx: TxObject({
237
+ params: { oracleId, fee, oracleTtl, nonce, ttl },
238
+ type: TX_TYPE.oracleExtend
239
+ }).encodedTx
240
+ }
241
241
  : await this.api.postOracleExtend({ oracleId, fee: parseInt(fee), oracleTtl, nonce, ttl })
242
242
 
243
243
  return tx
@@ -245,16 +245,16 @@ async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
245
245
 
246
246
  async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, queryFee, senderId }) {
247
247
  // 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) })
248
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleQuery, { senderId, ...arguments[0] })
249
249
 
250
250
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
251
251
  const { tx } = this.nativeMode
252
252
  ? {
253
- tx: TxObject({
254
- params: { oracleId, responseTtl, query, queryTtl, fee, queryFee, ttl, nonce, senderId },
255
- type: TX_TYPE.oracleQuery
256
- }).encodedTx
257
- }
253
+ tx: TxObject({
254
+ params: { oracleId, responseTtl, query, queryTtl, fee, queryFee, ttl, nonce, senderId },
255
+ type: TX_TYPE.oracleQuery
256
+ }).encodedTx
257
+ }
258
258
  : await this.api.postOracleQuery({
259
259
  oracleId,
260
260
  responseTtl,
@@ -272,27 +272,28 @@ async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, quer
272
272
 
273
273
  async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, response }) {
274
274
  // 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) })
275
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleResponse, { senderId: callerId, ...arguments[0] })
276
276
 
277
277
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
278
278
  const { tx } = this.nativeMode
279
279
  ? {
280
- tx: TxObject({
281
- params: { oracleId, responseTtl, queryId, response, fee, ttl, nonce },
282
- type: TX_TYPE.oracleResponse
283
- }).encodedTx
284
- }
280
+ tx: TxObject({
281
+ params: { oracleId, responseTtl, queryId, response, fee, ttl, nonce },
282
+ type: TX_TYPE.oracleResponse
283
+ }).encodedTx
284
+ }
285
285
  : await this.api.postOracleRespond({ oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce })
286
286
  return tx
287
287
  }
288
288
 
289
289
  async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
290
290
  // 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 })
291
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelCloseSolo, { senderId: fromId, ...arguments[0], payload })
292
292
 
293
293
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
294
294
  const { tx } = this.nativeMode
295
- ? buildTx(R.merge(R.head(arguments), {
295
+ ? buildTx({
296
+ ...arguments[0],
296
297
  channelId,
297
298
  fromId,
298
299
  payload,
@@ -300,8 +301,9 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
300
301
  ttl,
301
302
  fee,
302
303
  nonce
303
- }), TX_TYPE.channelCloseSolo)
304
- : await this.api.postChannelCloseSolo(R.merge(R.head(arguments), {
304
+ }, TX_TYPE.channelCloseSolo)
305
+ : await this.api.postChannelCloseSolo({
306
+ ...arguments[0],
305
307
  channelId,
306
308
  fromId,
307
309
  payload,
@@ -309,18 +311,19 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
309
311
  ttl,
310
312
  fee: parseInt(fee),
311
313
  nonce
312
- }))
314
+ })
313
315
 
314
316
  return tx
315
317
  }
316
318
 
317
319
  async function channelSlashTx ({ channelId, fromId, payload, poi }) {
318
320
  // 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 })
321
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSlash, { senderId: fromId, ...arguments[0], payload })
320
322
 
321
323
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
322
324
  const { tx } = this.nativeMode
323
- ? buildTx(R.merge(R.head(arguments), {
325
+ ? buildTx({
326
+ ...arguments[0],
324
327
  channelId,
325
328
  fromId,
326
329
  payload,
@@ -328,8 +331,9 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
328
331
  ttl,
329
332
  fee,
330
333
  nonce
331
- }), TX_TYPE.channelSlash)
332
- : await this.api.postChannelSlash(R.merge(R.head(arguments), {
334
+ }, TX_TYPE.channelSlash)
335
+ : await this.api.postChannelSlash({
336
+ ...arguments[0],
333
337
  channelId,
334
338
  fromId,
335
339
  payload,
@@ -337,18 +341,19 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
337
341
  ttl,
338
342
  fee: parseInt(fee),
339
343
  nonce
340
- }))
344
+ })
341
345
 
342
346
  return tx
343
347
  }
344
348
 
345
349
  async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, responderAmountFinal }) {
346
350
  // 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) })
351
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSettle, { senderId: fromId, ...arguments[0] })
348
352
 
349
353
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
350
354
  const { tx } = this.nativeMode
351
- ? buildTx(R.merge(R.head(arguments), {
355
+ ? buildTx({
356
+ ...arguments[0],
352
357
  channelId,
353
358
  fromId,
354
359
  initiatorAmountFinal,
@@ -356,8 +361,9 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
356
361
  ttl,
357
362
  fee,
358
363
  nonce
359
- }), TX_TYPE.channelSettle)
360
- : await this.api.postChannelSettle(R.merge(R.head(arguments), {
364
+ }, TX_TYPE.channelSettle)
365
+ : await this.api.postChannelSettle({
366
+ ...arguments[0],
361
367
  channelId,
362
368
  fromId,
363
369
  initiatorAmountFinal: parseInt(initiatorAmountFinal),
@@ -365,46 +371,48 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
365
371
  ttl,
366
372
  fee: parseInt(fee),
367
373
  nonce
368
- }))
374
+ })
369
375
 
370
376
  return tx
371
377
  }
372
378
 
373
379
  async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
374
380
  // 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 })
381
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...arguments[0], payload })
376
382
 
377
383
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
378
384
  const { tx } = this.nativeMode
379
- ? buildTx(R.merge(R.head(arguments), {
385
+ ? buildTx({
386
+ ...arguments[0],
380
387
  channelId,
381
388
  fromId,
382
389
  payload,
383
390
  ttl,
384
391
  fee,
385
392
  nonce
386
- }), TX_TYPE.channelSnapshotSolo)
387
- : await this.api.postChannelSnapshotSolo(R.merge(R.head(arguments), {
393
+ }, TX_TYPE.channelSnapshotSolo)
394
+ : await this.api.postChannelSnapshotSolo({
395
+ ...arguments[0],
388
396
  channelId,
389
397
  fromId,
390
398
  payload,
391
399
  ttl,
392
400
  fee: parseInt(fee),
393
401
  nonce
394
- }))
402
+ })
395
403
 
396
404
  return tx
397
405
  }
398
406
 
399
407
  async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData }) {
400
408
  // Get VM_ABI version
401
- const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
409
+ const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
402
410
  // 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 })
411
+ const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.gaAttach, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice })
404
412
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
405
413
  return {
406
414
  tx: TxObject({
407
- params: R.merge(R.head(arguments), { nonce, ttl, fee, ctVersion, gasPrice }),
415
+ params: { ...arguments[0], nonce, ttl, fee, ctVersion, gasPrice },
408
416
  type: TX_TYPE.gaAttach
409
417
  }).encodedTx,
410
418
  contractId: buildContractId(ownerId, nonce)
@@ -433,14 +441,16 @@ function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
433
441
  const protocolForTX = supportedProtocol[txType]
434
442
  if (!protocolForTX) throw new Error('Not supported tx type')
435
443
 
436
- const ctVersion = {
437
- abiVersion: abiVersion || protocolForTX.abiVersion[0],
438
- vmVersion: vmVersion || protocolForTX.vmVersion[0]
444
+ abiVersion = abiVersion || protocolForTX.abiVersion[0]
445
+ vmVersion = vmVersion || protocolForTX.vmVersion[0]
446
+ if (!protocolForTX.vmVersion.includes(vmVersion)) {
447
+ throw new Error(`VM VERSION ${vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
448
+ }
449
+ if (!protocolForTX.abiVersion.includes(abiVersion)) {
450
+ throw new Error(`ABI VERSION ${abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
439
451
  }
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
452
 
443
- return ctVersion
453
+ return { vmVersion, abiVersion }
444
454
  }
445
455
 
446
456
  /**
@@ -481,16 +491,10 @@ async function getAccountNonce (accountId, nonce) {
481
491
  * @param {Object} params Object which contains all tx data
482
492
  * @return {Object} { ttl, nonce, fee } Object with account nonce, absolute ttl and transaction fee
483
493
  */
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
- }
494
+ async function prepareTxParams (txType, { senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn, strategy }) {
495
+ n = n || (await this.api.getAccountNextNonce(senderId, { strategy }).catch(e => ({ nextNonce: 1 }))).nextNonce
492
496
  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 })
497
+ const fee = calculateFee(f, txType, { showWarning: this.showWarning, gas, params: { ...arguments[1], nonce: n, ttl }, vsn })
494
498
  return { fee, ttl, nonce: n }
495
499
  }
496
500
 
@@ -80,13 +80,15 @@ const validators = [
80
80
  const validNonce = account.nonce + 1
81
81
  if (nonce === validNonce) return []
82
82
  return [{
83
- ...nonce < validNonce ? {
84
- message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
85
- key: 'NonceAlreadyUsed'
86
- } : {
87
- message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
88
- key: 'NonceHigh'
89
- },
83
+ ...nonce < validNonce
84
+ ? {
85
+ message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
86
+ key: 'NonceAlreadyUsed'
87
+ }
88
+ : {
89
+ message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
90
+ key: 'NonceHigh'
91
+ },
90
92
  checkedKeys: ['nonce']
91
93
  }]
92
94
  },
@@ -5,9 +5,7 @@
5
5
  * @export AeppRpc
6
6
  * @example import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
7
7
  */
8
- import * as R from 'ramda'
9
8
  import { v4 as uuid } from 'uuid'
10
-
11
9
  import Ae from '../../../ae'
12
10
  import RpcClient from './rpc-client'
13
11
  import { getHandler, message, voidFn } from '../helpers'
@@ -236,7 +234,7 @@ export default Ae.compose({
236
234
  if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
237
235
  if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
238
236
  if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) throw new Error(`You do not have access to account ${options.onAccount}`)
239
- const opt = R.merge(this.Ae.defaults, options)
237
+ const opt = { ...this.Ae.defaults, ...options }
240
238
  if (!opt.walletBroadcast) {
241
239
  const signed = await this.signTransaction(tx, { onAccount: opt.onAccount })
242
240
  return this.sendTransaction(signed, opt)
@@ -74,7 +74,7 @@ const REQUESTS = {
74
74
  }
75
75
  }
76
76
  } catch (e) {
77
- console.error(e)
77
+ if (instance.debug) console.error(e)
78
78
  return { error: ERRORS.internalError({ msg: e.message }) }
79
79
  }
80
80
  },
@@ -112,7 +112,7 @@ const REQUESTS = {
112
112
  try {
113
113
  onAcc = resolveOnAccount(instance.addresses(), address, opt)
114
114
  } catch (e) {
115
- console.error(e)
115
+ if (instance.debug) console.error(e)
116
116
  return { error: ERRORS.internalError({ msg: e.message }) }
117
117
  }
118
118
  try {
@@ -156,7 +156,7 @@ const REQUESTS = {
156
156
  }
157
157
  }
158
158
  } catch (e) {
159
- console.error(e)
159
+ if (instance.debug) console.error(e)
160
160
  return { error: ERRORS.internalError({ msg: e.message }) }
161
161
  }
162
162
  },
@@ -1,6 +1,4 @@
1
- import * as R from 'ramda'
2
-
3
- const asEnum = (array) => R.zipObj(array, array)
1
+ const asEnum = (array) => Object.fromEntries(array.map(a => [a, a]))
4
2
 
5
3
  export const VERSION = 1
6
4
 
@@ -19,7 +19,8 @@ export const parseBigNumber = (number: string | number | BigNumber): string =>
19
19
  * @return {Boolean}
20
20
  */
21
21
  export const isBigNumber = (number: string | number | BigNumber): boolean =>
22
- !isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number)
22
+ ['number', 'object', 'string', 'bigint'].includes(typeof number) &&
23
+ (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))
23
24
 
24
25
  /**
25
26
  * BigNumber ceil operation
@@ -1,6 +1,6 @@
1
1
  import { snakeToPascal, pascalToSnake } from './string'
2
2
 
3
- export const pause = async (duration: number): Promise<undefined> =>
3
+ export const pause = async (duration: number): Promise<void> =>
4
4
  await new Promise(resolve => setTimeout(resolve, duration))
5
5
 
6
6
  export const mapObject = (
@@ -1,6 +1,6 @@
1
1
  export default function (version: string, geVersion: string, ltVersion: string): boolean {
2
2
  const getComponents = (v: string): number[] => v
3
- .split('-')[0].split('.').map(i => +i)
3
+ .split(/[-+]/)[0].split('.').map(i => +i)
4
4
 
5
5
  const versionComponents = getComponents(version)
6
6
  const geComponents = getComponents(geVersion)