1 | const BaseProvider = require('./BaseProvider');
|
2 | const HttpProvider = require('./HttpProvider');
|
3 |
|
4 |
|
5 | function providerFactory(url, options) {
|
6 | let provider;
|
7 |
|
8 | if (typeof url !== 'string') {
|
9 | throw new Error(`url must be string, got ${url}`);
|
10 | }
|
11 |
|
12 | if (!url) {
|
13 | provider = new BaseProvider(url, options);
|
14 | } else if (url.startsWith('http')) {
|
15 | provider = new HttpProvider(url, options);
|
16 | } else if (url.startsWith('ws')) {
|
17 | throw new Error(`Invalid protocol or url "${url}"`);
|
18 |
|
19 | } else {
|
20 | throw new Error(`Invalid protocol or url "${url}"`);
|
21 | }
|
22 |
|
23 | return provider;
|
24 | }
|
25 |
|
26 | module.exports = providerFactory;
|