@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.
- package/CHANGELOG.md +216 -337
- package/README.md +16 -9
- 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 +36 -120
- 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 +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- 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 +238 -465
- 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 +328 -495
- 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 +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- 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 +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- 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 +41 -106
- 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 +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- 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(
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: await this.api.postNamePreclaim(
|
|
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(
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
: await this.api.postNameClaim(
|
|
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(
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
: await this.api.postNameTransfer(
|
|
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(
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: await this.api.postNameUpdate(
|
|
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(
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
: await this.api.postNameRevoke(
|
|
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 ({
|
|
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,
|
|
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(
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: this.api.postContractCreate(
|
|
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 ({
|
|
168
|
-
|
|
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(
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
: await this.api.postContractCall(
|
|
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 ({
|
|
193
|
-
|
|
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(
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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(
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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(
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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(
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
: await this.api.postOracleRespond({
|
|
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(
|
|
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(
|
|
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
|
-
}
|
|
304
|
-
: await this.api.postChannelCloseSolo(
|
|
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(
|
|
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(
|
|
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
|
-
}
|
|
332
|
-
: await this.api.postChannelSlash(
|
|
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(
|
|
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(
|
|
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
|
-
}
|
|
360
|
-
: await this.api.postChannelSettle(
|
|
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(
|
|
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(
|
|
437
|
+
? buildTx({
|
|
438
|
+
...arguments[0],
|
|
380
439
|
channelId,
|
|
381
440
|
fromId,
|
|
382
441
|
payload,
|
|
383
442
|
ttl,
|
|
384
443
|
fee,
|
|
385
444
|
nonce
|
|
386
|
-
}
|
|
387
|
-
: await this.api.postChannelSnapshotSolo(
|
|
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 ({
|
|
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,
|
|
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(
|
|
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:
|
|
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
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
|
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)
|
|
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 (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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(
|
|
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
|
}
|