@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/builder/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js'
|
|
2
2
|
import { decode as rlpDecode, encode as rlpEncode } from 'rlp'
|
|
3
3
|
import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter'
|
|
4
|
-
import {
|
|
4
|
+
import { hash } from '../../utils/crypto'
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
DEFAULT_FEE,
|
|
@@ -24,8 +24,7 @@ import {
|
|
|
24
24
|
writeInt,
|
|
25
25
|
buildPointers,
|
|
26
26
|
encode,
|
|
27
|
-
decode
|
|
28
|
-
buildHash
|
|
27
|
+
decode
|
|
29
28
|
} from './helpers'
|
|
30
29
|
import { toBytes } from '../../utils/bytes'
|
|
31
30
|
import MPTree from '../../utils/mptree'
|
|
@@ -131,6 +130,8 @@ function serializeField (value, type, prefix) {
|
|
|
131
130
|
return toBytes(value)
|
|
132
131
|
case FIELD_TYPES.pointers:
|
|
133
132
|
return buildPointers(value)
|
|
133
|
+
case FIELD_TYPES.rlpBinary:
|
|
134
|
+
return value.rlpEncoded ?? value
|
|
134
135
|
case FIELD_TYPES.mptrees:
|
|
135
136
|
return value.map(t => t.serialize())
|
|
136
137
|
case FIELD_TYPES.ctVersion:
|
|
@@ -157,14 +158,16 @@ function validateField (value, key, type, prefix) {
|
|
|
157
158
|
case FIELD_TYPES.amount:
|
|
158
159
|
case FIELD_TYPES.int: {
|
|
159
160
|
const isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0)
|
|
160
|
-
return assert(
|
|
161
|
+
return assert(
|
|
162
|
+
(!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0),
|
|
163
|
+
{ value, isMinusValue }
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
case FIELD_TYPES.id: {
|
|
167
|
+
const prefixes = Array.isArray(prefix) ? prefix : [prefix]
|
|
168
|
+
const p = prefixes.find(p => p === value.split('_')[0])
|
|
169
|
+
return assert(p && PREFIX_ID_TAG[value.split('_')[0]], { value, prefix })
|
|
161
170
|
}
|
|
162
|
-
case FIELD_TYPES.id:
|
|
163
|
-
if (Array.isArray(prefix)) {
|
|
164
|
-
const p = prefix.find(p => p === value.split('_')[0])
|
|
165
|
-
return assert(p && PREFIX_ID_TAG[value.split('_')[0]], { value, prefix })
|
|
166
|
-
}
|
|
167
|
-
return assert(assertedType(value, prefix) && PREFIX_ID_TAG[value.split('_')[0]] && value.split('_')[0] === prefix, { value, prefix })
|
|
168
171
|
case FIELD_TYPES.binary:
|
|
169
172
|
return assert(value.split('_')[0] === prefix, { prefix, value })
|
|
170
173
|
case FIELD_TYPES.string:
|
|
@@ -181,7 +184,10 @@ function validateField (value, key, type, prefix) {
|
|
|
181
184
|
function transformParams (params, schema, { denomination } = {}) {
|
|
182
185
|
params = schema
|
|
183
186
|
.filter(([_, t]) => t === FIELD_TYPES.amount)
|
|
184
|
-
.reduce(
|
|
187
|
+
.reduce(
|
|
188
|
+
(acc, [key]) => ({ ...params, [key]: formatAmount(params[key], { denomination }) }),
|
|
189
|
+
params
|
|
190
|
+
)
|
|
185
191
|
const schemaKeys = schema.map(([k]) => k)
|
|
186
192
|
return Object
|
|
187
193
|
.entries(params)
|
|
@@ -253,7 +259,12 @@ function buildFee (txType, { params, gas = 0, multiplier, vsn }) {
|
|
|
253
259
|
const { rlpEncoded: txWithOutFee } = buildTx({ ...params }, txType, { vsn })
|
|
254
260
|
const txSize = txWithOutFee.length
|
|
255
261
|
return TX_FEE_BASE_GAS(txType)
|
|
256
|
-
.plus(TX_FEE_OTHER_GAS(txType
|
|
262
|
+
.plus(TX_FEE_OTHER_GAS(txType, txSize, {
|
|
263
|
+
relativeTtl: getOracleRelativeTtl(params, txType),
|
|
264
|
+
innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType)
|
|
265
|
+
? params.tx.tx.encodedTx.rlpEncoded.length
|
|
266
|
+
: 0
|
|
267
|
+
}))
|
|
257
268
|
.times(multiplier)
|
|
258
269
|
}
|
|
259
270
|
|
|
@@ -289,7 +300,9 @@ export function validateParams (params, schema, { excludeKeys = [] }) {
|
|
|
289
300
|
return schema
|
|
290
301
|
.filter(([key]) => !excludeKeys.includes(key) && key !== 'payload')
|
|
291
302
|
.reduce(
|
|
292
|
-
(acc, [key, type, prefix]) => Object.assign(
|
|
303
|
+
(acc, [key, type, prefix]) => Object.assign(
|
|
304
|
+
acc, validateField(params[key], key, type, prefix)
|
|
305
|
+
),
|
|
293
306
|
{}
|
|
294
307
|
)
|
|
295
308
|
}
|
|
@@ -301,12 +314,16 @@ export function validateParams (params, schema, { excludeKeys = [] }) {
|
|
|
301
314
|
* @param {Object} params Object with tx params
|
|
302
315
|
* @param {Array} schema Transaction schema
|
|
303
316
|
* @param {Object} [options={}] options
|
|
304
|
-
* @param {
|
|
305
|
-
* @param {String} [options.denomination='aettos']
|
|
317
|
+
* @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
|
|
318
|
+
* @param {String} [options.denomination='aettos'] Denomination of amounts
|
|
306
319
|
* @throws {Error} Validation error
|
|
307
320
|
* @return {Array} Array with binary fields of transaction
|
|
308
321
|
*/
|
|
309
|
-
export function buildRawTx (
|
|
322
|
+
export function buildRawTx (
|
|
323
|
+
params,
|
|
324
|
+
schema,
|
|
325
|
+
{ excludeKeys = [], denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
326
|
+
) {
|
|
310
327
|
const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key))
|
|
311
328
|
|
|
312
329
|
// Transform `amount` type fields to `aettos`
|
|
@@ -369,14 +386,25 @@ const getSchema = ({ vsn, objId, type }) => {
|
|
|
369
386
|
* @param {Object} params Object with tx params
|
|
370
387
|
* @param {String} type Transaction type
|
|
371
388
|
* @param {Object} [options={}] options
|
|
372
|
-
* @param {
|
|
389
|
+
* @param {String[]} [options.excludeKeys] Array of keys to exclude for validation and build
|
|
373
390
|
* @param {String} [options.prefix] Prefix of transaction
|
|
374
391
|
* @throws {Error} Validation error
|
|
375
|
-
* @
|
|
392
|
+
* @returns {Object} object
|
|
393
|
+
* @returns {String} object.tx Base64Check transaction hash with 'tx_' prefix
|
|
394
|
+
* @returns {Buffer} object.rlpEncoded rlp encoded transaction
|
|
395
|
+
* @returns {Array<Buffer>} object.binary binary transaction
|
|
376
396
|
*/
|
|
377
|
-
export function buildTx (
|
|
397
|
+
export function buildTx (
|
|
398
|
+
params,
|
|
399
|
+
type,
|
|
400
|
+
{ excludeKeys = [], prefix = 'tx', vsn = VSN, denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
401
|
+
) {
|
|
378
402
|
const [schema, tag] = getSchema({ type, vsn })
|
|
379
|
-
const binary = buildRawTx(
|
|
403
|
+
const binary = buildRawTx(
|
|
404
|
+
{ ...params, VSN: vsn, tag },
|
|
405
|
+
schema,
|
|
406
|
+
{ excludeKeys, denomination: params.denomination || denomination }
|
|
407
|
+
).filter(e => e !== undefined)
|
|
380
408
|
|
|
381
409
|
const rlpEncoded = rlpEncode(binary)
|
|
382
410
|
const tx = encode(rlpEncoded, prefix)
|
|
@@ -388,10 +416,14 @@ export function buildTx (params, type, { excludeKeys = [], prefix = 'tx', vsn =
|
|
|
388
416
|
* Unpack transaction hash
|
|
389
417
|
* @function
|
|
390
418
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
391
|
-
* @param {String|Buffer} encodedTx String or RLP encoded transaction array
|
|
419
|
+
* @param {String|Buffer} encodedTx String or RLP encoded transaction array
|
|
420
|
+
* (if fromRlpBinary flag is true)
|
|
392
421
|
* @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
|
|
393
422
|
* @param {String} prefix - Prefix of data
|
|
394
|
-
* @
|
|
423
|
+
* @returns {Object} object
|
|
424
|
+
* @returns {Object} object.tx Object with transaction param's
|
|
425
|
+
* @returns {Buffer} object.rlpEncoded rlp encoded transaction
|
|
426
|
+
* @returns {Array<Buffer>} object.binary binary transaction
|
|
395
427
|
*/
|
|
396
428
|
export function unpackTx (encodedTx, fromRlpBinary = false, prefix = 'tx') {
|
|
397
429
|
const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix)
|
|
@@ -409,13 +441,20 @@ export function unpackTx (encodedTx, fromRlpBinary = false, prefix = 'tx') {
|
|
|
409
441
|
* @function
|
|
410
442
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
411
443
|
* @param {String | Buffer} rawTx base64 or rlp encoded transaction
|
|
412
|
-
* @param {Object} options
|
|
413
|
-
* @param {Boolean} options.raw
|
|
414
444
|
* @return {String} Transaction hash
|
|
415
445
|
*/
|
|
416
|
-
export function buildTxHash (rawTx
|
|
417
|
-
|
|
418
|
-
return
|
|
446
|
+
export function buildTxHash (rawTx) {
|
|
447
|
+
const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx, 'tx') : rawTx
|
|
448
|
+
return encode(hash(data), 'th')
|
|
419
449
|
}
|
|
420
450
|
|
|
421
|
-
export default {
|
|
451
|
+
export default {
|
|
452
|
+
calculateMinFee,
|
|
453
|
+
calculateFee,
|
|
454
|
+
unpackTx,
|
|
455
|
+
unpackRawTx,
|
|
456
|
+
buildTx,
|
|
457
|
+
buildRawTx,
|
|
458
|
+
validateParams,
|
|
459
|
+
buildTxHash
|
|
460
|
+
}
|
package/src/tx/builder/schema.js
CHANGED
|
@@ -22,7 +22,7 @@ export const RESPONSE_TTL = { type: 'delta', value: 10 }
|
|
|
22
22
|
// # CONTRACT
|
|
23
23
|
export const DEPOSIT = 0
|
|
24
24
|
export const AMOUNT = 0
|
|
25
|
-
export const GAS =
|
|
25
|
+
export const GAS = 25000
|
|
26
26
|
export const MIN_GAS_PRICE = 1e9
|
|
27
27
|
export const MAX_AUTH_FUN_GAS = 50000
|
|
28
28
|
export const DRY_RUN_ACCOUNT = { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
|
|
@@ -36,18 +36,21 @@ export const NAME_MAX_CLIENT_TTL = 84600
|
|
|
36
36
|
export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
|
|
37
37
|
export const NAME_FEE = 0
|
|
38
38
|
// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
|
|
39
|
-
export const NAME_FEE_MULTIPLIER = 100000000000000
|
|
39
|
+
export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
|
|
40
40
|
export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
|
|
41
41
|
// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
|
|
42
42
|
export const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day
|
|
43
|
+
// # this is the max length for a domain that requires a base fee to be paid
|
|
44
|
+
export const NAME_MAX_LENGTH_FEE = 31
|
|
43
45
|
export const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid
|
|
44
|
-
export const
|
|
46
|
+
export const POINTER_KEY_BY_PREFIX = {
|
|
45
47
|
ak: 'account_pubkey',
|
|
46
48
|
ok: 'oracle_pubkey',
|
|
47
49
|
ct: 'contract_pubkey',
|
|
48
50
|
ch: 'channel'
|
|
49
51
|
}
|
|
50
|
-
// #
|
|
52
|
+
// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
|
|
53
|
+
// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
|
|
51
54
|
// # bid ranges:
|
|
52
55
|
export const NAME_BID_RANGES = {
|
|
53
56
|
31: BigNumber(3).times(NAME_FEE_MULTIPLIER),
|
|
@@ -149,12 +152,14 @@ const OBJECT_TAG_ORACLES_TREE = 625
|
|
|
149
152
|
const OBJECT_TAG_ACCOUNTS_TREE = 626
|
|
150
153
|
const OBJECT_TAG_GA_ATTACH = 80
|
|
151
154
|
const OBJECT_TAG_GA_META = 81
|
|
155
|
+
const OBJECT_TAG_PAYING_FOR = 82
|
|
152
156
|
const OBJECT_TAG_SOPHIA_BYTE_CODE = 70
|
|
153
157
|
|
|
154
158
|
const TX_FIELD = (name, type, prefix) => [name, type, prefix]
|
|
155
159
|
const TX_SCHEMA_FIELD = (schema, objectId) => [schema, objectId]
|
|
156
160
|
|
|
157
|
-
const revertObject = (obj) => Object.entries(obj)
|
|
161
|
+
const revertObject = (obj) => Object.entries(obj)
|
|
162
|
+
.reduce((acc, [key, v]) => (acc[v] = key) && acc, {})
|
|
158
163
|
|
|
159
164
|
/**
|
|
160
165
|
* @constant
|
|
@@ -225,6 +230,7 @@ export const TX_TYPE = {
|
|
|
225
230
|
// GA ACCOUNTS
|
|
226
231
|
gaAttach: 'gaAttach',
|
|
227
232
|
gaMeta: 'gaMeta',
|
|
233
|
+
payingFor: 'payingFor',
|
|
228
234
|
sophiaByteCode: 'sophiaByteCode'
|
|
229
235
|
}
|
|
230
236
|
|
|
@@ -324,6 +330,7 @@ export const OBJECT_ID_TX_TYPE = {
|
|
|
324
330
|
// GA Accounts
|
|
325
331
|
[OBJECT_TAG_GA_ATTACH]: TX_TYPE.gaAttach,
|
|
326
332
|
[OBJECT_TAG_GA_META]: TX_TYPE.gaMeta,
|
|
333
|
+
[OBJECT_TAG_PAYING_FOR]: TX_TYPE.payingFor,
|
|
327
334
|
[OBJECT_TAG_SOPHIA_BYTE_CODE]: TX_TYPE.sophiaByteCode
|
|
328
335
|
}
|
|
329
336
|
|
|
@@ -361,33 +368,39 @@ export const KEY_BLOCK_INTERVAL = 3
|
|
|
361
368
|
|
|
362
369
|
// MAP WITH FEE CALCULATION https://github.com/aeternity/protocol/blob/master/consensus/consensus.md#gas
|
|
363
370
|
export const TX_FEE_BASE_GAS = (txType) => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
371
|
+
const factor = ({
|
|
372
|
+
[TX_TYPE.channelForceProgress]: 30,
|
|
373
|
+
[TX_TYPE.channelOffChain]: 0,
|
|
374
|
+
[TX_TYPE.channelOffChainCallContract]: 0,
|
|
375
|
+
[TX_TYPE.channelOffChainCreateContract]: 0,
|
|
376
|
+
[TX_TYPE.channelOffChainUpdateDeposit]: 0,
|
|
377
|
+
[TX_TYPE.channelOffChainUpdateWithdrawal]: 0,
|
|
378
|
+
[TX_TYPE.channelOffChainUpdateTransfer]: 0,
|
|
379
|
+
[TX_TYPE.contractCreate]: 5,
|
|
380
|
+
[TX_TYPE.contractCall]: 12,
|
|
381
|
+
[TX_TYPE.gaAttach]: 5,
|
|
382
|
+
[TX_TYPE.gaMeta]: 5,
|
|
383
|
+
[TX_TYPE.payingFor]: 1 / 5
|
|
384
|
+
})[txType] || 1
|
|
385
|
+
return new BigNumber(factor * BASE_GAS)
|
|
376
386
|
}
|
|
377
387
|
|
|
378
|
-
export const TX_FEE_OTHER_GAS = (txType
|
|
388
|
+
export const TX_FEE_OTHER_GAS = (txType, txSize, { relativeTtl, innerTxSize }) => {
|
|
379
389
|
switch (txType) {
|
|
380
390
|
case TX_TYPE.oracleRegister:
|
|
381
391
|
case TX_TYPE.oracleExtend:
|
|
382
392
|
case TX_TYPE.oracleQuery:
|
|
383
393
|
case TX_TYPE.oracleResponse:
|
|
384
|
-
return BigNumber(txSize)
|
|
394
|
+
return new BigNumber(txSize)
|
|
385
395
|
.times(GAS_PER_BYTE)
|
|
386
396
|
.plus(
|
|
387
397
|
Math.ceil(32000 * relativeTtl / Math.floor(60 * 24 * 365 / KEY_BLOCK_INTERVAL))
|
|
388
398
|
)
|
|
399
|
+
case TX_TYPE.gaMeta:
|
|
400
|
+
case TX_TYPE.payingFor:
|
|
401
|
+
return new BigNumber(txSize).minus(innerTxSize).times(GAS_PER_BYTE)
|
|
389
402
|
default:
|
|
390
|
-
return BigNumber(txSize).times(GAS_PER_BYTE)
|
|
403
|
+
return new BigNumber(txSize).times(GAS_PER_BYTE)
|
|
391
404
|
}
|
|
392
405
|
}
|
|
393
406
|
|
|
@@ -547,6 +560,14 @@ const GA_META_TX_2 = [
|
|
|
547
560
|
TX_FIELD('tx', FIELD_TYPES.rlpBinary)
|
|
548
561
|
]
|
|
549
562
|
|
|
563
|
+
const PAYING_FOR_TX = [
|
|
564
|
+
...BASE_TX,
|
|
565
|
+
TX_FIELD('payerId', FIELD_TYPES.id, 'ak'),
|
|
566
|
+
TX_FIELD('nonce', FIELD_TYPES.int),
|
|
567
|
+
TX_FIELD('fee', FIELD_TYPES.int),
|
|
568
|
+
TX_FIELD('tx', FIELD_TYPES.rlpBinary)
|
|
569
|
+
]
|
|
570
|
+
|
|
550
571
|
const CONTRACT_CREATE_TX = [
|
|
551
572
|
...BASE_TX,
|
|
552
573
|
TX_FIELD('ownerId', FIELD_TYPES.id, 'ak'),
|
|
@@ -586,7 +607,8 @@ const CONTRACT_CALL_RESULT_TX = [
|
|
|
586
607
|
TX_FIELD('gasUsed', FIELD_TYPES.int),
|
|
587
608
|
TX_FIELD('returnValue', FIELD_TYPES.binary, 'cb'),
|
|
588
609
|
TX_FIELD('returnType', FIELD_TYPES.callReturnType),
|
|
589
|
-
// TODO: add serialization for
|
|
610
|
+
// TODO: add serialization for
|
|
611
|
+
// <log> :: [ { <address> :: id, [ <topics> :: binary() ], <data> :: binary() } ]
|
|
590
612
|
TX_FIELD('log', FIELD_TYPES.rawBinary)
|
|
591
613
|
]
|
|
592
614
|
|
|
@@ -966,19 +988,29 @@ export const TX_SERIALIZATION_SCHEMA = {
|
|
|
966
988
|
1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
|
|
967
989
|
},
|
|
968
990
|
[TX_TYPE.channelOffChainUpdateTransfer]: {
|
|
969
|
-
1: TX_SCHEMA_FIELD(
|
|
991
|
+
1: TX_SCHEMA_FIELD(
|
|
992
|
+
CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
|
|
993
|
+
)
|
|
970
994
|
},
|
|
971
995
|
[TX_TYPE.channelOffChainUpdateDeposit]: {
|
|
972
|
-
1: TX_SCHEMA_FIELD(
|
|
996
|
+
1: TX_SCHEMA_FIELD(
|
|
997
|
+
CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
|
|
998
|
+
)
|
|
973
999
|
},
|
|
974
1000
|
[TX_TYPE.channelOffChainUpdateWithdrawal]: {
|
|
975
|
-
1: TX_SCHEMA_FIELD(
|
|
1001
|
+
1: TX_SCHEMA_FIELD(
|
|
1002
|
+
CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
|
|
1003
|
+
)
|
|
976
1004
|
},
|
|
977
1005
|
[TX_TYPE.channelOffChainCreateContract]: {
|
|
978
|
-
1: TX_SCHEMA_FIELD(
|
|
1006
|
+
1: TX_SCHEMA_FIELD(
|
|
1007
|
+
CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
|
|
1008
|
+
)
|
|
979
1009
|
},
|
|
980
1010
|
[TX_TYPE.channelOffChainCallContract]: {
|
|
981
|
-
1: TX_SCHEMA_FIELD(
|
|
1011
|
+
1: TX_SCHEMA_FIELD(
|
|
1012
|
+
CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
|
|
1013
|
+
)
|
|
982
1014
|
},
|
|
983
1015
|
[TX_TYPE.channelReconnect]: {
|
|
984
1016
|
1: TX_SCHEMA_FIELD(CHANNEL_RECONNECT_TX, OBJECT_TAG_CHANNEL_RECONNECT_TX)
|
|
@@ -1018,6 +1050,9 @@ export const TX_SERIALIZATION_SCHEMA = {
|
|
|
1018
1050
|
},
|
|
1019
1051
|
[TX_TYPE.gaMeta]: {
|
|
1020
1052
|
2: TX_SCHEMA_FIELD(GA_META_TX_2, OBJECT_TAG_GA_META)
|
|
1053
|
+
},
|
|
1054
|
+
[TX_TYPE.payingFor]: {
|
|
1055
|
+
1: TX_SCHEMA_FIELD(PAYING_FOR_TX, OBJECT_TAG_PAYING_FOR)
|
|
1021
1056
|
}
|
|
1022
1057
|
}
|
|
1023
1058
|
|
|
@@ -1101,19 +1136,29 @@ export const TX_DESERIALIZATION_SCHEMA = {
|
|
|
1101
1136
|
1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
|
|
1102
1137
|
},
|
|
1103
1138
|
[OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX]: {
|
|
1104
|
-
1: TX_SCHEMA_FIELD(
|
|
1139
|
+
1: TX_SCHEMA_FIELD(
|
|
1140
|
+
CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
|
|
1141
|
+
)
|
|
1105
1142
|
},
|
|
1106
1143
|
[OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX]: {
|
|
1107
|
-
1: TX_SCHEMA_FIELD(
|
|
1144
|
+
1: TX_SCHEMA_FIELD(
|
|
1145
|
+
CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
|
|
1146
|
+
)
|
|
1108
1147
|
},
|
|
1109
1148
|
[OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX]: {
|
|
1110
|
-
1: TX_SCHEMA_FIELD(
|
|
1149
|
+
1: TX_SCHEMA_FIELD(
|
|
1150
|
+
CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
|
|
1151
|
+
)
|
|
1111
1152
|
},
|
|
1112
1153
|
[OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX]: {
|
|
1113
|
-
1: TX_SCHEMA_FIELD(
|
|
1154
|
+
1: TX_SCHEMA_FIELD(
|
|
1155
|
+
CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
|
|
1156
|
+
)
|
|
1114
1157
|
},
|
|
1115
1158
|
[OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX]: {
|
|
1116
|
-
1: TX_SCHEMA_FIELD(
|
|
1159
|
+
1: TX_SCHEMA_FIELD(
|
|
1160
|
+
CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
|
|
1161
|
+
)
|
|
1117
1162
|
},
|
|
1118
1163
|
[OBJECT_TAG_CHANNEL_RECONNECT_TX]: {
|
|
1119
1164
|
1: TX_SCHEMA_FIELD(CHANNEL_RECONNECT_TX, OBJECT_TAG_CHANNEL_RECONNECT_TX)
|
|
@@ -1154,6 +1199,9 @@ export const TX_DESERIALIZATION_SCHEMA = {
|
|
|
1154
1199
|
[OBJECT_TAG_GA_META]: {
|
|
1155
1200
|
2: TX_SCHEMA_FIELD(GA_META_TX_2, OBJECT_TAG_GA_META)
|
|
1156
1201
|
},
|
|
1202
|
+
[OBJECT_TAG_PAYING_FOR]: {
|
|
1203
|
+
1: TX_SCHEMA_FIELD(PAYING_FOR_TX, OBJECT_TAG_PAYING_FOR)
|
|
1204
|
+
},
|
|
1157
1205
|
[OBJECT_TAG_CHANNEL_FORCE_PROGRESS_TX]: {
|
|
1158
1206
|
1: TX_SCHEMA_FIELD(CHANNEL_FORCE_PROGRESS_TX, OBJECT_TAG_CHANNEL_FORCE_PROGRESS_TX)
|
|
1159
1207
|
},
|
|
@@ -1161,93 +1209,3 @@ export const TX_DESERIALIZATION_SCHEMA = {
|
|
|
1161
1209
|
3: TX_SCHEMA_FIELD(CONTRACT_BYTE_CODE_LIMA, OBJECT_TAG_SOPHIA_BYTE_CODE)
|
|
1162
1210
|
}
|
|
1163
1211
|
}
|
|
1164
|
-
|
|
1165
|
-
// VERIFICATION SCHEMA
|
|
1166
|
-
|
|
1167
|
-
const ERROR_TYPE = { ERROR: 'error', WARNING: 'warning' }
|
|
1168
|
-
const VERIFICATION_FIELD = (msg, verificationFn, error) => [msg, verificationFn, error]
|
|
1169
|
-
|
|
1170
|
-
const VALIDATORS = {
|
|
1171
|
-
signature: 'signature',
|
|
1172
|
-
insufficientFee: 'insufficientFee',
|
|
1173
|
-
expiredTTL: 'expiredTTL',
|
|
1174
|
-
insufficientBalanceForAmountFee: 'insufficientBalanceForAmountFee',
|
|
1175
|
-
insufficientBalanceForAmount: 'insufficientBalanceForAmount',
|
|
1176
|
-
nonceUsed: 'nonceUsed',
|
|
1177
|
-
nonceHigh: 'nonceHigh',
|
|
1178
|
-
minGasPrice: 'minGasPrice',
|
|
1179
|
-
vmAndAbiVersion: 'vmAndAbiVersion',
|
|
1180
|
-
insufficientBalanceForFeeNameFee: 'insufficientBalanceForFeeNameFee'
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
const ERRORS = {
|
|
1184
|
-
invalidSignature: { key: 'InvalidSignature', type: ERROR_TYPE.ERROR, txKey: 'signature' },
|
|
1185
|
-
insufficientFee: { key: 'InsufficientFee', type: ERROR_TYPE.ERROR, txKey: 'fee' },
|
|
1186
|
-
expiredTTL: { key: 'ExpiredTTL', type: ERROR_TYPE.ERROR, txKey: 'ttl' },
|
|
1187
|
-
insufficientBalanceForAmountFee: { key: 'InsufficientBalanceForAmountFee', type: ERROR_TYPE.WARNING, txKey: 'fee' },
|
|
1188
|
-
insufficientBalanceForAmount: { key: 'InsufficientBalanceForAmount', type: ERROR_TYPE.WARNING, txKey: 'amount' },
|
|
1189
|
-
nonceUsed: { key: 'NonceUsed', type: ERROR_TYPE.ERROR, txKey: 'nonce' },
|
|
1190
|
-
nonceHigh: { key: 'NonceHigh', type: ERROR_TYPE.WARNING, txKey: 'nonce' },
|
|
1191
|
-
minGasPrice: { key: 'minGasPrice', type: ERROR_TYPE.ERROR, txKey: 'gasPrice' },
|
|
1192
|
-
vmAndAbiVersion: { key: 'vmAndAbiVersion', type: ERROR_TYPE.ERROR, txKey: 'ctVersion' },
|
|
1193
|
-
insufficientBalanceForFeeNameFee: { key: 'insufficientBalanceForFeeNameFee', type: ERROR_TYPE.ERROR, txKey: 'nameFee' }
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
export const SIGNATURE_VERIFICATION_SCHEMA = [
|
|
1197
|
-
VERIFICATION_FIELD(
|
|
1198
|
-
() => 'The signature cannot be verified, please verify that you used the correct network id and the correct private key for the sender address',
|
|
1199
|
-
VALIDATORS.signature,
|
|
1200
|
-
ERRORS.invalidSignature
|
|
1201
|
-
)
|
|
1202
|
-
]
|
|
1203
|
-
export const CONTRACT_VERIFICATION_SCHEMA = [
|
|
1204
|
-
VERIFICATION_FIELD(
|
|
1205
|
-
({ ctVersion, consensusProtocolVersion, txType }) => `Wrong abi/vm version, Supported is: ${PROTOCOL_VM_ABI[consensusProtocolVersion] ? JSON.stringify(PROTOCOL_VM_ABI[consensusProtocolVersion][txType]) : ' None for this protocol ' + consensusProtocolVersion}`,
|
|
1206
|
-
VALIDATORS.vmAndAbiVersion,
|
|
1207
|
-
ERRORS.vmAndAbiVersion
|
|
1208
|
-
),
|
|
1209
|
-
VERIFICATION_FIELD(
|
|
1210
|
-
() => `The gasPrice must be bigger then ${MIN_GAS_PRICE}`,
|
|
1211
|
-
VALIDATORS.minGasPrice,
|
|
1212
|
-
ERRORS.minGasPrice
|
|
1213
|
-
)
|
|
1214
|
-
]
|
|
1215
|
-
export const NAME_CLAIM_VERIFICATION_SCHEMA = [
|
|
1216
|
-
VERIFICATION_FIELD(
|
|
1217
|
-
({ balance }) => `The account balance ${balance} is not enough to execute the transaction`,
|
|
1218
|
-
VALIDATORS.insufficientBalanceForFeeNameFee,
|
|
1219
|
-
ERRORS.insufficientBalanceForFeeNameFee
|
|
1220
|
-
)
|
|
1221
|
-
]
|
|
1222
|
-
export const BASE_VERIFICATION_SCHEMA = [
|
|
1223
|
-
VERIFICATION_FIELD(
|
|
1224
|
-
({ minFee }) => `The fee for the transaction is too low, the minimum fee for this transaction is ${minFee}`,
|
|
1225
|
-
VALIDATORS.insufficientFee,
|
|
1226
|
-
ERRORS.insufficientFee
|
|
1227
|
-
),
|
|
1228
|
-
VERIFICATION_FIELD(
|
|
1229
|
-
({ height }) => `The TTL is already expired, the current height is ${height}`,
|
|
1230
|
-
VALIDATORS.expiredTTL,
|
|
1231
|
-
ERRORS.expiredTTL
|
|
1232
|
-
),
|
|
1233
|
-
VERIFICATION_FIELD(
|
|
1234
|
-
({ balance }) => `The account balance ${balance} is not enough to execute the transaction`,
|
|
1235
|
-
VALIDATORS.insufficientBalanceForAmountFee,
|
|
1236
|
-
ERRORS.insufficientBalanceForAmountFee
|
|
1237
|
-
),
|
|
1238
|
-
VERIFICATION_FIELD(
|
|
1239
|
-
({ balance }) => `The account balance ${balance} is not enough to execute the transaction`,
|
|
1240
|
-
VALIDATORS.insufficientBalanceForAmount,
|
|
1241
|
-
ERRORS.insufficientBalanceForAmount
|
|
1242
|
-
),
|
|
1243
|
-
VERIFICATION_FIELD(
|
|
1244
|
-
({ accountNonce }) => `The nonce is invalid (already used). Next valid nonce is ${accountNonce + 1})`,
|
|
1245
|
-
VALIDATORS.nonceUsed,
|
|
1246
|
-
ERRORS.nonceUsed
|
|
1247
|
-
),
|
|
1248
|
-
VERIFICATION_FIELD(
|
|
1249
|
-
({ accountNonce }) => `The nonce is technically valid but will not be processed immediately by the node (next valid nonce is ${accountNonce + 1})`,
|
|
1250
|
-
VALIDATORS.nonceHigh,
|
|
1251
|
-
ERRORS.nonceHigh
|
|
1252
|
-
)
|
|
1253
|
-
]
|