aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rpc.js
blob: e8b4572cff0d9369c06462c0c77e615252adb3e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import got from "got";

export default ({ host, port, wallet, username, password }) =>
  new Proxy(
    {},
    {
      get:
        (target, prop) =>
        (...params) =>
          ((method, ...params) => {
            let url = `http://${host}:${port}/wallet/${wallet}`;
            return got
              .post(url, {
                json: {
                  method,
                  params,
                },
                headers: {
                  authorization: `Basic ${Buffer.from(
                    `${username}:${password}`
                  ).toString("base64")}`,
                },
              })
              .json()
              .then(({ result }) => result);
          })(prop.toLowerCase(), ...params),
    }
  );