1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
require=function e(t,r,n){function i(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){var r=t[s][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t){var r=e("./web3");BigNumber.config({ROUNDING_MODE:BigNumber.ROUND_DOWN});var n=32,i=function(e,t){for(var r=!1,n=0;n<e.length&&!r;n++)r=t(e[n]);return r?n-1:-1},o=function(e,t){return i(e,function(e){return e.name===t})},s=function(e,t,r){return new Array(t-e.length+1).join(r?r:"0")+e},a=function(e){return function(t){return 0===t.indexOf(e)}},u=function(e){return function(t){return e===t}},f=function(e){return"[]"===e.slice(-2)},c=function(e){var t=2*n;return e instanceof BigNumber||"number"==typeof e?("number"==typeof e&&(e=new BigNumber(e)),e=e.round(),e.lessThan(0)&&(e=new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16).plus(e).plus(1)),e=e.toString(16)):e=0===e.indexOf("0x")?e.substr(2):"string"==typeof e?c(new BigNumber(e)):(+e).toString(16),s(e,t)},l=function(e){return r.fromAscii(e,n).substr(2)},p=function(e){return"000000000000000000000000000000000000000000000000000000000000000"+(e?"1":"0")},h=function(e){return c(new BigNumber(e).times(new BigNumber(2).pow(128)))},d=function(e,t){return f(e)||a("string")(e)?c(t.length):""},v=function(){return[{type:a("uint"),format:c},{type:a("int"),format:c},{type:a("hash"),format:c},{type:a("string"),format:l},{type:a("real"),format:h},{type:a("ureal"),format:h},{type:u("address"),format:c},{type:u("bool"),format:p}]},g=v(),m=function(e,t,r){var n="",i=o(e,t);if(-1!==i){var s=e[i];return s.inputs.forEach(function(e,t){n+=d(e.type,r[t])}),s.inputs.forEach(function(e,t){for(var i=!1,o=0;o<g.length&&!i;o++)i=g[o].type(s.inputs[t].type,r[t]);i||console.error("input parser does not support type: "+s.inputs[t].type);var a=g[o-1].format,u="";u=f(s.inputs[t].type)?r[t].reduce(function(e,t){return e+a(t)},""):a(r[t]),n+=u}),n}},b=function(e){return"1"===new BigNumber(e.substr(0,1),16).toString(2).substr(0,1)},y=function(e){return b(e)?new BigNumber(e,16).minus(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",16)).minus(1):new BigNumber(e,16)},_=function(e){return new BigNumber(e,16)},w=function(e){return y(e).dividedBy(new BigNumber(2).pow(128))},N=function(e){return _(e).dividedBy(new BigNumber(2).pow(128))},S=function(e){return"0x"+e},x=function(e){return"0000000000000000000000000000000000000000000000000000000000000001"===e?!0:!1},O=function(e){return r.toAscii(e)},P=function(e){return"0x"+e.slice(e.length-40,e.length)},B=function(e){return f(e)||a("string")(e)?2*n:0},k=function(){return[{type:a("uint"),format:_},{type:a("int"),format:y},{type:a("hash"),format:S},{type:a("string"),format:O},{type:a("real"),format:w},{type:a("ureal"),format:N},{type:u("address"),format:P},{type:u("bool"),format:x}]},A=k(),q=function(e,t,r){var i=o(e,t);if(-1!==i){r=r.slice(2);var s=[],u=e[i],c=2*n,l=u.outputs.reduce(function(e,t){return e+B(t.type)},0),p=r.slice(0,l);return r=r.slice(l),u.outputs.forEach(function(e,t){for(var n=!1,i=0;i<A.length&&!n;i++)n=A[i].type(u.outputs[t].type);n||console.error("output parser does not support type: "+u.outputs[t].type);var o=A[i-1].format;if(f(u.outputs[t].type)){var l=_(p.slice(0,c));p=p.slice(c);for(var h=[],d=0;l>d;d++)h.push(o(r.slice(0,c))),r=r.slice(c);s.push(h)}else a("string")(u.outputs[t].type)?(p=p.slice(c),s.push(o(r.slice(0,c))),r=r.slice(c)):(s.push(o(r.slice(0,c))),r=r.slice(c))}),s}},E=function(e){var t=e.indexOf("(");return-1!==t?e.substr(0,t):e},F=function(e){var t=e.indexOf("(");return-1!==t?e.substr(t+1,e.length-1-(t+1)):""},M=function(e){var t={};return e.forEach(function(r){var n=E(r.name),i=F(r.name),o=function(){var t=Array.prototype.slice.call(arguments);return m(e,r.name,t)};void 0===t[n]&&(t[n]=o),t[n][i]=o}),t},T=function(e){var t={};return e.forEach(function(r){var n=E(r.name),i=F(r.name),o=function(t){return q(e,r.name,t)};void 0===t[n]&&(t[n]=o),t[n][i]=o}),t},D=function(e,t){return r.sha3(r.fromAscii(t))};t.exports={inputParser:M,outputParser:T,methodSignature:D,methodDisplayName:E,methodTypeName:F}},{"./web3":9}],2:[function(e,t){var r=e("./web3"),n=function(e){if(!r.haveProvider()){if(this.sendQueue=[],this.onmessageQueue=[],navigator.qt)return void(this.provider=new r.providers.QtProvider);e=e||{};var t={httprpc:e.httprpc||"http://localhost:8080",websockets:e.websockets||"ws://localhost:40404/eth"},n=this,i=function(e){o.close(),e?n.provider=new r.providers.WebSocketProvider(t.websockets):(n.provider=new r.providers.HttpRpcProvider(t.httprpc),n.poll=n.provider.poll.bind(n.provider)),n.sendQueue.forEach(function(e){n.provider.send(e)}),n.onmessageQueue.forEach(function(e){n.provider.onmessage=e})},o=new WebSocket(t.websockets);o.onopen=function(){i(!0)},o.onerror=function(){i(!1)}}};n.prototype.send=function(e){return this.provider?void this.provider.send(e):void this.sendQueue.push(e)},Object.defineProperty(n.prototype,"onmessage",{set:function(e){return this.provider?void(this.provider.onmessage=e):void this.onmessageQueue.push(e)}}),t.exports=n},{"./web3":9}],3:[function(e,t){var r=e("./web3"),n=e("./abi"),i=4,o=function(e,t){var o=n.inputParser(t),s=n.outputParser(t),a={};return t.forEach(function(u){var f=n.methodDisplayName(u.name),c=n.methodTypeName(u.name),l=function(){var a=Array.prototype.slice.call(arguments),l=o[f][c].apply(null,a),p=function(e){return s[f][c](e)};return{call:function(o){return o=o||{},o.to=e,n.methodSignature(t,u.name).then(function(e){return o.data=e.slice(0,2+2*i)+l,r.eth.call(o).then(p)})},transact:function(o){return o=o||{},o.to=e,n.methodSignature(t,u.name).then(function(n){return o.data=n.slice(0,2+2*i)+l,r._currentContractAbi=t,r._currentContractAddress=e,r.eth.transact(o).then(p)})}}};void 0===a[f]&&(a[f]=l),a[f][c]=l}),a};t.exports=o},{"./abi":1,"./web3":9}],4:[function(e,t){var r=e("./web3"),n=function(e,t){this.impl=t,this.callbacks=[];var n=this;this.promise=t.newFilter(e),this.promise.then(function(e){n.id=e,r.on(t.changed,e,n.trigger.bind(n)),r.provider.startPolling({call:t.changed,args:[e]},e)})};n.prototype.arrived=function(e){this.changed(e)},n.prototype.changed=function(e){var t=this;this.promise.then(function(){t.callbacks.push(e)})},n.prototype.trigger=function(e){for(var t=0;t<this.callbacks.length;t++)this.callbacks[t].call(this,e)},n.prototype.uninstall=function(){var e=this;this.promise.then(function(t){e.impl.uninstallFilter(t),r.provider.stopPolling(t),r.off(impl.changed,t)})},n.prototype.messages=function(){var e=this;return this.promise.then(function(t){return e.impl.getMessages(t)})},n.prototype.logs=function(){return this.messages()},t.exports=n},{"./web3":9}],5:[function(e,t){function r(e){return{jsonrpc:"2.0",method:e.call,params:e.args,id:e._id}}function n(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 n=r(e),i=new XMLHttpRequest;i.open("POST",this.host,!0),i.send(JSON.stringify(n)),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(r){r.call(t,n(e.responseText))})})},i.prototype.poll=function(e,t){var r=this;this.sendRequest(e,function(n){var i=JSON.parse(n.responseText);!i.error&&(i.result instanceof Array?0!==i.result.length:i.result)&&r.handlers.forEach(function(n){n.call(r,{_event:e.call,_id:t,data:i.result})})})},Object.defineProperty(i.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=i},{}],6:[function(e,t){function r(e){return{jsonrpc:"2.0",method:e.call,params:e.args,id:e._id}}var n=function(e){this.handlers=[],this.host=e};n.prototype.send=function(e){var t=r(e),n=new XMLHttpRequest;return n.open("POST",this.host,!1),n.send(JSON.stringify(t)),n.responseText},t.exports=n},{}],7:[function(e,t){var r=(e("./web3"),function(){this.queued=[],this.polls=[],this.ready=!1,this.provider=void 0,this.id=1;var 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)};t()});r.prototype.send=function(e){return e._id=this.id,e.args=e.args||[],this.id++,void 0===this.provider&&console.error("provider is not set"),this.provider.send(e)},r.prototype.set=function(e){void 0!==this.provider&&void 0!==this.provider.unload&&this.provider.unload(),this.provider=e,this.ready=!0},r.prototype.sendQueued=function(){for(var e=0;this.queued.length;e++)this.send(this.queued[e])},r.prototype.installed=function(){return void 0!==this.provider},r.prototype.startPolling=function(e,t){this.provider&&this.provider.poll&&this.polls.push({data:e,id:t})},r.prototype.stopPolling=function(e){for(var t=this.polls.length;t--;){var r=this.polls[t];r.id===e&&this.polls.splice(t,1)}},t.exports=r},{"./web3":9}],8:[function(e,t){var r=function(){this.handlers=[];var e=this;navigator.qt.onmessage=function(t){e.handlers.forEach(function(r){r.call(e,JSON.parse(t.data))})}};r.prototype.send=function(e){navigator.qt.postMessage(JSON.stringify(e))},Object.defineProperty(r.prototype,"onmessage",{set:function(e){this.handlers.push(e)}}),t.exports=r},{}],9:[function(e,t){function r(e){if(void 0!==e._event)return void d.trigger(e._event,e._id,e.data);if(e._id){var t=d._callbacks[e._id];t&&(t.call(this,e.error,e.data),delete d._callbacks[e._id])}}var n=function(){return[{name:"sha3",call:"web3_sha3"}]},i=function(){var e=function(e){return"string"==typeof e[0]?"eth_blockByHash":"eth_blockByNumber"},t=function(e){return"string"==typeof e[0]?"eth_transactionByHash":"eth_transactionByNumber"},r=function(e){return"string"==typeof e[0]?"eth_uncleByHash":"eth_uncleByNumber"},n=[{name:"balanceAt",call:"eth_balanceAt"},{name:"stateAt",call:"eth_stateAt"},{name:"storageAt",call:"eth_storageAt"},{name:"countAt",call:"eth_countAt"},{name:"codeAt",call:"eth_codeAt"},{name:"transact",call:"eth_transact"},{name:"call",call:"eth_call"},{name:"block",call:e},{name:"transaction",call:t},{name:"uncle",call:r},{name:"compilers",call:"eth_compilers"},{name:"lll",call:"eth_lll"},{name:"solidity",call:"eth_solidity"},{name:"serpent",call:"eth_serpent"},{name:"logs",call:"eth_logs"}];return n},o=function(){return[{name:"coinbase",getter:"eth_coinbase",setter:"eth_setCoinbase"},{name:"listening",getter:"eth_listening",setter:"eth_setListening"},{name:"mining",getter:"eth_mining",setter:"eth_setMining"},{name:"gasPrice",getter:"eth_gasPrice"},{name:"account",getter:"eth_account"},{name:"accounts",getter:"eth_accounts"},{name:"peerCount",getter:"eth_peerCount"},{name:"defaultBlock",getter:"eth_defaultBlock",setter:"eth_setDefaultBlock"},{name:"number",getter:"eth_number"}]},s=function(){return[{name:"put",call:"db_put"},{name:"get",call:"db_get"},{name:"putString",call:"db_putString"},{name:"getString",call:"db_getString"}]},a=function(){return[{name:"post",call:"shh_post"},{name:"newIdentity",call:"shh_newIdentity"},{name:"haveIdentity",call:"shh_haveIdentity"},{name:"newGroup",call:"shh_newGroup"},{name:"addToGroup",call:"shh_addToGroup"}]},u=function(){var e=function(e){return"string"==typeof e[0]?"eth_newFilterString":"eth_newFilter"};return[{name:"newFilter",call:e},{name:"uninstallFilter",call:"eth_uninstallFilter"},{name:"getMessages",call:"eth_filterLogs"}]},f=function(){return[{name:"newFilter",call:"shh_newFilter"},{name:"uninstallFilter",call:"shh_uninstallFilter"},{name:"getMessage",call:"shh_getMessages"}]},c=function(e,t){t.forEach(function(t){e[t.name]=function(){var e=Array.prototype.slice.call(arguments),r="function"==typeof t.call?t.call(e):t.call,n=d.provider.send({call:r,args:e});return n=JSON.parse(n),n.result}})},l=function(e,t){t.forEach(function(t){var r={};r.get=function(){var e=d.provider.send({call:t.getter});return e=JSON.parse(e),e.result},t.setter&&(r.set=function(e){var r=d.provider.send({call:t.setter,args:[e]});return r=JSON.parse(r),r.result}),Object.defineProperty(e,t.name,r)})},p=function(e){return parseInt(e,16).toString()},h=function(e){return parseInt(e).toString(16)},d={_callbacks:{},_events:{},providers:{},toHex:function(e){for(var t="",r=0;r<e.length;r++){var n=e.charCodeAt(r).toString(16);t+=n.length<2?"0"+n:n}return t},toAscii:function(e){var t="",r=0,n=e.length;for("0x"===e.substring(0,2)&&(r=2);n>r;r+=2){var i=parseInt(e.substr(r,2),16);if(0===i)break;t+=String.fromCharCode(i)}return t},fromAscii:function(e,t){t=void 0===t?0:t;for(var r=this.toHex(e);r.length<2*t;)r+="00";return"0x"+r},toDecimal:function(e){return p(e.substring(2))},fromDecimal:function(e){return"0x"+h(e)},toEth:function(e){for(var t="string"==typeof e?0===e.indexOf("0x")?parseInt(e.substr(2),16):parseInt(e):e,r=0,n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];t>3e3&&r<n.length-1;)t/=1e3,r++;for(var i=t.toString().length<t.toFixed(2).length?t.toString():t.toFixed(2),o=function(e,t,r){return t+","+r};;){var s=i;if(i=i.replace(/(\d)(\d\d\d[\.\,])/,o),s===i)break}return i+" "+n[r]},eth:{watch:function(e){return new d.filter(e,v)}},db:{},shh:{watch:function(e){return new d.filter(e,g)}},on:function(e,t,r){return void 0===d._events[e]&&(d._events[e]={}),d._events[e][t]=r,this},off:function(e,t){return void 0!==d._events[e]&&delete d._events[e][t],this},trigger:function(e,t,r){var n=d._events[e];if(n&&n[t]){var i=n[t];i(r)}},haveProvider:function(){return!!d.provider.provider}};c(d,n()),c(d.eth,i()),l(d.eth,o()),c(d.db,s()),c(d.shh,a());var v={changed:"eth_changed"};c(v,u());var g={changed:"shh_changed"};c(g,f()),d.setProvider=function(e){e.onmessage=r,d.provider.set(e),d.provider.sendQueued()},t.exports=d},{}],10:[function(e,t){var r=function(e){this.handlers=[],this.queued=[],this.ready=!1,this.ws=new WebSocket(e);var t=this;this.ws.onmessage=function(e){for(var r=0;r<t.handlers.length;r++)t.handlers[r].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])}};r.prototype.send=function(e){if(this.ready){var t=JSON.stringify(e);this.ws.send(t)}else this.queued.push(e)},r.prototype.onMessage=function(e){this.handlers.push(e)},r.prototype.unload=function(){this.ws.close()},Object.defineProperty(r.prototype,"onmessage",{set:function(e){this.onMessage(e)}}),"undefined"!=typeof t&&(t.exports=r)},{}],web3:[function(e,t){var r=e("./lib/web3"),n=e("./lib/providermanager");r.provider=new n,r.filter=e("./lib/filter"),r.providers.WebSocketProvider=e("./lib/websocket"),r.providers.HttpRpcProvider=e("./lib/httprpc"),r.providers.QtProvider=e("./lib/qt"),r.providers.HttpSyncProvider=e("./lib/httpsync"),r.providers.AutoProvider=e("./lib/autoprovider"),r.eth.contract=e("./lib/contract"),r.abi=e("./lib/abi"),t.exports=r},{"./lib/abi":1,"./lib/autoprovider":2,"./lib/contract":3,"./lib/filter":4,"./lib/httprpc":5,"./lib/httpsync":6,"./lib/providermanager":7,"./lib/qt":8,"./lib/web3":9,"./lib/websocket":10}]},{},["web3"]); |