1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.IpcProvider = void 0;
|
19 | var net_1 = require("net");
|
20 | var properties_1 = require("@ethersproject/properties");
|
21 | var logger_1 = require("@ethersproject/logger");
|
22 | var _version_1 = require("./_version");
|
23 | var logger = new logger_1.Logger(_version_1.version);
|
24 | var json_rpc_provider_1 = require("./json-rpc-provider");
|
25 | var IpcProvider = (function (_super) {
|
26 | __extends(IpcProvider, _super);
|
27 | function IpcProvider(path, network) {
|
28 | var _this = this;
|
29 | if (path == null) {
|
30 | logger.throwError("missing path", logger_1.Logger.errors.MISSING_ARGUMENT, { arg: "path" });
|
31 | }
|
32 | _this = _super.call(this, "ipc://" + path, network) || this;
|
33 | (0, properties_1.defineReadOnly)(_this, "path", path);
|
34 | return _this;
|
35 | }
|
36 |
|
37 | IpcProvider.prototype.send = function (method, params) {
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | var _this = this;
|
43 | var payload = JSON.stringify({
|
44 | method: method,
|
45 | params: params,
|
46 | id: 42,
|
47 | jsonrpc: "2.0"
|
48 | });
|
49 | return new Promise(function (resolve, reject) {
|
50 | var response = Buffer.alloc(0);
|
51 | var stream = (0, net_1.connect)(_this.path);
|
52 | stream.on("data", function (data) {
|
53 | response = Buffer.concat([response, data]);
|
54 | });
|
55 | stream.on("end", function () {
|
56 | try {
|
57 | resolve(JSON.parse(response.toString()).result);
|
58 |
|
59 | stream.destroy();
|
60 | }
|
61 | catch (error) {
|
62 | reject(error);
|
63 | stream.destroy();
|
64 | }
|
65 | });
|
66 | stream.on("error", function (error) {
|
67 | reject(error);
|
68 | stream.destroy();
|
69 | });
|
70 | stream.write(payload);
|
71 | stream.end();
|
72 | });
|
73 | };
|
74 | return IpcProvider;
|
75 | }(json_rpc_provider_1.JsonRpcProvider));
|
76 | exports.IpcProvider = IpcProvider;
|
77 |
|
\ | No newline at end of file |