@aeternity/aepp-sdk 12.0.0 → 12.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/channel/index.ts
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import BigNumber from 'bignumber.js'
|
|
18
|
-
import { snakeToPascal } from '../utils/string'
|
|
19
|
-
import { buildTx, unpackTx } from '../tx/builder'
|
|
20
|
-
import {
|
|
21
|
-
import * as handlers from './handlers'
|
|
17
|
+
import BigNumber from 'bignumber.js';
|
|
18
|
+
import { snakeToPascal } from '../utils/string';
|
|
19
|
+
import { buildTx, unpackTx } from '../tx/builder';
|
|
20
|
+
import { MIN_GAS_PRICE, Tag } from '../tx/builder/constants';
|
|
21
|
+
import * as handlers from './handlers';
|
|
22
22
|
import {
|
|
23
23
|
eventEmitters,
|
|
24
24
|
status as channelStatus,
|
|
@@ -33,42 +33,43 @@ import {
|
|
|
33
33
|
SignTx,
|
|
34
34
|
ChannelOptions,
|
|
35
35
|
ChannelState,
|
|
36
|
-
|
|
37
|
-
} from '
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
36
|
+
} from './internal';
|
|
37
|
+
import { UnknownChannelStateError, ChannelError } from '../utils/errors';
|
|
38
|
+
import { Encoded } from '../utils/encoder';
|
|
39
|
+
import { ContractCallReturnType } from '../apis/node';
|
|
40
|
+
import { pause } from '../utils/other';
|
|
40
41
|
|
|
41
|
-
function snakeToPascalObjKeys<Type>
|
|
42
|
+
function snakeToPascalObjKeys<Type>(obj: object): Type {
|
|
42
43
|
return Object.entries(obj).reduce((result, [key, val]) => ({
|
|
43
44
|
...result,
|
|
44
|
-
[snakeToPascal(key)]: val
|
|
45
|
-
}), {}) as Type
|
|
45
|
+
[snakeToPascal(key)]: val,
|
|
46
|
+
}), {}) as Type;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
type EventCallback = (...args: any[]) => void
|
|
49
|
+
type EventCallback = (...args: any[]) => void;
|
|
49
50
|
|
|
50
51
|
interface CallContractOptions {
|
|
51
|
-
amount?: number | BigNumber
|
|
52
|
-
callData?:
|
|
53
|
-
abiVersion?: number
|
|
54
|
-
contract?:
|
|
55
|
-
returnValue?: any
|
|
56
|
-
gasUsed?: number | BigNumber
|
|
57
|
-
gasPrice?: number | BigNumber
|
|
58
|
-
height?: number
|
|
59
|
-
callerNonce?: number
|
|
60
|
-
log?: any
|
|
61
|
-
returnType?:
|
|
52
|
+
amount?: number | BigNumber;
|
|
53
|
+
callData?: Encoded.ContractBytearray;
|
|
54
|
+
abiVersion?: number;
|
|
55
|
+
contract?: Encoded.ContractAddress;
|
|
56
|
+
returnValue?: any;
|
|
57
|
+
gasUsed?: number | BigNumber;
|
|
58
|
+
gasPrice?: number | BigNumber;
|
|
59
|
+
height?: number;
|
|
60
|
+
callerNonce?: number;
|
|
61
|
+
log?: any;
|
|
62
|
+
returnType?: ContractCallReturnType;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
interface Contract {
|
|
65
|
-
abiVersion: number
|
|
66
|
-
active: boolean
|
|
67
|
-
deposit: number | BigNumber
|
|
68
|
-
id: string
|
|
69
|
-
ownerId: string
|
|
70
|
-
referrerIds: string[]
|
|
71
|
-
vmVersion: number
|
|
66
|
+
abiVersion: number;
|
|
67
|
+
active: boolean;
|
|
68
|
+
deposit: number | BigNumber;
|
|
69
|
+
id: string;
|
|
70
|
+
ownerId: string;
|
|
71
|
+
referrerIds: string[];
|
|
72
|
+
vmVersion: number;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/**
|
|
@@ -139,15 +140,15 @@ export default class Channel {
|
|
|
139
140
|
* @param options.debug=false - Log websocket communication
|
|
140
141
|
* @param options.sign - Function which verifies and signs transactions
|
|
141
142
|
*/
|
|
142
|
-
static async initialize
|
|
143
|
-
const channel = new Channel()
|
|
143
|
+
static async initialize(options: ChannelOptions): Promise<Channel> {
|
|
144
|
+
const channel = new Channel();
|
|
144
145
|
await initialize(
|
|
145
146
|
channel,
|
|
146
147
|
options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,
|
|
147
148
|
handlers.channelOpen,
|
|
148
|
-
options
|
|
149
|
-
)
|
|
150
|
-
return channel
|
|
149
|
+
options,
|
|
150
|
+
);
|
|
151
|
+
return channel;
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
/**
|
|
@@ -168,10 +169,10 @@ export default class Channel {
|
|
|
168
169
|
* @param callback - Callback function
|
|
169
170
|
*/
|
|
170
171
|
// TODO define specific callback type depending on the event name
|
|
171
|
-
on
|
|
172
|
-
const eventEmitter = eventEmitters.get(this)
|
|
173
|
-
if (eventEmitter == null) throw new UnknownChannelStateError()
|
|
174
|
-
eventEmitter.on(eventName, callback)
|
|
172
|
+
on(eventName: string, callback: EventCallback): void {
|
|
173
|
+
const eventEmitter = eventEmitters.get(this);
|
|
174
|
+
if (eventEmitter == null) throw new UnknownChannelStateError();
|
|
175
|
+
eventEmitter.on(eventName, callback);
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
/**
|
|
@@ -179,34 +180,34 @@ export default class Channel {
|
|
|
179
180
|
* @param eventName - Event name
|
|
180
181
|
* @param callback - Callback function
|
|
181
182
|
*/
|
|
182
|
-
off
|
|
183
|
-
const eventEmitter = eventEmitters.get(this)
|
|
184
|
-
if (eventEmitter == null) throw new UnknownChannelStateError()
|
|
185
|
-
eventEmitter.removeListener(eventName, callback)
|
|
183
|
+
off(eventName: string, callback: EventCallback): void {
|
|
184
|
+
const eventEmitter = eventEmitters.get(this);
|
|
185
|
+
if (eventEmitter == null) throw new UnknownChannelStateError();
|
|
186
|
+
eventEmitter.removeListener(eventName, callback);
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
/**
|
|
189
190
|
* Close the connection
|
|
190
191
|
*/
|
|
191
|
-
disconnect
|
|
192
|
-
return channelDisconnect(this)
|
|
192
|
+
disconnect(): void {
|
|
193
|
+
return channelDisconnect(this);
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
/**
|
|
196
197
|
* Get current status
|
|
197
198
|
*
|
|
198
199
|
*/
|
|
199
|
-
status
|
|
200
|
-
const status = channelStatus.get(this)
|
|
201
|
-
if (status == null) throw new UnknownChannelStateError()
|
|
202
|
-
return status
|
|
200
|
+
status(): string {
|
|
201
|
+
const status = channelStatus.get(this);
|
|
202
|
+
if (status == null) throw new UnknownChannelStateError();
|
|
203
|
+
return status;
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
/**
|
|
206
207
|
* Get current state
|
|
207
208
|
*/
|
|
208
|
-
async state
|
|
209
|
-
return
|
|
209
|
+
async state(): Promise<ChannelState> {
|
|
210
|
+
return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
/**
|
|
@@ -216,21 +217,21 @@ export default class Channel {
|
|
|
216
217
|
* it will return `null`.
|
|
217
218
|
*
|
|
218
219
|
*/
|
|
219
|
-
round
|
|
220
|
-
const state = channelState.get(this)
|
|
220
|
+
round(): number | null {
|
|
221
|
+
const state = channelState.get(this);
|
|
221
222
|
if (state == null) {
|
|
222
|
-
return null
|
|
223
|
+
return null;
|
|
223
224
|
}
|
|
224
|
-
const { txType, tx } = unpackTx(state,
|
|
225
|
+
const { txType, tx } = unpackTx(state, Tag.SignedTx).tx.encodedTx;
|
|
225
226
|
switch (txType) {
|
|
226
|
-
case
|
|
227
|
-
return 1
|
|
228
|
-
case
|
|
229
|
-
case
|
|
230
|
-
case
|
|
231
|
-
return
|
|
227
|
+
case Tag.ChannelCreateTx:
|
|
228
|
+
return 1;
|
|
229
|
+
case Tag.ChannelOffChainTx:
|
|
230
|
+
case Tag.ChannelWithdrawTx:
|
|
231
|
+
case Tag.ChannelDepositTx:
|
|
232
|
+
return tx.round;
|
|
232
233
|
default:
|
|
233
|
-
return null
|
|
234
|
+
return null;
|
|
234
235
|
}
|
|
235
236
|
}
|
|
236
237
|
|
|
@@ -238,20 +239,20 @@ export default class Channel {
|
|
|
238
239
|
* Get channel id
|
|
239
240
|
*
|
|
240
241
|
*/
|
|
241
|
-
id
|
|
242
|
-
const id = channelId.get(this)
|
|
243
|
-
if (id == null) throw new ChannelError('Channel is not initialized')
|
|
244
|
-
return id
|
|
242
|
+
id(): string {
|
|
243
|
+
const id = channelId.get(this);
|
|
244
|
+
if (id == null) throw new ChannelError('Channel is not initialized');
|
|
245
|
+
return id;
|
|
245
246
|
}
|
|
246
247
|
|
|
247
248
|
/**
|
|
248
249
|
* Get channel's fsm id
|
|
249
250
|
*
|
|
250
251
|
*/
|
|
251
|
-
fsmId
|
|
252
|
-
const id = channelFsmId.get(this)
|
|
253
|
-
if (id == null) throw new ChannelError('Channel is not initialized')
|
|
254
|
-
return id
|
|
252
|
+
fsmId(): string {
|
|
253
|
+
const id = channelFsmId.get(this);
|
|
254
|
+
if (id == null) throw new ChannelError('Channel is not initialized');
|
|
255
|
+
return id;
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
/**
|
|
@@ -261,7 +262,7 @@ export default class Channel {
|
|
|
261
262
|
* The update is a change to be applied on top of the latest state.
|
|
262
263
|
*
|
|
263
264
|
* Sender and receiver are the channel parties. Both the initiator and responder
|
|
264
|
-
* can take those roles. Any public key outside
|
|
265
|
+
* can take those roles. Any public key outside the channel is considered invalid.
|
|
265
266
|
*
|
|
266
267
|
* @param from - Sender's public address
|
|
267
268
|
* @param to - Receiver's public address
|
|
@@ -283,38 +284,41 @@ export default class Channel {
|
|
|
283
284
|
* )
|
|
284
285
|
* ```
|
|
285
286
|
*/
|
|
286
|
-
async update
|
|
287
|
-
from:
|
|
288
|
-
to:
|
|
287
|
+
async update(
|
|
288
|
+
from: Encoded.AccountAddress,
|
|
289
|
+
to: Encoded.AccountAddress,
|
|
289
290
|
amount: number | BigNumber,
|
|
290
291
|
sign: SignTx,
|
|
291
|
-
metadata: string[] = []
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
292
|
+
metadata: string[] = [],
|
|
293
|
+
): Promise<{
|
|
294
|
+
accepted: boolean;
|
|
295
|
+
signedTx?: Encoded.Transaction;
|
|
296
|
+
errorCode?: number;
|
|
297
|
+
errorMessage?: string;
|
|
296
298
|
}> {
|
|
297
|
-
return
|
|
299
|
+
return new Promise((resolve, reject) => {
|
|
298
300
|
enqueueAction(
|
|
299
301
|
this,
|
|
300
302
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
301
|
-
(channel
|
|
303
|
+
(channel) => {
|
|
302
304
|
send(channel, {
|
|
303
305
|
jsonrpc: '2.0',
|
|
304
306
|
method: 'channels.update.new',
|
|
305
|
-
params: {
|
|
306
|
-
|
|
307
|
+
params: {
|
|
308
|
+
from, to, amount, meta: metadata,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
307
311
|
return {
|
|
308
312
|
handler: handlers.awaitingOffChainTx,
|
|
309
313
|
state: {
|
|
310
314
|
resolve,
|
|
311
315
|
reject,
|
|
312
|
-
sign
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
)
|
|
317
|
-
})
|
|
316
|
+
sign,
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
});
|
|
318
322
|
}
|
|
319
323
|
|
|
320
324
|
/**
|
|
@@ -337,16 +341,19 @@ export default class Channel {
|
|
|
337
341
|
* }).then(poi => console.log(poi))
|
|
338
342
|
* ```
|
|
339
343
|
*/
|
|
340
|
-
async poi
|
|
341
|
-
{ accounts, contracts }: {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
+
async poi(
|
|
345
|
+
{ accounts, contracts }: {
|
|
346
|
+
accounts: Encoded.AccountAddress[];
|
|
347
|
+
contracts?: Encoded.ContractAddress[];
|
|
348
|
+
},
|
|
349
|
+
): Promise<Encoded.Poi> {
|
|
350
|
+
return (await call(this, 'channels.get.poi', { accounts, contracts })).poi;
|
|
344
351
|
}
|
|
345
352
|
|
|
346
353
|
/**
|
|
347
354
|
* Get balances
|
|
348
355
|
*
|
|
349
|
-
* The accounts
|
|
356
|
+
* The accounts param contains a list of addresses to fetch balances of.
|
|
350
357
|
* Those can be either account balances or a contract ones, encoded as an account addresses.
|
|
351
358
|
*
|
|
352
359
|
* If a certain account address had not being found in the state tree - it is simply
|
|
@@ -364,14 +371,16 @@ export default class Channel {
|
|
|
364
371
|
* )
|
|
365
372
|
* ```
|
|
366
373
|
*/
|
|
367
|
-
async balances
|
|
374
|
+
async balances(
|
|
375
|
+
accounts: Encoded.AccountAddress[],
|
|
376
|
+
): Promise<{ [key: Encoded.AccountAddress]: string }> {
|
|
368
377
|
return Object.fromEntries(
|
|
369
378
|
(await call(this, 'channels.get.balances', { accounts }))
|
|
370
379
|
.map((item: {
|
|
371
|
-
account:
|
|
372
|
-
balance: string
|
|
373
|
-
}) => [item.account, item.balance])
|
|
374
|
-
)
|
|
380
|
+
account: Encoded.AccountAddress;
|
|
381
|
+
balance: string;
|
|
382
|
+
}) => [item.account, item.balance]),
|
|
383
|
+
);
|
|
375
384
|
}
|
|
376
385
|
|
|
377
386
|
/**
|
|
@@ -394,19 +403,20 @@ export default class Channel {
|
|
|
394
403
|
* })
|
|
395
404
|
* ```
|
|
396
405
|
*/
|
|
397
|
-
async leave
|
|
398
|
-
return
|
|
406
|
+
async leave(): Promise<{ channelId: string; signedTx: Encoded.Transaction }> {
|
|
407
|
+
return new Promise((resolve, reject) => {
|
|
399
408
|
enqueueAction(
|
|
400
409
|
this,
|
|
401
410
|
(channel, state) => state?.handler === handlers.channelOpen,
|
|
402
|
-
(channel
|
|
403
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} })
|
|
411
|
+
(channel) => {
|
|
412
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} });
|
|
404
413
|
return {
|
|
405
414
|
handler: handlers.awaitingLeave,
|
|
406
|
-
state: { resolve, reject }
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
415
|
+
state: { resolve, reject },
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
});
|
|
410
420
|
}
|
|
411
421
|
|
|
412
422
|
/**
|
|
@@ -423,24 +433,24 @@ export default class Channel {
|
|
|
423
433
|
* ).then(tx => console.log('on_chain_tx', tx))
|
|
424
434
|
* ```
|
|
425
435
|
*/
|
|
426
|
-
async shutdown
|
|
427
|
-
return
|
|
436
|
+
async shutdown(sign: Function): Promise<Encoded.Transaction> {
|
|
437
|
+
return new Promise((resolve, reject) => {
|
|
428
438
|
enqueueAction(
|
|
429
439
|
this,
|
|
430
440
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
431
441
|
(channel) => {
|
|
432
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} })
|
|
442
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} });
|
|
433
443
|
return {
|
|
434
444
|
handler: handlers.awaitingShutdownTx,
|
|
435
445
|
state: {
|
|
436
446
|
sign,
|
|
437
447
|
resolve,
|
|
438
|
-
reject
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
)
|
|
443
|
-
})
|
|
448
|
+
reject,
|
|
449
|
+
},
|
|
450
|
+
};
|
|
451
|
+
},
|
|
452
|
+
);
|
|
453
|
+
});
|
|
444
454
|
}
|
|
445
455
|
|
|
446
456
|
/**
|
|
@@ -492,18 +502,18 @@ export default class Channel {
|
|
|
492
502
|
* })
|
|
493
503
|
* ```
|
|
494
504
|
*/
|
|
495
|
-
async withdraw
|
|
505
|
+
async withdraw(
|
|
496
506
|
amount: number | BigNumber,
|
|
497
507
|
sign: SignTx,
|
|
498
508
|
{ onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked }:
|
|
499
|
-
|
|
500
|
-
): Promise<{ accepted: boolean
|
|
501
|
-
return
|
|
509
|
+
Pick<ChannelState, 'onOnChainTx' | 'onOwnWithdrawLocked' | 'onWithdrawLocked'> = {},
|
|
510
|
+
): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
|
|
511
|
+
return new Promise((resolve, reject) => {
|
|
502
512
|
enqueueAction(
|
|
503
513
|
this,
|
|
504
514
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
505
515
|
(channel) => {
|
|
506
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } })
|
|
516
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } });
|
|
507
517
|
return {
|
|
508
518
|
handler: handlers.awaitingWithdrawTx,
|
|
509
519
|
state: {
|
|
@@ -512,12 +522,12 @@ export default class Channel {
|
|
|
512
522
|
reject,
|
|
513
523
|
onOnChainTx,
|
|
514
524
|
onOwnWithdrawLocked,
|
|
515
|
-
onWithdrawLocked
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
)
|
|
520
|
-
})
|
|
525
|
+
onWithdrawLocked,
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
);
|
|
530
|
+
});
|
|
521
531
|
}
|
|
522
532
|
|
|
523
533
|
/**
|
|
@@ -570,18 +580,18 @@ export default class Channel {
|
|
|
570
580
|
* })
|
|
571
581
|
* ```
|
|
572
582
|
*/
|
|
573
|
-
async deposit
|
|
583
|
+
async deposit(
|
|
574
584
|
amount: number | BigNumber,
|
|
575
585
|
sign: SignTx,
|
|
576
586
|
{ onOnChainTx, onOwnDepositLocked, onDepositLocked }:
|
|
577
|
-
|
|
578
|
-
): Promise<{ accepted: boolean
|
|
579
|
-
return
|
|
587
|
+
Pick<ChannelState, 'onOnChainTx' | 'onOwnDepositLocked' | 'onDepositLocked'> = {},
|
|
588
|
+
): Promise<{ accepted: boolean; state: ChannelState }> {
|
|
589
|
+
return new Promise((resolve, reject) => {
|
|
580
590
|
enqueueAction(
|
|
581
591
|
this,
|
|
582
592
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
583
593
|
(channel) => {
|
|
584
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } })
|
|
594
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } });
|
|
585
595
|
return {
|
|
586
596
|
handler: handlers.awaitingDepositTx,
|
|
587
597
|
state: {
|
|
@@ -590,12 +600,12 @@ export default class Channel {
|
|
|
590
600
|
reject,
|
|
591
601
|
onOnChainTx,
|
|
592
602
|
onOwnDepositLocked,
|
|
593
|
-
onDepositLocked
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
)
|
|
598
|
-
})
|
|
603
|
+
onDepositLocked,
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
},
|
|
607
|
+
);
|
|
608
|
+
});
|
|
599
609
|
}
|
|
600
610
|
|
|
601
611
|
/**
|
|
@@ -632,17 +642,21 @@ export default class Channel {
|
|
|
632
642
|
* })
|
|
633
643
|
* ```
|
|
634
644
|
*/
|
|
635
|
-
async createContract
|
|
636
|
-
{
|
|
637
|
-
code
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
645
|
+
async createContract(
|
|
646
|
+
{
|
|
647
|
+
code, callData, deposit, vmVersion, abiVersion,
|
|
648
|
+
}: {
|
|
649
|
+
code: Encoded.ContractBytearray;
|
|
650
|
+
callData: Encoded.ContractBytearray;
|
|
651
|
+
deposit: number | BigNumber;
|
|
652
|
+
vmVersion: number;
|
|
653
|
+
abiVersion: number;
|
|
642
654
|
},
|
|
643
|
-
sign: SignTx
|
|
644
|
-
): Promise<{
|
|
645
|
-
|
|
655
|
+
sign: SignTx,
|
|
656
|
+
): Promise<{
|
|
657
|
+
accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;
|
|
658
|
+
}> {
|
|
659
|
+
return new Promise((resolve, reject) => {
|
|
646
660
|
enqueueAction(
|
|
647
661
|
this,
|
|
648
662
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
@@ -655,20 +669,20 @@ export default class Channel {
|
|
|
655
669
|
call_data: callData,
|
|
656
670
|
deposit,
|
|
657
671
|
vm_version: vmVersion,
|
|
658
|
-
abi_version: abiVersion
|
|
659
|
-
}
|
|
660
|
-
})
|
|
672
|
+
abi_version: abiVersion,
|
|
673
|
+
},
|
|
674
|
+
});
|
|
661
675
|
return {
|
|
662
676
|
handler: handlers.awaitingNewContractTx,
|
|
663
677
|
state: {
|
|
664
678
|
sign,
|
|
665
679
|
resolve,
|
|
666
|
-
reject
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
)
|
|
671
|
-
})
|
|
680
|
+
reject,
|
|
681
|
+
},
|
|
682
|
+
};
|
|
683
|
+
},
|
|
684
|
+
);
|
|
685
|
+
});
|
|
672
686
|
}
|
|
673
687
|
|
|
674
688
|
/**
|
|
@@ -709,11 +723,13 @@ export default class Channel {
|
|
|
709
723
|
* })
|
|
710
724
|
* ```
|
|
711
725
|
*/
|
|
712
|
-
async callContract
|
|
713
|
-
{
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
726
|
+
async callContract(
|
|
727
|
+
{
|
|
728
|
+
amount, callData, contract, abiVersion,
|
|
729
|
+
}: CallContractOptions,
|
|
730
|
+
sign: SignTx,
|
|
731
|
+
): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
|
|
732
|
+
return new Promise((resolve, reject) => {
|
|
717
733
|
enqueueAction(
|
|
718
734
|
this,
|
|
719
735
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
@@ -725,16 +741,16 @@ export default class Channel {
|
|
|
725
741
|
amount,
|
|
726
742
|
call_data: callData,
|
|
727
743
|
contract_id: contract,
|
|
728
|
-
abi_version: abiVersion
|
|
729
|
-
}
|
|
730
|
-
})
|
|
744
|
+
abi_version: abiVersion,
|
|
745
|
+
},
|
|
746
|
+
});
|
|
731
747
|
return {
|
|
732
748
|
handler: handlers.awaitingCallContractUpdateTx,
|
|
733
|
-
state: { resolve, reject, sign }
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
)
|
|
737
|
-
})
|
|
749
|
+
state: { resolve, reject, sign },
|
|
750
|
+
};
|
|
751
|
+
},
|
|
752
|
+
);
|
|
753
|
+
});
|
|
738
754
|
}
|
|
739
755
|
|
|
740
756
|
/**
|
|
@@ -766,19 +782,25 @@ export default class Channel {
|
|
|
766
782
|
* })
|
|
767
783
|
* ```
|
|
768
784
|
*/
|
|
769
|
-
async forceProgress
|
|
770
|
-
{
|
|
771
|
-
amount
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
785
|
+
async forceProgress(
|
|
786
|
+
{
|
|
787
|
+
amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,
|
|
788
|
+
}: {
|
|
789
|
+
amount: number;
|
|
790
|
+
callData: Encoded.ContractBytearray;
|
|
791
|
+
contract: Encoded.ContractAddress;
|
|
792
|
+
abiVersion: number;
|
|
793
|
+
gasLimit?: number;
|
|
794
|
+
gasPrice?: number;
|
|
777
795
|
},
|
|
778
796
|
sign: SignTx,
|
|
779
|
-
{ onOnChainTx }:
|
|
780
|
-
): Promise<{
|
|
781
|
-
|
|
797
|
+
{ onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},
|
|
798
|
+
): Promise<{
|
|
799
|
+
accepted: boolean;
|
|
800
|
+
signedTx: Encoded.Transaction;
|
|
801
|
+
tx: Encoded.Transaction | Uint8Array;
|
|
802
|
+
}> {
|
|
803
|
+
return new Promise((resolve, reject) => {
|
|
782
804
|
enqueueAction(
|
|
783
805
|
this,
|
|
784
806
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
@@ -792,16 +814,18 @@ export default class Channel {
|
|
|
792
814
|
contract_id: contract,
|
|
793
815
|
abi_version: abiVersion,
|
|
794
816
|
gas_price: gasPrice,
|
|
795
|
-
gas: gasLimit
|
|
796
|
-
}
|
|
797
|
-
})
|
|
817
|
+
gas: gasLimit,
|
|
818
|
+
},
|
|
819
|
+
});
|
|
798
820
|
return {
|
|
799
821
|
handler: handlers.awaitingCallContractForceProgressUpdate,
|
|
800
|
-
state: {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
822
|
+
state: {
|
|
823
|
+
resolve, reject, sign, onOnChainTx,
|
|
824
|
+
},
|
|
825
|
+
};
|
|
826
|
+
},
|
|
827
|
+
);
|
|
828
|
+
});
|
|
805
829
|
}
|
|
806
830
|
|
|
807
831
|
/**
|
|
@@ -811,7 +835,7 @@ export default class Channel {
|
|
|
811
835
|
* dry-run a contract call. It takes the exact same arguments as a call would
|
|
812
836
|
* and returns the call object.
|
|
813
837
|
*
|
|
814
|
-
* The call is executed in the channel's state but it does not impact the state
|
|
838
|
+
* The call is executed in the channel's state, but it does not impact the state
|
|
815
839
|
* whatsoever. It uses as an environment the latest channel's state and the current
|
|
816
840
|
* top of the blockchain as seen by the node.
|
|
817
841
|
*
|
|
@@ -833,16 +857,22 @@ export default class Channel {
|
|
|
833
857
|
* })
|
|
834
858
|
* ```
|
|
835
859
|
*/
|
|
836
|
-
async callContractStatic
|
|
837
|
-
{
|
|
838
|
-
|
|
860
|
+
async callContractStatic(
|
|
861
|
+
{
|
|
862
|
+
amount, callData, contract, abiVersion,
|
|
863
|
+
}: {
|
|
864
|
+
amount: number;
|
|
865
|
+
callData: Encoded.ContractBytearray;
|
|
866
|
+
contract: Encoded.ContractAddress;
|
|
867
|
+
abiVersion: number;
|
|
868
|
+
},
|
|
839
869
|
): Promise<CallContractOptions> {
|
|
840
|
-
return
|
|
870
|
+
return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
|
|
841
871
|
amount,
|
|
842
872
|
call_data: callData,
|
|
843
873
|
contract_id: contract,
|
|
844
|
-
abi_version: abiVersion
|
|
845
|
-
}))
|
|
874
|
+
abi_version: abiVersion,
|
|
875
|
+
}));
|
|
846
876
|
}
|
|
847
877
|
|
|
848
878
|
/**
|
|
@@ -866,27 +896,31 @@ export default class Channel {
|
|
|
866
896
|
* })
|
|
867
897
|
* ```
|
|
868
898
|
*/
|
|
869
|
-
async getContractCall
|
|
870
|
-
{ caller, contract, round }: {
|
|
899
|
+
async getContractCall(
|
|
900
|
+
{ caller, contract, round }: {
|
|
901
|
+
caller: Encoded.AccountAddress;
|
|
902
|
+
contract: Encoded.ContractAddress;
|
|
903
|
+
round: number;
|
|
904
|
+
},
|
|
871
905
|
): Promise<{
|
|
872
|
-
returnType:
|
|
873
|
-
returnValue: string
|
|
874
|
-
gasPrice: number | BigNumber
|
|
875
|
-
gasUsed: number | BigNumber
|
|
876
|
-
height: number
|
|
877
|
-
log: string
|
|
906
|
+
returnType: ContractCallReturnType;
|
|
907
|
+
returnValue: string;
|
|
908
|
+
gasPrice: number | BigNumber;
|
|
909
|
+
gasUsed: number | BigNumber;
|
|
910
|
+
height: number;
|
|
911
|
+
log: string;
|
|
878
912
|
}> {
|
|
879
|
-
return
|
|
913
|
+
return snakeToPascalObjKeys(
|
|
880
914
|
await call(this, 'channels.get.contract_call', {
|
|
881
915
|
caller_id: caller,
|
|
882
916
|
contract_id: contract,
|
|
883
|
-
round
|
|
884
|
-
})
|
|
885
|
-
)
|
|
917
|
+
round,
|
|
918
|
+
}),
|
|
919
|
+
);
|
|
886
920
|
}
|
|
887
921
|
|
|
888
922
|
/**
|
|
889
|
-
* Get
|
|
923
|
+
* Get the latest contract state
|
|
890
924
|
*
|
|
891
925
|
* @param contract - Address of the contract
|
|
892
926
|
* @example
|
|
@@ -898,14 +932,14 @@ export default class Channel {
|
|
|
898
932
|
* })
|
|
899
933
|
* ```
|
|
900
934
|
*/
|
|
901
|
-
async getContractState
|
|
902
|
-
contract:
|
|
903
|
-
): Promise<{ contract: Contract
|
|
904
|
-
const result = await call(this, 'channels.get.contract', { pubkey: contract })
|
|
905
|
-
return
|
|
935
|
+
async getContractState(
|
|
936
|
+
contract: Encoded.ContractAddress,
|
|
937
|
+
): Promise<{ contract: Contract; contractState: object }> {
|
|
938
|
+
const result = await call(this, 'channels.get.contract', { pubkey: contract });
|
|
939
|
+
return snakeToPascalObjKeys({
|
|
906
940
|
...result,
|
|
907
|
-
contract: snakeToPascalObjKeys(result.contract)
|
|
908
|
-
})
|
|
941
|
+
contract: snakeToPascalObjKeys(result.contract),
|
|
942
|
+
});
|
|
909
943
|
}
|
|
910
944
|
|
|
911
945
|
/**
|
|
@@ -916,8 +950,8 @@ export default class Channel {
|
|
|
916
950
|
* This cleans up all locally stored contract calls and those will no longer be available for
|
|
917
951
|
* fetching and inspection.
|
|
918
952
|
*/
|
|
919
|
-
async cleanContractCalls
|
|
920
|
-
return
|
|
953
|
+
async cleanContractCalls(): Promise<void> {
|
|
954
|
+
return new Promise((resolve, reject) => {
|
|
921
955
|
enqueueAction(
|
|
922
956
|
this,
|
|
923
957
|
(_channel, state) => state?.handler === handlers.channelOpen,
|
|
@@ -925,15 +959,15 @@ export default class Channel {
|
|
|
925
959
|
send(channel, {
|
|
926
960
|
jsonrpc: '2.0',
|
|
927
961
|
method: 'channels.clean_contract_calls',
|
|
928
|
-
params: {}
|
|
929
|
-
})
|
|
962
|
+
params: {},
|
|
963
|
+
});
|
|
930
964
|
return {
|
|
931
965
|
handler: handlers.awaitingCallsPruned,
|
|
932
|
-
state: { resolve, reject }
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
)
|
|
936
|
-
})
|
|
966
|
+
state: { resolve, reject },
|
|
967
|
+
};
|
|
968
|
+
},
|
|
969
|
+
);
|
|
970
|
+
});
|
|
937
971
|
}
|
|
938
972
|
|
|
939
973
|
/**
|
|
@@ -955,37 +989,37 @@ export default class Channel {
|
|
|
955
989
|
* )
|
|
956
990
|
* ```
|
|
957
991
|
*/
|
|
958
|
-
sendMessage
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
992
|
+
async sendMessage(
|
|
993
|
+
message: string | object,
|
|
994
|
+
recipient: Encoded.AccountAddress,
|
|
995
|
+
): Promise<void> {
|
|
996
|
+
const info = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
997
|
+
if (this.status() === 'connecting') {
|
|
998
|
+
await new Promise<void>((resolve) => {
|
|
999
|
+
const onStatusChanged = (status: string): void => {
|
|
1000
|
+
if (status === 'connecting') return;
|
|
1001
|
+
resolve();
|
|
1002
|
+
this.off('statusChanged', onStatusChanged);
|
|
1003
|
+
};
|
|
1004
|
+
this.on('statusChanged', onStatusChanged);
|
|
1005
|
+
});
|
|
1006
|
+
// For some reason we can't immediately send a message when connection is
|
|
1007
|
+
// established. Thus we wait 500ms which seems to work.
|
|
1008
|
+
await pause(500);
|
|
962
1009
|
}
|
|
963
|
-
|
|
1010
|
+
send(this, {
|
|
964
1011
|
jsonrpc: '2.0',
|
|
965
1012
|
method: 'channels.message',
|
|
966
|
-
params: { info, to: recipient }
|
|
967
|
-
})
|
|
968
|
-
if (this.status() === 'connecting') {
|
|
969
|
-
const onStatusChanged = (status: string): void => {
|
|
970
|
-
if (status !== 'connecting') {
|
|
971
|
-
// For some reason we can't immediately send a message when connection is
|
|
972
|
-
// established. Thus we wait 500ms which seems to work.
|
|
973
|
-
setTimeout(() => doSend(this), 500)
|
|
974
|
-
this.off('statusChanged', onStatusChanged)
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
this.on('statusChanged', onStatusChanged)
|
|
978
|
-
} else {
|
|
979
|
-
doSend(this)
|
|
980
|
-
}
|
|
1013
|
+
params: { info, to: recipient },
|
|
1014
|
+
});
|
|
981
1015
|
}
|
|
982
1016
|
|
|
983
|
-
static async reconnect
|
|
984
|
-
const { sign } = options
|
|
1017
|
+
static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {
|
|
1018
|
+
const { sign } = options;
|
|
985
1019
|
|
|
986
|
-
return
|
|
1020
|
+
return Channel.initialize({
|
|
987
1021
|
...options,
|
|
988
|
-
reconnectTx: await sign('reconnect', buildTx(txParams,
|
|
989
|
-
})
|
|
1022
|
+
reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),
|
|
1023
|
+
});
|
|
990
1024
|
}
|
|
991
1025
|
}
|