|
1 | 1 | import { types as T, matches } from "../deps.ts";
|
2 | 2 |
|
3 |
| -const { shape, arrayOf, number, boolean, string } = matches; |
| 3 | +const { shape, number, boolean, string } = matches; |
4 | 4 |
|
5 |
| -const matchProxyConfig = shape({ |
6 |
| - users: arrayOf( |
7 |
| - shape( |
8 |
| - { |
9 |
| - name: string, |
10 |
| - 'allowed-calls': arrayOf(string), |
11 |
| - password: string, |
12 |
| - 'fetch-blocks': boolean, |
13 |
| - }, |
14 |
| - ['fetch-blocks'], |
15 |
| - ), |
16 |
| - ), |
17 |
| -}) |
18 |
| - |
19 |
| -function times<T>(fn: (i: number) => T, amount: number): T[] { |
20 |
| - const answer = new Array(amount) |
21 |
| - for (let i = 0; i < amount; i++) { |
22 |
| - answer[i] = fn(i) |
23 |
| - } |
24 |
| - return answer |
25 |
| -} |
26 |
| - |
27 |
| -function randomItemString(input: string) { |
28 |
| - return input[Math.floor(Math.random() * input.length)] |
29 |
| -} |
30 |
| - |
31 |
| -const serviceName = 'electrs' |
32 |
| -const fullChars = |
33 |
| - 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' |
34 | 5 | type Check = {
|
35 | 6 | currentError(config: T.Config): string | void
|
36 | 7 | fix(config: T.Config): void
|
37 | 8 | }
|
38 | 9 |
|
39 |
| -const proxyChecks: Array<Check> = [ |
40 |
| - { |
41 |
| - currentError(config) { |
42 |
| - if (!matchProxyConfig.test(config)) { |
43 |
| - return 'Config is not the correct shape' |
44 |
| - } |
45 |
| - if (config.users.some((x) => x.name === serviceName)) { |
46 |
| - return |
47 |
| - } |
48 |
| - return `Must have an RPC user named "${serviceName}"` |
49 |
| - }, |
50 |
| - fix(config) { |
51 |
| - if (!matchProxyConfig.test(config)) { |
52 |
| - return |
53 |
| - } |
54 |
| - config.users.push({ |
55 |
| - name: serviceName, |
56 |
| - 'allowed-calls': [], |
57 |
| - password: times(() => randomItemString(fullChars), 22).join(''), |
58 |
| - }) |
59 |
| - }, |
60 |
| - }, |
61 |
| - ...[ |
62 |
| - 'estimatesmartfee', |
63 |
| - 'getblockchaininfo', |
64 |
| - 'getblockcount', |
65 |
| - 'getmempoolentry', |
66 |
| - 'getnetworkinfo', |
67 |
| - 'getrawmempool', |
68 |
| - 'getrawtransaction', |
69 |
| - ].map( |
70 |
| - (operator): Check => ({ |
71 |
| - currentError(config) { |
72 |
| - if (!matchProxyConfig.test(config)) { |
73 |
| - return 'Config is not the correct shape' |
74 |
| - } |
75 |
| - if ( |
76 |
| - config.users |
77 |
| - .find((x) => x.name === serviceName) |
78 |
| - ?.['allowed-calls']?.some((x) => x === operator) ?? |
79 |
| - false |
80 |
| - ) { |
81 |
| - return |
82 |
| - } |
83 |
| - return `RPC user "${serviceName}" must have "${operator}" enabled` |
84 |
| - }, |
85 |
| - fix(config) { |
86 |
| - if (!matchProxyConfig.test(config)) { |
87 |
| - throw new Error('Config is not the correct shape') |
88 |
| - } |
89 |
| - const found = config.users.find((x) => x.name === serviceName) |
90 |
| - if (!found) { |
91 |
| - throw new Error(`No user ${serviceName} found`) |
92 |
| - } |
93 |
| - found['allowed-calls'] = [...(found['allowed-calls'] ?? []), operator] |
94 |
| - }, |
95 |
| - }), |
96 |
| - ), |
97 |
| -] |
98 |
| - |
99 | 10 | const matchBitcoindConfig = shape({
|
100 | 11 | rpc: shape({
|
101 | 12 | enable: boolean,
|
@@ -168,31 +79,6 @@ const bitcoindChecks: Array<Check> = [
|
168 | 79 | ]
|
169 | 80 |
|
170 | 81 | export const dependencies: T.ExpectedExports.dependencies = {
|
171 |
| - 'btc-rpc-proxy': { |
172 |
| - // deno-lint-ignore require-await |
173 |
| - async check(effects, configInput) { |
174 |
| - effects.info('check btc-rpc-proxy') |
175 |
| - for (const checker of proxyChecks) { |
176 |
| - const error = checker.currentError(configInput) |
177 |
| - if (error) { |
178 |
| - effects.error(`throwing error: ${error}`) |
179 |
| - return { error } |
180 |
| - } |
181 |
| - } |
182 |
| - return { result: null } |
183 |
| - }, |
184 |
| - // deno-lint-ignore require-await |
185 |
| - async autoConfigure(effects, configInput) { |
186 |
| - effects.info('autoconfigure btc-rpc-proxy') |
187 |
| - for (const checker of proxyChecks) { |
188 |
| - const error = checker.currentError(configInput) |
189 |
| - if (error) { |
190 |
| - checker.fix(configInput) |
191 |
| - } |
192 |
| - } |
193 |
| - return { result: configInput } |
194 |
| - }, |
195 |
| - }, |
196 | 82 | bitcoind: {
|
197 | 83 | // deno-lint-ignore require-await
|
198 | 84 | async check(effects, configInput) {
|
|
0 commit comments