xrpl 2.9.1 → 2.11.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/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +2680 -481
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/client/index.d.ts +2 -1
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/index.d.ts +1 -0
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +3 -1
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +5 -0
- package/dist/npm/models/common/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/models/ledger/AMM.js +3 -0
- package/dist/npm/models/ledger/AMM.js.map +1 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts +5 -1
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +2 -0
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts +2 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/methods/accountInfo.d.ts +1 -0
- package/dist/npm/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/models/methods/ammInfo.js +3 -0
- package/dist/npm/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/models/methods/index.d.ts +4 -3
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +10 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMBid.js +56 -0
- package/dist/npm/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMVote.js +32 -0
- package/dist/npm/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/models/transactions/accountSet.d.ts +2 -1
- package/dist/npm/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountSet.js +1 -0
- package/dist/npm/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/models/transactions/clawback.d.ts +9 -0
- package/dist/npm/models/transactions/clawback.d.ts.map +1 -0
- package/dist/npm/models/transactions/clawback.js +19 -0
- package/dist/npm/models/transactions/clawback.js.map +1 -0
- package/dist/npm/models/transactions/common.d.ts +2 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +12 -1
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +7 -0
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +5 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +28 -0
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +17 -23
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/models/utils/index.js +1 -1
- package/dist/npm/models/utils/index.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/src/client/index.d.ts +2 -1
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -0
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +3 -1
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +5 -0
- package/dist/npm/src/models/common/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/AMM.js +3 -0
- package/dist/npm/src/models/ledger/AMM.js.map +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts +5 -1
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +2 -0
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts +2 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/methods/accountInfo.d.ts +1 -0
- package/dist/npm/src/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/src/models/methods/ammInfo.js +3 -0
- package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/src/models/methods/index.d.ts +4 -3
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +10 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMBid.js +56 -0
- package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.js +32 -0
- package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/src/models/transactions/accountSet.d.ts +2 -1
- package/dist/npm/src/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.js +1 -0
- package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/src/models/transactions/clawback.d.ts +9 -0
- package/dist/npm/src/models/transactions/clawback.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/clawback.js +19 -0
- package/dist/npm/src/models/transactions/clawback.js.map +1 -0
- package/dist/npm/src/models/transactions/common.d.ts +2 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +12 -1
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +7 -0
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +5 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +28 -0
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +17 -23
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/models/utils/index.js +1 -1
- package/dist/npm/src/models/utils/index.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +4 -3
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +4 -3
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/package.json +8 -6
- package/src/ECDSA.ts +6 -0
- package/src/Wallet/defaultFaucets.ts +82 -0
- package/src/Wallet/fundWallet.ts +344 -0
- package/src/Wallet/index.ts +504 -0
- package/src/Wallet/rfc1751.ts +190 -0
- package/src/Wallet/rfc1751Words.json +243 -0
- package/src/Wallet/signer.ts +173 -0
- package/src/Wallet/walletFromSecretNumbers.ts +37 -0
- package/src/client/BroadcastClient.ts +84 -0
- package/src/client/ConnectionManager.ts +40 -0
- package/src/client/ExponentialBackoff.ts +71 -0
- package/src/client/RequestManager.ts +194 -0
- package/src/client/WSWrapper.ts +106 -0
- package/src/client/connection.ts +593 -0
- package/src/client/index.ts +712 -0
- package/src/client/partialPayment.ts +153 -0
- package/src/errors.ts +161 -0
- package/src/index.ts +20 -0
- package/src/models/common/index.ts +149 -0
- package/src/models/index.ts +16 -0
- package/src/models/ledger/AMM.ts +78 -0
- package/src/models/ledger/AccountRoot.ts +217 -0
- package/src/models/ledger/Amendments.ts +45 -0
- package/src/models/ledger/BaseLedgerEntry.ts +3 -0
- package/src/models/ledger/Check.ts +70 -0
- package/src/models/ledger/DepositPreauth.ts +35 -0
- package/src/models/ledger/DirectoryNode.ts +46 -0
- package/src/models/ledger/Escrow.ts +74 -0
- package/src/models/ledger/FeeSettings.ts +52 -0
- package/src/models/ledger/Ledger.ts +65 -0
- package/src/models/ledger/LedgerEntry.ts +34 -0
- package/src/models/ledger/LedgerHashes.ts +24 -0
- package/src/models/ledger/NFTokenOffer.ts +16 -0
- package/src/models/ledger/NFTokenPage.ts +20 -0
- package/src/models/ledger/NegativeUNL.ts +34 -0
- package/src/models/ledger/Offer.ts +52 -0
- package/src/models/ledger/PayChannel.ts +107 -0
- package/src/models/ledger/RippleState.ts +88 -0
- package/src/models/ledger/SignerList.ts +56 -0
- package/src/models/ledger/Ticket.ts +36 -0
- package/src/models/ledger/index.ts +58 -0
- package/src/models/methods/accountChannels.ts +93 -0
- package/src/models/methods/accountCurrencies.ts +45 -0
- package/src/models/methods/accountInfo.ts +182 -0
- package/src/models/methods/accountLines.ts +137 -0
- package/src/models/methods/accountNFTs.ts +72 -0
- package/src/models/methods/accountObjects.ts +120 -0
- package/src/models/methods/accountOffers.ts +100 -0
- package/src/models/methods/accountTx.ts +109 -0
- package/src/models/methods/ammInfo.ts +145 -0
- package/src/models/methods/baseMethod.ts +58 -0
- package/src/models/methods/bookOffers.ts +96 -0
- package/src/models/methods/channelVerify.ts +41 -0
- package/src/models/methods/depositAuthorized.ts +56 -0
- package/src/models/methods/fee.ts +91 -0
- package/src/models/methods/gatewayBalances.ts +85 -0
- package/src/models/methods/index.ts +391 -0
- package/src/models/methods/ledger.ts +125 -0
- package/src/models/methods/ledgerClosed.ts +32 -0
- package/src/models/methods/ledgerCurrent.ts +31 -0
- package/src/models/methods/ledgerData.ts +78 -0
- package/src/models/methods/ledgerEntry.ts +177 -0
- package/src/models/methods/manifest.ts +54 -0
- package/src/models/methods/nftBuyOffers.ts +37 -0
- package/src/models/methods/nftHistory.ts +113 -0
- package/src/models/methods/nftInfo.ts +25 -0
- package/src/models/methods/nftSellOffers.ts +37 -0
- package/src/models/methods/norippleCheck.ts +82 -0
- package/src/models/methods/pathFind.ts +116 -0
- package/src/models/methods/ping.ts +21 -0
- package/src/models/methods/random.ts +23 -0
- package/src/models/methods/ripplePathFind.ts +81 -0
- package/src/models/methods/serverInfo.ts +257 -0
- package/src/models/methods/serverState.ts +77 -0
- package/src/models/methods/submit.ts +94 -0
- package/src/models/methods/submitMultisigned.ts +51 -0
- package/src/models/methods/subscribe.ts +435 -0
- package/src/models/methods/transactionEntry.ts +47 -0
- package/src/models/methods/tx.ts +69 -0
- package/src/models/methods/unsubscribe.ts +49 -0
- package/src/models/transactions/AMMBid.ts +140 -0
- package/src/models/transactions/AMMCreate.ts +80 -0
- package/src/models/transactions/AMMDelete.ts +55 -0
- package/src/models/transactions/AMMDeposit.ts +130 -0
- package/src/models/transactions/AMMVote.ts +71 -0
- package/src/models/transactions/AMMWithdraw.ts +126 -0
- package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
- package/src/models/transactions/NFTokenBurn.ts +48 -0
- package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
- package/src/models/transactions/NFTokenMint.ts +123 -0
- package/src/models/transactions/UNLModify.ts +20 -0
- package/src/models/transactions/accountDelete.ts +50 -0
- package/src/models/transactions/accountSet.ts +228 -0
- package/src/models/transactions/checkCancel.ts +34 -0
- package/src/models/transactions/checkCash.ts +73 -0
- package/src/models/transactions/checkCreate.ts +90 -0
- package/src/models/transactions/clawback.ts +49 -0
- package/src/models/transactions/common.ts +295 -0
- package/src/models/transactions/depositPreauth.ts +68 -0
- package/src/models/transactions/enableAmendment.ts +26 -0
- package/src/models/transactions/escrowCancel.ts +45 -0
- package/src/models/transactions/escrowCreate.ts +100 -0
- package/src/models/transactions/escrowFinish.ts +63 -0
- package/src/models/transactions/index.ts +66 -0
- package/src/models/transactions/metadata.ts +69 -0
- package/src/models/transactions/offerCancel.ts +37 -0
- package/src/models/transactions/offerCreate.ts +144 -0
- package/src/models/transactions/payment.ts +278 -0
- package/src/models/transactions/paymentChannelClaim.ts +165 -0
- package/src/models/transactions/paymentChannelCreate.ts +116 -0
- package/src/models/transactions/paymentChannelFund.ts +65 -0
- package/src/models/transactions/setFee.ts +48 -0
- package/src/models/transactions/setRegularKey.ts +33 -0
- package/src/models/transactions/signerListSet.ts +89 -0
- package/src/models/transactions/ticketCreate.ts +50 -0
- package/src/models/transactions/transaction.ts +303 -0
- package/src/models/transactions/trustSet.ts +146 -0
- package/src/models/utils/flags.ts +98 -0
- package/src/models/utils/index.ts +37 -0
- package/src/sugar/autofill.ts +373 -0
- package/src/sugar/balances.ts +123 -0
- package/src/sugar/getFeeXrp.ts +45 -0
- package/src/sugar/getLedgerIndex.ts +15 -0
- package/src/sugar/getOrderbook.ts +152 -0
- package/src/sugar/index.ts +11 -0
- package/src/sugar/submit.ts +305 -0
- package/src/sugar/utils.ts +29 -0
- package/src/utils/derive.ts +23 -0
- package/src/utils/getBalanceChanges.ts +186 -0
- package/src/utils/getNFTokenID.ts +97 -0
- package/src/utils/hashes/HashPrefix.ts +40 -0
- package/src/utils/hashes/README.md +65 -0
- package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
- package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
- package/src/utils/hashes/SHAMap/index.ts +41 -0
- package/src/utils/hashes/SHAMap/node.ts +14 -0
- package/src/utils/hashes/hashLedger.ts +236 -0
- package/src/utils/hashes/index.ts +187 -0
- package/src/utils/hashes/ledgerSpaces.ts +34 -0
- package/src/utils/hashes/sha512Half.ts +19 -0
- package/src/utils/index.ts +223 -0
- package/src/utils/parseNFTokenID.ts +84 -0
- package/src/utils/quality.ts +169 -0
- package/src/utils/signPaymentChannelClaim.ts +27 -0
- package/src/utils/stringConversion.ts +27 -0
- package/src/utils/timeConversion.ts +53 -0
- package/src/utils/verifyPaymentChannelClaim.ts +30 -0
- package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,593 @@
|
|
1
|
+
/* eslint-disable max-lines -- Connection is a large file w/ lots of imports/exports */
|
2
|
+
import { EventEmitter } from 'events'
|
3
|
+
import { Agent } from 'http'
|
4
|
+
|
5
|
+
import omitBy from 'lodash/omitBy'
|
6
|
+
import WebSocket from 'ws'
|
7
|
+
|
8
|
+
import {
|
9
|
+
DisconnectedError,
|
10
|
+
NotConnectedError,
|
11
|
+
ConnectionError,
|
12
|
+
XrplError,
|
13
|
+
} from '../errors'
|
14
|
+
import { BaseRequest } from '../models/methods/baseMethod'
|
15
|
+
|
16
|
+
import ConnectionManager from './ConnectionManager'
|
17
|
+
import ExponentialBackoff from './ExponentialBackoff'
|
18
|
+
import RequestManager from './RequestManager'
|
19
|
+
|
20
|
+
const SECONDS_PER_MINUTE = 60
|
21
|
+
const TIMEOUT = 20
|
22
|
+
const CONNECTION_TIMEOUT = 5
|
23
|
+
|
24
|
+
/**
|
25
|
+
* ConnectionOptions is the configuration for the Connection class.
|
26
|
+
*/
|
27
|
+
interface ConnectionOptions {
|
28
|
+
trace?: boolean | ((id: string, message: string) => void)
|
29
|
+
proxy?: string
|
30
|
+
proxyAuthorization?: string
|
31
|
+
authorization?: string
|
32
|
+
trustedCertificates?: string[]
|
33
|
+
key?: string
|
34
|
+
passphrase?: string
|
35
|
+
certificate?: string
|
36
|
+
// request timeout
|
37
|
+
timeout: number
|
38
|
+
connectionTimeout: number
|
39
|
+
headers?: { [key: string]: string }
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* ConnectionUserOptions is the user-provided configuration object. All configuration
|
44
|
+
* is optional, so any ConnectionOptions configuration that has a default value is
|
45
|
+
* still optional at the point that the user provides it.
|
46
|
+
*/
|
47
|
+
export type ConnectionUserOptions = Partial<ConnectionOptions>
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Represents an intentionally triggered web-socket disconnect code.
|
51
|
+
* WebSocket spec allows 4xxx codes for app/library specific codes.
|
52
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
53
|
+
*/
|
54
|
+
export const INTENTIONAL_DISCONNECT_CODE = 4000
|
55
|
+
|
56
|
+
type WebsocketState = 0 | 1 | 2 | 3
|
57
|
+
|
58
|
+
function getAgent(url: string, config: ConnectionOptions): Agent | undefined {
|
59
|
+
if (config.proxy == null) {
|
60
|
+
return undefined
|
61
|
+
}
|
62
|
+
|
63
|
+
const parsedURL = new URL(url)
|
64
|
+
const parsedProxyURL = new URL(config.proxy)
|
65
|
+
|
66
|
+
const proxyOptions = omitBy(
|
67
|
+
{
|
68
|
+
secureEndpoint: parsedURL.protocol === 'wss:',
|
69
|
+
secureProxy: parsedProxyURL.protocol === 'https:',
|
70
|
+
auth: config.proxyAuthorization,
|
71
|
+
ca: config.trustedCertificates,
|
72
|
+
key: config.key,
|
73
|
+
passphrase: config.passphrase,
|
74
|
+
cert: config.certificate,
|
75
|
+
href: parsedProxyURL.href,
|
76
|
+
origin: parsedProxyURL.origin,
|
77
|
+
protocol: parsedProxyURL.protocol,
|
78
|
+
username: parsedProxyURL.username,
|
79
|
+
password: parsedProxyURL.password,
|
80
|
+
host: parsedProxyURL.host,
|
81
|
+
hostname: parsedProxyURL.hostname,
|
82
|
+
port: parsedProxyURL.port,
|
83
|
+
pathname: parsedProxyURL.pathname,
|
84
|
+
search: parsedProxyURL.search,
|
85
|
+
hash: parsedProxyURL.hash,
|
86
|
+
},
|
87
|
+
(value) => value == null,
|
88
|
+
)
|
89
|
+
|
90
|
+
let HttpsProxyAgent: new (opt: typeof proxyOptions) => Agent
|
91
|
+
try {
|
92
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports,
|
93
|
+
node/global-require, global-require, -- Necessary for the `require` */
|
94
|
+
HttpsProxyAgent = require('https-proxy-agent')
|
95
|
+
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports,
|
96
|
+
node/global-require, global-require, */
|
97
|
+
} catch (_error) {
|
98
|
+
throw new Error('"proxy" option is not supported in the browser')
|
99
|
+
}
|
100
|
+
|
101
|
+
return new HttpsProxyAgent(proxyOptions)
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Create a new websocket given your URL and optional proxy/certificate
|
106
|
+
* configuration.
|
107
|
+
*
|
108
|
+
* @param url - The URL to connect to.
|
109
|
+
* @param config - THe configuration options for the WebSocket.
|
110
|
+
* @returns A Websocket that fits the given configuration parameters.
|
111
|
+
*/
|
112
|
+
function createWebSocket(
|
113
|
+
url: string,
|
114
|
+
config: ConnectionOptions,
|
115
|
+
): WebSocket | null {
|
116
|
+
const options: WebSocket.ClientOptions = {}
|
117
|
+
options.agent = getAgent(url, config)
|
118
|
+
if (config.headers) {
|
119
|
+
options.headers = config.headers
|
120
|
+
}
|
121
|
+
if (config.authorization != null) {
|
122
|
+
const base64 = Buffer.from(config.authorization).toString('base64')
|
123
|
+
options.headers = {
|
124
|
+
...options.headers,
|
125
|
+
Authorization: `Basic ${base64}`,
|
126
|
+
}
|
127
|
+
}
|
128
|
+
const optionsOverrides = omitBy(
|
129
|
+
{
|
130
|
+
ca: config.trustedCertificates,
|
131
|
+
key: config.key,
|
132
|
+
passphrase: config.passphrase,
|
133
|
+
cert: config.certificate,
|
134
|
+
},
|
135
|
+
(value) => value == null,
|
136
|
+
)
|
137
|
+
const websocketOptions = { ...options, ...optionsOverrides }
|
138
|
+
const websocket = new WebSocket(url, websocketOptions)
|
139
|
+
/*
|
140
|
+
* we will have a listener for each outstanding request,
|
141
|
+
* so we have to raise the limit (the default is 10)
|
142
|
+
*/
|
143
|
+
if (typeof websocket.setMaxListeners === 'function') {
|
144
|
+
websocket.setMaxListeners(Infinity)
|
145
|
+
}
|
146
|
+
return websocket
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Ws.send(), but promisified.
|
151
|
+
*
|
152
|
+
* @param ws - Websocket to send with.
|
153
|
+
* @param message - Message to send.
|
154
|
+
* @returns When the message has been sent.
|
155
|
+
*/
|
156
|
+
async function websocketSendAsync(
|
157
|
+
ws: WebSocket,
|
158
|
+
message: string,
|
159
|
+
): Promise<void> {
|
160
|
+
return new Promise<void>((resolve, reject) => {
|
161
|
+
ws.send(message, (error) => {
|
162
|
+
if (error) {
|
163
|
+
reject(new DisconnectedError(error.message, error))
|
164
|
+
} else {
|
165
|
+
resolve()
|
166
|
+
}
|
167
|
+
})
|
168
|
+
})
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* The main Connection class. Responsible for connecting to & managing
|
173
|
+
* an active WebSocket connection to a XRPL node.
|
174
|
+
*/
|
175
|
+
export class Connection extends EventEmitter {
|
176
|
+
private readonly url: string | undefined
|
177
|
+
private ws: WebSocket | null = null
|
178
|
+
// Typing necessary for Jest tests running in browser
|
179
|
+
private reconnectTimeoutID: null | ReturnType<typeof setTimeout> = null
|
180
|
+
// Typing necessary for Jest tetsts running in browser
|
181
|
+
private heartbeatIntervalID: null | ReturnType<typeof setTimeout> = null
|
182
|
+
private readonly retryConnectionBackoff = new ExponentialBackoff({
|
183
|
+
min: 100,
|
184
|
+
max: SECONDS_PER_MINUTE * 1000,
|
185
|
+
})
|
186
|
+
|
187
|
+
private readonly config: ConnectionOptions
|
188
|
+
private readonly requestManager = new RequestManager()
|
189
|
+
private readonly connectionManager = new ConnectionManager()
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Creates a new Connection object.
|
193
|
+
*
|
194
|
+
* @param url - URL to connect to.
|
195
|
+
* @param options - Options for the Connection object.
|
196
|
+
*/
|
197
|
+
public constructor(url?: string, options: ConnectionUserOptions = {}) {
|
198
|
+
super()
|
199
|
+
this.setMaxListeners(Infinity)
|
200
|
+
this.url = url
|
201
|
+
this.config = {
|
202
|
+
timeout: TIMEOUT * 1000,
|
203
|
+
connectionTimeout: CONNECTION_TIMEOUT * 1000,
|
204
|
+
...options,
|
205
|
+
}
|
206
|
+
if (typeof options.trace === 'function') {
|
207
|
+
this.trace = options.trace
|
208
|
+
} else if (options.trace) {
|
209
|
+
// eslint-disable-next-line no-console -- Used for tracing only
|
210
|
+
this.trace = console.log
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Gets the state of the websocket.
|
216
|
+
*
|
217
|
+
* @returns The Websocket's ready state.
|
218
|
+
*/
|
219
|
+
private get state(): WebsocketState {
|
220
|
+
return this.ws ? this.ws.readyState : WebSocket.CLOSED
|
221
|
+
}
|
222
|
+
|
223
|
+
/**
|
224
|
+
* Returns whether the server should be connected.
|
225
|
+
*
|
226
|
+
* @returns Whether the server should be connected.
|
227
|
+
*/
|
228
|
+
private get shouldBeConnected(): boolean {
|
229
|
+
return this.ws !== null
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Returns whether the websocket is connected.
|
234
|
+
*
|
235
|
+
* @returns Whether the websocket connection is open.
|
236
|
+
*/
|
237
|
+
public isConnected(): boolean {
|
238
|
+
return this.state === WebSocket.OPEN
|
239
|
+
}
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Connects the websocket to the provided URL.
|
243
|
+
*
|
244
|
+
* @returns When the websocket is connected.
|
245
|
+
* @throws ConnectionError if there is a connection error, RippleError if there is already a WebSocket in existence.
|
246
|
+
*/
|
247
|
+
// eslint-disable-next-line max-lines-per-function -- Necessary
|
248
|
+
public async connect(): Promise<void> {
|
249
|
+
if (this.isConnected()) {
|
250
|
+
return Promise.resolve()
|
251
|
+
}
|
252
|
+
if (this.state === WebSocket.CONNECTING) {
|
253
|
+
return this.connectionManager.awaitConnection()
|
254
|
+
}
|
255
|
+
if (!this.url) {
|
256
|
+
return Promise.reject(
|
257
|
+
new ConnectionError('Cannot connect because no server was specified'),
|
258
|
+
)
|
259
|
+
}
|
260
|
+
if (this.ws != null) {
|
261
|
+
return Promise.reject(
|
262
|
+
new XrplError('Websocket connection never cleaned up.', {
|
263
|
+
state: this.state,
|
264
|
+
}),
|
265
|
+
)
|
266
|
+
}
|
267
|
+
|
268
|
+
// Create the connection timeout, in case the connection hangs longer than expected.
|
269
|
+
const connectionTimeoutID: ReturnType<typeof setTimeout> = setTimeout(
|
270
|
+
() => {
|
271
|
+
this.onConnectionFailed(
|
272
|
+
new ConnectionError(
|
273
|
+
`Error: connect() timed out after ${this.config.connectionTimeout} ms. If your internet connection is working, the ` +
|
274
|
+
`rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.`,
|
275
|
+
),
|
276
|
+
)
|
277
|
+
},
|
278
|
+
this.config.connectionTimeout,
|
279
|
+
)
|
280
|
+
// Connection listeners: these stay attached only until a connection is done/open.
|
281
|
+
this.ws = createWebSocket(this.url, this.config)
|
282
|
+
|
283
|
+
if (this.ws == null) {
|
284
|
+
throw new XrplError('Connect: created null websocket')
|
285
|
+
}
|
286
|
+
|
287
|
+
this.ws.on('error', (error) => this.onConnectionFailed(error))
|
288
|
+
this.ws.on('error', () => clearTimeout(connectionTimeoutID))
|
289
|
+
this.ws.on('close', (reason) => this.onConnectionFailed(reason))
|
290
|
+
this.ws.on('close', () => clearTimeout(connectionTimeoutID))
|
291
|
+
this.ws.once('open', () => {
|
292
|
+
void this.onceOpen(connectionTimeoutID)
|
293
|
+
})
|
294
|
+
return this.connectionManager.awaitConnection()
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Disconnect the websocket connection.
|
299
|
+
* We never expect this method to reject. Even on "bad" disconnects, the websocket
|
300
|
+
* should still successfully close with the relevant error code returned.
|
301
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent for the full list.
|
302
|
+
* If no open websocket connection exists, resolve with no code (`undefined`).
|
303
|
+
*
|
304
|
+
* @returns A promise containing either `undefined` or a disconnected code, that resolves when the connection is destroyed.
|
305
|
+
*/
|
306
|
+
public async disconnect(): Promise<number | undefined> {
|
307
|
+
this.clearHeartbeatInterval()
|
308
|
+
if (this.reconnectTimeoutID !== null) {
|
309
|
+
clearTimeout(this.reconnectTimeoutID)
|
310
|
+
this.reconnectTimeoutID = null
|
311
|
+
}
|
312
|
+
if (this.state === WebSocket.CLOSED) {
|
313
|
+
return Promise.resolve(undefined)
|
314
|
+
}
|
315
|
+
if (this.ws == null) {
|
316
|
+
return Promise.resolve(undefined)
|
317
|
+
}
|
318
|
+
|
319
|
+
return new Promise((resolve) => {
|
320
|
+
if (this.ws == null) {
|
321
|
+
resolve(undefined)
|
322
|
+
}
|
323
|
+
if (this.ws != null) {
|
324
|
+
this.ws.once('close', (code) => resolve(code))
|
325
|
+
}
|
326
|
+
/*
|
327
|
+
* Connection already has a disconnect handler for the disconnect logic.
|
328
|
+
* Just close the websocket manually (with our "intentional" code) to
|
329
|
+
* trigger that.
|
330
|
+
*/
|
331
|
+
if (this.ws != null && this.state !== WebSocket.CLOSING) {
|
332
|
+
this.ws.close(INTENTIONAL_DISCONNECT_CODE)
|
333
|
+
}
|
334
|
+
})
|
335
|
+
}
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Disconnect the websocket, then connect again.
|
339
|
+
*/
|
340
|
+
public async reconnect(): Promise<void> {
|
341
|
+
/*
|
342
|
+
* NOTE: We currently have a "reconnecting" event, but that only triggers
|
343
|
+
* through an unexpected connection retry logic.
|
344
|
+
* See: https://github.com/XRPLF/xrpl.js/pull/1101#issuecomment-565360423
|
345
|
+
*/
|
346
|
+
this.emit('reconnect')
|
347
|
+
await this.disconnect()
|
348
|
+
await this.connect()
|
349
|
+
}
|
350
|
+
|
351
|
+
/**
|
352
|
+
* Sends a request to the rippled server.
|
353
|
+
*
|
354
|
+
* @param request - The request to send to the server.
|
355
|
+
* @param timeout - How long the Connection instance should wait before assuming that there will not be a response.
|
356
|
+
* @returns The response from the rippled server.
|
357
|
+
* @throws NotConnectedError if the Connection isn't connected to a server.
|
358
|
+
*/
|
359
|
+
public async request<T extends BaseRequest>(
|
360
|
+
request: T,
|
361
|
+
timeout?: number,
|
362
|
+
): Promise<unknown> {
|
363
|
+
if (!this.shouldBeConnected || this.ws == null) {
|
364
|
+
throw new NotConnectedError(JSON.stringify(request), request)
|
365
|
+
}
|
366
|
+
const [id, message, responsePromise] = this.requestManager.createRequest(
|
367
|
+
request,
|
368
|
+
timeout ?? this.config.timeout,
|
369
|
+
)
|
370
|
+
this.trace('send', message)
|
371
|
+
websocketSendAsync(this.ws, message).catch((error) => {
|
372
|
+
this.requestManager.reject(id, error)
|
373
|
+
})
|
374
|
+
|
375
|
+
return responsePromise
|
376
|
+
}
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Get the Websocket connection URL.
|
380
|
+
*
|
381
|
+
* @returns The Websocket connection URL.
|
382
|
+
*/
|
383
|
+
public getUrl(): string {
|
384
|
+
return this.url ?? ''
|
385
|
+
}
|
386
|
+
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, class-methods-use-this -- Does nothing on default
|
388
|
+
public readonly trace: (id: string, message: string) => void = () => {}
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Handler for when messages are received from the server.
|
392
|
+
*
|
393
|
+
* @param message - The message received from the server.
|
394
|
+
*/
|
395
|
+
private onMessage(message): void {
|
396
|
+
this.trace('receive', message)
|
397
|
+
let data: Record<string, unknown>
|
398
|
+
try {
|
399
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Must be a JSON dictionary
|
400
|
+
data = JSON.parse(message)
|
401
|
+
} catch (error) {
|
402
|
+
if (error instanceof Error) {
|
403
|
+
this.emit('error', 'badMessage', error.message, message)
|
404
|
+
}
|
405
|
+
return
|
406
|
+
}
|
407
|
+
if (data.type == null && data.error) {
|
408
|
+
// e.g. slowDown
|
409
|
+
this.emit('error', data.error, data.error_message, data)
|
410
|
+
return
|
411
|
+
}
|
412
|
+
if (data.type) {
|
413
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
|
414
|
+
this.emit(data.type as string, data)
|
415
|
+
}
|
416
|
+
if (data.type === 'response') {
|
417
|
+
try {
|
418
|
+
this.requestManager.handleResponse(data)
|
419
|
+
} catch (error) {
|
420
|
+
// eslint-disable-next-line max-depth -- okay here
|
421
|
+
if (error instanceof Error) {
|
422
|
+
this.emit('error', 'badMessage', error.message, message)
|
423
|
+
} else {
|
424
|
+
this.emit('error', 'badMessage', error, error)
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
/**
|
431
|
+
* Handler for what to do once the connection to the server is open.
|
432
|
+
*
|
433
|
+
* @param connectionTimeoutID - Timeout in case the connection hangs longer than expected.
|
434
|
+
* @returns A promise that resolves to void when the connection is fully established.
|
435
|
+
* @throws Error if the websocket initialized is somehow null.
|
436
|
+
*/
|
437
|
+
// eslint-disable-next-line max-lines-per-function -- Many error code conditionals to check.
|
438
|
+
private async onceOpen(
|
439
|
+
connectionTimeoutID: ReturnType<typeof setTimeout>,
|
440
|
+
): Promise<void> {
|
441
|
+
if (this.ws == null) {
|
442
|
+
throw new XrplError('onceOpen: ws is null')
|
443
|
+
}
|
444
|
+
|
445
|
+
// Once the connection completes successfully, remove all old listeners
|
446
|
+
this.ws.removeAllListeners()
|
447
|
+
clearTimeout(connectionTimeoutID)
|
448
|
+
// Add new, long-term connected listeners for messages and errors
|
449
|
+
this.ws.on('message', (message: string) => this.onMessage(message))
|
450
|
+
this.ws.on('error', (error) =>
|
451
|
+
this.emit('error', 'websocket', error.message, error),
|
452
|
+
)
|
453
|
+
// Handle a closed connection: reconnect if it was unexpected
|
454
|
+
this.ws.once('close', (code?: number, reason?: Buffer) => {
|
455
|
+
if (this.ws == null) {
|
456
|
+
throw new XrplError('onceClose: ws is null')
|
457
|
+
}
|
458
|
+
|
459
|
+
this.clearHeartbeatInterval()
|
460
|
+
this.requestManager.rejectAll(
|
461
|
+
new DisconnectedError(
|
462
|
+
`websocket was closed, ${new TextDecoder('utf-8').decode(reason)}`,
|
463
|
+
),
|
464
|
+
)
|
465
|
+
this.ws.removeAllListeners()
|
466
|
+
this.ws = null
|
467
|
+
|
468
|
+
if (code === undefined) {
|
469
|
+
// Useful to keep this code for debugging purposes.
|
470
|
+
// const reasonText = reason ? reason.toString() : 'undefined'
|
471
|
+
// // eslint-disable-next-line no-console -- The error is helpful for debugging.
|
472
|
+
// console.error(
|
473
|
+
// `Disconnected but the disconnect code was undefined (The given reason was ${reasonText}).` +
|
474
|
+
// `This could be caused by an exception being thrown during a 'connect' callback. ` +
|
475
|
+
// `Disconnecting with code 1011 to indicate an internal error has occurred.`,
|
476
|
+
// )
|
477
|
+
|
478
|
+
/*
|
479
|
+
* Error code 1011 represents an Internal Error according to
|
480
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
481
|
+
*/
|
482
|
+
const internalErrorCode = 1011
|
483
|
+
this.emit('disconnected', internalErrorCode)
|
484
|
+
} else {
|
485
|
+
this.emit('disconnected', code)
|
486
|
+
}
|
487
|
+
|
488
|
+
/*
|
489
|
+
* If this wasn't a manual disconnect, then lets reconnect ASAP.
|
490
|
+
* Code can be undefined if there's an exception while connecting.
|
491
|
+
*/
|
492
|
+
if (code !== INTENTIONAL_DISCONNECT_CODE && code !== undefined) {
|
493
|
+
this.intentionalDisconnect()
|
494
|
+
}
|
495
|
+
})
|
496
|
+
// Finalize the connection and resolve all awaiting connect() requests
|
497
|
+
try {
|
498
|
+
this.retryConnectionBackoff.reset()
|
499
|
+
this.startHeartbeatInterval()
|
500
|
+
this.connectionManager.resolveAllAwaiting()
|
501
|
+
this.emit('connected')
|
502
|
+
} catch (error) {
|
503
|
+
if (error instanceof Error) {
|
504
|
+
this.connectionManager.rejectAllAwaiting(error)
|
505
|
+
// Ignore this error, propagate the root cause.
|
506
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function -- Need empty catch
|
507
|
+
await this.disconnect().catch(() => {})
|
508
|
+
}
|
509
|
+
}
|
510
|
+
}
|
511
|
+
|
512
|
+
private intentionalDisconnect(): void {
|
513
|
+
const retryTimeout = this.retryConnectionBackoff.duration()
|
514
|
+
this.trace('reconnect', `Retrying connection in ${retryTimeout}ms.`)
|
515
|
+
this.emit('reconnecting', this.retryConnectionBackoff.attempts)
|
516
|
+
/*
|
517
|
+
* Start the reconnect timeout, but set it to `this.reconnectTimeoutID`
|
518
|
+
* so that we can cancel one in-progress on disconnect.
|
519
|
+
*/
|
520
|
+
this.reconnectTimeoutID = setTimeout(() => {
|
521
|
+
this.reconnect().catch((error: Error) => {
|
522
|
+
this.emit('error', 'reconnect', error.message, error)
|
523
|
+
})
|
524
|
+
}, retryTimeout)
|
525
|
+
}
|
526
|
+
|
527
|
+
/**
|
528
|
+
* Clears the heartbeat connection interval.
|
529
|
+
*/
|
530
|
+
private clearHeartbeatInterval(): void {
|
531
|
+
if (this.heartbeatIntervalID) {
|
532
|
+
clearInterval(this.heartbeatIntervalID)
|
533
|
+
}
|
534
|
+
}
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Starts a heartbeat to check the connection with the server.
|
538
|
+
*/
|
539
|
+
private startHeartbeatInterval(): void {
|
540
|
+
this.clearHeartbeatInterval()
|
541
|
+
this.heartbeatIntervalID = setInterval(() => {
|
542
|
+
void this.heartbeat()
|
543
|
+
}, this.config.timeout)
|
544
|
+
}
|
545
|
+
|
546
|
+
/**
|
547
|
+
* A heartbeat is just a "ping" command, sent on an interval.
|
548
|
+
* If this succeeds, we're good. If it fails, disconnect so that the consumer can reconnect, if desired.
|
549
|
+
*
|
550
|
+
* @returns A Promise that resolves to void when the heartbeat returns successfully.
|
551
|
+
*/
|
552
|
+
private async heartbeat(): Promise<void> {
|
553
|
+
this.request({ command: 'ping' }).catch(async () => {
|
554
|
+
return this.reconnect().catch((error: Error) => {
|
555
|
+
this.emit('error', 'reconnect', error.message, error)
|
556
|
+
})
|
557
|
+
})
|
558
|
+
}
|
559
|
+
|
560
|
+
/**
|
561
|
+
* Process a failed connection.
|
562
|
+
*
|
563
|
+
* @param errorOrCode - (Optional) Error or code for connection failure.
|
564
|
+
*/
|
565
|
+
private onConnectionFailed(errorOrCode: Error | number | null): void {
|
566
|
+
if (this.ws) {
|
567
|
+
this.ws.removeAllListeners()
|
568
|
+
this.ws.on('error', () => {
|
569
|
+
/*
|
570
|
+
* Correctly listen for -- but ignore -- any future errors: If you
|
571
|
+
* don't have a listener on "error" node would log a warning on error.
|
572
|
+
*/
|
573
|
+
})
|
574
|
+
this.ws.close()
|
575
|
+
this.ws = null
|
576
|
+
}
|
577
|
+
if (typeof errorOrCode === 'number') {
|
578
|
+
this.connectionManager.rejectAllAwaiting(
|
579
|
+
new NotConnectedError(`Connection failed with code ${errorOrCode}.`, {
|
580
|
+
code: errorOrCode,
|
581
|
+
}),
|
582
|
+
)
|
583
|
+
} else if (errorOrCode?.message) {
|
584
|
+
this.connectionManager.rejectAllAwaiting(
|
585
|
+
new NotConnectedError(errorOrCode.message, errorOrCode),
|
586
|
+
)
|
587
|
+
} else {
|
588
|
+
this.connectionManager.rejectAllAwaiting(
|
589
|
+
new NotConnectedError('Connection failed.'),
|
590
|
+
)
|
591
|
+
}
|
592
|
+
}
|
593
|
+
}
|