mainnet-js 3.1.7 → 4.0.0-next.10
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/module/cache/IndexedDbCache.d.ts +1 -1
- package/dist/module/cache/IndexedDbCache.d.ts.map +1 -1
- package/dist/module/cache/MemoryCache.d.ts +1 -1
- package/dist/module/cache/MemoryCache.d.ts.map +1 -1
- package/dist/module/cache/WebStorageCache.d.ts +1 -1
- package/dist/module/cache/WebStorageCache.d.ts.map +1 -1
- package/dist/module/cache/walletCache.d.ts +16 -6
- package/dist/module/cache/walletCache.d.ts.map +1 -1
- package/dist/module/cache/walletCache.js +92 -34
- package/dist/module/cache/walletCache.js.map +1 -1
- package/dist/module/cli.js +1 -2
- package/dist/module/cli.js.map +1 -1
- package/dist/module/db/index.d.ts +1 -1
- package/dist/module/db/index.d.ts.map +1 -1
- package/dist/module/db/index.js +1 -1
- package/dist/module/db/index.js.map +1 -1
- package/dist/module/enum.d.ts +1 -1
- package/dist/module/enum.d.ts.map +1 -1
- package/dist/module/history/getHistory.d.ts +1 -1
- package/dist/module/history/getHistory.d.ts.map +1 -1
- package/dist/module/history/getHistory.js +3 -3
- package/dist/module/history/getHistory.js.map +1 -1
- package/dist/module/index.d.ts +25 -22
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +33 -26
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +12 -2
- package/dist/module/interface.d.ts.map +1 -1
- package/dist/module/interface.js.map +1 -1
- package/dist/module/libauth.d.ts +1 -1
- package/dist/module/libauth.d.ts.map +1 -1
- package/dist/module/libauth.js +1 -1
- package/dist/module/libauth.js.map +1 -1
- package/dist/module/mine/mine.d.ts +2 -7
- package/dist/module/mine/mine.d.ts.map +1 -1
- package/dist/module/mine/mine.js +6 -27
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/Connection.d.ts +1 -12
- package/dist/module/network/Connection.d.ts.map +1 -1
- package/dist/module/network/Connection.js +24 -33
- package/dist/module/network/Connection.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +16 -17
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.js +91 -93
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/MockNetworkProvider.d.ts +28 -0
- package/dist/module/network/MockNetworkProvider.d.ts.map +1 -0
- package/dist/module/network/MockNetworkProvider.js +74 -0
- package/dist/module/network/MockNetworkProvider.js.map +1 -0
- package/dist/module/network/NetworkProvider.d.ts +9 -2
- package/dist/module/network/NetworkProvider.d.ts.map +1 -1
- package/dist/module/network/configuration.d.ts +2 -4
- package/dist/module/network/configuration.d.ts.map +1 -1
- package/dist/module/network/configuration.js +25 -50
- package/dist/module/network/configuration.js.map +1 -1
- package/dist/module/network/constant.d.ts +7 -7
- package/dist/module/network/constant.d.ts.map +1 -1
- package/dist/module/network/constant.js +21 -24
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/default.d.ts +5 -3
- package/dist/module/network/default.d.ts.map +1 -1
- package/dist/module/network/default.js +29 -51
- package/dist/module/network/default.js.map +1 -1
- package/dist/module/network/index.d.ts +4 -4
- package/dist/module/network/index.d.ts.map +1 -1
- package/dist/module/network/index.js +2 -2
- package/dist/module/network/index.js.map +1 -1
- package/dist/module/network/interface.d.ts +0 -6
- package/dist/module/network/interface.d.ts.map +1 -1
- package/dist/module/rate/ExchangeRate.d.ts +1 -1
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
- package/dist/module/rate/ExchangeRate.js +13 -7
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +3 -3
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +4 -4
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +1 -1
- package/dist/module/transaction/allocateFee.d.ts.map +1 -1
- package/dist/module/transaction/allocateFee.js +2 -2
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveNetwork.js +1 -1
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/getAddrsByXpubKey.js +1 -1
- package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
- package/dist/module/util/getXPubKey.js +1 -1
- package/dist/module/util/getXPubKey.js.map +1 -1
- package/dist/module/util/hd.d.ts +2 -0
- package/dist/module/util/hd.d.ts.map +1 -1
- package/dist/module/util/hd.js +41 -0
- package/dist/module/util/hd.js.map +1 -1
- package/dist/module/util/index.d.ts +7 -9
- package/dist/module/util/index.d.ts.map +1 -1
- package/dist/module/util/index.js +7 -9
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/transaction.js +1 -1
- package/dist/module/util/transaction.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +13 -9
- package/dist/module/wallet/Base.d.ts.map +1 -1
- package/dist/module/wallet/Base.js +54 -58
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/HDWallet.d.ts.map +1 -1
- package/dist/module/wallet/HDWallet.js +19 -38
- package/dist/module/wallet/HDWallet.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +4 -22
- package/dist/module/wallet/Util.d.ts.map +1 -1
- package/dist/module/wallet/Util.js +75 -102
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Watch.d.ts +24 -5
- package/dist/module/wallet/Watch.d.ts.map +1 -1
- package/dist/module/wallet/Watch.js +141 -17
- package/dist/module/wallet/Watch.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +2 -6
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +3 -69
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/createWallet.d.ts +1 -1
- package/dist/module/wallet/createWallet.d.ts.map +1 -1
- package/dist/module/wallet/createWallet.js +2 -1
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +3 -2
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/wallet/model.d.ts +2 -1
- package/dist/module/wallet/model.d.ts.map +1 -1
- package/dist/module/wallet/model.js +1 -1
- package/dist/module/wallet/model.js.map +1 -1
- package/package.json +17 -29
- package/dist/index.html +0 -9
- package/dist/mainnet-3.1.7.js +0 -2066
- package/dist/module/network/util.d.ts +0 -3
- package/dist/module/network/util.d.ts.map +0 -1
- package/dist/module/network/util.js +0 -27
- package/dist/module/network/util.js.map +0 -1
- package/dist/module/test/expect.d.ts +0 -12
- package/dist/module/test/expect.d.ts.map +0 -1
- package/dist/module/test/expect.js +0 -47
- package/dist/module/test/expect.js.map +0 -1
- package/dist/module/test/fetch.d.ts +0 -3
- package/dist/module/test/fetch.d.ts.map +0 -1
- package/dist/module/test/fetch.js +0 -32
- package/dist/module/test/fetch.js.map +0 -1
- package/dist/module/util/randomBytes.d.ts +0 -2
- package/dist/module/util/randomBytes.d.ts.map +0 -1
- package/dist/module/util/randomBytes.js +0 -13
- package/dist/module/util/randomBytes.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/cache/IndexedDbCache.test.ts +0 -15
- package/src/cache/IndexedDbCache.ts +0 -172
- package/src/cache/MemoryCache.test.ts +0 -15
- package/src/cache/MemoryCache.ts +0 -32
- package/src/cache/WebStorageCache.test.ts +0 -15
- package/src/cache/WebStorageCache.ts +0 -38
- package/src/cache/index.ts +0 -2
- package/src/cache/interface.ts +0 -9
- package/src/cache/walletCache.ts +0 -254
- package/src/chain.ts +0 -3
- package/src/cli.ts +0 -32
- package/src/config.ts +0 -23
- package/src/constant.ts +0 -27
- package/src/db/ExchangeRateProvider.ts +0 -28
- package/src/db/StorageProvider.ts +0 -64
- package/src/db/index.ts +0 -2
- package/src/db/interface.ts +0 -11
- package/src/enum.ts +0 -34
- package/src/history/getHistory.test.ts +0 -290
- package/src/history/getHistory.ts +0 -411
- package/src/history/interface.ts +0 -24
- package/src/index.ts +0 -48
- package/src/interface.ts +0 -72
- package/src/libauth.ts +0 -11
- package/src/message/index.ts +0 -2
- package/src/message/interface.ts +0 -40
- package/src/message/signed.test.ts +0 -309
- package/src/message/signed.ts +0 -201
- package/src/mine/index.ts +0 -1
- package/src/mine/mine.test.ts +0 -10
- package/src/mine/mine.ts +0 -42
- package/src/network/Connection.test.ts +0 -51
- package/src/network/Connection.ts +0 -73
- package/src/network/ElectrumNetworkProvider.ts +0 -657
- package/src/network/NetworkProvider.ts +0 -180
- package/src/network/Rpc.test.ts +0 -130
- package/src/network/configuration.test.ts +0 -59
- package/src/network/configuration.ts +0 -72
- package/src/network/constant.ts +0 -43
- package/src/network/default.ts +0 -120
- package/src/network/electrum.test.ts +0 -28
- package/src/network/getRelayFeeCache.test.ts +0 -15
- package/src/network/getRelayFeeCache.ts +0 -23
- package/src/network/index.ts +0 -14
- package/src/network/interface.ts +0 -80
- package/src/network/util.test.ts +0 -24
- package/src/network/util.ts +0 -30
- package/src/rate/ExchangeRate.test.headless.js +0 -35
- package/src/rate/ExchangeRate.test.ts +0 -51
- package/src/rate/ExchangeRate.ts +0 -142
- package/src/test/expect.ts +0 -59
- package/src/test/fetch.ts +0 -39
- package/src/test/json.test.ts +0 -13
- package/src/transaction/Wif.ts +0 -680
- package/src/transaction/allocateFee.test.ts +0 -298
- package/src/transaction/allocateFee.ts +0 -149
- package/src/util/amountInSatoshi.test.ts +0 -27
- package/src/util/amountInSatoshi.ts +0 -33
- package/src/util/asSendRequestObject.ts +0 -81
- package/src/util/base64.test.ts +0 -39
- package/src/util/base64.ts +0 -12
- package/src/util/browserNotSupported.ts +0 -7
- package/src/util/checkForEmptySeed.ts +0 -9
- package/src/util/checkUtxos.ts +0 -29
- package/src/util/checkWifNetwork.ts +0 -24
- package/src/util/convert.test.ts +0 -46
- package/src/util/convert.ts +0 -50
- package/src/util/delay.ts +0 -3
- package/src/util/deriveCashaddr.test.ts +0 -164
- package/src/util/deriveCashaddr.ts +0 -143
- package/src/util/deriveLockscript.ts +0 -16
- package/src/util/deriveNetwork.ts +0 -19
- package/src/util/derivePublicKeyHash.test.ts +0 -55
- package/src/util/derivePublicKeyHash.ts +0 -64
- package/src/util/floor.test.ts +0 -21
- package/src/util/floor.ts +0 -4
- package/src/util/getAddrsByXpubKey.test.ts +0 -115
- package/src/util/getAddrsByXpubKey.ts +0 -86
- package/src/util/getRuntimePlatform.test.headless.js +0 -40
- package/src/util/getRuntimePlatform.test.ts +0 -5
- package/src/util/getRuntimePlatform.ts +0 -31
- package/src/util/getUsdRate.ts +0 -5
- package/src/util/getXPubKey.ts +0 -39
- package/src/util/hash160.test.ts +0 -18
- package/src/util/hash160.ts +0 -12
- package/src/util/hd.ts +0 -16
- package/src/util/header.test.ts +0 -34
- package/src/util/header.ts +0 -26
- package/src/util/index.ts +0 -33
- package/src/util/randomBytes.ts +0 -13
- package/src/util/randomInt.test.ts +0 -15
- package/src/util/randomInt.ts +0 -4
- package/src/util/sanitizeAddress.ts +0 -10
- package/src/util/sanitizeUnit.ts +0 -11
- package/src/util/satoshiToAmount.test.ts +0 -6
- package/src/util/satoshiToAmount.ts +0 -33
- package/src/util/sumSendRequestAmounts.ts +0 -34
- package/src/util/sumUtxoValue.ts +0 -27
- package/src/util/transaction.ts +0 -10
- package/src/wallet/Base.ts +0 -1563
- package/src/wallet/Cashtokens.test.headless.js +0 -730
- package/src/wallet/Cashtokens.test.ts +0 -1411
- package/src/wallet/HDWallet.test.ts +0 -1086
- package/src/wallet/HDWallet.ts +0 -992
- package/src/wallet/Util.test.ts +0 -134
- package/src/wallet/Util.ts +0 -191
- package/src/wallet/WalletCache.test.ts +0 -45
- package/src/wallet/Watch.ts +0 -441
- package/src/wallet/Wif.bip39.test.ts +0 -48
- package/src/wallet/Wif.test.ts +0 -1189
- package/src/wallet/Wif.ts +0 -687
- package/src/wallet/Wif.watchOnly.test.ts +0 -58
- package/src/wallet/createWallet.ts +0 -238
- package/src/wallet/enum.ts +0 -18
- package/src/wallet/interface.ts +0 -102
- package/src/wallet/model.test.ts +0 -24
- package/src/wallet/model.ts +0 -352
- package/tsconfig.browser.json +0 -11
- package/tsconfig.json +0 -33
- package/webpack.config.cjs +0 -132
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { TxI, Utxo, Network, HexHeaderI, HeaderI } from "../interface.js";
|
|
2
|
-
import {
|
|
3
|
-
ElectrumRawTransaction,
|
|
4
|
-
ElectrumRawTransactionWithInputValues,
|
|
5
|
-
} from "./interface.js";
|
|
6
|
-
import { CancelFn } from "../wallet/interface.js";
|
|
7
|
-
|
|
8
|
-
export default interface NetworkProvider {
|
|
9
|
-
/**
|
|
10
|
-
* Variable indicating the network that this provider connects to.
|
|
11
|
-
*/
|
|
12
|
-
network: Network;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Retrieve all UTXOs (confirmed and unconfirmed) for a given address.
|
|
16
|
-
* @param cashaddr The CashAddress for which we wish to retrieve UTXOs.
|
|
17
|
-
* @returns List of UTXOs spendable by the provided address.
|
|
18
|
-
*/
|
|
19
|
-
getUtxos(cashaddr: string): Promise<Utxo[]>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Retrieve all balance of an address in satoshi
|
|
23
|
-
* @param cashaddr The CashAddress for which we wish to retrieve UTXOs.
|
|
24
|
-
* @returns the balance.
|
|
25
|
-
*/
|
|
26
|
-
getBalance(cashaddr: string): Promise<bigint>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @returns The block header fetched at blockheight @param height.
|
|
30
|
-
* @param verbose steers the response type. If true, a verbose response is returned.
|
|
31
|
-
*/
|
|
32
|
-
getHeader(height: number, verbose: boolean): Promise<HeaderI | HexHeaderI>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @returns The current block height.
|
|
36
|
-
*/
|
|
37
|
-
getBlockHeight(): Promise<number>;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @returns The current minimum relay fee per kb
|
|
41
|
-
*/
|
|
42
|
-
getRelayFee(): Promise<number>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Retrieve transaction details for a given transaction ID.
|
|
46
|
-
* @param txHash Hex of transaction hash.
|
|
47
|
-
* @param verbose When true, returns a decoded transaction object instead of hex.
|
|
48
|
-
* @param loadInputValues When true (requires verbose), each vin is enriched with value, address and tokenData from the parent output.
|
|
49
|
-
* @throws {Error} If the transaction does not exist
|
|
50
|
-
* @returns The hex string (non-verbose) or decoded transaction object (verbose).
|
|
51
|
-
*/
|
|
52
|
-
getRawTransaction(
|
|
53
|
-
txHash: string,
|
|
54
|
-
verbose: true,
|
|
55
|
-
loadInputValues: true
|
|
56
|
-
): Promise<ElectrumRawTransactionWithInputValues>;
|
|
57
|
-
getRawTransaction(
|
|
58
|
-
txHash: string,
|
|
59
|
-
verbose: true,
|
|
60
|
-
loadInputValues?: false
|
|
61
|
-
): Promise<ElectrumRawTransaction>;
|
|
62
|
-
getRawTransaction(
|
|
63
|
-
txHash: string,
|
|
64
|
-
verbose?: false,
|
|
65
|
-
loadInputValues?: false
|
|
66
|
-
): Promise<string>;
|
|
67
|
-
getRawTransaction(
|
|
68
|
-
txHash: string,
|
|
69
|
-
verbose?: boolean,
|
|
70
|
-
loadInputValues?: boolean
|
|
71
|
-
): Promise<
|
|
72
|
-
string | ElectrumRawTransaction | ElectrumRawTransactionWithInputValues
|
|
73
|
-
>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Batch retrieve raw transactions by their hashes.
|
|
77
|
-
* @param hashes Array of transaction hashes.
|
|
78
|
-
* @returns Map from hash to hex transaction string.
|
|
79
|
-
*/
|
|
80
|
-
getRawTransactions(hashes: string[]): Promise<Map<string, string>>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Batch retrieve block headers by their heights.
|
|
84
|
-
* @param heights Array of block heights.
|
|
85
|
-
* @returns Map from height to decoded header.
|
|
86
|
-
*/
|
|
87
|
-
getHeaders(heights: number[]): Promise<Map<number, HeaderI>>;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Retrieve a verbose coin-specific response transaction details for a given transaction ID.
|
|
91
|
-
* @param txHash Hex of transaction hash.
|
|
92
|
-
* @param loadInputValues When true, each vin is enriched with value, address and tokenData from the parent output.
|
|
93
|
-
* @throws {Error} If the transaction does not exist
|
|
94
|
-
* @returns The decoded transaction object.
|
|
95
|
-
*/
|
|
96
|
-
getRawTransactionObject(
|
|
97
|
-
txHash: string,
|
|
98
|
-
loadInputValues: true
|
|
99
|
-
): Promise<ElectrumRawTransactionWithInputValues>;
|
|
100
|
-
getRawTransactionObject(
|
|
101
|
-
txHash: string,
|
|
102
|
-
loadInputValues?: false
|
|
103
|
-
): Promise<ElectrumRawTransaction>;
|
|
104
|
-
getRawTransactionObject(
|
|
105
|
-
txHash: string,
|
|
106
|
-
loadInputValues?: boolean
|
|
107
|
-
): Promise<ElectrumRawTransaction | ElectrumRawTransactionWithInputValues>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Broadcast a raw hex transaction to the Bitcoin Cash network.
|
|
111
|
-
* @param txHex The raw transaction hex to be broadcast.
|
|
112
|
-
* @param awaitPropagation Wait for transaction to be registered in the bitcoind or indexer. If set to false, function returns computed transaction hash immediately.
|
|
113
|
-
* @throws {Error} If the transaction was not accepted by the network.
|
|
114
|
-
* @returns The transaction ID (hash) corresponding to the broadcast transaction.
|
|
115
|
-
*/
|
|
116
|
-
sendRawTransaction(
|
|
117
|
-
txHex: string,
|
|
118
|
-
awaitPropagation?: boolean
|
|
119
|
-
): Promise<string>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Return the confirmed and unconfirmed history of a Bitcoin Cash address.
|
|
123
|
-
* @param cashaddr The CashAddress for which we wish to retrieve history.
|
|
124
|
-
* @throws {Error} When failing to get history.
|
|
125
|
-
* @returns Array of transactions.
|
|
126
|
-
*/
|
|
127
|
-
getHistory(
|
|
128
|
-
cashaddr: string,
|
|
129
|
-
fromHeight?: number,
|
|
130
|
-
toHeight?: number
|
|
131
|
-
): Promise<TxI[]>;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Wait for the next block or a block at given blockchain height.
|
|
135
|
-
* @param height If specified, waits for blockchain to reach this height.
|
|
136
|
-
* @returns Block header.
|
|
137
|
-
*/
|
|
138
|
-
waitForBlock(height?: number): Promise<HexHeaderI>;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Subscribe to the address change events
|
|
142
|
-
* @param cashaddr The CashAddress for which we wish to retrieve history.
|
|
143
|
-
* @throws {Error} If the subscription failed.
|
|
144
|
-
* @returns nothing.
|
|
145
|
-
*/
|
|
146
|
-
subscribeToAddress(
|
|
147
|
-
cashaddr: string,
|
|
148
|
-
callback: (data: any) => void
|
|
149
|
-
): Promise<CancelFn>;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Subscribe to a transaction in order to receive future notifications if its confirmation status changes.
|
|
153
|
-
* @param txHash The transaction hash as a hexadecimal string.
|
|
154
|
-
* @throws {Error} If the subscription failed.
|
|
155
|
-
* @returns nothing.
|
|
156
|
-
*/
|
|
157
|
-
subscribeToTransaction(
|
|
158
|
-
txHash: string,
|
|
159
|
-
callback: (data: any) => void
|
|
160
|
-
): Promise<CancelFn>;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Function to wait for connection to be ready
|
|
164
|
-
* @param timeout number of milliseconds to wait before throwing error
|
|
165
|
-
* @returns true when ready, or an error
|
|
166
|
-
*/
|
|
167
|
-
ready(timeout?: number): Promise<boolean | unknown>;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Function to connect manually if using persistent connection
|
|
171
|
-
* @returns a promise resolving when the connection is established.
|
|
172
|
-
*/
|
|
173
|
-
connect(): Promise<void>;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Function to disconnect manually if using persistent connection
|
|
177
|
-
* @returns true if successfully disconnected, or false if there was no connection
|
|
178
|
-
*/
|
|
179
|
-
disconnect(): Promise<boolean>;
|
|
180
|
-
}
|
package/src/network/Rpc.test.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { disconnectProviders, initProviders } from "./Connection";
|
|
2
|
-
import { RegTestWallet } from "../wallet/Wif";
|
|
3
|
-
import { getNetworkProvider } from "../network/default";
|
|
4
|
-
import { mine } from "../mine";
|
|
5
|
-
import { Network } from "../interface";
|
|
6
|
-
|
|
7
|
-
const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
|
|
8
|
-
|
|
9
|
-
beforeAll(async () => {
|
|
10
|
-
await initProviders();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterAll(async () => {
|
|
14
|
-
await disconnectProviders();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe("Rpc tests", () => {
|
|
18
|
-
test("get utxos", async () => {
|
|
19
|
-
const provider = getNetworkProvider(Network.REGTEST);
|
|
20
|
-
expect(
|
|
21
|
-
await provider.getUtxos(
|
|
22
|
-
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0"
|
|
23
|
-
)
|
|
24
|
-
).not.toHaveLength(0);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("subcribe to address", async () => {
|
|
28
|
-
const provider = getNetworkProvider(Network.REGTEST);
|
|
29
|
-
try {
|
|
30
|
-
await provider.subscribeToAddress(
|
|
31
|
-
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0",
|
|
32
|
-
async (data) => {
|
|
33
|
-
expect(data).not.toBe("");
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
38
|
-
} catch (e: any) {
|
|
39
|
-
console.log(e, e.message, e.stack);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("subcribe to muliple addresses bug", async () => {
|
|
44
|
-
const provider = getNetworkProvider(Network.REGTEST);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
await provider.subscribeToAddress(
|
|
48
|
-
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0",
|
|
49
|
-
async (data) => {
|
|
50
|
-
// console.log("First", data);
|
|
51
|
-
expect(data).not.toBe("");
|
|
52
|
-
data;
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
await provider.subscribeToAddress(
|
|
57
|
-
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0",
|
|
58
|
-
async (data) => {
|
|
59
|
-
// console.log("Second", data);
|
|
60
|
-
expect(data).not.toBe("");
|
|
61
|
-
data;
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
66
|
-
} catch (e: any) {
|
|
67
|
-
console.log(e, e.message, e.stack);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("Watch wallet balance", async () => {
|
|
72
|
-
const aliceWallet = await RegTestWallet.fromId(aliceWif);
|
|
73
|
-
|
|
74
|
-
let result = false;
|
|
75
|
-
aliceWallet.watchBalance((balance) => {
|
|
76
|
-
expect(balance).toBeGreaterThan(0);
|
|
77
|
-
result = true;
|
|
78
|
-
// stop watching
|
|
79
|
-
return true;
|
|
80
|
-
});
|
|
81
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
82
|
-
// we do not trigger the callback upon subscription anymore
|
|
83
|
-
expect(result).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("Wait for block timeout", async () => {
|
|
87
|
-
const provider = getNetworkProvider(Network.REGTEST);
|
|
88
|
-
let promiseResult;
|
|
89
|
-
const timeout = new Promise((resolve) =>
|
|
90
|
-
setTimeout(resolve, 1000, "timeout")
|
|
91
|
-
);
|
|
92
|
-
await Promise.race([provider.waitForBlock(), timeout]).then(
|
|
93
|
-
(result) => (promiseResult = result)
|
|
94
|
-
);
|
|
95
|
-
expect(promiseResult).toBe("timeout");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("Wait for block success", async () => {
|
|
99
|
-
const provider = getNetworkProvider(Network.REGTEST);
|
|
100
|
-
|
|
101
|
-
const aliceWallet = await RegTestWallet.fromId(aliceWif);
|
|
102
|
-
const bobWallet = await RegTestWallet.newRandom();
|
|
103
|
-
const minerWallet = await RegTestWallet.newRandom();
|
|
104
|
-
|
|
105
|
-
await aliceWallet.send([
|
|
106
|
-
{
|
|
107
|
-
cashaddr: bobWallet.cashaddr!,
|
|
108
|
-
value: 1000n,
|
|
109
|
-
},
|
|
110
|
-
]);
|
|
111
|
-
|
|
112
|
-
const height = await provider.getBlockHeight();
|
|
113
|
-
|
|
114
|
-
setTimeout(
|
|
115
|
-
async () => await mine({ cashaddr: minerWallet.cashaddr!, blocks: 1 }),
|
|
116
|
-
2000
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
let header = await provider.waitForBlock();
|
|
120
|
-
expect(header.height).toBe(height + 1);
|
|
121
|
-
|
|
122
|
-
setTimeout(
|
|
123
|
-
async () => await mine({ cashaddr: minerWallet.cashaddr!, blocks: 1 }),
|
|
124
|
-
2000
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
header = await provider.waitForBlock(height + 2);
|
|
128
|
-
expect(header.height).toBe(height + 2);
|
|
129
|
-
}, 20000);
|
|
130
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Network } from "../interface";
|
|
2
|
-
import * as config from "./configuration";
|
|
3
|
-
import * as primary from "./constant";
|
|
4
|
-
|
|
5
|
-
test("Should get electrum settings from defaults", async () => {
|
|
6
|
-
expect(config.getDefaultServers(Network.MAINNET)).toBe(
|
|
7
|
-
primary.mainnetServers
|
|
8
|
-
);
|
|
9
|
-
expect(config.getDefaultServers(Network.TESTNET)).toBe(
|
|
10
|
-
primary.testnetServers
|
|
11
|
-
);
|
|
12
|
-
expect(config.getDefaultServers(Network.REGTEST)).toBe(
|
|
13
|
-
primary.regtestServers
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("Should get electrum settings from DefaultProvider", async () => {
|
|
18
|
-
config.DefaultProvider.servers.mainnet = ["wss://example.com:777"];
|
|
19
|
-
|
|
20
|
-
expect(config.getDefaultServers(Network.MAINNET)).toStrictEqual([
|
|
21
|
-
"wss://example.com:777",
|
|
22
|
-
]);
|
|
23
|
-
expect(config.getDefaultServers(Network.TESTNET)).toBe(
|
|
24
|
-
primary.testnetServers
|
|
25
|
-
);
|
|
26
|
-
expect(config.getDefaultServers(Network.REGTEST)).toBe(
|
|
27
|
-
primary.regtestServers
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
config.DefaultProvider.servers.mainnet = [];
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("Should get electrum settings from env", async () => {
|
|
34
|
-
process.env.ELECTRUM = "https://example.com:1234";
|
|
35
|
-
process.env.ELECTRUM_TESTNET =
|
|
36
|
-
"https://test.example.com:1234,https://test.example.dk:1234";
|
|
37
|
-
process.env.ELECTRUM_REGTEST = "ws://reg.example.com:1234";
|
|
38
|
-
expect(config.getDefaultServers(Network.MAINNET)).toStrictEqual([
|
|
39
|
-
"https://example.com:1234",
|
|
40
|
-
]);
|
|
41
|
-
expect(config.getDefaultServers(Network.TESTNET)).toStrictEqual([
|
|
42
|
-
"https://test.example.com:1234",
|
|
43
|
-
"https://test.example.dk:1234",
|
|
44
|
-
]);
|
|
45
|
-
expect(config.getDefaultServers(Network.REGTEST)).toStrictEqual([
|
|
46
|
-
"ws://reg.example.com:1234",
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("Should get electrum cluster confidence from defaults", async () => {
|
|
51
|
-
let c = config.getConfidence();
|
|
52
|
-
expect(c).toStrictEqual(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("Should get electrum cluster confidence from env", async () => {
|
|
56
|
-
process.env.ELECTRUM_CONFIDENCE = "2";
|
|
57
|
-
let c = config.getConfidence();
|
|
58
|
-
expect(c).toStrictEqual(2);
|
|
59
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Network } from "../interface.js";
|
|
2
|
-
import { getRuntimePlatform } from "../util/index.js";
|
|
3
|
-
import * as primary from "./constant.js";
|
|
4
|
-
|
|
5
|
-
let mainnetServers: string[],
|
|
6
|
-
testnetServers: string[],
|
|
7
|
-
regtestServers: string[];
|
|
8
|
-
|
|
9
|
-
export class DefaultProvider {
|
|
10
|
-
static servers: { [name: string]: string[] } = {
|
|
11
|
-
mainnet: [] as string[],
|
|
12
|
-
testnet: [] as string[],
|
|
13
|
-
regtest: [] as string[],
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getDefaultServers(network: Network) {
|
|
18
|
-
let env: any;
|
|
19
|
-
if (getRuntimePlatform() == "node") {
|
|
20
|
-
env = process.env;
|
|
21
|
-
} else {
|
|
22
|
-
env = {};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
mainnetServers = DefaultProvider.servers.mainnet.length
|
|
26
|
-
? DefaultProvider.servers.mainnet
|
|
27
|
-
: env.ELECTRUM
|
|
28
|
-
? env.ELECTRUM.split(",")
|
|
29
|
-
: primary.mainnetServers;
|
|
30
|
-
testnetServers = DefaultProvider.servers.testnet.length
|
|
31
|
-
? DefaultProvider.servers.testnet
|
|
32
|
-
: env.ELECTRUM_TESTNET
|
|
33
|
-
? env.ELECTRUM_TESTNET.split(",")
|
|
34
|
-
: primary.testnetServers;
|
|
35
|
-
regtestServers = DefaultProvider.servers.regtest.length
|
|
36
|
-
? DefaultProvider.servers.regtest
|
|
37
|
-
: env.ELECTRUM_REGTEST
|
|
38
|
-
? env.ELECTRUM_REGTEST.split(",")
|
|
39
|
-
: primary.regtestServers;
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
mainnet: mainnetServers,
|
|
43
|
-
testnet: testnetServers,
|
|
44
|
-
regtest: regtestServers,
|
|
45
|
-
}[network];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getUserAgent() {
|
|
49
|
-
// Allow users to configure the cluster confidence
|
|
50
|
-
let ua;
|
|
51
|
-
if (getRuntimePlatform() === "node") {
|
|
52
|
-
ua = process.env.ELECTRUM_USER_AGENT
|
|
53
|
-
? process.env.ELECTRUM_USER_AGENT
|
|
54
|
-
: "mainnet-js-" + getRuntimePlatform();
|
|
55
|
-
} else {
|
|
56
|
-
ua = "mainnet-js-" + getRuntimePlatform();
|
|
57
|
-
}
|
|
58
|
-
return ua;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function getConfidence() {
|
|
62
|
-
// Allow users to configure the cluster confidence
|
|
63
|
-
let confidence;
|
|
64
|
-
if (getRuntimePlatform() === "node") {
|
|
65
|
-
confidence = process.env.ELECTRUM_CONFIDENCE
|
|
66
|
-
? parseInt(process.env.ELECTRUM_CONFIDENCE)
|
|
67
|
-
: 1;
|
|
68
|
-
} else {
|
|
69
|
-
confidence = 1;
|
|
70
|
-
}
|
|
71
|
-
return confidence;
|
|
72
|
-
}
|
package/src/network/constant.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const ELECTRUM_CASH_PROTOCOL_VERSION = "1.5";
|
|
2
|
-
|
|
3
|
-
export const networkTickerMap = {
|
|
4
|
-
mainnet: "BCH",
|
|
5
|
-
testnet: "tBCH",
|
|
6
|
-
regtest: "rBCH",
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const mainnetServers = [
|
|
10
|
-
// "wss://bch.imaginary.cash:50004",
|
|
11
|
-
"wss://blackie.c3-soft.com:50004",
|
|
12
|
-
// "wss://electrum.imaginary.cash:50004",
|
|
13
|
-
// "wss://fulcrum.fountainhead.cash",
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
// export const testnetServers = [
|
|
17
|
-
// // "wss://tbch.loping.net:60004",
|
|
18
|
-
// "wss://blackie.c3-soft.com:60004",
|
|
19
|
-
// // "wss://testnet.bitcoincash.network:60004",
|
|
20
|
-
// //,"wss://unavailable.invalid:50004"
|
|
21
|
-
// ];
|
|
22
|
-
|
|
23
|
-
// testnet4
|
|
24
|
-
// export const testnetServers = [
|
|
25
|
-
// //"wss://t4fork.c3-soft.com:61004",
|
|
26
|
-
// "wss://testnet4.imaginary.cash:50004",
|
|
27
|
-
// //,"wss://unavailable.invalid:50004"
|
|
28
|
-
// ];
|
|
29
|
-
|
|
30
|
-
// chipnet
|
|
31
|
-
export const testnetServers = [
|
|
32
|
-
"wss://chipnet.imaginary.cash:50004",
|
|
33
|
-
//"wss://blackie.c3-soft.com:64004", // chipnet with protocol 1.5.0
|
|
34
|
-
// "wss://chipnet.bch.ninja:50004",
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export const regtestServers = ["ws://127.0.0.1:60003"];
|
|
38
|
-
|
|
39
|
-
export const defaultServers = {
|
|
40
|
-
mainnet: mainnetServers,
|
|
41
|
-
testnet: testnetServers,
|
|
42
|
-
regtest: regtestServers,
|
|
43
|
-
};
|
package/src/network/default.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { default as ElectrumNetworkProvider } from "./ElectrumNetworkProvider.js";
|
|
2
|
-
import { ElectrumClient } from "@electrum-cash/network";
|
|
3
|
-
import { ElectrumWebSocket } from "@electrum-cash/web-socket";
|
|
4
|
-
import { default as NetworkProvider } from "./NetworkProvider.js";
|
|
5
|
-
import { getDefaultServers, getUserAgent } from "./configuration.js";
|
|
6
|
-
import { parseElectrumUrl } from "./util.js";
|
|
7
|
-
import { ElectrumHostParams } from "./interface.js";
|
|
8
|
-
import { Network } from "../interface.js";
|
|
9
|
-
import {
|
|
10
|
-
networkTickerMap,
|
|
11
|
-
ELECTRUM_CASH_PROTOCOL_VERSION,
|
|
12
|
-
} from "./constant.js";
|
|
13
|
-
|
|
14
|
-
export function setGlobalProvider(
|
|
15
|
-
network: Network,
|
|
16
|
-
provider: NetworkProvider
|
|
17
|
-
): NetworkProvider {
|
|
18
|
-
const accessor = networkTickerMap[network];
|
|
19
|
-
globalThis[accessor] = provider;
|
|
20
|
-
return provider;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getGlobalProvider(
|
|
24
|
-
network: Network
|
|
25
|
-
): NetworkProvider | undefined {
|
|
26
|
-
const accessor = networkTickerMap[network];
|
|
27
|
-
return globalThis[accessor];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function removeGlobalProvider(network: Network): void {
|
|
31
|
-
const accessor = networkTickerMap[network];
|
|
32
|
-
if (accessor in globalThis) {
|
|
33
|
-
delete globalThis[accessor];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function getNetworkProvider(
|
|
38
|
-
network: Network = Network.MAINNET,
|
|
39
|
-
servers?: string[] | string,
|
|
40
|
-
manualConnectionManagement?: boolean,
|
|
41
|
-
options?: ElectrumHostParams
|
|
42
|
-
): NetworkProvider {
|
|
43
|
-
const globalContext =
|
|
44
|
-
servers === undefined &&
|
|
45
|
-
manualConnectionManagement === undefined &&
|
|
46
|
-
options === undefined;
|
|
47
|
-
if (globalContext) {
|
|
48
|
-
const globalProvider = getGlobalProvider(network);
|
|
49
|
-
if (globalProvider) {
|
|
50
|
-
return globalProvider;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
manualConnectionManagement = manualConnectionManagement
|
|
55
|
-
? manualConnectionManagement
|
|
56
|
-
: false;
|
|
57
|
-
servers = servers ? servers : getDefaultServers(network);
|
|
58
|
-
// If the user has passed a single string, assume a single client connection
|
|
59
|
-
if (typeof servers === "string") {
|
|
60
|
-
servers = [servers as string];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// There were server(s)
|
|
64
|
-
if (servers) {
|
|
65
|
-
const client = getClient(servers[0], network, options);
|
|
66
|
-
let provider = new ElectrumNetworkProvider(
|
|
67
|
-
client,
|
|
68
|
-
network,
|
|
69
|
-
manualConnectionManagement
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (globalContext) {
|
|
73
|
-
return setGlobalProvider(network, provider);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return provider;
|
|
77
|
-
} else {
|
|
78
|
-
throw Error("No servers provided, defaults not available.");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// create a client with a server
|
|
83
|
-
function getClient(
|
|
84
|
-
server: string,
|
|
85
|
-
network: Network,
|
|
86
|
-
options?: ElectrumHostParams
|
|
87
|
-
) {
|
|
88
|
-
let url = parseElectrumUrl(server);
|
|
89
|
-
return getElectrumClient(url, options?.timeout ?? 120000, network);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function getElectrumClient(
|
|
93
|
-
params: ElectrumHostParams,
|
|
94
|
-
timeout: number,
|
|
95
|
-
network: Network
|
|
96
|
-
) {
|
|
97
|
-
if (params.scheme?.includes("tcp")) {
|
|
98
|
-
throw Error("TCP connections are not supported.");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const webSocket = new ElectrumWebSocket(
|
|
102
|
-
params.host,
|
|
103
|
-
params.port,
|
|
104
|
-
params.scheme === "wss",
|
|
105
|
-
timeout,
|
|
106
|
-
{
|
|
107
|
-
disableBrowserConnectivityHandling: true,
|
|
108
|
-
disableBrowserVisibilityHandling: true,
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
return new ElectrumClient(
|
|
112
|
-
getUserAgent(),
|
|
113
|
-
ELECTRUM_CASH_PROTOCOL_VERSION,
|
|
114
|
-
webSocket,
|
|
115
|
-
{
|
|
116
|
-
disableBrowserConnectivityHandling: true,
|
|
117
|
-
disableBrowserVisibilityHandling: true,
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ElectrumClient } from "@electrum-cash/network";
|
|
2
|
-
import { getNetworkProvider } from ".";
|
|
3
|
-
import { Network } from "../interface";
|
|
4
|
-
|
|
5
|
-
test("Should get a transaction with bare electrum", async () => {
|
|
6
|
-
const electrum = new ElectrumClient(
|
|
7
|
-
"Electrum client example",
|
|
8
|
-
"1.4.1",
|
|
9
|
-
"bch.imaginary.cash"
|
|
10
|
-
);
|
|
11
|
-
await electrum.connect();
|
|
12
|
-
const transactionID =
|
|
13
|
-
"4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251";
|
|
14
|
-
const transactionHex = await electrum.request(
|
|
15
|
-
"blockchain.transaction.get",
|
|
16
|
-
transactionID
|
|
17
|
-
);
|
|
18
|
-
await electrum.disconnect();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("Should get a transaction with provider", async () => {
|
|
22
|
-
const provider = getNetworkProvider(Network.MAINNET);
|
|
23
|
-
const transactionID =
|
|
24
|
-
"4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251";
|
|
25
|
-
const transactionHex = await provider.getRawTransaction(transactionID);
|
|
26
|
-
//console.log(transactionHex);
|
|
27
|
-
await provider.disconnect();
|
|
28
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getRelayFeeCache } from "./getRelayFeeCache";
|
|
2
|
-
import { getNetworkProvider } from "./default";
|
|
3
|
-
|
|
4
|
-
test("Should return ", async () => {
|
|
5
|
-
let provider = getNetworkProvider();
|
|
6
|
-
let fee = await getRelayFeeCache(provider);
|
|
7
|
-
expect(fee).toBe(1);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("Should return ", async () => {
|
|
11
|
-
let provider = getNetworkProvider();
|
|
12
|
-
globalThis.BCH_RELAY_FEE = 0.00005;
|
|
13
|
-
let fee2 = await getRelayFeeCache(provider);
|
|
14
|
-
expect(fee2).toBe(5);
|
|
15
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { bchParam } from "../chain.js";
|
|
2
|
-
import { networkTickerMap } from "./constant.js";
|
|
3
|
-
import { default as NetworkProvider } from "./NetworkProvider.js";
|
|
4
|
-
|
|
5
|
-
export async function getRelayFeeCache(provider: NetworkProvider) {
|
|
6
|
-
let relayFeePerKbInCoins;
|
|
7
|
-
if (networkTickerMap[provider.network] + "_RELAY_FEE" in globalThis) {
|
|
8
|
-
// Stores the fee in BCH_RELAY_FEE, tBCH_RELAY_FEE, etc
|
|
9
|
-
relayFeePerKbInCoins =
|
|
10
|
-
globalThis[networkTickerMap[provider.network] + "_RELAY_FEE"];
|
|
11
|
-
}
|
|
12
|
-
if (typeof relayFeePerKbInCoins !== "number") {
|
|
13
|
-
relayFeePerKbInCoins = await provider.getRelayFee();
|
|
14
|
-
globalThis[networkTickerMap[provider.network] + "_RELAY_FEE"] =
|
|
15
|
-
relayFeePerKbInCoins;
|
|
16
|
-
}
|
|
17
|
-
if (typeof relayFeePerKbInCoins === "number") {
|
|
18
|
-
return Math.round(relayFeePerKbInCoins * Number(bchParam.subUnits)) / 1000;
|
|
19
|
-
} else {
|
|
20
|
-
console.warn("Couldn't get min relay fee, using default instead");
|
|
21
|
-
return Math.round(0.00001 * Number(bchParam.subUnits)) / 1000;
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/network/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { getNetworkProvider } from "./default.js";
|
|
2
|
-
export {
|
|
3
|
-
Connection,
|
|
4
|
-
initProviders,
|
|
5
|
-
initProvider,
|
|
6
|
-
disconnectProviders,
|
|
7
|
-
} from "./Connection.js";
|
|
8
|
-
export { default as ElectrumNetworkProvider } from "./ElectrumNetworkProvider.js";
|
|
9
|
-
export { default as NetworkProvider } from "./NetworkProvider.js";
|
|
10
|
-
export {
|
|
11
|
-
ElectrumRawTransaction,
|
|
12
|
-
ElectrumRawTransactionWithInputValues,
|
|
13
|
-
ElectrumRawTransactionVinWithValues,
|
|
14
|
-
} from "./interface.js";
|