@solana/web3.js 1.5.1 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.esm.js +38 -8
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +38 -8
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +30 -2
- package/lib/index.esm.js +38 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +38 -8
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +1 -1
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +46 -5
- package/package.json +1 -1
- package/src/connection.ts +83 -9
package/module.flow.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.14.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
declare module "@solana/web3.js" {
|
|
8
8
|
/**
|
|
9
9
|
* Maximum length of derived pubkey seed
|
|
10
10
|
*/
|
|
11
|
-
declare export var MAX_SEED_LENGTH:
|
|
11
|
+
declare export var MAX_SEED_LENGTH: 32;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A public key
|
|
@@ -1621,6 +1621,44 @@ declare module "@solana/web3.js" {
|
|
|
1621
1621
|
...
|
|
1622
1622
|
};
|
|
1623
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* An object defining headers to be passed to the RPC server
|
|
1626
|
+
*/
|
|
1627
|
+
declare export type HttpHeaders = {
|
|
1628
|
+
[header: string]: string,
|
|
1629
|
+
...
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* A callback used to augment the outgoing HTTP request
|
|
1634
|
+
*/
|
|
1635
|
+
declare export type FetchMiddleware = (
|
|
1636
|
+
url: string,
|
|
1637
|
+
options: any,
|
|
1638
|
+
fetch: Function
|
|
1639
|
+
) => void;
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* Configuration for instantiating a Connection
|
|
1643
|
+
*/
|
|
1644
|
+
declare export type ConnectionConfig = {
|
|
1645
|
+
/**
|
|
1646
|
+
* Optional commitment level
|
|
1647
|
+
*/
|
|
1648
|
+
commitment?: Commitment,
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* Optional HTTP headers object
|
|
1652
|
+
*/
|
|
1653
|
+
httpHeaders?: HttpHeaders,
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* Optional fetch middleware callback
|
|
1657
|
+
*/
|
|
1658
|
+
fetchMiddleware?: FetchMiddleware,
|
|
1659
|
+
...
|
|
1660
|
+
};
|
|
1661
|
+
|
|
1624
1662
|
/**
|
|
1625
1663
|
* A connection to a fullnode JSON RPC endpoint
|
|
1626
1664
|
*/
|
|
@@ -1628,9 +1666,12 @@ declare module "@solana/web3.js" {
|
|
|
1628
1666
|
/**
|
|
1629
1667
|
* Establish a JSON RPC connection
|
|
1630
1668
|
* @param endpoint URL to the fullnode JSON RPC endpoint
|
|
1631
|
-
* @param
|
|
1669
|
+
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
1632
1670
|
*/
|
|
1633
|
-
constructor(
|
|
1671
|
+
constructor(
|
|
1672
|
+
endpoint: string,
|
|
1673
|
+
commitmentOrConfig?: Commitment | ConnectionConfig
|
|
1674
|
+
): this;
|
|
1634
1675
|
|
|
1635
1676
|
/**
|
|
1636
1677
|
* The default commitment used for requests
|
|
@@ -3367,5 +3408,5 @@ feeCalculator: FeeCalculator,...
|
|
|
3367
3408
|
/**
|
|
3368
3409
|
* There are 1-billion lamports in one SOL
|
|
3369
3410
|
*/
|
|
3370
|
-
declare export var LAMPORTS_PER_SOL:
|
|
3411
|
+
declare export var LAMPORTS_PER_SOL: 1000000000;
|
|
3371
3412
|
}
|
package/package.json
CHANGED
package/src/connection.ts
CHANGED
|
@@ -622,21 +622,45 @@ export type PerfSample = {
|
|
|
622
622
|
samplePeriodSecs: number;
|
|
623
623
|
};
|
|
624
624
|
|
|
625
|
-
function createRpcClient(
|
|
625
|
+
function createRpcClient(
|
|
626
|
+
url: string,
|
|
627
|
+
useHttps: boolean,
|
|
628
|
+
httpHeaders?: HttpHeaders,
|
|
629
|
+
fetchMiddleware?: FetchMiddleware,
|
|
630
|
+
): RpcClient {
|
|
626
631
|
let agentManager: AgentManager | undefined;
|
|
627
632
|
if (!process.env.BROWSER) {
|
|
628
633
|
agentManager = new AgentManager(useHttps);
|
|
629
634
|
}
|
|
630
635
|
|
|
636
|
+
let fetchWithMiddleware: (url: string, options: any) => Promise<Response>;
|
|
637
|
+
|
|
638
|
+
if (fetchMiddleware) {
|
|
639
|
+
fetchWithMiddleware = (url: string, options: any) => {
|
|
640
|
+
return new Promise<Response>((resolve, reject) => {
|
|
641
|
+
fetchMiddleware(url, options, async (url: string, options: any) => {
|
|
642
|
+
try {
|
|
643
|
+
resolve(await fetch(url, options));
|
|
644
|
+
} catch (error) {
|
|
645
|
+
reject(error);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
631
652
|
const clientBrowser = new RpcClient(async (request, callback) => {
|
|
632
653
|
const agent = agentManager ? agentManager.requestStart() : undefined;
|
|
633
654
|
const options = {
|
|
634
655
|
method: 'POST',
|
|
635
656
|
body: request,
|
|
636
657
|
agent,
|
|
637
|
-
headers:
|
|
638
|
-
|
|
639
|
-
|
|
658
|
+
headers: Object.assign(
|
|
659
|
+
{
|
|
660
|
+
'Content-Type': 'application/json',
|
|
661
|
+
},
|
|
662
|
+
httpHeaders || {},
|
|
663
|
+
),
|
|
640
664
|
};
|
|
641
665
|
|
|
642
666
|
try {
|
|
@@ -644,7 +668,12 @@ function createRpcClient(url: string, useHttps: boolean): RpcClient {
|
|
|
644
668
|
let res: Response;
|
|
645
669
|
let waitTime = 500;
|
|
646
670
|
for (;;) {
|
|
647
|
-
|
|
671
|
+
if (fetchWithMiddleware) {
|
|
672
|
+
res = await fetchWithMiddleware(url, options);
|
|
673
|
+
} else {
|
|
674
|
+
res = await fetch(url, options);
|
|
675
|
+
}
|
|
676
|
+
|
|
648
677
|
if (res.status !== 429 /* Too many requests */) {
|
|
649
678
|
break;
|
|
650
679
|
}
|
|
@@ -1673,6 +1702,32 @@ export type ConfirmedSignatureInfo = {
|
|
|
1673
1702
|
blockTime?: number | null;
|
|
1674
1703
|
};
|
|
1675
1704
|
|
|
1705
|
+
/**
|
|
1706
|
+
* An object defining headers to be passed to the RPC server
|
|
1707
|
+
*/
|
|
1708
|
+
export type HttpHeaders = {[header: string]: string};
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* A callback used to augment the outgoing HTTP request
|
|
1712
|
+
*/
|
|
1713
|
+
export type FetchMiddleware = (
|
|
1714
|
+
url: string,
|
|
1715
|
+
options: any,
|
|
1716
|
+
fetch: Function,
|
|
1717
|
+
) => void;
|
|
1718
|
+
|
|
1719
|
+
/**
|
|
1720
|
+
* Configuration for instantiating a Connection
|
|
1721
|
+
*/
|
|
1722
|
+
export type ConnectionConfig = {
|
|
1723
|
+
/** Optional commitment level */
|
|
1724
|
+
commitment?: Commitment;
|
|
1725
|
+
/** Optional HTTP headers object */
|
|
1726
|
+
httpHeaders?: HttpHeaders;
|
|
1727
|
+
/** Optional fetch middleware callback */
|
|
1728
|
+
fetchMiddleware?: FetchMiddleware;
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1676
1731
|
/**
|
|
1677
1732
|
* A connection to a fullnode JSON RPC endpoint
|
|
1678
1733
|
*/
|
|
@@ -1734,18 +1789,36 @@ export class Connection {
|
|
|
1734
1789
|
* Establish a JSON RPC connection
|
|
1735
1790
|
*
|
|
1736
1791
|
* @param endpoint URL to the fullnode JSON RPC endpoint
|
|
1737
|
-
* @param
|
|
1792
|
+
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
1738
1793
|
*/
|
|
1739
|
-
constructor(
|
|
1794
|
+
constructor(
|
|
1795
|
+
endpoint: string,
|
|
1796
|
+
commitmentOrConfig?: Commitment | ConnectionConfig,
|
|
1797
|
+
) {
|
|
1740
1798
|
this._rpcEndpoint = endpoint;
|
|
1741
1799
|
|
|
1742
1800
|
let url = urlParse(endpoint);
|
|
1743
1801
|
const useHttps = url.protocol === 'https:';
|
|
1744
1802
|
|
|
1745
|
-
|
|
1803
|
+
let httpHeaders;
|
|
1804
|
+
let fetchMiddleware;
|
|
1805
|
+
if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
|
|
1806
|
+
this._commitment = commitmentOrConfig;
|
|
1807
|
+
} else if (commitmentOrConfig) {
|
|
1808
|
+
this._commitment = commitmentOrConfig.commitment;
|
|
1809
|
+
httpHeaders = commitmentOrConfig.httpHeaders;
|
|
1810
|
+
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
this._rpcClient = createRpcClient(
|
|
1814
|
+
url.href,
|
|
1815
|
+
useHttps,
|
|
1816
|
+
httpHeaders,
|
|
1817
|
+
fetchMiddleware,
|
|
1818
|
+
);
|
|
1746
1819
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
1747
1820
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
1748
|
-
|
|
1821
|
+
|
|
1749
1822
|
this._blockhashInfo = {
|
|
1750
1823
|
recentBlockhash: null,
|
|
1751
1824
|
lastFetch: 0,
|
|
@@ -1764,6 +1837,7 @@ export class Connection {
|
|
|
1764
1837
|
if (url.port !== null) {
|
|
1765
1838
|
url.port = String(Number(url.port) + 1);
|
|
1766
1839
|
}
|
|
1840
|
+
|
|
1767
1841
|
this._rpcWebSocket = new RpcWebSocketClient(urlFormat(url), {
|
|
1768
1842
|
autoconnect: false,
|
|
1769
1843
|
max_reconnects: Infinity,
|