@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.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/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- 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 → base.mjs} +23 -11
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +14 -11
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +69 -59
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/{index.js → index.mjs} +12 -10
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +37 -20
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +28 -8
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +133 -90
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +43 -22
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +51 -35
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/{index.js → index.mjs} +40 -28
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/encoder.d.ts +26 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/{index.js → index.mjs} +15 -12
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +17 -11
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/constants.mjs +108 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +321 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +92 -74
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +16 -172
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +106 -14
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/{crypto.js → crypto.mjs} +42 -156
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.mjs +106 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +49 -15
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +49 -58
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +16 -6
- package/src/ae/aens.js +52 -58
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +21 -154
- package/src/ae/index.js +6 -4
- package/src/ae/oracle.js +33 -14
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -65
- package/src/channel/handlers.js +30 -20
- package/src/channel/index.js +46 -16
- package/src/channel/internal.js +35 -30
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +22 -113
- package/src/contract/ga/helpers.js +10 -6
- package/src/contract/ga/index.js +31 -24
- package/src/index.js +9 -8
- package/src/node-pool/index.js +13 -10
- package/src/node.js +11 -10
- package/src/tx/builder/constants.js +100 -0
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +99 -103
- package/src/tx/builder/index.js +81 -40
- package/src/tx/builder/schema.js +44 -132
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +110 -35
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +11 -155
- package/src/utils/encoder.ts +101 -0
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +68 -45
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -308
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -356
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -242
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -56
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -318
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/index.js +0 -310
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2018 aeternity developers
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
* copyright notice and this permission notice appear in all copies.
|
|
8
|
-
*
|
|
9
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* ContractACI module
|
|
20
|
-
*
|
|
21
|
-
* @module @aeternity/aepp-sdk/es/contract/aci
|
|
22
|
-
* @export getContractInstance
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import * as R from 'ramda'
|
|
26
|
-
import BigNumber from 'bignumber.js'
|
|
27
|
-
import { Encoder as Calldata } from '@aeternity/aepp-calldata'
|
|
28
|
-
import { decodeEvents } from './transformation'
|
|
29
|
-
import { DRY_RUN_ACCOUNT, DEPOSIT } from '../../tx/builder/schema'
|
|
30
|
-
import TxObject from '../../tx/tx-object'
|
|
31
|
-
import { decode } from '../../tx/builder/helpers'
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get function schema from contract ACI object
|
|
35
|
-
* @param {Object} aci Contract ACI object
|
|
36
|
-
* @param {String} name Function name
|
|
37
|
-
* @param external
|
|
38
|
-
* @return {Object} function ACI
|
|
39
|
-
*/
|
|
40
|
-
function getFunctionACI (aci, name, external) {
|
|
41
|
-
const fn = aci.functions.find(f => f.name === name)
|
|
42
|
-
if (!fn && name !== 'init') throw new Error(`Function ${name} doesn't exist in contract`)
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
...fn,
|
|
46
|
-
bindings: [
|
|
47
|
-
{
|
|
48
|
-
state: aci.state,
|
|
49
|
-
type_defs: aci.type_defs,
|
|
50
|
-
name: aci.name
|
|
51
|
-
},
|
|
52
|
-
...external.map(R.pick(['state', 'type_defs', 'name']))
|
|
53
|
-
],
|
|
54
|
-
event: aci.event ? aci.event.variant : []
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Generate contract ACI object with predefined js methods for contract usage - can be used for creating a reference to already deployed contracts
|
|
60
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
61
|
-
* @param {Object} [options={}] Options object
|
|
62
|
-
* @param {String} [options.source] Contract source code
|
|
63
|
-
* @param {String} [options.bytecode] Contract bytecode
|
|
64
|
-
* @param {Object} [options.aci] Contract ACI
|
|
65
|
-
* @param {String} [options.contractAddress] Contract address
|
|
66
|
-
* @param {Object} [options.filesystem] Contact source external namespaces map
|
|
67
|
-
* @param {Boolean} [options.validateBytecode] Compare source code with on-chain version
|
|
68
|
-
* @return {ContractInstance} JS Contract API
|
|
69
|
-
* @example
|
|
70
|
-
* const contractIns = await client.getContractInstance({ source })
|
|
71
|
-
* await contractIns.deploy([321]) or await contractIns.methods.init(321)
|
|
72
|
-
* const callResult = await contractIns.call('setState', [123]) or await contractIns.methods.setState.send(123, options)
|
|
73
|
-
* const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or await contractIns.methods.setState.get(123, options)
|
|
74
|
-
* Also you can call contract like: await contractIns.methods.setState(123, options)
|
|
75
|
-
* Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is stateful or not
|
|
76
|
-
*/
|
|
77
|
-
export default async function getContractInstance ({
|
|
78
|
-
source,
|
|
79
|
-
bytecode,
|
|
80
|
-
aci,
|
|
81
|
-
contractAddress,
|
|
82
|
-
filesystem = {},
|
|
83
|
-
validateBytecode,
|
|
84
|
-
...otherOptions
|
|
85
|
-
} = {}) {
|
|
86
|
-
aci = aci || (source && await this.contractGetACI(source, { filesystem }))
|
|
87
|
-
if (!aci) throw new Error('Either ACI or source code is required')
|
|
88
|
-
contractAddress = contractAddress && await this.resolveName(
|
|
89
|
-
contractAddress, 'ct', { resolveByNode: true }
|
|
90
|
-
)
|
|
91
|
-
if (!contractAddress && !source && !bytecode) throw new Error('Can\'t create instance by ACI without address')
|
|
92
|
-
|
|
93
|
-
if (contractAddress) {
|
|
94
|
-
const contract = await this.getContract(contractAddress).catch(() => null)
|
|
95
|
-
if (!contract) throw new Error(`Contract with address ${contractAddress} not found on-chain`)
|
|
96
|
-
if (!contract.active) throw new Error(`Contract with address ${contractAddress} not active`)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const instance = {
|
|
100
|
-
interface: R.defaultTo(null, R.prop('interface', aci)),
|
|
101
|
-
aci: R.defaultTo(null, R.path(['encoded_aci', 'contract'], aci)),
|
|
102
|
-
calldata: new Calldata([aci.encoded_aci, ...aci.external_encoded_aci]),
|
|
103
|
-
externalAci: aci.external_encoded_aci ? aci.external_encoded_aci.map(a => a.contract || a.namespace) : [],
|
|
104
|
-
source,
|
|
105
|
-
bytecode,
|
|
106
|
-
deployInfo: { address: contractAddress },
|
|
107
|
-
options: {
|
|
108
|
-
...this.Ae.defaults,
|
|
109
|
-
callStatic: false,
|
|
110
|
-
filesystem,
|
|
111
|
-
...otherOptions
|
|
112
|
-
},
|
|
113
|
-
compilerVersion: this.compilerVersion
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (validateBytecode) {
|
|
117
|
-
if (!contractAddress) throw new Error('Can\'t validate bytecode without contract address')
|
|
118
|
-
const onChanBytecode = (await this.getContractByteCode(contractAddress)).bytecode
|
|
119
|
-
const isValid = (source && await this
|
|
120
|
-
.validateByteCodeAPI(onChanBytecode, source, instance.options).catch(() => false)) ||
|
|
121
|
-
bytecode === onChanBytecode
|
|
122
|
-
if (!isValid) throw new Error(`Contract ${source ? 'source' : 'bytecode'} do not correspond to the bytecode deployed on the chain`)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Compile contract
|
|
127
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
128
|
-
* @rtype () => ContractInstance: Object
|
|
129
|
-
* @return {String} bytecode bytecode
|
|
130
|
-
*/
|
|
131
|
-
instance.compile = async (options = {}) => {
|
|
132
|
-
if (instance.bytecode) throw new Error('Contract already compiled')
|
|
133
|
-
if (!instance.source) throw new Error('Can\'t compile without source code')
|
|
134
|
-
const { bytecode } = await this.contractCompile(instance.source, { ...instance.options, ...options })
|
|
135
|
-
instance.bytecode = bytecode
|
|
136
|
-
return instance.bytecode
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const sendAndProcess = async (tx, options) => {
|
|
140
|
-
const txData = await this.send(tx, options)
|
|
141
|
-
const result = {
|
|
142
|
-
hash: txData.hash, tx: TxObject({ tx: txData.rawTx }), txData, rawTx: txData.rawTx
|
|
143
|
-
}
|
|
144
|
-
if (options.waitMined === false) return result
|
|
145
|
-
const txInfo = await this.getTxInfo(txData.hash)
|
|
146
|
-
await handleCallError(txInfo)
|
|
147
|
-
return { ...result, result: txInfo }
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const handleCallError = ({ returnType, returnValue }) => {
|
|
151
|
-
let message
|
|
152
|
-
// TODO: ensure that it works correctly https://github.com/aeternity/aepp-calldata-js/issues/88
|
|
153
|
-
switch (returnType) {
|
|
154
|
-
case 'ok': return
|
|
155
|
-
case 'revert':
|
|
156
|
-
message = instance.calldata.decodeFateString(returnValue)
|
|
157
|
-
break
|
|
158
|
-
case 'error':
|
|
159
|
-
message = decode(returnValue).toString()
|
|
160
|
-
break
|
|
161
|
-
default: throw new Error(`Unknown returnType: ${returnType}`)
|
|
162
|
-
}
|
|
163
|
-
throw new Error(`Invocation failed${message ? `: "${message}"` : ''}`)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Deploy contract
|
|
168
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
169
|
-
* @rtype (init: Array, options: Object) => ContractInstance: Object
|
|
170
|
-
* @param {Array} params Contract init function arguments array
|
|
171
|
-
* @param {Object} [options] options
|
|
172
|
-
* @return {Object} deploy info
|
|
173
|
-
*/
|
|
174
|
-
instance.deploy = async (params = [], options) => {
|
|
175
|
-
const opt = { ...instance.options, ...options, deposit: DEPOSIT }
|
|
176
|
-
if (!instance.bytecode) await instance.compile(opt)
|
|
177
|
-
if (opt.callStatic) return instance.call('init', params, opt)
|
|
178
|
-
if (instance.deployInfo.address) throw new Error('Contract already deployed')
|
|
179
|
-
|
|
180
|
-
const ownerId = await this.address(opt)
|
|
181
|
-
const { tx, contractId } = await this.contractCreateTx({
|
|
182
|
-
...opt,
|
|
183
|
-
callData: instance.calldata.encode(instance.aci.name, 'init', params),
|
|
184
|
-
code: instance.bytecode,
|
|
185
|
-
ownerId
|
|
186
|
-
})
|
|
187
|
-
const { hash, rawTx, result, txData } = await sendAndProcess(tx, opt)
|
|
188
|
-
instance.deployInfo = Object.freeze({
|
|
189
|
-
result,
|
|
190
|
-
owner: ownerId,
|
|
191
|
-
transaction: hash,
|
|
192
|
-
rawTx,
|
|
193
|
-
txData,
|
|
194
|
-
address: contractId,
|
|
195
|
-
call: (name, args, options) =>
|
|
196
|
-
this.contractCall(instance.source, contractId, name, args, { ...opt, ...options }),
|
|
197
|
-
callStatic: (name, args, options) =>
|
|
198
|
-
this.contractCallStatic(instance.source, contractId, name, args, { ...opt, ...options }),
|
|
199
|
-
createdAt: new Date()
|
|
200
|
-
})
|
|
201
|
-
return instance.deployInfo
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Call contract function
|
|
206
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
207
|
-
* @rtype (init: Array, options: Object = { callStatic: false }) => CallResult: Object
|
|
208
|
-
* @param {String} fn Function name
|
|
209
|
-
* @param {Array} params Array of function arguments
|
|
210
|
-
* @param {Object} [options={}] Array of function arguments
|
|
211
|
-
* @param {Boolean} [options.callStatic=false] Static function call
|
|
212
|
-
* @return {Object} CallResult
|
|
213
|
-
*/
|
|
214
|
-
instance.call = async (fn, params = [], options = {}) => {
|
|
215
|
-
const opt = { ...instance.options, ...options }
|
|
216
|
-
const fnACI = getFunctionACI(instance.aci, fn, instance.externalAci)
|
|
217
|
-
const contractId = instance.deployInfo.address
|
|
218
|
-
|
|
219
|
-
if (!fn) throw new Error('Function name is required')
|
|
220
|
-
if (fn === 'init' && !opt.callStatic) throw new Error('"init" can be called only via dryRun')
|
|
221
|
-
if (!contractId && fn !== 'init') throw new Error('You need to deploy contract before calling!')
|
|
222
|
-
if (
|
|
223
|
-
BigNumber(opt.amount).gt(0) &&
|
|
224
|
-
(Object.prototype.hasOwnProperty.call(fnACI, 'payable') && !fnACI.payable)
|
|
225
|
-
) throw new Error(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept tokens`)
|
|
226
|
-
|
|
227
|
-
const callerId = await this.address(opt).catch(error => {
|
|
228
|
-
if (opt.callStatic) return DRY_RUN_ACCOUNT.pub
|
|
229
|
-
else throw error
|
|
230
|
-
})
|
|
231
|
-
const callData = instance.calldata.encode(instance.aci.name, fn, params)
|
|
232
|
-
|
|
233
|
-
let res
|
|
234
|
-
if (opt.callStatic) {
|
|
235
|
-
if (typeof opt.top === 'number') {
|
|
236
|
-
opt.top = (await this.getKeyBlock(opt.top)).hash
|
|
237
|
-
}
|
|
238
|
-
const txOpt = {
|
|
239
|
-
...opt,
|
|
240
|
-
callData,
|
|
241
|
-
nonce: opt.top && (await this.getAccount(callerId, { hash: opt.top })).nonce + 1
|
|
242
|
-
}
|
|
243
|
-
const tx = fn === 'init'
|
|
244
|
-
? (await this.contractCreateTx({ ...txOpt, code: instance.bytecode, ownerId: callerId })).tx
|
|
245
|
-
: await this.contractCallTx({ ...txOpt, callerId, contractId })
|
|
246
|
-
|
|
247
|
-
const { callObj, ...dryRunOther } = await this.txDryRun(tx, callerId, opt)
|
|
248
|
-
await handleCallError(callObj)
|
|
249
|
-
res = { ...dryRunOther, tx: TxObject({ tx }), result: callObj }
|
|
250
|
-
} else {
|
|
251
|
-
const tx = await this.contractCallTx({ ...opt, callerId, contractId, callData })
|
|
252
|
-
res = await sendAndProcess(tx, opt)
|
|
253
|
-
}
|
|
254
|
-
if (opt.waitMined || opt.callStatic) {
|
|
255
|
-
res.decodedResult = fnACI.returns && fnACI.returns !== 'unit' && fn !== 'init' &&
|
|
256
|
-
instance.calldata.decode(instance.aci.name, fn, res.result.returnValue)
|
|
257
|
-
res.decodedEvents = instance.decodeEvents(res.result.log)
|
|
258
|
-
}
|
|
259
|
-
return res
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Decode Events
|
|
264
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
265
|
-
* @rtype (events: Array) => DecodedEvents: Array
|
|
266
|
-
* @param {Array} events Array of encoded events(callRes.result.log)
|
|
267
|
-
* @return {Object} DecodedEvents
|
|
268
|
-
*/
|
|
269
|
-
instance.decodeEvents = (events) => {
|
|
270
|
-
const eventsACI = instance.aci.event ? instance.aci.event.variant : []
|
|
271
|
-
const eventsSchema = eventsACI.map(e => {
|
|
272
|
-
const name = Object.keys(e)[0]
|
|
273
|
-
return { name, types: e[name] }
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
return decodeEvents(events, eventsSchema)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Generate proto function based on contract function using Contract ACI schema
|
|
281
|
-
* All function can be called like:
|
|
282
|
-
* 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx on-chain base on if function stateful or not.
|
|
283
|
-
* Also you can manually do that:
|
|
284
|
-
* `await contract.methods.testFunction.get()` -> use call-static(dry-run)
|
|
285
|
-
* `await contract.methods.testFunction.send()` -> send tx on-chain
|
|
286
|
-
*/
|
|
287
|
-
instance.methods = Object.fromEntries(instance.aci.functions
|
|
288
|
-
.map(({ name, arguments: aciArgs, stateful }) => {
|
|
289
|
-
const genHandler = callStatic => (...args) => {
|
|
290
|
-
const options = args.length === aciArgs.length + 1 ? args.pop() : {}
|
|
291
|
-
if (typeof options !== 'object') throw new Error(`Options should be an object: ${options}`)
|
|
292
|
-
if (name === 'init') return instance.deploy(args, { callStatic, ...options })
|
|
293
|
-
return instance.call(name, args, { callStatic, ...options })
|
|
294
|
-
}
|
|
295
|
-
return [
|
|
296
|
-
name,
|
|
297
|
-
Object.assign(
|
|
298
|
-
genHandler(name === 'init' ? false : !stateful),
|
|
299
|
-
{
|
|
300
|
-
get: genHandler(true),
|
|
301
|
-
send: genHandler(false),
|
|
302
|
-
decodeEvents: events => instance.decodeEvents(events)
|
|
303
|
-
}
|
|
304
|
-
)
|
|
305
|
-
]
|
|
306
|
-
})
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
return instance
|
|
310
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { toBytes } from '../../utils/bytes'
|
|
2
|
-
import { decode } from '../../tx/builder/helpers'
|
|
3
|
-
import { parseBigNumber } from '../../utils/bignumber'
|
|
4
|
-
import { addressFromDecimal, hash } from '../../utils/crypto'
|
|
5
|
-
|
|
6
|
-
export const SOPHIA_TYPES = [
|
|
7
|
-
'int',
|
|
8
|
-
'string',
|
|
9
|
-
'tuple',
|
|
10
|
-
'address',
|
|
11
|
-
'bool',
|
|
12
|
-
'list',
|
|
13
|
-
'map',
|
|
14
|
-
'record',
|
|
15
|
-
'option',
|
|
16
|
-
'oracle',
|
|
17
|
-
'oracleQuery',
|
|
18
|
-
'hash',
|
|
19
|
-
'signature',
|
|
20
|
-
'bytes',
|
|
21
|
-
'variant'
|
|
22
|
-
].reduce((acc, type) => ({ ...acc, [type]: type }), { ChainTtl: 'Chain.ttl' })
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Decode events fields
|
|
26
|
-
* @param {Object[]} events Array of events with encoded fields
|
|
27
|
-
* @param {Array} schemas Smart contract event ACI schemas
|
|
28
|
-
* @return {Object}
|
|
29
|
-
*/
|
|
30
|
-
export const decodeEvents = (events, schemas = []) => events.reduce((acc, event) => {
|
|
31
|
-
const [nameHash, ...params] = event.topics
|
|
32
|
-
const schema = schemas.find((s) => hash(s.name).equals(toBytes(nameHash, true)))
|
|
33
|
-
if (!schema) return acc
|
|
34
|
-
const stringCount = schema.types.filter(t => t === SOPHIA_TYPES.string).length
|
|
35
|
-
if (stringCount > 1) throw new Error(`Event schema contains more than one string: ${schema.types}`)
|
|
36
|
-
const topicsCount = schema.types.length - stringCount
|
|
37
|
-
if (topicsCount !== params.length) {
|
|
38
|
-
throw new Error(`Schema defines ${topicsCount} types, but ${params.length} topics present`)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
acc.push({
|
|
42
|
-
...event,
|
|
43
|
-
name: schema.name,
|
|
44
|
-
decoded: schema.types.map((type) =>
|
|
45
|
-
decodeEventField(type === SOPHIA_TYPES.string ? event.data : params.shift(), type))
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return acc
|
|
49
|
-
}, [])
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Transform Event based on type
|
|
53
|
-
* @param {String|Number} field Event data
|
|
54
|
-
* @param {String} type Event type from schema
|
|
55
|
-
* @return {*}
|
|
56
|
-
*/
|
|
57
|
-
function decodeEventField (field, type) {
|
|
58
|
-
switch (type) {
|
|
59
|
-
case SOPHIA_TYPES.int:
|
|
60
|
-
return parseBigNumber(field)
|
|
61
|
-
case SOPHIA_TYPES.bool:
|
|
62
|
-
return !!field
|
|
63
|
-
case SOPHIA_TYPES.hash:
|
|
64
|
-
return toBytes(field, true).toString('hex')
|
|
65
|
-
case SOPHIA_TYPES.address:
|
|
66
|
-
return addressFromDecimal(field)
|
|
67
|
-
case SOPHIA_TYPES.string:
|
|
68
|
-
return decode(field).toString('utf-8')
|
|
69
|
-
default:
|
|
70
|
-
return toBytes(field, true)
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/contract/index.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2018 aeternity developers
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
* copyright notice and this permission notice appear in all copies.
|
|
8
|
-
*
|
|
9
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Contract Base module
|
|
20
|
-
* @module @aeternity/aepp-sdk/es/contract
|
|
21
|
-
* @export Contract
|
|
22
|
-
* @example import ContractBase from '@aeternity/aepp-sdk/es/contract'
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import stampit from '@stamp/it'
|
|
26
|
-
import { required } from '@stamp/required'
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Basic Contract Stamp
|
|
30
|
-
*
|
|
31
|
-
* This stamp include api call's related to contract functionality.
|
|
32
|
-
* Attempting to create instances from the Stamp without overwriting all
|
|
33
|
-
* abstract methods using composition will result in an exception.
|
|
34
|
-
* @function
|
|
35
|
-
* @alias module:@aeternity/aepp-sdk/es/contract
|
|
36
|
-
* @rtype Stamp
|
|
37
|
-
* @param {Object} [options={}] - Initializer object
|
|
38
|
-
* @return {Object} Contract instance
|
|
39
|
-
*/
|
|
40
|
-
const ContractBase = stampit(required({
|
|
41
|
-
methods: {
|
|
42
|
-
contractEncodeCallDataAPI: required,
|
|
43
|
-
compileContractAPI: required,
|
|
44
|
-
contractGetACI: required,
|
|
45
|
-
setCompilerUrl: required,
|
|
46
|
-
getCompilerVersion: required,
|
|
47
|
-
contractDecodeCallResultAPI: required,
|
|
48
|
-
validateByteCodeAPI: required,
|
|
49
|
-
getFateAssembler: required,
|
|
50
|
-
getBytecodeCompilerVersion: required
|
|
51
|
-
}
|
|
52
|
-
}))
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get contract ACI
|
|
56
|
-
* @function contractGetACI
|
|
57
|
-
* @instance
|
|
58
|
-
* @abstract
|
|
59
|
-
* @category async
|
|
60
|
-
* @rtype (source: String, options: Array) => aciObject: Promise[Object]
|
|
61
|
-
* @param {String} source - Contract source code
|
|
62
|
-
* @param {Object} [options={}] Options
|
|
63
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
64
|
-
* @return {Object} - Contract aci object
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Encode contract data
|
|
69
|
-
* @function contractEncodeCallDataAPI
|
|
70
|
-
* @instance
|
|
71
|
-
* @abstract
|
|
72
|
-
* @category async
|
|
73
|
-
* @rtype (source: String, name: String, args: Array, options: Array) => callData: Promise[String]
|
|
74
|
-
* @param {String} source - Contract source code
|
|
75
|
-
* @param {String} name - Function name
|
|
76
|
-
* @param {Array} args - Function argument's
|
|
77
|
-
* @param {Object} [options={}] Options
|
|
78
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
79
|
-
* @return {String} - Contract encoded data
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Decode contract call result data
|
|
84
|
-
* @function contractDecodeCallResultAPI
|
|
85
|
-
* @instance
|
|
86
|
-
* @abstract
|
|
87
|
-
* @category async
|
|
88
|
-
* @rtype (source: String, fn: String, callValue: String, callResult: String, options: Array) => decodedResult: Promise[String]
|
|
89
|
-
* @param {String} source - Contract source
|
|
90
|
-
* @param {String} fn - Fn name
|
|
91
|
-
* @param {String} callValue - result data (cb_das...)
|
|
92
|
-
* @param {String} callResult - contract call result status('ok', 'revert', ...)
|
|
93
|
-
* @param {Object} [options={}] Options
|
|
94
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
95
|
-
* @return {String} - Decoded contract call result
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Decode call data by source
|
|
100
|
-
* @function contractDecodeCallDataBySourceAPI
|
|
101
|
-
* @instance
|
|
102
|
-
* @abstract
|
|
103
|
-
* @category async
|
|
104
|
-
* @rtype (source: String, function: String, callData: String, options: Array) => decodedResult: Promise[String]
|
|
105
|
-
* @param {String} source - contract source
|
|
106
|
-
* @param {String} function - function name
|
|
107
|
-
* @param {String} callData - Encoded contract call data
|
|
108
|
-
* @param {Object} [options={}] Options
|
|
109
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
110
|
-
* @return {String} - Decoded contract call data
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Decode call data by bytecode
|
|
115
|
-
* @function contractDecodeCallDataByCodeAPI
|
|
116
|
-
* @instance
|
|
117
|
-
* @abstract
|
|
118
|
-
* @category async
|
|
119
|
-
* @rtype (code: String, callData: String) => decodedResult: Promise[String]
|
|
120
|
-
* @param {String} code - contract byte code
|
|
121
|
-
* @param {String} callData - Encoded contract call data
|
|
122
|
-
* @return {String} - Decoded contract call data
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Compile contract
|
|
127
|
-
* @function compileContractAPI
|
|
128
|
-
* @instance
|
|
129
|
-
* @abstract
|
|
130
|
-
* @category async
|
|
131
|
-
* @rtype (code: String, options?: Object) => compiledContract: Object
|
|
132
|
-
* @param {String} code - Contract source code
|
|
133
|
-
* @param {Object} [options={}] Options
|
|
134
|
-
* @param {Object} [options.filesystem] Contract external namespaces map
|
|
135
|
-
* @return {Object} Object which contain bytecode of contract
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Set compiler url
|
|
140
|
-
* @function setCompilerUrl
|
|
141
|
-
* @instance
|
|
142
|
-
* @abstract
|
|
143
|
-
* @category async
|
|
144
|
-
* @rtype (url: String) => void
|
|
145
|
-
* @param {String} url - Compiler url
|
|
146
|
-
* @return {void}
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Get Compiler Version
|
|
151
|
-
* @function getCompilerVersion
|
|
152
|
-
* @instance
|
|
153
|
-
* @abstract
|
|
154
|
-
* @category async
|
|
155
|
-
* @rtype () => String
|
|
156
|
-
* @return {String} Compiler version
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
export default ContractBase
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const asEnum = (array) => Object.fromEntries(array.map(a => [a, a]))
|
|
2
|
-
|
|
3
|
-
export const VERSION = 1
|
|
4
|
-
|
|
5
|
-
export const MESSAGE_DIRECTION = asEnum(['to_waellet', 'to_aepp'])
|
|
6
|
-
|
|
7
|
-
export const WALLET_TYPE = asEnum([
|
|
8
|
-
'window',
|
|
9
|
-
'extension'
|
|
10
|
-
])
|
|
11
|
-
|
|
12
|
-
export const NOTIFICATIONS = asEnum([
|
|
13
|
-
'readyToConnect',
|
|
14
|
-
'closeConnection',
|
|
15
|
-
'updateNetwork',
|
|
16
|
-
'updateAddress'
|
|
17
|
-
])
|
|
18
|
-
|
|
19
|
-
export const REQUESTS = asEnum([
|
|
20
|
-
'connect',
|
|
21
|
-
'subscribeAddress',
|
|
22
|
-
'sign',
|
|
23
|
-
'address',
|
|
24
|
-
'signMessage'
|
|
25
|
-
])
|
|
26
|
-
|
|
27
|
-
export const SUBSCRIPTION_VALUES = asEnum([
|
|
28
|
-
'current',
|
|
29
|
-
'connected'
|
|
30
|
-
])
|
|
31
|
-
|
|
32
|
-
export const SUBSCRIPTION_TYPES = asEnum([
|
|
33
|
-
'subscribe',
|
|
34
|
-
'unsubscribe'
|
|
35
|
-
])
|
|
36
|
-
|
|
37
|
-
export const METHODS = {
|
|
38
|
-
wallet: {
|
|
39
|
-
[NOTIFICATIONS.readyToConnect]: 'connection.announcePresence',
|
|
40
|
-
[NOTIFICATIONS.updateAddress]: 'address.update'
|
|
41
|
-
},
|
|
42
|
-
aepp: {
|
|
43
|
-
[REQUESTS.address]: 'address.get',
|
|
44
|
-
[REQUESTS.connect]: 'connection.open',
|
|
45
|
-
[REQUESTS.sign]: 'transaction.sign',
|
|
46
|
-
[REQUESTS.signMessage]: 'message.sign',
|
|
47
|
-
[REQUESTS.subscribeAddress]: 'address.subscribe'
|
|
48
|
-
},
|
|
49
|
-
[NOTIFICATIONS.updateNetwork]: 'networkId.update',
|
|
50
|
-
[NOTIFICATIONS.closeConnection]: 'connection.close'
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const RPC_STATUS = {
|
|
54
|
-
CONNECTED: 'CONNECTED',
|
|
55
|
-
DISCONNECTED: 'DISCONNECTED',
|
|
56
|
-
CONNECTION_REJECTED: 'CONNECTION_REJECTED',
|
|
57
|
-
WAITING_FOR_CONNECTION_APPROVE: 'WAITING_FOR_CONNECTION_APPROVE',
|
|
58
|
-
WAITING_FOR_CONNECTION_REQUEST: 'WAITING_FOR_CONNECTION_REQUEST',
|
|
59
|
-
WAITING_FOR_SUBSCRIPTION: 'WAITING_FOR_SUBSCRIPTION'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const ERRORS = {
|
|
63
|
-
broadcastFailed: (error = {}) => ({
|
|
64
|
-
code: 3,
|
|
65
|
-
data: error,
|
|
66
|
-
message: 'Broadcast failed'
|
|
67
|
-
}),
|
|
68
|
-
invalidTransaction: (error = {}) => ({
|
|
69
|
-
code: 2,
|
|
70
|
-
data: error,
|
|
71
|
-
message: 'Invalid transaction'
|
|
72
|
-
}),
|
|
73
|
-
rejectedByUser: (error = {}) => ({
|
|
74
|
-
code: 4,
|
|
75
|
-
data: error,
|
|
76
|
-
message: 'Operation rejected by user'
|
|
77
|
-
}),
|
|
78
|
-
connectionDeny: (error = {}) => ({
|
|
79
|
-
code: 9,
|
|
80
|
-
data: error,
|
|
81
|
-
message: 'Wallet deny your connection request'
|
|
82
|
-
}),
|
|
83
|
-
permissionDeny: (error = {}) => ({
|
|
84
|
-
code: 11,
|
|
85
|
-
data: error,
|
|
86
|
-
message: `You are not subscribed for account ${error.account}`
|
|
87
|
-
}),
|
|
88
|
-
internalError: (error = {}) => ({
|
|
89
|
-
code: 12,
|
|
90
|
-
data: error,
|
|
91
|
-
message: error.msg
|
|
92
|
-
}),
|
|
93
|
-
notAuthorize: (error = {}) => ({
|
|
94
|
-
code: 10,
|
|
95
|
-
data: error,
|
|
96
|
-
message: 'You are not connected to the wallet'
|
|
97
|
-
}),
|
|
98
|
-
unsupportedProtocol: (error = {}) => ({
|
|
99
|
-
code: 5,
|
|
100
|
-
data: error,
|
|
101
|
-
message: 'Unsupported Protocol Version'
|
|
102
|
-
}),
|
|
103
|
-
unsupportedNetwork: (error = {}) => ({
|
|
104
|
-
code: 8,
|
|
105
|
-
data: error,
|
|
106
|
-
message: 'Unsupported Network'
|
|
107
|
-
})
|
|
108
|
-
}
|