From fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 26 Aug 2024 21:17:43 -0700 Subject: typescript --- lib/rpc.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/rpc.ts (limited to 'lib/rpc.ts') diff --git a/lib/rpc.ts b/lib/rpc.ts new file mode 100644 index 00000000..bb57d075 --- /dev/null +++ b/lib/rpc.ts @@ -0,0 +1,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), + }, + ); -- cgit v1.2.3