plugeth/dist/ethereum.min.js
Marian Oancea 4be4db5e6c Converted to node module
Converted to npm package
Added brower
Added browserify with minification
Updated Readme
2014-11-05 19:46:01 +02:00

1 line
8.7 KiB
JavaScript

require=function t(e,n,r){function o(s,a){if(!n[s]){if(!e[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[s]={exports:{}};e[s][0].call(u.exports,function(t){var n=e[s][1][t];return o(n?n:t)},u,u.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e){function n(t){var e;return e=new r(t)}var r=(function(){return this}(),window.XMLHttpRequest);e.exports.XMLHttpRequest=r?n:null,r&&(n.prototype=r.prototype)},{}],2:[function(t,e){function n(t){return{jsonrpc:"2.0",method:t.call,params:t.args,id:t._id}}function r(t){var e=JSON.parse(t);return{_id:e.id,data:e.result}}var o=t("xmlhttprequest").XMLHttpRequest,i=function(t){this.handlers=[],this.host=t};i.prototype.sendRequest=function(t,e){var r=n(t),i=new o;i.open("POST",this.host,!0),i.send(JSON.stringify(r)),i.onreadystatechange=function(){4===i.readyState&&e&&e(i)}},i.prototype.send=function(t){var e=this;this.sendRequest(t,function(t){e.handlers.forEach(function(n){n.call(e,r(t.responseText))})})},i.prototype.poll=function(t,e){var n=this;this.sendRequest(t,function(r){var o=JSON.parse(r.responseText);(o.result instanceof Array?0!==o.result.length:o.result)&&n.handlers.forEach(function(r){r.call(n,{_event:t.call,_id:e,data:o.result})})})},Object.defineProperty(i.prototype,"onmessage",{set:function(t){this.handlers.push(t)}}),e.exports=i},{xmlhttprequest:1}],3:[function(t,e){function n(t){return t instanceof Promise?Promise.resolve(t):t instanceof Array?new Promise(function(e){var r=t.map(function(t){return n(t)});return Promise.all(r).then(function(n){for(var r=0;r<t.length;r++)t[r]=n[r];e(t)})}):t instanceof Object?new Promise(function(e){var r=Object.keys(t),o=r.map(function(e){return n(t[e])});return Promise.all(o).then(function(n){for(var o=0;o<r.length;o++)t[r[o]]=n[o];e(t)})}):Promise.resolve(t)}function r(t){if(void 0!==t._event)return void f.trigger(t._event,t._id,t.data);if(t._id){var e=f._callbacks[t._id];e&&(e.call(this,t.data),delete f._callbacks[t._id])}}var o=function(){var t=function(t){return"string"==typeof t[0]?"blockByHash":"blockByNumber"},e=function(t){return"string"==typeof t[0]?"transactionByHash":"transactionByNumber"},n=function(t){return"string"==typeof t[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:t},{name:"transaction",call:e},{name:"uncle",call:n},{name:"compile",call:"compile"}];return r},i=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"}]},s=function(){return[{name:"put",call:"put"},{name:"get",call:"get"},{name:"putString",call:"putString"},{name:"getString",call:"getString"}]},a=function(){return[{name:"post",call:"post"},{name:"newIdentity",call:"newIdentity"},{name:"haveIdentity",call:"haveIdentity"},{name:"newGroup",call:"newGroup"},{name:"addToGroup",call:"addToGroup"}]},c=function(){var t=function(t){return"string"==typeof t[0]?"newFilterString":"newFilter"};return[{name:"newFilter",call:t},{name:"uninstallFilter",call:"uninstallFilter"},{name:"getMessages",call:"getMessages"}]},l=function(){return[{name:"newFilter",call:"shhNewFilter"},{name:"uninstallFilter",call:"shhUninstallFilter"},{name:"getMessage",call:"shhGetMessages"}]},u=function(t,e){e.forEach(function(e){t[e.name]=function(){return n(Array.prototype.slice.call(arguments)).then(function(t){var n="function"==typeof e.call?e.call(t):e.call;return{call:n,args:t}}).then(function(t){return new Promise(function(e,n){f.provider.send(t,function(t){return t||"boolean"==typeof t?void e(t):void n(t)})})}).catch(function(t){console.error(t)})}})},p=function(t,e){e.forEach(function(e){var r={};r.get=function(){return new Promise(function(t){f.provider.send({call:e.getter},function(e){t(e)})})},e.setter&&(r.set=function(t){return n([t]).then(function(t){return new Promise(function(n){f.provider.send({call:e.setter,args:t},function(t){t?n(t):reject(t)})})}).catch(function(t){console.error(t)})}),Object.defineProperty(t,e.name,r)})},f={_callbacks:{},_events:{},providers:{},toHex:function(t){for(var e="",n=0;n<t.length;n++){var r=t.charCodeAt(n).toString(16);e+=r.length<2?"0"+r:r}return e},toAscii:function(t){for(var e="",n=0,r=t.length;r>n;n+=2){var o=t.charCodeAt(n);if(0===o)break;e+=String.fromCharCode(parseInt(t.substr(n,2),16))}return e},toDecimal:function(t){return parseInt(t,16)},fromAscii:function(t,e){e=void 0===e?32:e;for(var n=this.toHex(t);n.length<2*e;)n+="00";return n},eth:{prototype:Object(),watch:function(t){return new m(t,d)}},db:{prototype:Object()},shh:{prototype:Object(),watch:function(t){return new m(t,v)}},on:function(t,e,n){return void 0===f._events[t]&&(f._events[t]={}),f._events[t][e]=n,this},off:function(t,e){return void 0!==f._events[t]&&delete f._events[t][e],this},trigger:function(t,e,n){var r=f._events[t];if(r&&r[e]){var o=r[e];o(n)}}},h=f.eth;u(h,o()),p(h,i()),u(f.db,s()),u(f.shh,a());var d={changed:"changed"};u(d,c());var v={changed:"shhChanged"};u(v,l());var g=function(){this.queued=[],this.polls=[],this.ready=!1,this.provider=void 0,this.id=1;var t=this,e=function(){t.provider&&t.provider.poll&&t.polls.forEach(function(e){e.data._id=t.id,t.id++,t.provider.poll(e.data,e.id)}),setTimeout(e,12e3)};e()};g.prototype.send=function(t,e){t._id=this.id,e&&(f._callbacks[t._id]=e),t.args=t.args||[],this.id++,void 0!==this.provider?this.provider.send(t):(console.warn("provider is not set"),this.queued.push(t))},g.prototype.set=function(t){void 0!==this.provider&&void 0!==this.provider.unload&&this.provider.unload(),this.provider=t,this.ready=!0},g.prototype.sendQueued=function(){for(var t=0;this.queued.length;t++)this.send(this.queued[t])},g.prototype.installed=function(){return void 0!==this.provider},g.prototype.startPolling=function(t,e){this.provider&&this.provider.poll&&this.polls.push({data:t,id:e})},g.prototype.stopPolling=function(t){for(var e=this.polls.length;e--;){var n=this.polls[e];n.id===t&&this.polls.splice(e,1)}},f.provider=new g,f.setProvider=function(t){t.onmessage=r,f.provider.set(t),f.provider.sendQueued()};var m=function(t,e){this.impl=e,this.callbacks=[];var n=this;this.promise=e.newFilter(t),this.promise.then(function(t){n.id=t,f.on(e.changed,t,n.trigger.bind(n)),f.provider.startPolling({call:e.changed,args:[t]},t)})};m.prototype.arrived=function(t){this.changed(t)},m.prototype.changed=function(t){var e=this;this.promise.then(function(){e.callbacks.push(t)})},m.prototype.trigger=function(t){for(var e=0;e<this.callbacks.length;e++)this.callbacks[e].call(this,t)},m.prototype.uninstall=function(){var t=this;this.promise.then(function(e){t.impl.uninstallFilter(e),f.provider.stopPolling(e),f.off(impl.changed,e)})},m.prototype.messages=function(){var t=this;return this.promise.then(function(e){return t.impl.getMessages(e)})},e.exports=f},{}],4:[function(t,e){var n=function(){this.handlers=[];var t=this;navigator.qt.onmessage=function(e){t.handlers.forEach(function(n){n.call(t,JSON.parse(e.data))})}};n.prototype.send=function(t){navigator.qt.postMessage(JSON.stringify(t))},Object.defineProperty(n.prototype,"onmessage",{set:function(t){this.handlers.push(t)}}),e.exports=n},{}],5:[function(t,e){var n=t("ws"),r=function(t){this.handlers=[],this.queued=[],this.ready=!1,this.ws=new n(t);var e=this;this.ws.onmessage=function(t){for(var n=0;n<e.handlers.length;n++)e.handlers[n].call(e,JSON.parse(t.data),t)},this.ws.onopen=function(){e.ready=!0;for(var t=0;t<e.queued.length;t++)e.send(e.queued[t])}};r.prototype.send=function(t){if(this.ready){var e=JSON.stringify(t);this.ws.send(e)}else this.queued.push(t)},r.prototype.onMessage=function(t){this.handlers.push(t)},r.prototype.unload=function(){this.ws.close()},Object.defineProperty(r.prototype,"onmessage",{set:function(t){this.onMessage(t)}}),e.exports=r},{ws:6}],6:[function(t,e){function n(t,e){var n;return n=e?new o(t,e):new o(t)}var r=function(){return this}(),o=r.WebSocket||r.MozWebSocket;e.exports=o?n:null,o&&(n.prototype=o.prototype)},{}],web3:[function(t,e){var n=t("./lib/main");n.providers.WebSocketProvider=t("./lib/websocket"),n.providers.HttpRpcProvider=t("./lib/httprpc"),n.providers.QtProvider=t("./lib/qt"),e.exports=n},{"./lib/httprpc":2,"./lib/main":3,"./lib/qt":4,"./lib/websocket":5}]},{},[]);