-
Notifications
You must be signed in to change notification settings - Fork 106
/
hooked-web3-provider.min.js
1 lines (1 loc) · 2.92 KB
/
hooked-web3-provider.min.js
1
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),_get=function(t,e,r){for(var n=!0;n;){var o=t,a=e,i=r;s=l=c=void 0,n=!1,null===o&&(o=Function.prototype);var s=Object.getOwnPropertyDescriptor(o,a);if(void 0!==s){if("value"in s)return s.value;var c=s.get;return void 0===c?void 0:c.call(i)}var l=Object.getPrototypeOf(o);if(null===l)return void 0;t=l,e=a,r=i,n=!0}},factory=function(t){var e=function(e){function r(t){var e=t.host,n=t.transaction_signer;_classCallCheck(this,r),_get(Object.getPrototypeOf(r.prototype),"constructor",this).call(this,e),this.transaction_signer=n,this.global_nonces={}}return _inherits(r,e),_createClass(r,[{key:"send",value:function(t,e){var n=this,o=t;o instanceof Array||(o=[o]);var a=!0,i=!1,s=void 0;try{for(var c,l=o[Symbol.iterator]();!(a=(c=l.next()).done);a=!0){var u=c.value;if("eth_sendTransaction"==u.method)throw new Error("HookedWeb3Provider does not support synchronous transactions. Please provide a callback.")}}catch(f){i=!0,s=f}finally{try{!a&&l["return"]&&l["return"]()}finally{if(i)throw s}}var p=function(){return _get(Object.getPrototypeOf(r.prototype),"send",n).call(n,t,e)};return this.rewritePayloads(0,o,{},p)}},{key:"sendAsync",value:function(t,e){var n=this,o=function(){_get(Object.getPrototypeOf(r.prototype),"sendAsync",n).call(n,t,e)},a=t;t instanceof Array||(a=[t]),this.rewritePayloads(0,a,{},o)}},{key:"rewritePayloads",value:function(e,r,n,o){var a=this;if(e>=r.length)return o();var i=r[e],s=function(t){return null!=t?o(t):a.rewritePayloads(e+1,r,n,o)};if("eth_sendTransaction"!=i.method)return s();var c=i.params[0],l=c.from;this.transaction_signer.hasAddress(l,function(e,r){if(null!=e||0==r)return s(e);var u=function(e){var r=n[l];null!=r?e(null,r):a.sendAsync({jsonrpc:"2.0",method:"eth_getTransactionCount",params:[l,"pending"],id:(new Date).getTime()},function(r,n){if(null!=r)e(r);else{var o=n.result;e(null,t.prototype.toDecimal(o))}})};u(function(e,r){if(null!=e)return o(e);var u=Math.max(r,a.global_nonces[l]||0);c.nonce=t.prototype.toHex(u),n[l]=u+1,a.global_nonces[l]=u+1,a.transaction_signer.signTransaction(c,function(t,e){return null!=t?s(t):(i.method="eth_sendRawTransaction",i.params=[e],s())})})})}}]),r}(t.providers.HttpProvider);return e};"undefined"!=typeof module?module.exports=factory(require("web3")):window.HookedWeb3Provider=factory(Web3);