2019-05-15 01:48:48 +03:00
|
|
|
"use strict";
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
|
|
return extendStatics(d, b);
|
|
|
|
};
|
|
|
|
return function (d, b) {
|
|
|
|
extendStatics(d, b);
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
var properties_1 = require("@ethersproject/properties");
|
2019-08-02 09:10:58 +03:00
|
|
|
var logger_1 = require("@ethersproject/logger");
|
|
|
|
var _version_1 = require("./_version");
|
|
|
|
var logger = new logger_1.Logger(_version_1.version);
|
2019-05-15 01:48:48 +03:00
|
|
|
var json_rpc_provider_1 = require("./json-rpc-provider");
|
|
|
|
/*
|
|
|
|
@TODO
|
|
|
|
utils.defineProperty(Web3Signer, "onchange", {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
*/
|
|
|
|
var Web3Provider = /** @class */ (function (_super) {
|
|
|
|
__extends(Web3Provider, _super);
|
|
|
|
function Web3Provider(web3Provider, network) {
|
|
|
|
var _newTarget = this.constructor;
|
|
|
|
var _this = this;
|
2019-08-02 09:10:58 +03:00
|
|
|
logger.checkNew(_newTarget, Web3Provider);
|
2019-05-15 01:48:48 +03:00
|
|
|
// HTTP has a host; IPC has a path.
|
|
|
|
_this = _super.call(this, web3Provider.host || web3Provider.path || "", network) || this;
|
|
|
|
if (web3Provider) {
|
|
|
|
if (web3Provider.sendAsync) {
|
|
|
|
_this._sendAsync = web3Provider.sendAsync.bind(web3Provider);
|
|
|
|
}
|
|
|
|
else if (web3Provider.send) {
|
|
|
|
_this._sendAsync = web3Provider.send.bind(web3Provider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!web3Provider || !_this._sendAsync) {
|
2019-08-02 09:10:58 +03:00
|
|
|
logger.throwArgumentError("invalid web3Provider", "web3Provider", web3Provider);
|
2019-05-15 01:48:48 +03:00
|
|
|
}
|
|
|
|
properties_1.defineReadOnly(_this, "_web3Provider", web3Provider);
|
|
|
|
return _this;
|
|
|
|
}
|
|
|
|
Web3Provider.prototype.send = function (method, params) {
|
|
|
|
var _this = this;
|
|
|
|
// Metamask complains about eth_sign (and on some versions hangs)
|
|
|
|
if (method == "eth_sign" && this._web3Provider.isMetaMask) {
|
|
|
|
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
|
|
|
|
method = "personal_sign";
|
|
|
|
params = [params[1], params[0]];
|
|
|
|
}
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var request = {
|
|
|
|
method: method,
|
|
|
|
params: params,
|
|
|
|
id: 42,
|
|
|
|
jsonrpc: "2.0"
|
|
|
|
};
|
|
|
|
_this._sendAsync(request, function (error, result) {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result.error) {
|
|
|
|
// @TODO: not any
|
|
|
|
var error_1 = new Error(result.error.message);
|
|
|
|
error_1.code = result.error.code;
|
|
|
|
error_1.data = result.error.data;
|
|
|
|
reject(error_1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve(result.result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
return Web3Provider;
|
|
|
|
}(json_rpc_provider_1.JsonRpcProvider));
|
|
|
|
exports.Web3Provider = Web3Provider;
|