@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.
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +30 -122
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +73 -164
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +82 -759
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +78 -315
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +130 -498
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +1 -1
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +288 -1008
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +203 -451
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +319 -480
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +129 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +16 -114
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +101 -242
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +1 -2
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +38 -75
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +196 -294
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +577 -459
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -132
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +808 -1628
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +132 -268
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +353 -600
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +47 -62
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +85 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +44 -40
- package/src/account/multiple.js +18 -19
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +32 -163
- package/src/ae/index.js +3 -3
- package/src/ae/oracle.js +18 -14
- package/src/chain/node.js +2 -4
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -102
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +1 -8
- package/src/contract/ga/index.js +13 -11
- package/src/index.js +0 -2
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/index.js +2 -1
- package/src/tx/builder/schema.js +2 -1
- package/src/tx/tx.js +147 -143
- package/src/tx/validator.js +9 -7
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +14 -7
- 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, ...
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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, ...
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: await this.api.postNamePreclaim(
|
|
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, ...
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
: await this.api.postNameClaim(
|
|
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, ...
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
: await this.api.postNameTransfer(
|
|
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, ...
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: await this.api.postNameUpdate(
|
|
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, ...
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
: await this.api.postNameRevoke(
|
|
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,
|
|
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, ...
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: this.api.postContractCreate(
|
|
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,
|
|
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, ...
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
: await this.api.postContractCall(
|
|
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,
|
|
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, ...
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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, ...
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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, ...
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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, ...
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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, ...
|
|
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(
|
|
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
|
-
}
|
|
304
|
-
: await this.api.postChannelCloseSolo(
|
|
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, ...
|
|
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(
|
|
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
|
-
}
|
|
332
|
-
: await this.api.postChannelSlash(
|
|
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, ...
|
|
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(
|
|
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
|
-
}
|
|
360
|
-
: await this.api.postChannelSettle(
|
|
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, ...
|
|
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(
|
|
385
|
+
? buildTx({
|
|
386
|
+
...arguments[0],
|
|
380
387
|
channelId,
|
|
381
388
|
fromId,
|
|
382
389
|
payload,
|
|
383
390
|
ttl,
|
|
384
391
|
fee,
|
|
385
392
|
nonce
|
|
386
|
-
}
|
|
387
|
-
: await this.api.postChannelSnapshotSolo(
|
|
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,
|
|
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, ...
|
|
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:
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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
|
|
package/src/tx/validator.js
CHANGED
|
@@ -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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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 =
|
|
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
|
},
|
package/src/utils/bignumber.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
package/src/utils/other.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { snakeToPascal, pascalToSnake } from './string'
|
|
2
2
|
|
|
3
|
-
export const pause = async (duration: number): Promise<
|
|
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(
|
|
3
|
+
.split(/[-+]/)[0].split('.').map(i => +i)
|
|
4
4
|
|
|
5
5
|
const versionComponents = getComponents(version)
|
|
6
6
|
const geComponents = getComponents(geVersion)
|