mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
8.3 KiB
1 lines
8.3 KiB
require=function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(o)return o(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[s]={exports:{}};t[s][0].call(u.exports,function(e){var n=t[s][1][e];return i(n?n:e)},u,u.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t){function n(e){return{jsonrpc:"2.0",method:e.call,params:e.args,id:e._id}}function r(e){var t=JSON.parse(e);return{_id:t.id,data:t.result,error:t.error}}var i=function(e){this.handlers=[],this.host=e};i.prototype.sendRequest=function(e,t){var r=n(e),i=new XMLHttpRequest;i.open("POST",this.host,!0),i.send(JSON.stringify(r)),i.onreadystatechange=function(){4===i.readyState&&t&&t(i)}},i.prototype.send=function(e){var t=this;this.sendRequest(e,function(e){t.handlers.forEach(function(n){n.call(t,r(e.responseText))})})},i.prototype.poll=function(e,t){var n=this;this.sendRequest(e,function(r){var i=JSON.parse(r.responseText);!i.error&&(i.result instanceof Array?0!==i.result.length:i.result)&&n.handlers.forEach(function(r){r.call(n,{_event:e.call,_id:t,data:i.result})})})},Object.defineProperty(i.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=i},{}],2:[function(e,t){function n(e){return e instanceof Promise?Promise.resolve(e):e instanceof Array?new Promise(function(t){var r=e.map(function(e){return n(e)});return Promise.all(r).then(function(n){for(var r=0;r<e.length;r++)e[r]=n[r];t(e)})}):e instanceof Object?new Promise(function(t){var r=Object.keys(e),i=r.map(function(t){return n(e[t])});return Promise.all(i).then(function(n){for(var i=0;i<r.length;i++)e[r[i]]=n[i];t(e)})}):Promise.resolve(e)}function r(e){if(void 0!==e._event)return void g.trigger(e._event,e._id,e.data);if(e._id){var t=g._callbacks[e._id];t&&(t.call(this,e.error,e.data),delete g._callbacks[e._id])}}var i,o,s,a,c=function(){var e=function(e){return"string"==typeof e[0]?"blockByHash":"blockByNumber"},t=function(e){return"string"==typeof e[0]?"transactionByHash":"transactionByNumber"},n=function(e){return"string"==typeof e[0]?"uncleByHash":"uncleByNumber"},r=[{name:"balanceAt",call:"balanceAt"},{name:"stateAt",call:"stateAt"},{name:"countAt",call:"countAt"},{name:"codeAt",call:"codeAt"},{name:"transact",call:"transact"},{name:"call",call:"call"},{name:"block",call:e},{name:"transaction",call:t},{name:"uncle",call:n},{name:"compile",call:"compile"}];return r},l=function(){return[{name:"coinbase",getter:"coinbase",setter:"setCoinbase"},{name:"listening",getter:"listening",setter:"setListening"},{name:"mining",getter:"mining",setter:"setMining"},{name:"gasPrice",getter:"gasPrice"},{name:"account",getter:"account"},{name:"accounts",getter:"accounts"},{name:"peerCount",getter:"peerCount"},{name:"defaultBlock",getter:"defaultBlock",setter:"setDefaultBlock"},{name:"number",getter:"number"}]},u=function(){return[{name:"put",call:"put"},{name:"get",call:"get"},{name:"putString",call:"putString"},{name:"getString",call:"getString"}]},d=function(){return[{name:"post",call:"post"},{name:"newIdentity",call:"newIdentity"},{name:"haveIdentity",call:"haveIdentity"},{name:"newGroup",call:"newGroup"},{name:"addToGroup",call:"addToGroup"}]},p=function(){var e=function(e){return"string"==typeof e[0]?"newFilterString":"newFilter"};return[{name:"newFilter",call:e},{name:"uninstallFilter",call:"uninstallFilter"},{name:"getMessages",call:"getMessages"}]},h=function(){return[{name:"newFilter",call:"shhNewFilter"},{name:"uninstallFilter",call:"shhUninstallFilter"},{name:"getMessage",call:"shhGetMessages"}]},f=function(e,t){t.forEach(function(t){e[t.name]=function(){return n(Array.prototype.slice.call(arguments)).then(function(e){var n="function"==typeof t.call?t.call(e):t.call;return{call:n,args:e}}).then(function(e){return new Promise(function(t,n){g.provider.send(e,function(e,r){return e?void n(e):void t(r)})})}).catch(function(e){console.error(e)})}})},v=function(e,t){t.forEach(function(t){var r={};r.get=function(){return new Promise(function(e,n){g.provider.send({call:t.getter},function(t,r){return t?void n(t):void e(r)})})},t.setter&&(r.set=function(e){return n([e]).then(function(e){return new Promise(function(n){g.provider.send({call:t.setter,args:e},function(e,t){return e?void reject(e):void n(t)})})}).catch(function(e){console.error(e)})}),Object.defineProperty(e,t.name,r)})},g={_callbacks:{},_events:{},providers:{},toHex:function(e){var t,n,r="";for(t=0;t<e.length;t++)n=e.charCodeAt(t).toString(16),r+=n.length<2?"0"+n:n;return r},toAscii:function(e){var t,n="",r=0,i=e.length;for("0x"===e.substring(0,2)&&(r=2);i>r&&(t=e.charCodeAt(r),0!==t);r+=2)n+=String.fromCharCode(parseInt(e.substr(r,2),16));return n},toDecimal:function(e){return parseInt(e,16)},fromAscii:function(e,t){t=void 0===t?32:t;for(var n=this.toHex(e);n.length<2*t;)n+="00";return"0x"+n},eth:{prototype:Object(),watch:function(e){return new a(e,i)}},db:{prototype:Object()},shh:{prototype:Object(),watch:function(e){return new a(e,o)}},on:function(e,t,n){return void 0===g._events[e]&&(g._events[e]={}),g._events[e][t]=n,this},off:function(e,t){return void 0!==g._events[e]&&delete g._events[e][t],this},trigger:function(e,t,n){var r,i=g._events[e];i&&i[t]&&(r=i[t])(n)}},m=g.eth;f(m,c()),v(m,l()),f(g.db,u()),f(g.shh,d()),i={changed:"changed"},f(i,p()),o={changed:"shhChanged"},f(o,h()),s=function(){var e,t;this.queued=[],this.polls=[],this.ready=!1,this.provider=void 0,this.id=1,e=this,(t=function(){e.provider&&e.provider.poll&&e.polls.forEach(function(t){t.data._id=e.id,e.id++,e.provider.poll(t.data,t.id)}),setTimeout(t,12e3)})()},s.prototype.send=function(e,t){e._id=this.id,t&&(g._callbacks[e._id]=t),e.args=e.args||[],this.id++,void 0!==this.provider?this.provider.send(e):(console.warn("provider is not set"),this.queued.push(e))},s.prototype.set=function(e){void 0!==this.provider&&void 0!==this.provider.unload&&this.provider.unload(),this.provider=e,this.ready=!0},s.prototype.sendQueued=function(){for(var e=0;this.queued.length;e++)this.send(this.queued[e])},s.prototype.installed=function(){return void 0!==this.provider},s.prototype.startPolling=function(e,t){this.provider&&this.provider.poll&&this.polls.push({data:e,id:t})},s.prototype.stopPolling=function(e){var t,n;for(t=this.polls.length;t--;)n=this.polls[t],n.id===e&&this.polls.splice(t,1)},g.provider=new s,g.setProvider=function(e){e.onmessage=r,g.provider.set(e),g.provider.sendQueued()},a=function(e,t){this.impl=t,this.callbacks=[];var n=this;this.promise=t.newFilter(e),this.promise.then(function(e){n.id=e,g.on(t.changed,e,n.trigger.bind(n)),g.provider.startPolling({call:t.changed,args:[e]},e)})},a.prototype.arrived=function(e){this.changed(e)},a.prototype.changed=function(e){var t=this;this.promise.then(function(){t.callbacks.push(e)})},a.prototype.trigger=function(e){for(var t=0;t<this.callbacks.length;t++)this.callbacks[t].call(this,e)},a.prototype.uninstall=function(){var e=this;this.promise.then(function(t){e.impl.uninstallFilter(t),g.provider.stopPolling(t),g.off(impl.changed,t)})},a.prototype.messages=function(){var e=this;return this.promise.then(function(t){return e.impl.getMessages(t)})},t.exports=g},{}],3:[function(e,t){var n=function(){this.handlers=[];var e=this;navigator.qt.onmessage=function(t){e.handlers.forEach(function(n){n.call(e,JSON.parse(t.data))})}};n.prototype.send=function(e){navigator.qt.postMessage(JSON.stringify(e))},Object.defineProperty(n.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=n},{}],4:[function(e,t){var n=function(e){this.handlers=[],this.queued=[],this.ready=!1,this.ws=new WebSocket(e);var t=this;this.ws.onmessage=function(e){for(var n=0;n<t.handlers.length;n++)t.handlers[n].call(t,JSON.parse(e.data),e)},this.ws.onopen=function(){t.ready=!0;for(var e=0;e<t.queued.length;e++)t.send(t.queued[e])}};n.prototype.send=function(e){if(this.ready){var t=JSON.stringify(e);this.ws.send(t)}else this.queued.push(e)},n.prototype.onMessage=function(e){this.handlers.push(e)},n.prototype.unload=function(){this.ws.close()},Object.defineProperty(n.prototype,"onmessage",{set:function(e){this.onMessage(e)}}),t.exports=n},{}],web3:[function(e,t){var n=e("./lib/main");n.providers.WebSocketProvider=e("./lib/websocket"),n.providers.HttpRpcProvider=e("./lib/httprpc"),n.providers.QtProvider=e("./lib/qt"),t.exports=n},{"./lib/httprpc":1,"./lib/main":2,"./lib/qt":3,"./lib/websocket":4}]},{},[]); |